<?php

/* $Id: SelectCustomer.php 7133 2015-02-07 03:23:51Z daintree $*/

//include('includes/session.inc');
//$Title = _('HRMS');
//include('includes/header.inc');
//include('includes/SQL_CommonFunctions.inc');
//echo '<link href="' . $RootPath . '/css/evergreen2'.'/default.css" rel="stylesheet" type="text/css" media="screen"/>';

      

//check.php  

$connect = mysqli_connect("localhost", "sooggoo", "4Compassion*", "evergreenint"); 
if(isset($_POST["start_time"]))
	

{
	
	
	

 $starttime =  $_POST["start_time"];
	 $endtime =  $_POST["end_time"];
 $rosterid =  $_POST["rosterid"];
	 $employeeid =  $_POST["employeeid"];
	$calendarid =$_POST['calendarid'];
	
	//quickly get calendar ID since calendar ID is only available for already in rostering timehsheet records. What if new person is added to the timesheet. Therefore its better to get this using rosterid.
	$query = "SELECT id FROM timesheetsuva  WHERE  timesuvaid ='".$rosterid."' ";
	$result = mysqli_query($connect, $query);
	$myrow = mysqli_fetch_assoc($result);
	$calendar_id = $myrow['id'];

	
	$timestampin = strtotime( $starttime) ;
	  $timestampout= strtotime( $endtime);
	//get mon shift 1 range
	$query1 = "SELECT timesuvaid FROM timesheetsuvadetails  WHERE  calendar_id = '".$calendar_id."' AND employeeid ='".$employeeid."'AND ((montime_in >=  '".$starttime."'  and montime_out <= '". $endtime."') OR (montime_in <=  '".$endtime."'  and montime_out >= '". $endtime."')OR (montime_in <=  '".$starttime."'  and montime_out >= '". $starttime."'))   ";
	$result1 = mysqli_query($connect, $query1);
	
   $row = mysqli_fetch_assoc($result1);
	  
	  $roster= $row['timesuvaid'];
	if (mysqli_num_rows($result1)){
		
		
		$query2 = "SELECT timesheetsuva.patrol_location FROM timesheetsuva 
		
		WHERE  timsuvaid = '".$roster."'  ";
	$result2 = mysqli_query($connect, $query2);
		$row1 = mysqli_fetch_assoc($result2);
		$clientid = $row1['patrol_location'];
		
		$query3= "SELECT debtorsmaster.name, guardforceclient.patrollocation from guardforceclient 
		INNER JOIN debtorsmaster on guardforceclient.debtorno = debtorsmaster.debtorno 
		WHERE  clientid = '".$clientid."'  ";
		
	$result3 = mysqli_query($connect, $query3);
		$row3 = mysqli_fetch_assoc($result3);
		$locationname = $row3['patrollocation'];
		$debtorsname = $row3['name'];
	
		
		$data = array($roster,$locationname,$debtorsname);
		
		echo json_encode($data);
		
	  //echo "Already rostered at rosterno-:".$roster." Location-".$locationname."Client Name:".$debtorsname;
  
	
	}
	else{
		echo "0";
	}
}

mysqli_close($connect);

?>

