<?php
	//Connects to your Database
	include "../db_connection/db_connection.php";
	include "../config/config.php";		
	$page_id	=	base64_decode(base64_decode(base64_decode($_GET['page_id']))); //THIS IS PAGE ID  
	$ids		=	base64_decode(base64_decode(base64_decode($_GET['ids'])));
	$po_del_id	=	base64_decode(base64_decode(base64_decode($_GET['po_del_id'])));
	$po_id		=	base64_decode(base64_decode(base64_decode($_GET['po_id'])));                  
	
	//echo $po_id;
	//po_no,co_cod,pod,remak
if($page_id==1) //this is for basic details add page	
{ 		
		$SLCT_po = "SELECT * FROM po_entry WHERE po_entry_id='$po_id'";
		//echo $SLCT_po;
		$QURY_po = mysqli_query($connect,$SLCT_po);
		$FTCH_po = mysqli_fetch_object($QURY_po);		
		
		$SLCT_tp = "SELECT * FROM party_det WHERE party_det_id = '$FTCH_po->party_det_id'";
		//echo $SLCT_tp;
		$QURY_tp = mysqli_query($connect,$SLCT_tp);
		$FTCH_tp = mysqli_fetch_object($QURY_tp);
		
		$cli_emailid = $FTCH_tp->email_id_1;
		$com_name  	 = $FTCH_tp->cmp_name;	
		$mobile_no=$FTCH_tp->con_no_1;
		
		$tpe	= $_POST['tpe'][$ids];
		$date_dl = $_POST['date_dl'][$ids];
		
		if($tpe==2)
		{		
			$cour_id = $_POST['cour'][$ids];
			$track_id = $_POST['track_id'][$ids];
					
			$INSRT		= "INSERT INTO po_del_cour_det(`po_delivery_id`, `mas_cour_det_id`, `track_id`,`del_date`, `post_dt`) VALUES('$po_del_id','$cour_id','$track_id','$date_dl','$cur_time')";		
			//echo $INSRT;
			$QURY		= mysqli_query($connect,$INSRT);
			
			$SLCT_m = "SELECT * FROM mas_cour_det WHERE mas_cour_det_id = '$cour_id'";
			$QURY_m = mysqli_query($connect,$SLCT_m);
			$FTCH_m = mysqli_fetch_object($QURY_m);		
			
			$cour_name = $FTCH_m->cour_name;
			$cour_url  = $FTCH_m->cour_url;
			$emp_name = '';
			
			if($mobile_no!='')
			{
				$to = $mobile_no;
				//$sms = "Your Order has shipped, Tracking details of the shipment.".$cour_name." Courier and Track no:".$track_id.". Further contact-9894347273.Thahaayaa Sales Team";
				//$sms = "Your Order has shipped successfully, Tracking details of the shipment.BlueDart Courier&Track no:".$track_id.". Further contact-9894347273.Thahaayaa Sales Team";
				//$sms_url = sprintf("http://alerts.kapsystem.com/api/web2sms.php?workingkey=%s&to=%s&sender=%s&message=%s", $workingkey, $to , $sender, urlencode($sms) );
				//echo $sms_url;
				$sms = "Your Order has shipped, Tracking details of the shipment. ".$cour_name." Courier and Track no:".$track_id.". Further contact-9894347273.Thahaayaa Sales Team";
				$sms_url   	= 	sprintf($sms_domain, $workingkey, $to , $senderid, urlencode($sms));				
				openurl($sms_url);
			}
		}
		else if($tpe==1)
		{
			$hnd = $_POST['hnd'][$ids];
			
					
			$INSRT		= "INSERT INTO po_del_cour_det(`po_delivery_id`, `emp_det_id`,`del_date`, `post_dt`) VALUES('$po_del_id','$hnd','$date_dl','$cur_time')";		
			//echo $INSRT;
			$QURY		= mysqli_query($connect,$INSRT);
			
			$SLCT_m = "SELECT * FROM emp_det WHERE emp_det_id = '$hnd'";
			$QURY_m = mysqli_query($connect,$SLCT_m);
			$FTCH_m = mysqli_fetch_object($QURY_m);		
			
			$emp_name = $FTCH_m->name;
			$cour_name = '';
			$cour_url  = '';
			$track_id = '';
			
			if($mobile_no!='')
			{
				$to = $mobile_no;
				//$sms   = "Your Order is ready for the shipment, You will receive the goods in 1 working day. Further contact-9894347273.Thahaayaa Sales Team.";
				//$sms = "Your Order has shipped, Tracking details of the shipment.".$cour_name." Courier and Track no:".$track_id.". Further contact-9894347273.Thahaayaa Sales Team";
				//$sms = "Your Order has shipped successfully, Tracking details of the shipment.BlueDart Courier&Track no:".$track_id.". Further contact-9894347273.Thahaayaa Sales Team";
				//$sms_url = sprintf("http://alerts.kapsystem.com/api/web2sms.php?workingkey=%s&to=%s&sender=%s&message=%s", $workingkey, $to , $sender, urlencode($sms) );
				//echo $sms_url;
				$sms   = "Your Order is ready for the shipment, You will receive the goods in 1 working day. Further contact-9894347273.Thahaayaa Sales Team.";
				$sms_url   	= 	sprintf($sms_domain, $workingkey, $to, $senderid, urlencode($sms));
				openurl($sms_url);
			}
			
		}
		if($tpe==1){ $tpee = 'Hand Delivery'; }else if($tpe==2){ $tpee = 'Courier Delivery'; }
				
		/*$email_ida="sales@thahaayaa.com";
		$subject ="Reg:Po Delivery Details"; */
		
				
		include "../mail/po_delivery_mail.php";
		//echo $mail_body;
			
		//if(mail($cli_emailid, $subject,$mail_body, "From:" . $email_ida ));
		
		$tto=$cli_emailid;
		$subject="Reg:Po Delivery Details";
		
		$headers = "MIME-Version: 1.0" . "\r\n";
		$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
		
		// More headers
		$headers .= 'From: Thahaayaa Sales Team <sales@thahaayaa.com>' . "\r\n";				
		$headers .= 'Bcc:'.$cc_id. "\r\n";	
		mail("$tto",$subject,$mail_body,$headers);
		
		
		
?>
		<script type="text/javascript">
            //alert("Data inserted successfully");
            //history.back();
            window.location='../po_delivery_list.php';
        </script>
<?php
}
?>