<?php
// array for JSON response

$response = array();
	
//check for required fields
if (isset($_POST['MessageID']) && 
		isset($_POST['SenderMobileNo']) && 
		isset($_POST['ReceiverMobileNo']) && 
		isset($_POST['Message']) &&   
		isset($_POST['MessageWritingTime']) &&   
		isset($_POST['MessageServerTime']) &&
		isset($_POST['ReceiveTime']) && 
		isset($_POST['ReadTime']) && 
		isset($_POST['NetCode']) &&                                         
		isset($_POST['SysCode']) &&        
		isset($_POST['SenderStatus']) &&                                                                                  
		isset($_POST['ReplyOn'])) {

		$MessageID= $_POST['MessageID'];   
		$SenderMobileNo= $_POST['SenderMobileNo'];   
		$ReceiverMobileNo= $_POST['ReceiverMobileNo'];   
		$Message= $_POST['Message'];
		$MessageWritingTime= $_POST['MessageWritingTime'];   
		$MessageServerTime= $_POST['MessageServerTime'];
		$ReceiveTime= $_POST['ReceiveTime'];   
		$ReadTime= $_POST['ReadTime'];   
		$NetCode= $_POST['NetCode'];                                           
		$SysCode= $_POST['SysCode'];        
		$SenderStatus= $_POST['SenderStatus'];                                                                                 
		$ReplyOn= $_POST['ReplyOn'];

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

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

        $sql = "UPDATE Chat SET SenderMobileNo = '$SenderMobileNo',ReceiverMobileNo = '$ReceiverMobileNo',Message = '$Message',MessageWritingTime = '$MessageWritingTime', MessageServerTime = '$MessageServerTime',ReceiveTime = '$ReceiveTime',ReadTime = '$ReadTime', NetCode = '$NetCode',
          SysCode = '$SysCode', UpdatedDate = '$UpdatedDate' ,SenderStatus='$SenderStatus',ReplyOn='$ReplyOn' WHERE MessageID = $MessageID ";
          
        $params = array();
          
         
		 
		try{	
			$stmt = $conn->prepare($sql);
			$stmt->execute();
			$result= $stmt->rowCount();
		}
		catch(PDOException $e){
			echo $sql . "<br>" . $e->getMessage();
		}
	
		if ( $result=== TRUE) {
				$rows_affected= "No information available.";
				$response["success"] = 1;
				$response["roweffected"] = $rows_affected;
				$response["UpdatedDate"] = $UpdatedDate;
				$response["message"] = "Update Successfully";
				require __DIR__ . '/pusher.php';
				// 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);
    }
?>
