<?php
require 'database.inc.php';
if (Test_User($lg_user, $lg_password) == TRUE) {
  if ($valid == 1) {
    echo "<SCRIPT language=JavaScript>\n";
    $requette = "SELECT * FROM articles LEFT JOIN stock" . ID_GARAGE . " ON articles.NoArticleRR = stock" . ID_GARAGE . ".NoArticleRR WHERE articles.NoArticleRR LIKE '" . addslashes($NoArticle) . "%' ORDER BY articles.NoArticleRR";
    if ($resultat = Connection::executeRawQueryWithfetchAll($requette)) {
      if ($ligne = $resultat[0]) {
        $result = Affecte_Resultat_Article($ligne, $NoClient);
        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="NoClient" value="<?php echo $NoClient; ?>">
      <select name="NoArticle">
        <?php
        $requette = "SELECT * FROM articles LEFT JOIN stock" . ID_GARAGE . " ON articles.NoArticleRR = stock" . ID_GARAGE . ".NoArticleRR WHERE articles.NoArticleRR LIKE '" . addslashes($NoArticle) . "%' ORDER BY articles.NoArticleRR";
        $requette = "SELECT * FROM articles WHERE NoArticleRR LIKE '" . addslashes($NoArticle) . "%' ORDER BY NoArticleRR";
        //$requette="SELECT * FROM vehicules WHERE Client=$NoClient ORDER BY DateModif DESC";
        //echo $requette."<br />";
        if ($resultat = Article::getArticleByNoArticleRR(addslashes($NoArticle))) {
          foreach ($resultat as $ligne) {
            echo "<option value='" . $ligne['NoArticleRR'] . "'>" . $ligne['NoArticleRR'] . " " . $ligne['Description'] . "</option>\n";
          }
        }
        ?>
      </select><br />
      <button type="submit">Valider</button>
    </form>
    <SCRIPT language=JavaScript>
      this.document.forms[0].NoArticle.focus();
      this.document.onkeydown = formkeydown;
      actif = 0;
    </SCRIPT>
    <br />
    <form action="recherche_article_find.php">
      <input type="hidden" name="NoClient" value="<?php echo $NoClient; ?>" />
      <input type="hidden" name="Commande" value="<?php echo $Commande; ?>" />
      <input type="hidden" name="AchatMarchandise" value="<?php echo $AchatMarchandise; ?>" />
      <input type="hidden" name="NbArticles" value="<?php echo $NbArticles; ?>" />
      <BUTTON type='submit'>Rechercher véhicule</BUTTON>
    </form>
  </body>

  </html>
<?php
}
?>