<?php
if (isset($lesUsers) && is_array($lesUsers)) {
?>
<div class="home">
          
          <div>
              <br /><br />
              <?php
              echo '<div id="Titles">Utilisateur connecté : '.$_SESSION['ident']."</div><br />";
                ?>
                <form id="connexion" method = "POST" action="index.php?uc=gestion&action=user&role=ajouter">Ajouter un utilisateur <input type="submit" class="btn btn-info connectbt" value="+"></form>
                <br><br>
                <?php
                echo 'Afficher les utilisateurs<br /><br>' ;
                        $cpt=0 ;
                        foreach ($lesUsers as $leUser) {
                                //entête tableau 
                                if ($cpt==0)
                                {
                                echo '<div id="list_paiements"><table><tr>'
                                        . '<th>Nom</th>'
                                        . '<th>Prénom</th>'
                                        . '<th>Classe</th>'  
                                        . '<th>Login</th>' 
                                        . '<th>Statut</th>'                                          
                                        . '</tr>' ;
                                }
                                
                                echo '<tr>';

                                if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'user' && isset($_REQUEST['role']) && $_REQUEST['role'] == 'modifier' && isset($_REQUEST['id']) && $_REQUEST['id'] == $leUser['id']){
                                echo'<form method="POST" action="index.php?uc=gestion&action=user&role=valideModification"> <input type="hidden" name="idUtilisateur" value="'.$leUser['id'].'">
                                                <td> <input type="text" name="nouveauNom" placeHolder="'.$leUser['nom'].'"></td>
                                               <td> <input type="text" name="nouveauPrenom" placeHolder="'.$leUser['prenom'].'"> </td>
                                               <td> <input type="text" name="nouvelleClasse" placeHolder="'.$leUser['idClasse'].'"> </td>
                                               <td> <input type="text" name="nouveauLogin" placeHolder="'.$leUser['login'].'"> </td>
                                               <td> <input type="text" name="nouveauStatut" placeHolder="'.$leUser['statut'].'"> </td>
                                                <td> <input type="submit" class="btn btn-info connectbt" value="valider"> </td>
                                        
                                </form></tr>';
                                }       
                                else{
                        echo'<tr><td>'.$leUser['nom'].'</td>'
                        . '<td>'.$leUser['prenom'].'</td>'
                        . '<td>BTS'.$leUser['idClasse'].'</td>'
                        . '<td>BTS'.$leUser['login'].'</td>'
                        . '<td>BTS'.$leUser['statut'].'</td>'
                        . '<td> <br> <form method="POST" action="index.php?uc=gestion&action=user&role=modifier&id='.$leUser['id'].'"><input type="hidden" name="id" value="'.$leUser['id'].'"> <input type="submit" class="btn btn-info connectbt" value="modifier"></form><br></td>'
                        . '<td> <br> <form method="POST" action="index.php?uc=gestion&action=user&role=supprimer"><input type="hidden" name="id" value="'.$leUser['id'].'"> <input type="submit" class="btn btn-info connectbt" value="supprimer"></form><br></td>'

                        . '</tr>' ;
                                }
                        $cpt++;
                
                        }
                        echo '</table></div></div>' ;
                }
                ?>
        </div>
</div>
