<?php
session_start();

require_once("connection/db.php");		
$username = $_SESSION['User_Name'];
		################################ Code To Assign reference Type As New Or Current ##############################
					require_once('convert_marathi.php');
					
					convert_marathi();
					$qry1 =("SELECT * FROM desk_transaction, incoming_letters_transaction, tapal_to_dpt_transaction WHERE (desk_transaction.ltr_approval='Approve') AND (desk_transaction.ltr_category='')
					AND (desk_transaction.ltr_status!='closed')
					AND (desk_transaction.dpt_ltr_id=tapal_to_dpt_transaction.dpt_ltr_id) AND (tapal_to_dpt_transaction.ltr_id=incoming_letters_transaction.ltr_id) AND desk_transaction.desk_id_from=(SELECT desk_id FROM login WHERE login_id='$username') order by incoming_letters_transaction.ltr_inword_no DESC");	
					$rs1=mysql_query($qry1);
					
					while($row1=mysql_fetch_array($rs1))
					{	
						$no=$row1['desk_ltr_id'];
						
						$receive_dt=strtotime($row1['receive_dt']);
						$priority_days=$row1['priority_days'];
						$ltr_type=$row1['ltr_type'];
						
						$ltr_qry=mysql_query("SELECT sandharbh_nm from  sandharbh_master where sandhrbh_id='$ltr_type' ");
						$rss=mysql_fetch_array($ltr_qry);
						
						$sandarbh_nm=$rss['sandharbh_nm'];
						$final_dt =  strtotime("+".$priority_days." days",$receive_dt);
						$final_dt =  date('Y-m-d',$final_dt);
						
						if(isset($_POST['category' . $row1['desk_ltr_id']])) 
						{	
							$ltrcate = $_POST['category' . $row1['desk_ltr_id']];
							$assign_no=$_POST['assign_no'. $row1['desk_ltr_id']];
							
							$send_to=$_POST['nm'. $row1['desk_ltr_id']];
							$mobno=$_POST['mob'. $row1['desk_ltr_id']];
							
							
							
							if($ltrcate=='current')
							{
								if($assign_no!='')
								{
									convert_marathi();
									$qry13=("UPDATE desk_transaction set ltr_category='$ltrcate', assign_no='$assign_no', send_to='$send_to', mobno='$mobno' WHERE desk_ltr_id='$no'");
									$result=mysql_query($qry13) or die("dfdf".mysql_error());
									
									
								}
								else
								{
									//echo "<script type='text/javascript'>alert('कृपया संदर्भ क्रमांक निवडा !')</script>";
									//echo '<script language="JavaScript"> window.location.href ="performaction.php" </script>';
								}
								
							}
							else  if($ltrcate=='new')
						   {
							   convert_marathi();
								$qry13=("UPDATE desk_transaction set ltr_category='$ltrcate', send_to='$send_to', mobno='$mobno' WHERE desk_ltr_id='$no'");
								$result=mysql_query($qry13) or die("dfdf".mysql_error());
								
								/*$sms_api_result = sendSMS($mobno,$no,$sandarbh_nm,$final_dt);
	
									//echo $mob1.",".$ename.",".$yid.",".$kholi_no.",".$place;
									echo $sms_api_result[0]."----";
									echo "<script type='text/javascript'>alert('".$sms_api_result[0]."')</script>";
									if ($sms_api_result[0] == 'Message+Sent+Successfully ') 
									{
										//echo "Sent Successful !";
										echo "300";
									}
									else 
									{
										//print_r($sms_api_result);
										echo "200";
									}*/
						   }
						   
						   /*
						   if($result)
							{ 
								echo "<script type='text/javascript'>alert('Updated Successfully!')</script>";
								echo '<script language="JavaScript"> window.location.href ="performaction.php" </script>';
							}
							else
							{   
								echo "<script type='text/javascript'>alert('Problem to Update!')</script>";
								echo '<script language="JavaScript"> window.location.href ="performaction.php" </script>';
							}
							*/
						}
					}
					
					
					?>
					
					
					
					
					
					<?php
function sendSMS($mobno,$no,$sandarbh_nm,$final_dt) 
{
	$ch = curl_init();

	$mobno="9657437444";
	
	$msg = "http://104.155.195.12/API/WebSMS/Http/v1.0a/index.php?username=opolice&password=opolice&sender=OSMBAD&to=$mobno&message=डेस्क आयडी : ".$no." , संदर्भ प्रकार : ".$sandarbh_nm." , कार्यवाहीची अंतिम दिनांक : ".$final_dt." &msgtype=unicode";	
	
	$msg = str_replace(" ","+",$msg);
	
	//curl_setopt($ch, CURLOPT_URL, $request);
	curl_setopt($ch, CURLOPT_URL,$msg);
	
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$response = curl_exec($ch);
	curl_close($ch);
	return split(',',$response);
}
?>