<?php
// array for JSON response
$response = array();

//check for required fields
if ( isset($_POST['VehicleID']) && isset($_POST['VehicleGroupID']) 
	&& isset($_POST['VehicleName']) && isset($_POST['Brand'])
	&& isset($_POST['Model']) && isset($_POST['Colour']) 
	&& isset($_POST['RegistrationNo']) && isset($_POST['Account3ID']) 
	&& isset($_POST['Status']) && isset($_POST['Lng']) 
	&& isset($_POST['Lat']) && isset($_POST['ContactNo']) 
	&& isset($_POST['SerialNo']) && isset($_POST['UpdatedDate']) 
	&& isset($_POST['ClientID']) && isset($_POST['ClientUserID']) 
	&& isset($_POST['NetCode']) && isset($_POST['SysCode']) ){

		$VehicleID = $_POST['VehicleID'];
  		$VehicleGroupID = $_POST['VehicleGroupID'];
		$VehicleName = $_POST['VehicleName'];
  		$Brand = $_POST['Brand'];
		$Model = $_POST['Model'];
  		$Colour = $_POST['Colour'];
		$RegistrationNo = $_POST['RegistrationNo'];
  		$Account3ID = $_POST['Account3ID'];
		$Status = $_POST['Status'];
  		$Lng = $_POST['Lng'];
		$Lat = $_POST['Lat'];
  		$ContactNo = $_POST['ContactNo'];
		$SerialNo = $_POST['SerialNo'];
  		$UpdatedDate = $_POST['UpdatedDate'];
  		$ClientID = $_POST['ClientID'];
  		$ClientUserID = $_POST['ClientUserID'];
  		$NetCode = $_POST['NetCode'];
  		$SysCode = $_POST['SysCode'];

      // include db connect class
      require_once __DIR__ . '/../DBConnect.php';

			    $UpdatedDate = date("Y-m-d H:i:s");

          $sql = "UPDATE Vehicle2Name SET VehicleID = '$VehicleID', VehicleGroupID = '$VehicleGroupID', VehicleName = '$VehicleName', Brand = '$Brand', Model = '$Model',  Colour = '$Colour', RegistrationNo = '$RegistrationNo', Account3ID = '$Account3ID', Status = '$Status', Lng = '$Lng', Lat = '$Lat', ContactNo = '$ContactNo', SerialNo = '$SerialNo',  ClientID = '$ClientID', ClientUserID = '$ClientUserID', NetCode = '$NetCode',
          SysCode = '$SysCode', UpdatedDate = '$UpdatedDate'  WHERE VehicleID = '$VehicleID' AND ClientID= '$ClientID' ";
          $params = array();
      		
      		 $result=0;
		try{	
			$stmt = $conn->prepare($sql);
			$stmt->execute();
			$result= $stmt->rowCount();
		}
		catch(PDOException $e){
			echo $sql . "<br>" . $e->getMessage();
		}
		if ( $result!= 0) {
				$rows_affected= "No information available.";
				$response["success"] = 1;
				$response["roweffected"] = $result;
				$response["UpdatedDate"] = $UpdatedDate;
				$response["message"] = "Update Successfully";
				// echoing JSON response
				echo json_encode($response);
		}else{
				$response["success"] = 0;
				$response["roweffected"] = $result;      
				$response["message"] = "Not updated row ".$result;
				// echoing JSON response
				echo json_encode($response);
		}
    }else{
      // success
      $response["success"] = 0;
      $response["message"] = "No Update";
      // echoing JSON response
      echo json_encode($response);
    }
?>
