<?php
require 'database.inc.php';
header('Content-Type: text/html; charset=utf-8');
function auto_vhc($NoClient, $Mode)
{
  $Force = $GLOBALS["Force"];
  $requette = "SELECT * FROM vehicules WHERE Client=$NoClient ORDER BY DateModif DESC";
  if ($resultat = Vehicule::getVehiculeByClient($NoClient)) {
    $nb = count($resultat);
    if ($nb == 0 && isset($GLOBALS["Force"]) && $Force != 1) {
    } else {
      echo "  window.open('recherche_vhc_filter.php?NoClient=$NoClient&Mode=$Mode', '', 'width=400, height=120, resizable=yes, toolbar=no, scrollbars=yes, status=no');\n";
    }
  }
}
if (Test_User($lg_user, $lg_password) == TRUE) {
  if (!isset($Type)) {
    $Type = 0;
  }
  if (!isset($Mode)) {
    $Mode = 0;
  }
  if ($Type == 2) {
    switch ($Sous_Type) {
      case 3:
        switch ($Etape) {
          case 0:
            Affiche_formulaire(2, NOUVEAU, 1, '', $NoVisu, $param1, '', $Mode);
            break;
          case 1:
            Valide_Modif(
              2,
              NOUVEAU,
              1,
              '',
              $NoVisu,
              ", DateModif, PersonneModif",
              ", '" . date("Y-m-d") . "', '" . addslashes($lg_user) . "'"
            );
            auto_vhc($param1, $Mode);
            break;
        }
        break;
      case 2:
        switch ($Etape) {
          case 0:
            if (isset($param2)) {
              echo "ici<BR>";
              $Mode = $param2;
            }
            Affiche_No_Visu_recherche(2, VISU_DATA, '', $param1, $Mode);
            echo "  <form name='info'>\n";
            echo "   <input type='hidden' name='Type' value=$Type>\n";
            echo "   <input type='hidden' name='Sous_Type' value=$Sous_Type>\n";
            echo "   <input type='hidden' name='Etape' value='1'>\n";
            echo "   <input type='hidden' name='param1' value='$param1'>\n";
            echo "   <input type='hidden' name='NoVisu' value='$NoVisu'>\n";
            echo "   <input type='hidden' name='Mode' value='$Mode'>\n";
            Create_Recherche(2, $NoVisu);
            echo "   <button type='submit'>Rechercher</button>\n";
            echo "  </form>\n";
            break;
          case 1:
            echo "  <form name='info'>\n";
            echo "   <input type='hidden' name='Type' value=$Type>\n";
            echo "   <input type='hidden' name='Sous_Type' value=$Sous_Type>\n";
            echo "   <input type='hidden' name='Etape' value='2'>\n";
            echo "   <input type='hidden' name='NoVisu' value=0>\n";
            echo "   <input type='hidden' name='Mode' value='$Mode'>\n";
            echo "   <input type='hidden' name='param1' value='$param1'>\n";
            Affiche_Resultat_Recherche(2, 7, $NoVisu);
            echo "  </form>\n";
            break;
          case 2:
            if (isset($Modif)) {
              Valide_Modif(
                2,
                MODIFICATION,
                1,
                ${GetNomClef(2)},
                $NoVisu,
                ",DateModif='" . date("Y-m-d") . "',PersonneModif='" . addslashes($lg_user) . "'",
                ''
              );
              auto_vhc($param1, $Mode);
            }
            Affiche_formulaire(2, MODIFICATION, $no_division = 1, $clef = ${GetNomClef(2)}, $no_visu = $NoVisu, $param1, '', $Mode);
            break;
          case 3:
            echo "$Mode<BR>";
            Valide_Modif(
              2,
              MODIFICATION,
              1,
              ${GetNomClef(2)},
              $NoVisu,
              ",DateModif='" . date("Y-m-d") . "',PersonneModif='" . addslashes($lg_user) . "'",
              ''
            );
            auto_vhc($param1, $Mode);
            break;
        }
        break;
    }
  } else {
    $param1 = $NoClient;
    auto_vhc($NoClient, $Mode);
  }
}
