<?php
$sender = $_GET['from'];
$res = substr($_GET['message'],10);
$message = trim($res," ");
date_default_timezone_set('Asia/Kolkata');
$datetime = date('Y-m-d H:i:s');
$shortcode ="56161";

$db_hostname = "localhost";
$db_username = "tapal_police";
$db_password = "police@123";
$db_database = "tapal_police";
// 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("SELECT * FROM incoming_letters_transaction WHERE padtalni_no='$message'");
	$c1 = mysql_num_rows($q1);
	if($c1>=1)
	{
		$r1 = mysql_fetch_array($q1);
		$ltr_id   = $r1['ltr_id'];
		$ltr_iwno = $r1['ltr_inword_no'];
		$dept_id  = $r1['dept_id'];
		$status   = $r1['status'];
		
		if($dept_id==0 and $status=="pending")
		{
			$reply = "Vibhag Lavlela Nahi.";
		}
		else if($dept_id!=0 and $status=="pending")
		{
			$reply = "Vibhags Pathavanyat aale.";
		}
		else if($dept_id!=0 and $status=="approve")
		{
			$q3 = mysql_query("SELECT * FROM department_master WHERE dept_id='$dept_id'");
			$r3 = mysql_fetch_array($q3);
			$desk_flag = $r3['desk_flag'];
			
			if($desk_flag=="N")
			{
				$q2 = mysql_query("SELECT * FROM tapal_to_dpt_transaction WHERE ltr_id='$ltr_id'");
				$c2 = mysql_num_rows($q2);
				if($c2>=1)
				{
					$r2 = mysql_fetch_array($q2);
					$ltr_status = $r2['ltr_status'];
					if($ltr_status=="")
					{
						$reply = "karyvahi karne baki aahe.";
					}
					else if($ltr_status=="updated")
					{
						$reply = "patra Adyawat kele.";
					}
					else if($ltr_status=="dispatched")
					{
						$reply = "patra pathavinyat aale.";
					}
					
				}
				else
				{
					$reply = "Vibhagane Swikarle.";
				}
				
			}
			else if($desk_flag=="Y")
			{
				$q2 = mysql_query("SELECT * FROM tapal_to_dpt_transaction WHERE ltr_id='$ltr_id'");
				$c2 = mysql_num_rows($q2);
				if($c2>=1)
				{
					$r2 = mysql_fetch_array($q2);
					$dpt_ltr_id = $r2['dpt_ltr_id'];
					
					$q4 = mysql_query("SELECT * FROM desk_transaction WHERE dpt_ltr_id='$dpt_ltr_id'");
					$c4 = mysql_num_rows($q4);
					if($c4>=1)
					{
						$r4 = mysql_fetch_array($q4);
						$ltr_status = $r4['ltr_status'];
						if($ltr_status=="")
						{
							$reply = "Deskne Swikarle pan karyvahi karne baki aahe.";
						}
						else if($ltr_status=="updated")
						{
							$reply = "patra Adyawat kele.";
						}
						else if($ltr_status=="dispatched")
						{
							$reply = "patra pathavinyat aale.";
						}
					}
					else
					{
						$reply = "Deskla Pathavale.";
					}
					
				}
				else
				{
					$reply = "Vibhagane Swikarle.";
				}
			}
		}
	}
	else
	{
		$reply = "Padtalni No is not Valid";
	}
	
	
	echo $reply_sms."Padtalni No: ".$message." of Letter whose status is: ".$reply.", Thank You for Contacting Rahuri Panchayat Samity.";
?>

<?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);
}
?>