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

 			$sql = "SELECT * FROM Chat WHERE UpdatedDate >= '$SessionDate'";

			//$sql = "SELECT * FROM Chat";


			$stmt = $conn->prepare($sql);
			$stmt->execute();
			$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
			   
		   if($result!=null &&  $result>0){
					  $response["Chat"] = array();
			 foreach($result as $row) { 
					
			$Chat["ID"] = $row["ID"];
            $Chat["MessageID"] = $row["MessageID"];
            $Chat["SenderMobileNo"] = $row["SenderMobileNo"];
            $Chat["ReceiverMobileNo"] = $row["ReceiverMobileNo"];
            $Chat["Message"] = $row["Message"];
            $Chat["MessageWritingTime"] = $row["MessageWritingTime"];
            $Chat["MessageServerTime"]=$row["MessageServerTime"];
            $Chat["ReceiveTime"]=$row["ReceiveTime"];
            $Chat["ReadTime"]=$row["ReadTime"];
            $Chat["NetCode"] = $row["NetCode"];
            $Chat["SysCode"] = $row["SysCode"];
            $Chat["SenderStatus"] = $row["SenderStatus"];
            $Chat["UpdatedDate"] = $row["UpdatedDate"];
            $Chat["ReplyOn"] = $row["ReplyOn"];
				  // push single product into final response array
				  array_push($response["Chat"], $Chat);
			  }
			  // success
			  $response["success"] = 1;
			  // echoing JSON response
			  //require __DIR__ . '/pusher.php';
			  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);
	}

?>
