<?php
// include db connect class
	require_once __DIR__ . '/../DBConnect.php';
	if (isset($_POST['ClientID']) && isset($_POST['SessionDate'])) {
    $ClientID = $_POST['ClientID'];
  
    $SessionDate = $_POST['SessionDate'];

  $sql = "SELECT * FROM Vehicle2Name WHERE ClientID = $ClientID AND  UpdatedDate > '$SessionDate'";

$stmt = $conn->prepare($sql);
			$stmt->execute();
			$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
			
			
			if($result!=null &&  $result>0){
					  $response["Vehicle2Name"] = array();
			 foreach($result as $row) { 
		    
		$Vehicle2Name["ID"] = $row["ID"];          
		$Vehicle2Name["VehicleID"] = $row["VehicleID"];
  		$Vehicle2Name["VehicleGroupID"] = $row["VehicleGroupID"];
		$Vehicle2Name["VehicleName"] = $row["VehicleName"];
  		$Vehicle2Name["Brand"] = $row["Brand"];
		$Vehicle2Name["Model"] = $row["Model"];
  		$Vehicle2Name["Colour"] = $row["Colour"];
		$Vehicle2Name["RegistrationNo"]= $row["RegistrationNo"];
  		$Vehicle2Name["Account3ID"] = $row["Account3ID"];
		$Vehicle2Name["Status"] = $row["Status"];
  		$Vehicle2Name["Lng"] = $row["Lng"];
		$Vehicle2Name["Lat"] = $row["Lat"];
  		$Vehicle2Name["ContactNo"] = $row["ContactNo"];
		$Vehicle2Name["SerialNo"] = $row["SerialNo"];
  		$Vehicle2Name["UpdatedDate"] = $row["UpdatedDate"];
  		$Vehicle2Name["ClientID"] = $row["ClientID"];
  		$Vehicle2Name["ClientUserID"] = $row["ClientUserID"];
  		$Vehicle2Name["NetCode"] = $row["NetCode"];
  		$Vehicle2Name["SysCode"] = $row["SysCode"];
		

          // push single product into final response array
          array_push($response["Vehicle2Name"], $Vehicle2Name);
      }
      // success
      $response["success"] = 1;
      // echoing JSON response
      echo json_encode($response);
    }else {
      // success
      $response["success"] = 0;
      $response["message"] = "No Data Availaible";
      // echoing JSON response
      echo json_encode($response);
    }
  }else if (isset($_POST['ClientID']) && isset($_POST['MaxID'])) {
      $ClientID = $_POST['ClientID'];
      $MaxID = $_POST['MaxID'];
      
		$sql = "SELECT * FROM Vehicle2Name WHERE ClientID = $ClientID  AND VehicleID > $MaxID";

	$params = array();
			$stmt = $conn->prepare($sql);
			$stmt->execute();
			$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
			
			
			
			if($result!=null &&  $result>0){
			  $response["Vehicle2Name"] = array();
			 foreach($result as $row) { 
		 
		$Vehicle2Name["ID"] = $row["ID"];          
		$Vehicle2Name["VehicleID"] = $row["VehicleID"];
  		$Vehicle2Name["VehicleGroupID"] = $row["VehicleGroupID"];
		$Vehicle2Name["VehicleName"] = $row["VehicleName"];
  		$Vehicle2Name["Brand"] = $row["Brand"];
		$Vehicle2Name["Model"] = $row["Model"];
  		$Vehicle2Name["Colour"] = $row["Colour"];
		$Vehicle2Name["RegistrationNo"]= $row["RegistrationNo"];
  		$Vehicle2Name["Account3ID"] = $row["Account3ID"];
		$Vehicle2Name["Status"] = $row["Status"];
  		$Vehicle2Name["Lng"] = $row["Lng"];
		$Vehicle2Name["Lat"] = $row["Lat"];
  		$Vehicle2Name["ContactNo"] = $row["ContactNo"];
		$Vehicle2Name["SerialNo"] = $row["SerialNo"];
  		$Vehicle2Name["UpdatedDate"] = $row["UpdatedDate"];
  		$Vehicle2Name["ClientID"] = $row["ClientID"];
  		$Vehicle2Name["ClientUserID"] = $row["ClientUserID"];
  		$Vehicle2Name["NetCode"] = $row["NetCode"];
  		$Vehicle2Name["SysCode"] = $row["SysCode"];
		
          // push single product into final response array
          array_push($response["Vehicle2Name"], $Vehicle2Name);
        }
	
        // success
         $response["success"] = 1;
      
        // echoing JSON response
        echo json_encode($response);
      }else {
        // success
        $response["success"] = 0;
        $response["message"] = "No Data Availaible";
        // echoing JSON response
    		echo json_encode($response);
      }
	}else {
        // success
        $response["success"] = 0;
        $response["message"] = "No Data Availaible";
        // echoing JSON response
    		echo json_encode($response);
  }

?>
