<?php
$sender = $_GET['from'];
$message = $_GET['message'];
$datetime = date('Y-m-d H:i:s');
$shortcode ="56161";
$replay_message = "Thank You for Contacting Rahuri Panchayat Samity We Will Fulfill Your Required information 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_sms(sender,message,datetime) VALUES ('$sender','$message','$datetime')");
if($q1)
{
	echo $reply_sms."Thank you for Contacting your requested yojna details send shortly.     Regards :- Rahuri Panchayat Samiti ,Dist:- Ahmednagar";
	
	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 shortco WHERE shortid='$message'");
	$row=mysql_fetch_array($q2);
	// $short=$rowp['shortid']
	$yname=$row['yname'];
	$ydes=$row['ydes'];
	$ph=$sender;
	
	$msg  = $message.", योजनाचे नाव -".$yname.", थोडक्यात योजनेची माहिती :".$ydes .". Regards :- राहुरी पंचायत समिति,अहमदनगर  ";
	$message1 = str_replace(" ","+",$msg);

	$sms_api_result = sendSMS($ph,$message1);
	
	if ($sms_api_result[0] == 'OK') 
	{
		//echo "<br>".$ph;	
	}
	else 
	{
		//echo "<br>".$ph;	
		//print_r($sms_api_result);
	}
	
	/*if($message=='RAHURI IAY 1')
	{
		echo "50 Percent Fees for Girl";
	}
	else if ($message=='RAHURI IAY')
	{
		echo "12000 Funding for Toilet";
	}
	else 
	{
		echo "wrong code send please check";
	}*/
}
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);
}
?>