<?php
    include_once 'opendb.php';
    $filter="";
    $RqID=0;
    
     $CompID=0;
      if (isset($_POST["comp_id"]))
    {
        $CompID=$_POST["comp_id"]; 
         $filter.=" where comp_id=" . $CompID;
    }
    if($CompID==0) {
        
         $response["message"] = "Error: Web Co ID invalid";
            // echo no users JSON
            die( json_encode($response));
    }
    
    
    if(isset($_POST["ReqID"])){
        $RqID=$_POST["ReqID"];
    }
    if($RqID>0){
        $filter.=" and request_id= ".$RqID;
    }
    elseif (isset($_POST["clientcode"]))
    {
         $filter.=" and (counter_code like'" . $_POST["clientcode"]."' or client_app_id like '".$_POST["AppID"]."')";
    }
    
    
    
    $Qry="SELECT request_id,client_app_id,notes,request_type,request_time,counter_code,cust_code,reply_message,req_status,reply_time,file_name from client_requests ";
    $Qry.=$filter;
   // die($Qry);
    if ($result = mysqli_query ($conn,$Qry))
  {
    if (mysqli_num_rows($result) > 0)
    {
            $response = array();
            while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
            {
               
                // temp user array
                $request = array();
                   
                $request["request_id"] = $row["request_id"];
                $request["notes"] = $row["notes"];
                $request["request_type"] = $row["request_type"];
                $request["request_time"] = $row["request_time"];
                $request["cust_code"] = $row["cust_code"];
                $request["reply_message"] = $row["reply_message"];
                $request["req_status"] = $row["req_status"];
                $request["reply_time"] = $row["reply_time"];
               // $request["file_data"] = $row["file_data"];
                $request["file_name"] = $row["file_name"];
                
                array_push($response, $request);
            }
            echo json_encode($response);
     } else
     {   
            $response["message"] = "NoData";
            echo json_encode($response);
     }
  }
 else {
      $response["message"] = "NoData";
            echo json_encode($response); 
}
 $conn->close();
?>