<?php
  switch($Etape)
  {
    case 0:
      Create_Recherche_Form(2,$NoVisu);
    break;
    case 1:
      Create_Recherche_Form(2,$NoVisu);
      Affiche_Resultat_Recherche_Form(2,$NoVisu);
    break;
    case 2:
      switch ($Action)
	  {
		case "Edit":
		  $requette = "UPDATE alertes_vehicules SET Message = '".addslashes($Message)."', Etat = '$Statut' WHERE Id = $Id";
		  echo $requette;
		  Connection::executeRawQuery($requette);
		  break;
		case "Del":
		  $requette = "DELETE FROM alertes_vehicules WHERE Id = $Id";
		  echo $requette;
		  Connection::executeRawQuery($requette);
		  break;
		case "New":
		  $requette = "INSERT INTO alertes_vehicules (NoChasis, Message, Etat) VALUES ('".addslashes($NoChasis)."', '".addslashes($Message)."', 'actif')";
		  echo $requette;
		  Connection::executeRawQuery($requette);
		  break;
      }
	  $resultat = AlertesVehicules::getAlerteVehiculeByNoChassis($NoChasis);
	  echo "<table><tr><th>Alerte</th><th>Etat</th><th>&nbsp;</th></tr>";
	  foreach($resultat as $ligne)
      {
	    echo "<tr><form method='POST'><input type=\"hidden\" name=\"Action\" value=\"Edit\" /><input type=\"hidden\" name=\"Id\" value=\"".$ligne["Id"]."\" /><td>";
		echo "<textarea name=\"Message\" rows=\"4\" cols=\"80\">".$ligne["Message"]."</textarea>";
		echo "</td><td>";
		echo "<select name=\"Statut\">";
		echo "<option value=\"actif\"";
		if ($ligne["Etat"] == "actif")
		{
		  echo " selected=\"selected\"";
		}
		echo ">actif</option>";
		echo "<option value=\"ferme\"";
		if ($ligne["Etat"] == "ferme")
		{
		  echo " selected=\"selected\"";
		}
		echo ">fermé</option>";
		echo "</select>";
		echo "</td><td>";
		echo "<input type=\"submit\" value=\"Enregistrer\" />";
		echo "</td></form><form method='POST'><input type=\"hidden\" name=\"Action\" value=\"Del\" /><input type=\"hidden\" name=\"Id\" value=\"".$ligne["Id"]."\" /><td><input type=\"submit\" value=\"Supprimer\" /></td></form></tr>";
      }
	  echo "<tr><form method='POST'><input type=\"hidden\" name=\"Action\" value=\"New\" /><td><textarea name=\"Message\" rows=\"4\" cols=\"80\"></textarea></td><td><select><option value=\"actif\">Nouveau</option></select></td><td><input type=\"submit\" value=\"Créer\" /></td></form></tr>";
	  echo "</table>";
    break;
  }
?>
