<?php
require 'database.inc.php';
if (Test_User($lg_user, $lg_password) == TRUE) {
?>
  <table border="1">
    <tr>
      <th>Date</th>
      <th>Km</th>
      <th>NoAtelier</th>
      <th>NoCommande</th>
      <th>Type</th>
      <th>Options</th>
      <th>Description</th>
    </tr>
    <?php
    $requette = "SELECT * FROM atelier" . ID_GARAGE . " WHERE NoChasis = '" . $nochasis . "' AND NoCommande <> 0 ORDER BY Date DESC";
    $resultat = Connection::executeRawQueryWithfetchAll($requette);
    $num_rows = count($resultat);
    if ($num_rows > 0) {
      $requetteint = "SELECT c.* FROM atelier" . ID_GARAGE . " AS a, commande" . ID_GARAGE . " AS c WHERE a.NoChasis = '" . $nochasis . "' AND a.NoCommande <> 0 AND a.NoCommande = c.NoCommande ORDER BY a.Date DESC";
      $_SESSION["memres4"] = $requetteint;
    }
    foreach ($resultat as $ligne) {
      $type_service = "Autre";
      if ($ligne["Id_Service"] != 0) {
        if ($ligne2 = ServiceVHC::getServiceVHCByID($ligne["Id_Service"])) {
          $type_service = $ligne2["Nom"];
        }
      }
      $options = "";
      $requette2 = "SELECT so.Nom_court FROM atelier_option" . ID_GARAGE . " AS ao, vhc_option AS vo, service_option AS so WHERE ao.Id_atelier = " . $ligne["NoAtelier"] . " AND ao.Id_option = vo.Id AND vo.Id_option = so.Id";
      $resultat2 =  Connection::executeRawQueryWithfetchAll($requette2);
      foreach ($resultat2 as $ligne2) {
        if ($options != "") $options .= ", ";
        $options .= $ligne2["Nom_court"];
      }
      echo "<tr><td>" . Cree_Entree_Type("", 2, 0, $ligne["Date"], AFFICHAGE) . "</td><td>" . $ligne["Km"] . "</td><td>" . $ligne["NoAtelier"] . "</td><td><a href=\"default.php?NoCommande=" . $ligne["NoCommande"] . "&Type=4&Sous_Type=1&Etape=3&NoVisu=0\" target=\"_blank\" rel='opener'>" . $ligne["NoCommande"] . "</td><td>$type_service</td><td>$options</td><td>" . $ligne["Description"] . "</td></tr>";
    }
    ?>
  </table>
<?php
  //echo $requette."<br>";
  //echo $requette2."<br>";
}
?>