<?php  
session_start(); 

	include("connect.php");	
	header("Access-Control-Allow-Origin: *");
	if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
		$brmid=$_SESSION['linkarisebranchid'];
		$cmpmid=$_SESSION['linkarisecmpmid'];
		
		 if(isset($_SESSION['spotmid']))
	 {
		 $spotmid = $_SESSION['spotmid'];
		if($spotmid == 'All')
		{
			$bb = "";
		}else{
			$bb = "and spotmid='$spotmid'";
		}			
	 }else
	 {
		$bb = ""; 
	 }
	 
	 if(isset($_SESSION['lowerdate']))
	 {
		 $lowerdate = $_SESSION['lowerdate'];
		 $upperdate = $_SESSION['upperdate'];
		$aa = "and Date(bookingdate) between '$lowerdate' and '$upperdate'";		
	 }else
	 {
		$aa = ""; 
	 }
		
	$eve = "select * from res_booking_master where cmpmid=$cmpmid $aa $bb";
	
	$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))
		{
			 	$bookingmid=$rt['bookingmid'];
			 	$spotmid=$rt['spotmid'];
			 	$partymid=$rt['partymid'];
			 	$startdate=date("d-m-Y",strtotime($rt['functionstartdate']));	
			 	$enddate=date("d-m-Y",strtotime($rt['functionenddate']));	
			 	$bookingdate=date("d-m-Y",strtotime($rt['bookingdate']));	
				
				$uedit="<a href='bookingedit.php?id=".$rt['bookingmid']."'data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg' >  </a>";
				//$uedit="<a href='useredit.php?id=".$rt['umid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-pencil fa-md' > </a>";
				$udelete="";
			$uview="<a href='bookingdetail.php?id=".$rt['bookingmid']."'data-toggle='tooltip' data-placement='top' title='View' class='fa fa-eye fa-lg' >  </a>";
				$udelete="<a href='bookingdelete.php?id=".$rt['bookingmid']."' onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);' data-toggle='tooltip' data-placement='top' title='Delete' class='far fa-trash-alt fa-lg'>  </a>";
				//$udelete="<a href='userdelete.php?id=".$rt['umid']."' data-toggle='tooltip' data-placement='top' title='Delete' class='fa fa-trash-o fa-md' onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);'> </a>";
				
				 $op=$uview;
				//$cdelete="<a href='customeredit.php?id=$bumid' onClick=\"return confirm('are you sure you want to delete??');\">Delete</a>";
				
				$eve1 = "select * from res_spot_master where spotmid=$spotmid";
	$re1 = mysqli_query($conn, $eve1);
	if(mysqli_num_rows($re1) > 0)
	{
		while($rt1 = mysqli_fetch_assoc($re1))
		{
			$spotname=$rt1['spotname'];
			$spotaddress=$rt1['spotaddress'];
			$cpname=$rt1['spotcpname'];
			$cpmobile=$rt1['cpmobile']	;
			
			
		}
	}
$eve11 = "select * from res_party_master where partymid=$partymid";
	$re11= mysqli_query($conn, $eve11);
	if(mysqli_num_rows($re11) > 0)
	{
		while($rt11 = mysqli_fetch_assoc($re11))
		{
			$partyname=$rt11['partyname'];
			$partymobile=$rt11['partymobile'];
	
			
		}
	}
	
	 $eve12 = "select * from res_slots_master where slotmid in (select slotmid from res_booking_detail where bookingmid=$bookingmid and spotmid=$spotmid)";
	$re12= mysqli_query($conn, $eve12);
	if(mysqli_num_rows($re12) > 0)
	{
		while($rt12 = mysqli_fetch_assoc($re12))
		{
			$slotname1=$rt12['slotname'];
			$slotstart=$rt12['slotstarttime'];
			$slotend=$rt12['slotendtime'];
			$slotname=$rt12['slotname'].'<br>('.$rt12['slotstarttime'].'-'.$rt12['slotendtime'].')';
			
		}
	}
	
				$posts[] = array('spotmid'=> $i, 'uedit'=> $uedit, 'udelete'=> $udelete,'spotname'=> $spotname, 'spotaddress'=> $spotaddress,'cpname'=> $cpname,'cpmobile'=> $cpmobile,'op'=> $op,'startdate'=>$startdate,'enddate'=>$enddate,'bookingdate'=>$bookingdate,'partyname'=>$partyname,'partymobile'=>$partymobile,'slot'=>$slotname);
	
			
			$i++;
			
		}
		 
		$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);	
?>