<?php
    include_once 'opendb.php';
    
   // die(isset($_POST["Category"]) );
     $mess="";
    if (isset($_POST["AccessCode"]))
    {
    
       $Access=$_POST["AccessCode"]=="Manacc Delete All";
       $CompID=$_POST["comp_id"]; 
       if($Access && isset($_POST["Category"]) )
       {
            if($_POST["Category"]=="Products")
             {
            
                      $sql = "delete from products where comp_id=" .$CompID;
                           if ($conn->query($sql) === TRUE)
                           {
                              $mess.="Products cleared";
                           } else
                           {
                              $mess= "Error: " . $sql . "<br>" . $conn->error;
                           } 
                        /*    $sql = "delete from batchs where comp_id=" .$CompID;
                           if ($conn->query($sql) === TRUE)
                           {
                              $mess.=" and batchs too";
                           } else
                           {
                              $mess= "Error: " . $sql . "<br>" . $conn->error;
                           } */
             }
             if($_POST["Category"]=="Customers")
             {
            
                      $sql = "delete from subsidiary where sub_type='C' and comp_id=" .$CompID;
                           if ($conn->query($sql) === TRUE)
                           {
                              $mess.="Customers cleared";
                           } else
                           {
                              $mess= "Error: " . $sql . "<br>" . $conn->error;
                           } 
                           
             }
              if($_POST["Category"]=="Mobile Clients")
             {
            
                      $sql = "delete from mobile_clients where comp_id=" .$CompID;
                           if ($conn->query($sql) === TRUE)
                           {
                              $mess.="mobile clients cleared";
                           } else
                           {
                              $mess= "Error: " . $sql . "<br>" . $conn->error;
                           } 
                           
             }
             
        
      }  
      else {
              $mess= "Error : IAC";
      }
        
    }
    else
    {
        $mess= "Error : No parameters!";
    }
    echo $mess;
    $conn->close();
?>