<?php


/*
 
 * WARNING! WARNING!
 
 * This script required firmware version 2.2.9 or greater!
 
 * If You want to send non english text in sms, You MAST use
 
 * UTF-8 encoding!!
 
 * Created by KTS 2016
 
 * Corrected by Ivanov Ivan 27.12.2016
 
 */



/* Example */

$url = '192.168.101.250';				/* URL of the KTS GSM gate or IP address */

$username = 'user';					/* username for KTS gate web access */

$passwd = 'Cds#disP';					/* password for KTS gate web access */

$from = 'd.gorbunov@vodocanal.org';			/* Email address for SMS delivery report */

$phone = '+79622229813';				/* Phone for SMS destination */
$text = 'Test_script - dlinnoe_SMS:';			/* SMS text. MUST BE IN UTF-8 encoding! */



/*
 
 * SMS sendding function.
 *
 
 * Parametrs:
 
 * $url - URL or IP address of KTS GSM gate.
 
 * $username - username for KTS gate web access.
 
 * $password - password for KTS gate web access.
 
 * $from - Email address for SMS delivery report.
 
 * $phone - SMS destination phone number.
 
 * $text - SMS message text. MUST BE IN UTF-8 ENCODING!!!!!!!!!!
 
 *
 
 * Optional parametrs: 
 
 * $is_flush - true: SMS immediately displayed on phone) defaulr: false.
 
 * $channel - Channel number for SMS delivery. default: -1, first available ch#.
 
 * $kts16 - true, if You use KTS8 or KTS16 GSM Gate. Default: true.
 
 *
 
 * Return value:
 
 *  OK - SMS accepted for delivery by KTS GSM gate.
 
 *  FAILED - if something wrong
 
 */


function SendSMS($url, $username, $password, $from, $phone, $text, $channel=-1, $is_flush=false)

{
	
	$cu = curl_init($url . '/sendsms');

	

	if (empty($username) || empty($password) || empty($from) || empty($phone) || empty($text)) 
	{
		
		return 'FAILED';
	
	}

	
	
	$encoded =
		
		'email=' . urlencode($from) .
		
		'&ch=' . intval($channel) .
		
		'&is_flush=' . intval($is_flush) .
		
		'&phone=' . urlencode($phone) .
		
		'&text=' . urlencode($text);

	
	
	curl_setopt($cu, CURLOPT_HEADER, 0);
	
	curl_setopt($cu, CURLOPT_POSTFIELDS,  $encoded);
	
	curl_setopt($cu, CURLOPT_POST, 1);
	
	curl_setopt($cu, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
	
	curl_setopt($cu, CURLOPT_USERPWD, $username . ':'. $password);
	
	curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1);
	
	$output = curl_exec($cu);
		
	curl_close($cu);
	
	return $output;

}



/*
 
 * Example:
 
 * */

echo SendSMS($url, $username, $passwd, $from, $phone, $text, 1, false);

exit;

?>