<?php
    include_once 'opendb.php';
    $filter="";
    $RqID=0;
    
     $CompID=0;
      if (isset($_POST["comp_id"]))
    {
        $CompID=$_POST["comp_id"]; 
         $filter.=" where comp_id=" . $CompID;
    } else {
         $response["message"] = "Error: Web Co ID invalid";
         die( json_encode($response));
    }
       
    if (isset($_POST["clientcode"]))
    {
       $filter.=" and sman_code like '" . $_POST["clientcode"]."'";
    }
      else {
         $response["message"] = "Error: client code invalid";
         die( json_encode($response));
    }
    if (isset($_POST["webentry_no_del"])){
        $DelEntryNo=$_POST["webentry_no_del"]; 
        if ($DelEntryNo>0){
            $Qry="delete  from sman_reminders where comp_id=$CompID and Entry_No= $DelEntryNo";
            $conn->query($Qry);
        }
    }
    
    
     $today=date("Ymd");
     $filter.=" and rem_date <= ".$today. " and rem_date > 0 ";
    $Qry="SELECT entry_no,sub_code,sman_code,notes,rem_date,rem_type  from sman_reminders";
    $Qry.=$filter. " order by rem_date  ";
   // die($Qry);
    if ($result = mysqli_query ($conn,$Qry))
        {
          if (mysqli_num_rows($result) > 0)
          {
                  $response = array();
                  while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
                  {

                      $request = array();

                      $request["entry_no"] = $row["entry_no"];
                      $request["sub_code"] = $row["sub_code"];               
                      $request["rem_date"] = $row["rem_date"];
                      $request["notes"] = $row["notes"];
                      $request["rem_type"] = $row["rem_type"];

                      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();
?>