<?php
require 'database.inc.php';
if (Test_User($lg_user, $lg_password) == TRUE) {
  if ($valid == 1) {
    echo "<SCRIPT language=JavaScript>\n";
    if ($ligne = Client::getClientByNoClient($NoClient)) {
      $result = Affecte_Resultat_Client($ligne, $Mode);
      echo "window.opener.local_eval(\"$result\");\n";
    }
    echo "window.close();\n";
    echo "</SCRIPT>\n";
    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>
    <form>
      <input type="hidden" name="valid" value="1">
      <input type="hidden" name="Mode" value="<?php echo $Mode; ?>">
      <select name="NoClient">
        <?php
        if (empty($Nom) && empty($Prenom))
          $requette = "SELECT * FROM clients ORDER BY Nom, Prenom";
        else if (empty($Nom))
          $requette = "SELECT * FROM clients WHERE " . Compare_Sans_Accents("Prenom", addslashes($Prenom)) . " ORDER BY Nom, Prenom";
        else if (empty($Prenom))
          $requette = "SELECT * FROM clients WHERE " . Compare_Sans_Accents("Nom", $Nom) . " ORDER BY Nom, Prenom";
        else
          $requette = "SELECT * FROM clients WHERE " . Compare_Sans_Accents("Nom", $Nom) . " AND " . Compare_Sans_Accents("Prenom", $Prenom) . "ORDER BY Nom, Prenom";
        //echo $requette."<br />";
        if ($resultat = Connection::executeRawQueryWithfetchAll($requette)) {
          foreach ($resultat as $ligne) {
            echo "<option value=\"" . $ligne["NoClient"] . "\">" . htmlentities($ligne["Nom"], ENT_COMPAT | ENT_HTML401, 'UTF-8') . " " . htmlentities($ligne["Prenom"], ENT_COMPAT | ENT_HTML401, 'UTF-8') . "</option>";
          }
        }
        ?>
      </select><br />
      <button type="submit">Valider</button>
    </form>
    <SCRIPT language=JavaScript>
      this.document.forms[0].NoClient.focus();
      this.document.onkeydown = formkeydown;
      actif = 0;
    </SCRIPT>
    <br />
    <form action="recherche_client_create.php">
      <input type="hidden" name="Nom" value="<?php echo $Nom; ?>" />
      <input type="hidden" name="Prenom" value="<?php echo $Prenom; ?>" />
      <input type="hidden" name="Mode" value="<?php echo $Mode; ?>" />
      <BUTTON type='submit'>Nouveau client</BUTTON>
    </form>
  </body>

  </html>
<?php
}
?>