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

//check for required fields
if (isset($_POST['ID3']) && isset($_POST['AddStatus']) && isset($_POST['AddTitle'])
	  && isset($_POST['AddDetail']) && isset($_POST['Price']) && isset($_POST['AddGPSPostFrom']) && isset($_POST['AddGPSLocation'])
	   && isset($_POST['AddArea']) && isset($_POST['AddCategory']) && isset($_POST['ContactNo']) && isset($_POST['NameOfPerson']) 
	   && isset($_POST['ClientID']) && isset($_POST['ClientUserID']) && isset($_POST['NetCode']) && isset($_POST['SysCode']) 
	   && isset($_POST['AddPostingDate']) && isset($_POST['Country']) && isset($_POST['City'])) {

		$AddPostingDate = $_POST['AddPostingDate'];
        $CAddPostingDate = date("Y-m-d", strtotime($AddPostingDate));
        
            $ID4 = $_POST['ID4'];
    		$ID3 = $_POST['ID3'];
    		$AddStatus = $_POST['AddStatus'];
    		$AddTitle = $_POST['AddTitle'];
    		$AddDetail = $_POST['AddDetail'];
    		$Price = $_POST['Price'];
    		$AddGPSPostFrom = $_POST['AddGPSPostFrom'];
    		$AddGPSLocation = $_POST['AddGPSLocation'];
    		$AddArea = $_POST['AddArea'];
		    $AddCategory = $_POST['AddCategory'];
			$ContactNo = $_POST['ContactNo'];
			$NameOfPerson = $_POST['NameOfPerson'];
			$CountryClientID = $_POST['ClientID'];
			$CountryClientUserID = $_POST['ClientUserID'];
			$NetCode = $_POST['NetCode'];
			$SysCode = $_POST['SysCode'];
			$Country = $_POST['Country'];
			$City = $_POST['City'];

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

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

      $sql = "UPDATE AddCategory4 SET ID3 = '$ID3', AddStatus = '$AddStatus', AddTitle = '$AddTitle', AddDetail = '$AddDetail', Price = '$Price',
	   AddGPSPostFrom = '$AddGPSPostFrom', AddGPSLocation = '$AddGPSLocation', AddArea = '$AddArea', AddCategory = '$AddCategory', ContactNo = '$ContactNo'
	   , NameOfPerson = '$NameOfPerson', ClientID = '$CountryClientID', ClientUserID = '$CountryClientUserID', NetCode = '$NetCode'
	   , SysCode = '$SysCode', Country = '$Country', City = '$City', UpdatedDate = '$UpdatedDate' WHERE ClientID = $CountryClientID AND ClientUserID = $CountryClientUserID AND ID4 = $ID4" ;
      $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{
		$response["success"] = 0;
        $response["message"] = "No Update";
        // echo no users JSON
        echo json_encode($response);
	}
?>
