<?php  
session_start(); 

if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}
	include("connect.php");	header("Access-Control-Allow-Origin: *");
	
	 
	  $eve = "select * from res_logisticin_master,res_contact_master where res_contact_master.clinkid = res_logisticin_master.linmid and res_contact_master.clinktype = 'Logistic Sender'";
	$re = mysqli_query($conn, $eve);
	
	
	$response = array();
	$posts = array();
	
	$result="0";
	
	if(mysqli_num_rows($re) > 0)
	{
		$i=1;
		 while($rt = mysqli_fetch_assoc($re))
		 {
				$linmid=$rt['linmid'];
				$imid=$rt['imid'];
				
				$eve1 = "select * from res_inquiry_master where imid=$imid";

					$re1 = mysqli_query($conn, $eve1);
					
					while($rt1 = mysqli_fetch_assoc($re1))

					{											
						
						
						$ipname=$rt1['ipname'];
						$ipmiddlename=$rt1['ipmiddlename'];
						$ipsurname=$rt1['ipsurname'];
						
						$name = $ipname." ".$ipmiddlename." ".$ipsurname;
						 
					}
					$logisticmid=$rt['logisticmid'];
				
				$eve1 = "select * from res_logistics_master where logisticmid=$logisticmid";

					$re1 = mysqli_query($conn, $eve1);
					
					while($rt1 = mysqli_fetch_assoc($re1))

					{											
						
						
						$logisticname=$rt1['logisticname'];
						
						 
					}
				$lindate=date("d-m-Y",strtotime($rt['lindate']));
				
			
				$pidedit='';
				$currentfile1 = basename($_SERVER['PHP_SELF']);
				 $currentfile = ltrim($currentfile1, 'json');
											$eve23 = "select * from res_moduleallocation_detail where smodulemid in (select smodulemid from res_submodule_master where smfilename='$currentfile') and maedit=1 and  rolemid = ".$_SESSION['userrolemid'];
											$re23 = mysqli_query($conn, $eve23);
	
				if(mysqli_num_rows($re23)>0 || $_SESSION['utype'] == 'admin')
					{
				$pidedit="<a href='campusedit.php?id=".$rt['linmid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg'>  </a>";
				
				}
				
				$piddelete='';
				$eve23 = "select * from res_moduleallocation_detail where smodulemid in (select smodulemid from res_submodule_master where smfilename='$currentfile') and madelete=1 and  rolemid = ".$_SESSION['userrolemid'];
											$re23 = mysqli_query($conn, $eve23);
	
				if(mysqli_num_rows($re23)>0 || $_SESSION['utype'] == 'admin')
					{
				$piddelete="<a href='campusdelete.php?id=".$rt['linmid']."' onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);' data-toggle='tooltip' data-placement='top' title='Delete' class='fa fa-trash-o fa-lg'> </a>";	
					}				
$op=$pidedit."&nbsp;&nbsp;&nbsp; ".$piddelete;
								
								
				
				
				 $cmiddlename=str_replace ("'","'",$rt['cmiddlename']);
				$cmiddlename=str_replace ('"','\"',$cmiddlename);
				 $lrecevirername=str_replace ("'","'",$rt['lrecevirername']);
				$lrecevirername=str_replace ('"','\"',$lrecevirername);
				
				$contactname=str_replace ("'","'",$rt['contactname']);
				$contactname=str_replace ('"','\"',$contactname);
				$csurname=str_replace ("'","'",$rt['csurname']);
				$csurname=str_replace ('"','\"',$csurname);
				
				$lsendername = $contactname." ".$cmiddlename." ".$csurname;
				
				
		
				
				
								
				$posts[] = array('srno'=> $i++,'op'=> $op, 'imid'=> $name, 'lindate'=> $lindate, 'lsendername'=> $lsendername, 'lrecevirername'=> $lrecevirername, 'logisticname'=> $logisticname);
		 }
		 
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('data' => $posts)));
		mysqli_close($conn);
		return;
	}
	
   else
   {
		$result="0";
		$msg="Invalid Error";
		
		$posts[] = array('p1'=> $result,'p2'=> $msg);
	
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('item' => $posts)));
   }
   
	mysqli_close($conn);
	
	
?>