<?php
  switch($Etape)
  {
    case 0:
      if ($resultat = User::getAll())
      {
        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='user'>\n";
        foreach($resultat as $ligne)
        {
          echo "    <option value='" . $ligne['Nom'] . "'>" . $ligne['Nom'] . "</option>\n";
        }
        echo "   </select><BR>\n";
        echo "   <button type='submit'>Suite</button>\n";
        echo "  </form>\n";
      }
    break;
    case 1:
      if ($resultat = User::getByNom($user))
      {
        if($ligne = $resultat[0])
        {
          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='2'>\n";
          echo "   <input type='hidden' name='user' value='$user'>\n";
          echo "<TABLE border=1>\n";
          echo "   <TR><TH>Nom</TH><TD><input type='texte' name='Nom' value='" . $ligne['Nom'] . "'></TD></TR>\n";
          echo "   <TR><TH>Password</TH><TD><input type='password' name='Password'></TD></TR>\n";
          echo "   <TR><TH>Groupe</TH><TD><SELECT name='nogroupeusers'>\n";
          if ($resultat2 = GroupeUsers::getAll())
          {
            foreach($resultat2 as $ligne2)
            {
              echo "<OPTION value='".$ligne2['NoGroupeUsers']."'";
              if ($ligne['NoGroupeUsers']==$ligne2['NoGroupeUsers'])
              {
                echo " SELECTED";
              }
              echo ">".$ligne2['Description']."</OPTION>\n";
            }
          }
          echo "   </SELECT></TD></TR>\n";
          echo "</TABLE>\n";
          echo "   <button type='submit'>Modifier</button>\n";
          echo "  </form>\n";
        }
      }
    break;
    case 2:
      $requette = "UPDATE users SET Nom='$Nom', NoGroupeUsers='$nogroupeusers'";
      if (strlen($Password) != 0) $requette .= ", Password='".md5($Password)."'"; 
      $requette .= " WHERE Nom='$user'";
      if ($resultat = Connection::executeRawQuery($requette))
      {
        echo "OK";
      }
    break;
  }
?>
