<?php
  switch($Etape)
  {
    case 0:
      if ($resultat = Employee::getEmployee())
      {
        echo "  <form>\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='NoClient'>\n";
        foreach($resultat as $ligne)
        {
          $ligne2 = Client::getClientByNoClient($ligne['NoClient']);
          echo "    <option value='" . $ligne['NoClient'] . "'>" . $ligne2['Nom']. " " . $ligne2['Prenom']. "</option>\n";
        }
        echo "   </select><BR>\n";
        echo "   <button type='submit'>Modifier</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='NoClient' value=$NoClient>\n";
      echo "   <input type='hidden' name='Etape' value='2'>\n";
      echo "<TABLE border=1>\n";
      $ligne = Client::getClientByNoClient($NoClient);
      echo "   <TR><TH>Employé</TH><TD>".$ligne['Nom']." ".$ligne['Prenom']."</TD></TR>\n";
      $ligne = Employee::getEmployeeByClient($NoClient)[0];
      echo "   <TR><TH>Heures atelier</TH><TD><input type='text' name='Heure' value='".$ligne['HeureAtelier']."'></TD></TR>\n";
      echo "   <TR><TH>Articles atelier</TH><TD><input type='text' size='32' name='ArticlesAtelier' value='".$ligne['ArticlesAtelier']."'></TD></TR>\n";
      echo "   <TR><TH>Article dépannage</TH><TD><input type='text' name='ArticleDepannage' value='".$ligne['ArticleDepannage']."'></TD></TR>\n";
      echo "   <TR><TH>Actif</TH><TD><input type='checkbox' name='Actif' value='1'";
      if ($ligne["Actif"]==1)
        echo " checked";
      echo "></TD></TR>\n";
      echo "</TABLE>\n";
      echo "   <button type='submit'>Valider</button>\n";
      echo "  </form>\n";
    break;
    case 2:
      $requette = "UPDATE employes".ID_GARAGE." SET HeureAtelier='$Heure', Actif=";
      if (isset($Actif))
      {
        $requette .= "1";
      }
      else
      {
        $requette .= "0";
      }
      $requette .= ", ArticlesAtelier = '$ArticlesAtelier', ArticleDepannage = '$ArticleDepannage'";
      $requette .= " WHERE NoClient=$NoClient";
      if ($resultat = Connection::executeRawQuery($requette))
      {
        echo "OK";
      }
    break;
  }
?>
