<?php
  function Select_Etape_Service()
  {
    global $Type, $Sous_Type, $Etape, $Id;
    echo "<table class='table_etape_facture'><tr>\n";
    echo "<td class='td_coordonnees";
    if ($Etape==4)
    {
      echo " bt_actif";
    }
    echo "'><form><input type='hidden' name='Type' value=$Type><input type='hidden' name='Sous_Type' value=$Sous_Type><input type='hidden' name='Etape' value=4><input type='hidden' name='Id' value=$Id><input type='button' class='button' onClick='test_change(this.form);' value='Véhicule' /></form></td>\n";
    echo "<td class='td_coordonnees";
    if ($Etape==1)
    {
      echo " bt_actif";
    }
    echo "'><form><input type='hidden' name='Type' value=$Type><input type='hidden' name='Sous_Type' value=$Sous_Type><input type='hidden' name='Etape' value=1><input type='hidden' name='Id' value=$Id><input type='button' class='button' onClick='test_change(this.form);' value='Actions' /></form></td>\n";
    echo "<td class='td_facture";
    if ($Etape==2)
    {
      echo " bt_actif";
    }
    echo "'><form><input type='hidden' name='Type' value=$Type><input type='hidden' name='Sous_Type' value=$Sous_Type><input type='hidden' name='Etape' value=2><input type='hidden' name='Id' value=$Id><input type='button' class='button facture' onClick='test_change(this.form);' value='Pièces' /></form></td>\n";
    echo "<td class='td_imprimer";
    if ($Etape==3)
    {
      echo " bt_actif";
    }
    echo "'><form><input type='hidden' name='Type' value=$Type><input type='hidden' name='Sous_Type' value=$Sous_Type><input type='hidden' name='Etape' value=3><input type='hidden' name='Id' value=$Id><input type='button' class='button imprimer' onClick='test_change(this.form);' value='Calendrier' /></form></td>\n";
    echo "<td class='td_coordonnees";
    if ($Etape==6)
    {
      echo " bt_actif";
    }
    echo "'><form><input type='hidden' name='Type' value=$Type><input type='hidden' name='Sous_Type' value=$Sous_Type><input type='hidden' name='Etape' value=6><input type='hidden' name='Id' value=$Id><input type='button' class='button' onClick='test_change(this.form);' value='Options' /></form></td>\n";
    echo "<td class='td_coordonnees";
    if ($Etape==7)
    {
      echo " bt_actif";
    }
    echo "'><form><input type='hidden' name='Type' value=$Type><input type='hidden' name='Sous_Type' value=$Sous_Type><input type='hidden' name='Etape' value=7><input type='hidden' name='Id' value=$Id><input type='button' class='button' onClick='test_change(this.form);' value='Options actions' /></form></td>\n";
    echo "<td class='td_coordonnees";
    if ($Etape==8)
    {
      echo " bt_actif";
    }
    echo "'><form><input type='hidden' name='Type' value=$Type><input type='hidden' name='Sous_Type' value=$Sous_Type><input type='hidden' name='Etape' value=8><input type='hidden' name='Id' value=$Id><input type='button' class='button' onClick='test_change(this.form);' value='Options pièces' /></form></td>\n";
    echo "<td class='td_coordonnees";
    if ($Etape==9)
    {
      echo " bt_actif";
    }
    echo "'><form><input type='hidden' name='Type' value=$Type><input type='hidden' name='Sous_Type' value=$Sous_Type><input type='hidden' name='Etape' value=9><input type='hidden' name='Id' value=$Id><input type='button' class='button' onClick='test_change(this.form);' value='Options remplacement' /></form></td>\n";
    echo "<td class='td_coordonnees";
    if ($Etape==5)
    {
      echo " bt_actif";
    }
    echo "'><form><input type='hidden' name='Type' value=$Type><input type='hidden' name='Sous_Type' value=$Sous_Type><input type='hidden' name='Etape' value=5><input type='hidden' name='Id' value=$Id><input type='button' class='button' onClick='test_change(this.form);' value='Copie vers' /></form></td>\n";
    echo "</tr></table>\n";
  }
  switch($Etape)
  {
    case 0:
      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 "<TABLE border=1>\n";
	  $resultat = ChassisModel::getAll();
      echo "   <TR><TH>Model</TH><TD><select name='Id'>";
	  foreach($resultat as $ligne)
	  {
		echo "<option value='".$ligne["Id"]."'>".$ligne["Chassis"]." ".$ligne["Model"]." ".$ligne["Cylindree"]." ".$ligne["Homologation"]."</option>";
	  }
	  echo "</TD></TR>\n";
      echo "</TABLE>\n";
      echo "   <button type='submit'>Modifier</button>\n";
      echo "  </form>\n";  
    break;
    case 1:
	  if ($Edit==1)
	  {
		$requette = "DELETE FROM vhc_action WHERE Id_vhc = '$Id'";
	    Connection::executeRawQuery($requette);
		$postdata = file_get_contents("php://input");
		$pos1 = strpos($postdata, "action%5B%5D=");
		if ($pos1 !== FALSE)
		{
			$action = array();
		}
		while ($pos1 !== FALSE)
		{
			$pos2 = strpos($postdata, "&", $pos1);
			if ($pos2 !== FALSE)
			{
				$tmp_no = substr($postdata, $pos1 + 13, $pos2 - $pos1 - 13);
			}
			else
			{
				$tmp_no = substr($postdata, $pos1 + 13);
			}
			array_push($action, $tmp_no);
			$pos1 = strpos($postdata, "action%5B%5D=", $pos1 + 13);
		}
		foreach ($action as $act)
		{
		  $requette = "INSERT INTO vhc_action (Id_vhc, Id_action) VALUES ('$Id', '$act')";
		  Connection::executeRawQuery($requette);
		}
	  }
	  if ($ligne = ChassisModel::getChassisModelByNoChassis($Id))
	  {
		echo "<TABLE border='1'><TR><TH>".$ligne["Chassis"]."</TH><TH>".$ligne["Marque"]."</TH><TH>".$ligne["Model"]."</TH></TR></TABLE>";
		Select_Etape_Service();
	    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 "   <input type='hidden' name='Id' value='$Id'>\n";
	    echo "   <input type='hidden' name='Edit' value='1'>\n";
		echo "<TABLE border='1'><TR><TH>Nom</TH><TH>Action</TH></TR>\n";
		$resultat3 = Action::getActionActionType();
		$last_rubrique = 0;
		foreach($resultat3 as $ligne3)
		{
		  if ($ligne3['Id_Rubrique']!=$last_rubrique)
		  {
		    if($ligne4 = ActionRubrique::getById($ligne3['Id_Rubrique']))
		    {
			  echo "<TR><TH colspan='2'>".$ligne4['Nom_Rubrique']."</TH></TR>\n";
			}
			$last_rubrique=$ligne3['Id_Rubrique'];
		  }
		  echo "<TR><TD>".$ligne3["Description"]." ".$ligne3["Texte"]."</TD><TD><input name='action[]' type='checkbox' value='".$ligne3["Id"]."' onChange='AsChange=1;'";
		  if($ligne4 = VHCAction::getByIdVHCAndIDAction($Id, $ligne3["Id"]))
		  {
		    echo " checked='1'";
		  }
		  echo "></TD></TR>\n";
		}
		echo "</TABLE>\n";
        echo "   <button type='submit'>Modifier</button>\n";
        echo "  </form>\n";  
	  }
    break;
    case 2:
	  if ($Edit==1)
	  {
		$requette = "DELETE FROM service_article WHERE Id_Vhc = '$Id'";
	    Connection::executeRawQuery($requette);
		$requette2 = "SELECT action.* FROM vhc_action, action, action_type WHERE vhc_action.Id_vhc = $Id AND vhc_action.Id_action = action.Id AND action_type.Avec_Article = 1 AND action.Id_Type = action_type.Id ORDER BY action.Id_Rubrique, action.Position";
		$resultat2 = Connection::executeRawQueryWithfetchAll($requette2);
		foreach($resultat2 as $ligne2)
		{
		  $act = $ligne2["Id"];
		  $requette = "INSERT INTO service_article (Id_Vhc, Id_Action, NoArticle, Quantite) VALUES ('$Id', '$act', '".${"NoArticle".$act}."', '".${"Quantite".$act}."')";
		  echo $requette."<BR />\n";
		  Connection::executeRawQuery($requette);
		}
	  }
	  if ($ligne = ChassisModel::getChassisModelByNoChassis($Id))
	  {
		echo "<TABLE border='1'><TR><TH>".$ligne["Chassis"]."</TH><TH>".$ligne["Marque"]."</TH><TH>".$ligne["Model"]."</TH></TR></TABLE>";
	    Select_Etape_Service();
	    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='2'>\n";
	    echo "   <input type='hidden' name='Id' value='$Id'>\n";
	    echo "   <input type='hidden' name='Edit' value='1'>\n";
		echo "<TABLE><TR><TH>Nom</TH><TH>NoArticle</TH><TH>Quantité</TH></TR>\n";
		$requette2 = "SELECT action.* FROM vhc_action, action, action_type WHERE vhc_action.Id_vhc = $Id AND vhc_action.Id_action = action.Id AND action_type.Avec_Article = 1 AND action.Id_Type = action_type.Id ORDER BY action.Id_Rubrique, action.Position";
		$resultat2 = Connection::executeRawQueryWithfetchAll($requette2);
		foreach($resultat2 as $ligne2)
		{
		  $requette3 = "SELECT * FROM service_article WHERE Id_Vhc = $Id AND Id_Action = ".$ligne2["Id"];
		  $resultat3 = Connection::executeRawQueryWithfetchAll($requette3);
		  echo "<TR><TD>".$ligne2["Texte"]."</TD><TD><input type='text' name='NoArticle".$ligne2["Id"]."' onChange='AsChange=1;'";
		  if ($ligne3 = $resultat3[0])
		  {
			echo " value='".$ligne3["NoArticle"]."'";
		  }
		  echo " /></TD><TD><input type='text' name='Quantite".$ligne2["Id"]."' onChange='AsChange=1;'";
		  if ($ligne3)
		  {
			echo " value='".$ligne3["Quantite"]."'";
		  }
		  echo " /></TD></TR>\n";
		}
		echo "</TABLE>\n";
        echo "   <button type='submit'>Modifier</button>\n";
        echo "  </form>\n";  
	  }
    break;
    case 3:
	  if ($Edit==1)
	  {
		$requette = "SELECT chassis_model.*, service_km.Km, service_km.Type FROM chassis_model, service_km WHERE chassis_model.Id=$Id AND chassis_model.Id_Service = service_km.Id";
		$resultat = Connection::executeRawQueryWithfetchAll($requette);
		if ($ligne = $resultat[0])
		{
		  $kms = explode(";",$ligne["Km"]);
		}
		foreach ($kms as $kmk => $km)
		{
		  switch ($ligne['Type'])
		  {
			case "Texte":
		    $requette = "UPDATE service_vhc SET Duree = ".${"Duree".$kmk}." WHERE Id_vhc = $Id AND Nom = '$km'";
			break;
			default:
		    $requette = "UPDATE service_vhc SET Duree = ".${"Duree".$kmk}." WHERE Id_vhc = $Id AND Km = $km";
			break;
		  }
		  Connection::executeRawQuery($requette);
		}
		$requette = "SELECT service_action.Id FROM service_vhc, service_action WHERE service_vhc.Id_vhc = $Id AND service_action.Id_Service = service_vhc.Id";
		$resultat = Connection::executeRawQueryWithfetchAll($requette);
		foreach ($resultat as $ligne0 )
		{
		  $requette = "DELETE FROM service_action WHERE Id = ".$ligne0["Id"];
		  Connection::executeRawQuery($requette);
		}
		$requette2 = "SELECT action.* FROM vhc_action, action WHERE vhc_action.Id_vhc = $Id AND vhc_action.Id_action = action.Id ORDER BY action.Id_Rubrique, action.Position";
		$resultat2 = Connection::executeRawQueryWithfetchAll($requette2);
		foreach($resultat2 as $ligne2)
		{
		  $ats = explode(";",$ligne2["Id_Type"]);
		  if (count($ats)>1)
		  {
			foreach ($kms as $kmk => $km)
			{
			  switch ($ligne['Type'])
			  {
				case "Texte":
				$requette3="SELECT * FROM service_vhc WHERE Id_vhc = $Id AND Nom = '$km'";
				break;
				default:
				$requette3="SELECT * FROM service_vhc WHERE Id_vhc = $Id AND Km = $km";
				break;
			  }
			  $resultat3 = Connection::executeRawQueryWithfetchAll($requette3);
			  if ($ligne3 = $resultat3[0])
			  {
			    if (isset(${"ActionS".$kmk."A".$ligne2["Id"]}))
				{
				  if (isset(${"ActionTypeS".$kmk."A".$ligne2["Id"]}))
				  {
				    $requette4 = "INSERT INTO service_action (Id_Service, Id_Action, Id_Action_Type) VALUE ('".$ligne3["Id"]."', '".$ligne2["Id"]."', '".${"ActionTypeS".$kmk."A".$ligne2["Id"]}."')";
				    //echo $requette4."<BR />\n";
			        Connection::executeRawQuery($requette4);
				  }
				}
			  }
			}
		  }
		  else
		  {
		    foreach ($kms as $kmk => $km)
		    {
			  switch ($ligne['Type'])
			  {
				case "Texte":
				$requette3="SELECT * FROM service_vhc WHERE Id_vhc = $Id AND Nom = '$km'";
				break;
				default:
				$requette3="SELECT * FROM service_vhc WHERE Id_vhc = $Id AND Km = $km";
				break;
			  }
			  $resultat3 = Connection::executeRawQueryWithfetchAll($requette3);
			  if ($ligne3 = $resultat3[0])
			  {
			    if (isset(${"ActionS".$kmk."A".$ligne2["Id"]}))
				{
				  $requette4 = "INSERT INTO service_action (Id_Service, Id_Action, Id_Action_Type) VALUE ('".$ligne3["Id"]."', '".$ligne2["Id"]."', '".$ats[0]."')";
				  //echo $requette4."<BR />\n";
			      Connection::executeRawQuery($requette4);
				}
			  }
		    }
		  }
		}		
	  }
	  if ($ligne0 = ChassisModel::getChassisModelByNoChassis($Id))
	  {
	    /*switch($ligne0['Type_Service'])
		{
		  case "Texte":
	        $requette = "SELECT chassis_model.*, service_km.Km FROM chassis_model, service_km WHERE chassis_model.Id=$Id AND chassis_model.Id_Service = service_km.Id";
		  break;
		  default:
	        $requette = "SELECT chassis_model.*, service_km.Km FROM chassis_model, service_km WHERE chassis_model.Id=$Id AND chassis_model.Id_Km_Service = service_km.Id";
		  break;
	    }*/
	  $requette = "SELECT chassis_model.*, service_km.Km, service_km.Type FROM chassis_model, service_km WHERE chassis_model.Id=$Id AND chassis_model.Id_Service = service_km.Id";
	  $resultat = Connection::executeRawQueryWithfetchAll($requette);
	  if ($ligne = $resultat[0])
	  {
		echo "<script language='javascript'>\n";
		echo "function set_all_service_actions(id, ob)\n";
		echo "{\n";
		echo "  var cb = document.getElementsByTagName('input');\n";
		echo "  for(var i=0 ; i<cb.length ; ++i)\n";
		echo "  {\n";
		echo "    if (cb[i].id==('act'+id))\n";
		echo "    {\n";
		echo "      cb[i].checked=ob.checked;\n";
		echo "    }\n";
		echo "  }\n";
		echo "}\n";
		echo "</script>\n";
		echo "<TABLE border='1'><TR><TH>".$ligne["Chassis"]."</TH><TH>".$ligne["Marque"]."</TH><TH>".$ligne["Model"]."</TH></TR></TABLE>";
		Select_Etape_Service();
	    $kms = explode(";",$ligne["Km"]);
		$tmp_out="";
		foreach ($kms as $km)
		{
		  $tmp_out.="<TH>S$km</TH>";
		}
	    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='3'>\n";
	    echo "   <input type='hidden' name='Id' value='$Id'>\n";
	    echo "   <input type='hidden' name='Edit' value='1'>\n";
		
		echo "<TABLE border='1'><TR><TH>Nom</TH>$tmp_out<TH>Tous</TH></TR>\n";
		echo "<TR><TD>Duree</TD>";
		foreach ($kms as $kmk => $km)
		{
		  switch ($ligne['Type'])
		  {
		    case "Texte":
		    $requette2="SELECT * FROM service_vhc WHERE Id_vhc = $Id AND Nom = '$km'";
			break;
			default:
			$requette2="SELECT * FROM service_vhc WHERE Id_vhc = $Id AND Km = $km";
			break;
		  }
		  $resultat2=Connection::executeRawQueryWithfetchAll($requette2);
		  $ligne2=$resultat2[0];
		  echo "<TD><input type='text' value='".$ligne2["Duree"]."' name='Duree$kmk' size='3'></TD>";
		}
		echo "<TD>-</TD></TR>\n";
		$requette2 = "SELECT action.* FROM vhc_action, action WHERE vhc_action.Id_vhc = $Id AND vhc_action.Id_action = action.Id ORDER BY action.Id_Rubrique, action.Position";
		$resultat2 = VHCAction::getByIdVHC($Id);
		$last_rubrique = 0;
		foreach($resultat2 as $ligne2)
		{
		  if ($ligne2['Id_Rubrique']!=$last_rubrique)
		  {
		    if($ligne3 = ActionRubrique::getById($ligne2['Id_Rubrique']))
		    {
			  echo "<TR><TH colspan='".(count($kms)+2)."'>".$ligne3['Nom_Rubrique']."</TH></TR>\n";
			}
			$last_rubrique=$ligne2['Id_Rubrique'];
		  }
		  $ats = explode(";",$ligne2["Id_Type"]);
		  if (count($ats)>1)
		  {
		    echo "<TR><TD>";
			$first = true;
			foreach ($ats as $at)
			{
			  if ($ligne3 = ActionType::getById($at))
			  {
				if($first)
				{
				  $first = false;
				}
				else
				{
				  echo "<BR />";
				}
				echo $ligne3["Description"]." ".$ligne2["Texte"];
			  }
			}
			echo "</TD>";
			foreach ($kms as $kmk => $km)
			{
			  echo "<TD>$kmk";
			  $first = true;
			  foreach ($ats as $at)
			  {
			    if ($ligne3 = ActionType::getById($at))
			    {
				  if($first)
				  {
				    echo "<input type='radio' id='act".$ligne2["Id"]."O".$ligne3["Id"]."' name='ActionTypeS".$kmk."A".$ligne2["Id"]."' value='".$ligne3["Id"]."'";
				    switch ($ligne['Type'])
				    {
					  case "Texte":
					  $req = "SELECT service_action.* FROM service_vhc, service_action, action WHERE service_vhc.Id_vhc = $Id AND service_vhc.Nom = '$km' AND service_vhc.Id = service_action.Id_Service AND service_action.Id_Action = action.Id AND service_action.Id_Action = ".$ligne2["Id"]." ORDER BY action.Id_Rubrique, action.Position";
					  break;
					  default:
					  $req = "SELECT service_action.* FROM service_vhc, service_action, action WHERE service_vhc.Id_vhc = $Id AND service_vhc.Km = $km AND service_vhc.Id = service_action.Id_Service AND service_action.Id_Action = action.Id AND service_action.Id_Action = ".$ligne2["Id"]." ORDER BY action.Id_Rubrique, action.Position";
					  break;
				    }
					$res = Connection::executeRawQueryWithfetchAll($req);
					if ($lig = $res[0])
					{
					  if ($lig["Id_Action_Type"]==$ligne3["Id"])
					  {
					    echo " checked='1'";
					  }
					}
					echo " /><input type='checkbox' id='act".$ligne2["Id"]."' name='ActionS".$kmk."A".$ligne2["Id"]."'";
					if ($lig)
					{
					  echo " checked='1'";
					}
					echo " />";
					$first=false;
				  }
				  else
				  {
				    echo "<BR /><input type='radio' id='act".$ligne2["Id"]."O".$ligne3["Id"]."' name='ActionTypeS".$kmk."A".$ligne2["Id"]."' value='".$ligne3["Id"]."'";
				    switch ($ligne['Type'])
				    {
					  case "Texte":
					  $req = "SELECT service_action.* FROM service_vhc, service_action, action WHERE service_vhc.Id_vhc = $Id AND service_vhc.Nom = '$km' AND service_vhc.Id = service_action.Id_Service AND service_action.Id_Action = action.Id AND service_action.Id_Action = ".$ligne2["Id"]." ORDER BY action.Id_Rubrique, action.Position";
					  break;
					  default:
					  $req = "SELECT service_action.* FROM service_vhc, service_action, action WHERE service_vhc.Id_vhc = $Id AND service_vhc.Km = $km AND service_vhc.Id = service_action.Id_Service AND service_action.Id_Action = action.Id AND service_action.Id_Action = ".$ligne2["Id"]." ORDER BY action.Id_Rubrique, action.Position";
					  break;
				    }
					$res = Connection::executeRawQueryWithfetchAll($req);
					if ($lig = $res[0])
					{
					  if ($lig["Id_Action_Type"]==$ligne3["Id"])
					  {
					    echo " checked='1'";
					  }
					}
					echo " />";				  
				  }
				}
			  }
			  echo "</TD>";
			}
			echo "<TD>";
			$first = true;
			foreach ($ats as $at)
			{
			  if ($ligne3 = ActionType::getById($at))
			  {
				if($first)
				{
				  echo "<input type='radio' name='ActionTypeA".$ligne2["Id"]."' onclick='set_all_service_actions(\"".$ligne2["Id"]."O".$ligne3["Id"]."\", this);'><input type='checkbox' onclick='set_all_service_actions(".$ligne2["Id"].", this);'>";
				  $first = false;
				}
				else
				{
				  echo "<BR /><input type='radio' name='ActionTypeA".$ligne2["Id"]."' onclick='set_all_service_actions(\"".$ligne2["Id"]."O".$ligne3["Id"]."\", this);'>";
				}
			  }
			}
			echo "</TD></TR>\n";
		  }
		  else
		  {
			if ($ligne3 = ActionType::getById($ats[0]))
			{
			  echo "<TR><TD>".$ligne3["Description"]." ".$ligne2["Texte"]."</TD>";
			  foreach ($kms as $kmk => $km)
			  {
				echo "<TD><input type='checkbox' id='act".$ligne2["Id"]."' name='ActionS".$kmk."A".$ligne2["Id"]."'";
				switch ($ligne['Type'])
				{
				  case "Texte":
				  $req = "SELECT service_action.* FROM service_vhc, service_action, action WHERE service_vhc.Id_vhc = $Id AND service_vhc.Nom = '$km' AND service_vhc.Id = service_action.Id_Service AND service_action.Id_Action = action.Id AND service_action.Id_Action = ".$ligne2["Id"]." ORDER BY action.Id_Rubrique, action.Position";
				  break;
				  default:
				  $req = "SELECT service_action.* FROM service_vhc, service_action, action WHERE service_vhc.Id_vhc = $Id AND service_vhc.Km = $km AND service_vhc.Id = service_action.Id_Service AND service_action.Id_Action = action.Id AND service_action.Id_Action = ".$ligne2["Id"]." ORDER BY action.Id_Rubrique, action.Position";
				  break;
				}
				$res = Connection::executeRawQueryWithfetchAll($req);
				if ($lig = $res[0])
				{
				  echo " checked='1'";
				}
				echo " /></TD>";
			  }
			  echo "<TD><input type='checkbox' onclick='set_all_service_actions(".$ligne2["Id"].", this);'></TD></TR>\n";
			}
		  }
		}
		echo "</TABLE>\n";
        echo "   <button type='submit'>Modifier</button>\n";
        echo "  </form>\n";  
	  }
	  }
    break;
    case 4:
  	  if ($Edit==1)
  	  {
        $requette = "UPDATE chassis_model SET Chassis = '$NoChassis', Marque = '".Connection::getConnection()->quote($Marque)."', Model = '".Connection::getConnection()->quote($Model)."', Cylindree = '".Connection::getConnection()->quote($Cylindree)."', Homologation = '".Connection::getConnection()->quote($Homologation)."' WHERE Id = $Id";
        Connection::executeRawQuery($requette);
  	  }
  	  if ($ligne = ChassisModel::getChassisModelByNoChassis($Id))
  	  {
    		echo "<TABLE border='1'><TR><TH>".$ligne["Chassis"]."</TH><TH>".$ligne["Marque"]."</TH><TH>".$ligne["Model"]."</TH></TR></TABLE>";
    		Select_Etape_Service();
  	    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='4'>\n";
  	    echo "   <input type='hidden' name='Id' value='$Id'>\n";
  	    echo "   <input type='hidden' name='Edit' value='1'>\n";
    		echo "<TABLE border='1'>\n";
        echo "   <TR><TH>Début no chassis</TH><TD><input type='texte' name='NoChassis' value='".$ligne["Chassis"]."' onChange='AsChange=1;' /></TD></TR>\n";
        echo "   <TR><TH>Marque</TH><TD><input type='text' name='Marque' value='".$ligne["Marque"]."' onChange='AsChange=1;' /></TD></TR>\n";
        echo "   <TR><TH>Model</TH><TD><input type='text' name='Model' value='".$ligne["Model"]."' onChange='AsChange=1;' /></TD></TR>\n";
        echo "   <TR><TH>Cylindrée</TH><TD><input type='text' name='Cylindree' value='".$ligne["Cylindree"]."' onChange='AsChange=1;' /></TD></TR>\n";
        echo "   <TR><TH>Homologation</TH><TD><input type='text' name='Homologation' value='".$ligne["Homologation"]."' onChange='AsChange=1;' /></TD></TR>\n";
    		echo "</TABLE>\n";
        echo "   <button type='submit'>Modifier</button>\n";
        echo "  </form>\n";  
  	  }
    break;
    case 5:
  	  if ($Edit==1)
  	  {   // TODO revoir cette partie car pause problème pour l'historique
    	  if ($ligne = ChassisModel::getChassisModelByNoChassis($Id))
    	  {
          // On supprime tout ce qui existe dans le vehicule actuellement
          $resultat2 = ServiceVHC::getServiceVHCByID($Vhc_dest);
          foreach($resultat2 as $ligne2)
          {
            $requette2 = "DELETE FROM service_action WHERE Id_Service = ".$ligne2['Id'];
            Connection::executeRawQuery($requette2);
          }
          $requette2 = "DELETE FROM service_vhc WHERE Id_vhc = $Vhc_dest";
          Connection::executeRawQuery($requette2);
          $requette2 = "DELETE FROM vhc_action WHERE Id_vhc = $Vhc_dest";
          Connection::executeRawQuery($requette2);
          $requette2 = "DELETE FROM service_article WHERE Id_Vhc = $Vhc_dest";
          Connection::executeRawQuery($requette2);
		  $requette2 = "DELETE FROM vhc_option WHERE Id_vhc = $Vhc_dest";
          Connection::executeRawQuery($requette2);
		  $requette2 = "DELETE FROM vhc_option_action WHERE Id_vhc = $Vhc_dest";
          Connection::executeRawQuery($requette2);
		  $requette2 = "DELETE FROM service_option_article WHERE Id_Vhc = $Vhc_dest";
	      Connection::executeRawQuery($requette2);
		  $requette2 = "DELETE FROM vhc_option_action_remplacement WHERE Id_vhc = $Vhc_dest";
	      Connection::executeRawQuery($requette2);
          // On met à jour l'intervalle des services
          $requette2 = "UPDATE chassis_model SET Id_Service = '".$ligne["Id_Service"]."' WHERE Id = '$Vhc_dest'";
          Connection::executeRawQuery($requette2);
          // On copie toutes les données de service
          $resultat3 = ServiceVHC::getServiceVHCByID($Id);
          foreach($resultat3 as $ligne3)
          {
		    switch ($ligne["Type_Service"])
		    {
			  case "Texte":
                $requette4 = "INSERT INTO service_vhc (Id_vhc, Nom, Duree) VALUES ('$Vhc_dest', '".$ligne3["Nom"]."', '".$ligne3["Duree"]."')";
			  break;
			  default:
                $requette4 = "INSERT INTO service_vhc (Id_vhc, Km, Duree) VALUES ('$Vhc_dest', '".$ligne3["Km"]."', '".$ligne3["Duree"]."')";
			  break;
		    }
            Connection::executeRawQuery($requette4);
            $Id_service = Connection::getConnection()->lastInsertId();
            $requette5 = "SELECT service_action.* FROM service_action, action WHERE Id_Service = ".$ligne3["Id"]." AND service_action.Id_Action = action.Id ORDER BY action.Id_Rubrique, action.Position";
            $resultat5 = Connection::executeRawQueryWithfetchAll($requette5);
            foreach ($resultat5 as $ligne5)
            {
              $requette6 = "INSERT INTO service_action (Id_Service, Id_Action, Id_Action_Type) VALUES ('$Id_service', '".$ligne5["Id_Action"]."', '".$ligne5["Id_Action_Type"]."')";
              Connection::executeRawQuery($requette6);
            }
          }
          $requette3 = "SELECT * FROM service_article WHERE Id_Vhc = $Id";
          $resultat3 = Connection::executeRawQueryWithfetchAll($requette3);
          foreach($resultat3 as $ligne3)
          {
            $requette4 = "INSERT INTO service_article (Id_Vhc, Id_Action, NoArticle, Quantite) VALUES ('$Vhc_dest', '".$ligne3["Id_Action"]."', '".$ligne3["NoArticle"]."', '".$ligne3["Quantite"]."')";
            Connection::executeRawQuery($requette4);
          }
          $requette3 = "SELECT * FROM vhc_action WHERE Id_Vhc = $Id";
          $resultat3 = Connection::executeRawQueryWithfetchAll($requette3);
          foreach($resultat3 as $ligne3)
          {
            $requette4 = "INSERT INTO vhc_action (Id_vhc, Id_action) VALUES ('$Vhc_dest', '".$ligne3["Id_action"]."')";
            Connection::executeRawQuery($requette4);
          }
          $requette3 = "SELECT * FROM vhc_option WHERE Id_vhc = $Id";
          $resultat3 = Connection::executeRawQueryWithfetchAll($requette3);
          foreach($resultat3 as $ligne3)
          {
			$requette4 = "INSERT INTO vhc_option (Id_vhc, Id_option, Duree) VALUES ('$Vhc_dest', '".$ligne3["Id_option"]."', '".$ligne3["Duree"]."')";
            Connection::executeRawQuery($requette4);
          }
          $requette3 = "SELECT * FROM vhc_option_action WHERE Id_vhc = $Id";
          $resultat3 = Connection::executeRawQueryWithfetchAll($requette3);
          foreach($resultat3 as $ligne3)
          {
            $requette4 = "INSERT INTO vhc_option_action (Id_vhc, Id_option, Id_action) VALUES ('$Vhc_dest', '".$ligne3["Id_option"]."', '".$ligne3["Id_action"]."')";
            Connection::executeRawQuery($requette4);
          }
          $requette3 = "SELECT * FROM service_option_article WHERE Id_Vhc = $Id";
          $resultat3 = Connection::executeRawQueryWithfetchAll($requette3);
          foreach($resultat3 as $ligne3)
          {
		    $requette4 = "INSERT INTO service_option_article (Id_Vhc, Id_Action, NoArticle, Quantite) VALUES ('$Vhc_dest', '".$ligne3["Id_Action"]."', '".$ligne3["NoArticle"]."', '".$ligne3["Quantite"]."')";
            Connection::executeRawQuery($requette4);
          }
          $requette3 = "SELECT * FROM vhc_option_action_remplacement WHERE Id_vhc = $Id";
          $resultat3 = Connection::executeRawQueryWithfetchAll($requette3);
          foreach($resultat3 as $ligne3)
          {
		    $requette4 = "INSERT INTO vhc_option_action_remplacement (Id_vhc, Id_option, Id_action) VALUES ('$Vhc_dest', '".$ligne3["Id_option"]."', '".$ligne3["Id_action"]."')";
            Connection::executeRawQuery($requette4);
          }
        }
  	  }
  	  if ($ligne = ChassisModel::getChassisModelByNoChassis($Id))
  	  {
    		echo "<TABLE border='1'><TR><TH>".$ligne["Chassis"]."</TH><TH>".$ligne["Marque"]."</TH><TH>".$ligne["Model"]."</TH></TR></TABLE>";
    		Select_Etape_Service();
  	    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='5'>\n";
  	    echo "   <input type='hidden' name='Id' value='$Id'>\n";
  	    echo "   <input type='hidden' name='Edit' value='1'>\n";
    		echo "<TABLE border='1'>\n";
    	  $resultat2 = ChassisModel::getChassisModelNotById($$Id);
        echo "   <TR><TH>Model</TH><TD><select name='Vhc_dest'>";
    	  foreach($resultat2 as $ligne2)
    	  {
    		echo "<option value='".$ligne2["Id"]."'>".$ligne2["Chassis"]." ".$ligne2["Model"]."</option>";
    	  }
    	  echo "</TD></TR>\n";
    		echo "</TABLE>\n";
        echo "   <button type='submit'>Copier vers</button>\n";
        echo "  </form>\n";  
  	  }
    break;
    case 6:
  	  if ($Edit==1)
  	  {
		$requette = "DELETE FROM vhc_option WHERE Id_vhc = '$Id'";
		//echo $requette."<br/>";
	    Connection::executeRawQuery($requette);
		$postdata = file_get_contents("php://input");
		$pos1 = strpos($postdata, "action%5B%5D=");
		if ($pos1 !== FALSE)
		{
			$action = array();
		}
		while ($pos1 !== FALSE)
		{
			$pos2 = strpos($postdata, "&", $pos1);
			if ($pos2 !== FALSE)
			{
				$tmp_no = substr($postdata, $pos1 + 13, $pos2 - $pos1 - 13);
			}
			else
			{
				$tmp_no = substr($postdata, $pos1 + 13);
			}
			array_push($action, $tmp_no);
			$pos1 = strpos($postdata, "action%5B%5D=", $pos1 + 13);
		}
		foreach ($action as $act)
		{
		  $requette = "INSERT INTO vhc_option (Id_vhc, Id_option) VALUES ('$Id', '$act')";
		  //echo $requette."<br/>";
		  Connection::executeRawQuery($requette);
		}
  	  }
  	  if ($ligne = ChassisModel::getChassisModelByNoChassis($Id))
  	  {
    		echo "<TABLE border='1'><TR><TH>".$ligne["Chassis"]."</TH><TH>".$ligne["Marque"]."</TH><TH>".$ligne["Model"]."</TH></TR></TABLE>";
    		Select_Etape_Service();
  	    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='6'>\n";
  	    echo "   <input type='hidden' name='Id' value='$Id'>\n";
  	    echo "   <input type='hidden' name='Edit' value='1'>\n";
		$resultat3 = ServiceOption::getAll();
		echo "<TABLE border='1'><TR><TH>Nom</TH><TH>Action</TH></TR>\n";
		foreach($resultat3 as $ligne3)
		{
		  echo "<TR><TD>".$ligne3["Nom"]."</TD><TD><input name='action[]' type='checkbox' value='".$ligne3["Id"]."' onChange='AsChange=1;'";
		  if($ligne4 = VHCOptions::getByIdVHCAndIdOption($Id, $ligne3["Id"]))
		  {
		    echo " checked='1'";
		  }
		  echo "></TD></TR>\n";
		}
		echo "</TABLE>\n";
        echo "   <button type='submit'>Modifier</button>\n";
        echo "  </form>\n";  
  	  }
    break;
    case 7:
  	  if ($Edit==1)
  	  {
		$requette = "DELETE FROM vhc_option_action WHERE Id_vhc = '$Id'";
		//echo $requette."<br/>";
	    Connection::executeRawQuery($requette);
		$requette2 = "SELECT * FROM vhc_option WHERE Id_vhc = '$Id'";
		$resultat2 = VHCOptions::getByIdVHC($Id);
		foreach($resultat2 as $ligne2)
		{
		$requette = "UPDATE vhc_option SET Duree = ".${"Duree_option_".$ligne2["Id"]}." WHERE Id = ".$ligne2["Id"];
		echo $requette."<br/>";
		Connection::executeRawQuery ($requette);
		$postdata = file_get_contents("php://input");
		$numlen = strlen($ligne2["Id_option"]);
		$pos1 = strpos($postdata, "action".$ligne2["Id_option"]."%5B%5D=");
		if ($pos1 !== FALSE)
		{
			$action = array();
		
		while ($pos1 !== FALSE)
		{
			$pos2 = strpos($postdata, "&", $pos1);
			if ($pos2 !== FALSE)
			{
				$tmp_no = substr($postdata, $pos1 + 13 + $numlen, $pos2 - $pos1 - 13 - $numlen);
			}
			else
			{
				$tmp_no = substr($postdata, $pos1 + 13 + $numlen);
			}
			array_push($action, $tmp_no);
			$pos1 = strpos($postdata, "action".$ligne2["Id_option"]."%5B%5D=", $pos1 + 13 + $numlen);
		}
		foreach ($action as $act)
		{
		  $requette = "INSERT INTO vhc_option_action (Id_vhc, Id_option, Id_action) VALUES ('$Id', '".$ligne2["Id_option"]."', '$act')";
		  //echo $requette."<br/>";
		  Connection::executeRawQuery($requette);
		}
		}
		}
  	  }
  	  if ($ligne = ChassisModel::getChassisModelByNoChassis($Id))
  	  {
    		echo "<TABLE border='1'><TR><TH>".$ligne["Chassis"]."</TH><TH>".$ligne["Marque"]."</TH><TH>".$ligne["Model"]."</TH></TR></TABLE>";
    		Select_Etape_Service();
  	    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='7'>\n";
  	    echo "   <input type='hidden' name='Id' value='$Id'>\n";
  	    echo "   <input type='hidden' name='Edit' value='1'>\n";
		$requette2 = "SELECT service_option.Nom, service_option.Id, vhc_option.Duree, vhc_option.Id AS Id2 FROM vhc_option, service_option WHERE vhc_option.Id_vhc = $Id AND vhc_option.Id_option = service_option.Id";
		$resultat2 = Connection::executeRawQueryWithfetchAll($requette2);
		$nb_options = count($resultat2);
		$nb_cols = $nb_options + 1;
		echo "<TABLE border='1'><TR><TH>Action</TH>";
		foreach($resultat2 as $ligne2)
		{
		  echo "<TH>".$ligne2["Nom"]."</TH>";
        }		
		echo "</TR>\n";
		$resultat2 = Connection::executeRawQueryWithfetchAll($requette2);
		echo "<TR><TD>Duree</TD>";
		foreach($resultat2 as $ligne2)
		{
		  //$requette3 = "SELECT * FROM vhc_option WHERE Id_vhc = $Id AND Id_Option = ".$ligne2["Id"];
		  //$resultat3 = mysql_query($requette3);
		  echo "<TD><input type=\"text\" name=\"Duree_option_".$ligne2["Id2"]."\" value=\"".$ligne2["Duree"]."\" size=\"3\"/></TD>";
        }		
		echo "</TR>\n";
		$resultat3 = Action::getActionActionType();
		$last_rubrique = 0;
		foreach($resultat3 as $ligne3)
		{
		  if ($ligne3['Id_Rubrique']!=$last_rubrique)
		  {
		    if($ligne4 = ActionRubrique::getById($ligne3['Id_Rubrique']))
		    {
			  echo "<TR><TH colspan='".$nb_cols."'>".$ligne4['Nom_Rubrique']."</TH></TR>\n";
			}
			$last_rubrique=$ligne3['Id_Rubrique'];
		  }
		  echo "<TR><TD>".$ligne3["Description"]." ".$ligne3["Texte"]."</TD>"; //<TD>";
		  $resultat2 = Connection::executeRawQueryWithfetchAll($requette2);
		  foreach($resultat2 as $ligne2)
		  {
		    echo "<TD><input name='action".$ligne2["Id"]."[]' type='checkbox' value='".$ligne3["Id"]."' onChange='AsChange=1;'";
			$requette4 = "SELECT * FROM vhc_option_action WHERE Id_vhc = '$Id' AND Id_option = ".$ligne2["Id"]." AND Id_action = '".$ligne3["Id"]."'";
		    $resultat4 = Connection::executeRawQueryWithfetchAll($requette4);
		    if($ligne4 = $resultat4[0])
		    {
		      echo " checked='1'";
		    }
			echo "></TD>";
          }		
		  echo "</TR>\n";
		}
		echo "</TABLE>\n";
        echo "   <button type='submit'>Modifier</button>\n";
        echo "  </form>\n";  
  	  }
    break;
    case 8:
  	  if ($Edit==1)
  	  {
		$requette = "DELETE FROM service_option_article WHERE Id_Vhc = '$Id'";
	    Connection::executeRawQuery($requette);
		$requette2 = "SELECT DISTINCT action.* FROM vhc_option_action, action, action_type WHERE vhc_option_action.Id_vhc = $Id AND vhc_option_action.Id_action = action.Id AND action.Id_Type = action_type.Id AND action_type.Avec_Article = 1";
		$resultat2 =  Connection::executeRawQueryWithfetchAll($requette2);
		foreach($resultat2 as $ligne2)
		{
		  $act = $ligne2["Id"];
		  $requette = "INSERT INTO service_option_article (Id_Vhc, Id_Action, NoArticle, Quantite) VALUES ('$Id', '$act', '".${"NoArticle".$act}."', '".${"Quantite".$act}."')";
		  //echo $requette."<BR />\n";
		  Connection::executeRawQuery($requette);
		}
  	  }
  	  if ($ligne = ChassisModel::getChassisModelByNoChassis($Id))
  	  {
    		echo "<TABLE border='1'><TR><TH>".$ligne["Chassis"]."</TH><TH>".$ligne["Marque"]."</TH><TH>".$ligne["Model"]."</TH></TR></TABLE>";
    		Select_Etape_Service();
  	    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='8'>\n";
  	    echo "   <input type='hidden' name='Id' value='$Id'>\n";
  	    echo "   <input type='hidden' name='Edit' value='1'>\n";
		$requette2 = "SELECT DISTINCT action.* FROM vhc_option_action, action, action_type WHERE vhc_option_action.Id_vhc = $Id AND vhc_option_action.Id_action = action.Id AND action.Id_Type = action_type.Id AND action_type.Avec_Article = 1";
		$resultat2 =  Connection::executeRawQueryWithfetchAll($requette2);
		echo "<TABLE border='1'><TR><TH>Action</TH><TH>NoArticle</TH><TH>Quantite</TH></TR>\n";
		foreach($resultat2 as $ligne2)
		{
		  $requette3 = "SELECT * FROM service_option_article WHERE Id_Vhc = $Id AND Id_Action = ".$ligne2["Id"];
		  $resultat3 =  Connection::executeRawQueryWithfetchAll($requette3);
		  echo "<TR><TD>".$ligne2["Texte"]."</TD><TD><input type='text' name='NoArticle".$ligne2["Id"]."' onChange='AsChange=1;'";
		  if ($ligne3 = $resultat3[0])
		  {
			echo " value='".$ligne3["NoArticle"]."'";
		  }
		  echo " /></TD><TD><input type='text' name='Quantite".$ligne2["Id"]."' onChange='AsChange=1;'";
		  if ($ligne3)
		  {
			echo " value='".$ligne3["Quantite"]."'";
		  }
		  echo " /></TD></TR>\n";
		}
		echo "</TABLE>\n";
        echo "   <button type='submit'>Modifier</button>\n";
        echo "  </form>\n";  
  	  }
    break;
    case 9:
  	  if ($Edit==1)
  	  {
		$requette = "DELETE FROM vhc_option_action_remplacement WHERE Id_vhc = '$Id'";
		//echo $requette."<br/>";
	    Connection::executeRawQuery($requette);
		$resultat2 = VHCOptions::getByIdVHC($Id);
		foreach($resultat2 as $ligne2)
		{
		$action = array();
		$postdata = file_get_contents("php://input");
		$numlen = strlen($ligne2["Id_option"]);
		$pos1 = strpos($postdata, "action".$ligne2["Id_option"]."%5B%5D=");
		while ($pos1 !== FALSE)
		{
			$pos2 = strpos($postdata, "&", $pos1);
			if ($pos2 !== FALSE)
			{
				$tmp_no = substr($postdata, $pos1 + 13 + $numlen, $pos2 - $pos1 - 13 - $numlen);
			}
			else
			{
				$tmp_no = substr($postdata, $pos1 + 13 + $numlen);
			}
			array_push($action, $tmp_no);
			$pos1 = strpos($postdata, "action".$ligne2["Id_option"]."%5B%5D=", $pos1 + 13 + $numlen);
		}
		foreach ($action as $act)
		{
		  $requette = "INSERT INTO vhc_option_action_remplacement (Id_vhc, Id_option, Id_action) VALUES ('$Id', '".$ligne2["Id_option"]."', '$act')";
		  //echo $requette."<br/>";
		  Connection::executeRawQuery($requette);
		}
		}
  	  }
  	  if ($ligne = ChassisModel::getChassisModelByNoChassis($Id))
  	  {
    		echo "<TABLE border='1'><TR><TH>".$ligne["Chassis"]."</TH><TH>".$ligne["Marque"]."</TH><TH>".$ligne["Model"]."</TH></TR></TABLE>";
    		Select_Etape_Service();
  	    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='9'>\n";
  	    echo "   <input type='hidden' name='Id' value='$Id'>\n";
  	    echo "   <input type='hidden' name='Edit' value='1'>\n";
		$requette2 = "SELECT service_option.Nom, service_option.Id FROM vhc_option, service_option WHERE vhc_option.Id_vhc = $Id AND vhc_option.Id_option = service_option.Id";
		$resultat2 = Connection::executeRawQueryWithfetchAll($requette2);
		$nb_options = count($resultat2);
		$nb_cols = $nb_options + 1;
		echo "<TABLE border='1'><TR><TH>Action</TH>";
		foreach($resultat2 as $ligne2)
		{
		  echo "<TH>".$ligne2["Nom"]."</TH>";
        }		
		echo "</TR>\n";
		$requette3 = "SELECT DISTINCT action.Id, action.Texte, action_type.Description, action.Id_Rubrique FROM action, action_type, vhc_action WHERE action.Id = vhc_action.Id_Action AND action.Id_Type = action_type.Id ORDER BY action.Id_Rubrique, action.Position";
		//$requette3 = "SELECT action.Id, action.Texte, action_type.Description, action.Id_Rubrique FROM action, action_type WHERE action.Id_Type = action_type.Id ORDER BY action.Id_Rubrique, action.Position";
		$resultat3 =  Connection::executeRawQueryWithfetchAll($requette3);
		$last_rubrique = 0;
		foreach($resultat3 as $ligne3)
		{
		  if ($ligne3['Id_Rubrique']!=$last_rubrique)
		  {
		    if($ligne4 = ActionRubrique::getById($ligne3['Id_Rubrique']))
		    {
			  echo "<TR><TH colspan='".$nb_cols."'>".$ligne4['Nom_Rubrique']."</TH></TR>\n";
			}
			$last_rubrique=$ligne3['Id_Rubrique'];
		  }
		  echo "<TR><TD>".$ligne3["Description"]." ".$ligne3["Texte"]."</TD>"; //<TD>";
		  $resultat2 =  Connection::executeRawQueryWithfetchAll($requette2);
		  foreach($resultat2 as $ligne2)
		  {
		    echo "<TD><input name='action".$ligne2["Id"]."[]' type='checkbox' value='".$ligne3["Id"]."' onChange='AsChange=1;'";
			$requette4 = "SELECT * FROM vhc_option_action_remplacement WHERE Id_vhc = '$Id' AND Id_option = ".$ligne2["Id"]." AND Id_action = '".$ligne3["Id"]."'";
		    $resultat4 =  Connection::executeRawQueryWithfetchAll($requette4);
		    if($ligne4 = $resultat4[0])
		    {
		      echo " checked='1'";
		    }
			echo "></TD>";
          }		
		  echo "</TR>\n";
		}
		echo "</TABLE>\n";
        echo "   <button type='submit'>Modifier</button>\n";
        echo "  </form>\n";  
  	  }
    break;
  }
?>
