<?php
require 'database.inc.php';
if (Test_User($lg_user, $lg_password) == TRUE) {
  if ($valid == 1) {
    echo "<SCRIPT language=JavaScript>\n";
    $GLOBALS["Special"] = "";
    if ($ligne = Vehicule::getVehiculeByNoChassis($NoChasis)) {
      $result = Affecte_Resultat_Vehicule($ligne, $Mode);
      echo "window.opener.local_eval(\"$result\");\n";
    }
    if ($GLOBALS["Special"] != "") {
      echo "eval(\"" . $GLOBALS["Special"] . "\")\n";
    } else {
      echo "window.close();\n";
    }
    echo "</SCRIPT>\n";
    if ($GLOBALS["Special"] == "") {
      exit;
    }
  }
?>
  <html>

  <head>
    <meta http-equiv='content-type' content='text/html;charset=utf-8'>
    <SCRIPT language=JavaScript src='valideformulaire.js' type=text/javascript></SCRIPT>
    <title>WebBike V<?php echo VERSION; ?></title>
    <?php
    $size = 2;
    if ($ligne = Poste::getPostesByIP()) {
      $size = $ligne['Size'];
    }
    echo "<link href='css/style$size.css' rel='stylesheet' media='screen'>\n";

    echo "<link href='" . CSS_FOLDER . "style.css' rel='stylesheet' media='screen'>\n"
    ?>
  </head>

  <body>
    <?php
    if ($valid == 1) {
      if ($GLOBALS["Special"] != "") {
    ?>
        Service ?<br />
        <button id="bt_oui" onclick="window.opener.document.forms['info'].service.selectedIndex = <?php echo $GLOBALS["Special"] ?>;window.opener.duree_service();window.close();">OUI</button><button onclick="window.close();">NON</button>
        <SCRIPT language="JavaScript">
          var bt_oui = document.getElementById("bt_oui");
          bt_oui.focus();
        </SCRIPT>
      <?php
      }
    } else {
      ?>
      <form>
        <input type="hidden" name="valid" value="1">
        <input type="hidden" name="Mode" value="<?php echo $Mode; ?>">
        <select name="NoChasis">
          <?php
          //echo $requette."<br />";
          if ($resultat = Vehicule::getVehiculeByClient($NoClient)) {
            foreach ($resultat as $ligne) {
              echo "<option value='" . $ligne['NoChasis'] . "'>" . $ligne['NoChasis'] . " " . $ligne['MarqueModel'] . " " . $ligne['Model'] . " " . $ligne['NoPlaque'] . "</option>\n";
            }
          }
          ?>
        </select><br />
        <button type="submit">Valider</button>
      </form>
      <SCRIPT language=JavaScript>
        this.document.forms[0].NoChasis.focus();
        this.document.onkeydown = formkeydown;
        actif = 0;
      </SCRIPT>
      <br />
      <form action="recherche_vhc_create.php">
        <input type="hidden" name="NoClient" value="<?php echo $NoClient; ?>" />
        <input type="hidden" name="Mode" value="<?php echo $Mode; ?>" />
        <BUTTON type='submit' style='width:120px;'>Nouveau véhicule</BUTTON>
      </form>
      <form action="recherche_vhc_find.php">
        <input type="hidden" name="NoClient" value="<?php echo $NoClient; ?>" />
        <input type="hidden" name="Mode" value="<?php echo $Mode; ?>" />
        <BUTTON type='submit' style='width:120px;'>Rechercher véhicule</BUTTON>
      </form>
    <?php
    }
    ?>
  </body>

  </html>
<?php
}
?>