<?php
$sender = $_GET['from'];
$message = $_GET['message'];
date_default_timezone_set('Asia/Kolkata');
$datetime = date('Y-m-d H:i:s');
$shortcode ="56161";
$replay_message = "Thank You for Contacting. Your Area Officer will contact you Shortly.";


$db_hostname = "localhost";
$db_username = "tapal_admin";
$db_password = "tapal@123";
$db_database = "tapal_management";
// Connect to server.
$db_server = mysql_connect($db_hostname, $db_username, $db_password)
    or die("Unable to connect to MySQL: " . mysql_error());
	
// Select the database.
mysql_select_db($db_database)
or die("Unable to select database: " . mysql_error());

$q1 = mysql_query("INSERT INTO incoming_sms1(sender,message,datetime) VALUES ('$sender','$message','$datetime')");
if($q1)
{
	$cno = mysql_insert_id();
	
	echo $reply_sms."Thank You for Contacting Rahuri Panchayat Samity We Will Fulfill Your Required information shortly";
	
	
	mysql_query('SET character_set_results=utf8');
	mysql_query('SET names=utf8');
	mysql_query('SET character_set_client=utf8');
	mysql_query('SET character_set_connection=utf8');
	mysql_query('SET character_set_results=utf8');
	mysql_query('SET collation_connection=utf8_general_ci');
	
	
	
	$q2 = mysql_query("SELECT * FROM m_adhikari WHERE id = '1' ");
	$row=mysql_fetch_array($q2);
	$yname=$row['name'];
	$yph=$row['ph1'];
	
	$msg  = "वांबोरी अधिकारी आपल्याकडे पुढील प्रमाणे तक्रार आली आहे- ".$message.". तक्रार केस नं-".$cno.".  तक्रारदाराचा मोबा. क्रं- ".$sender." संबधितास लवकरात लवकर संपर्क करून तक्रारीचे निवारण करावे.";
	$message1 = str_replace(" ","+",$msg);

	$sms_api_result = sendSMS($yph,$message1);
	
	if ($sms_api_result[0] == 'OK') 
	{
		//echo "<br>".$ph;
		echo $reply_sms;		
	}
	else 
	{
		//echo "<br>".$ph;	
		//print_r($sms_api_result);
	}
}
else
{
	echo "false";
}

?>

<?php  
function sendSMS($ph,$message1) 
{
	//$ph = "8600257157";
	$ch = curl_init();
	//curl_setopt($ch, CURLOPT_URL, "http://104.155.195.12/API/WebSMS/Http/v1.0a/index.php?username=opolice&password=opolice&sender=OSMBAD&to=$ph&message=$message1&msgtype=unicode");
	curl_setopt($ch,CURLOPT_URL,"http://upolice.cwsdomians.in/submitsms.jsp?user=opolice&key=f582b39eecXX&mobile=$ph&message=$message1&senderid=OSMBAD&accusage=1&unicode=1");	
	// http://alotsolutions.in/API/WebSMS/Http/v1.0a/index.php?username=apolice&password=Apolice@123&sender=CWSFOT&to=$ph&message=$message1&msgtype=unicode

	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$response = curl_exec($ch);
	curl_close($ch);
	return split(',',$response);
}
?>