<?php
 include "dbPDO.php";
 if(isset($_POST["branch"])){
    $branch     = $_POST["branch"];
    $car_job_id = $_POST["car_job_id"];
    $woner      = $_POST["woner"];
    $kind       = $_POST["kind"];
    $model      = $_POST["model"];
    $sql = "";
      if($branch != "*"){ $sql = $sql." AND branch = ".$branch ;}
      if($car_job_id != "*"){ $sql = $sql." AND car_job_id = ".$car_job_id ;}
      if($woner != "*"){$sql = $sql." AND woner = ".$woner ;}
      if($kind != "*"){$sql = $sql." AND kind LIKE '$kind%'" ;} //$kind = "%".$kind."%";UNHEX(str)
      if($model != "*"){$sql = $sql." AND model = ".$model ;}
  $output = '';
  echo $sql;
  $sql2 =$db->prepare("SELECT carid,kind,concat(letters ,' ',numbers) as numbers,b_name,model,lic_expire,
  insurance_expire from cars , branches
  where cars.branch = branches.branchID $sql order by model DESC ");
  $sql2->execute();
   if($sql2->rowCount()>0)
  { $nn = 0;
     while($row = $sql2->fetch())
       { $nn++ ;
            $output .= '
                 <tr><td>' . $nn . '</td>
                      <td>
                      <a href="a/car_update.php?id=' . $row['carid'] . '"target="_blank"><button type="button" class="btn btn-success btn-xs ">تحديث</button></a>
                      <a href="a/photo_print.php?carid=' . $row['carid'] . '"target="_blank"><button type="button" class="btn btn-info btn-xs ">الرخصة</button></a>
                      <a href="acc/car_contracts.php?dd=' . $row['carid'] . '"target="_blank"><button type="button" class="btn btn-danger btn-xs ">عقود السيارة</button></a>
                      </td>
                      <td class="text-center">' . $row['kind'] . '</td>
                      <td>' . $row['numbers'] . '</td>
                      <td>' . $row['b_name'] . '</td>
                      <td>' . $row['model'] . '</td>
                      <td class="text-center" >' . $row['lic_expire'] . '</td>
                      <td class="text-center" >' . $row['insurance_expire'] . '</td>
                   </tr> '; }
  }
  else
  { $output .= '<tr><td colspan="7">  لا توجد سيارات يا نجم..</td></tr>'; }
  echo $output;
  }
  ?>
