<?php
  switch($Etape)
  {
    case 0:
?>
<script language=JavaScript>
  function move_up2()
  {
    no=this.info.liste_vehicules.selectedIndex;
    if (no>0)
    {
      tmp_text=this.info.liste_vehicules.options[no].text;
      this.info.liste_vehicules.options[no].text=this.info.liste_vehicules.options[(no-1)].text;
      this.info.liste_vehicules.options[(no-1)].text=tmp_text;
      nom='MemNoChasis' + no;
      nom2='MemNoChasis' + (no-1);
      tmp_value=this.info.elements[nom].value;
      this.info.elements[nom].value=this.info.elements[nom2].value;
      this.info.elements[nom2].value=tmp_value;
      this.info.liste_vehicules.selectedIndex=(no-1);
    }
  }
  function move_down2()
  {
    no=this.info.liste_vehicules.selectedIndex;
    if ((no+1)!=this.info.liste_vehicules.length)
    {
      tmp_text=this.info.liste_vehicules.options[no].text;
      this.info.liste_vehicules.options[no].text=this.info.liste_vehicules.options[(no+1)].text;
      this.info.liste_vehicules.options[(no+1)].text=tmp_text;
      nom='MemNoChasis' + no;
      nom2='MemNoChasis' + (no+1);
      tmp_value=this.info.elements[nom].value;
      this.info.elements[nom].value=this.info.elements[nom2].value;
      this.info.elements[nom2].value=tmp_value;
      this.info.liste_vehicules.selectedIndex=(no+1);
    }
  }
</script>
<?php
      if($resultat =  VehiculesLocation::getAll())
      {
        $nb=count($resultat);
        echo "  <form name='info' method='post'>\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 "<SELECT name='liste_vehicules' size='$nb'>\n";
        $cpt=0;
        $out="";
        foreach($resultat as $ligne)
        {
          $ligne2=Vehicule::getVehiculeByNoChassis($ligne['NoChasis']);
          echo "<option value='".$ligne['NoChasis']."'>" . str_replace(" ","&nbsp;",taille_text($ligne2['Model'], 10, 0)) . " " . str_replace(" ","&nbsp;",taille_text($ligne['NoPlaque'], 10, 0)) . " " . taille_text($ligne['NoChasis'], 20, 0) ."</option>\n";
          $out.="<input type='hidden' name='MemNoChasis$cpt' value='".$ligne['NoChasis']."'>\n";
          $cpt++;
        }
        echo "</SELECT><BR>\n";
        echo $out;
        echo "<input type='button' value='Up' onclick='move_up2();'>\n";
        echo "<input type='button' value='Down' onclick='move_down2();'>\n";
        echo "   <button type='submit'>Valider</button>\n";
        echo "  </form>\n";
      }
    break;
    case 1:
      $cpt=0;
      while(isset(${"MemNoChasis".$cpt}))
      {
        $requette="UPDATE vehiculeslocation".ID_GARAGE." SET Position=$cpt WHERE NoChasis='".addslashes(${"MemNoChasis".$cpt})."'";
        Connection::executeRawQuery($requette);
        $cpt++;
      }
    break;
  }
?>
