<!doctype html>
<?php
	session_start();
	if (!isset($_SESSION['Autorisation']) or ($_SESSION['Autorisation'] != 1))  //prof 
	{
		echo 'page atteinte par erreur';
		header("Location: index.php");
  		exit();
	}
?>

<html lang=fr>
	<head>
		<title>Liste des étudiants</title>
		<meta charset=utf-8> <meta name=viewport content="width=device-width, initial-scale=1">
		<link rel="stylesheet"  href="nogstyle.css">		
		
		<style type="text/css">

		   #left {
				float:left;
				width:140px;
				height:50px;
				margin-left:0px;
			}
			
			#right {
				float:left;
				width:200px;
				height:50px;
			}
			
		</style>
	</head>

	<body>
		<header>
			<?php include('includes/header_simple.inc'); 
			echo'<h3>'.$_SESSION['PrenomAct'].' '.$_SESSION['NomAct'].' '.$_SESSION['NomEtab'].'</h3>';
			include('includes/menu_prof.inc'); ?>
		</header>
		
		<article>
			<h2>Liste des étudiants</h2>
			<form class="centre40" action="prof_listeetudiants.php" method="post">
				<p>
					<label class="label1" for="Nom">Session </label>
					<select name="Session" >
						<option value="-1"> Toutes
				 		<?php
				 			$annee=intval(date('Y'));
					  		for ($i = $annee -1; $i<= $annee+2 ; $i++)
							{
								echo '<option value="' . $i . '"';
								echo ">" . $i . "</option>";
							}
				 		?>
					</select>
				
				
				
						<td><input id="submit" type="submit" name="submit" value="Sélection">
				</p>				
			</form>	
					
			<?php 
				if ($_SERVER['REQUEST_METHOD'] == 'POST')
				{
					$sessionex = $_POST['Session'];
					
					if($sessionex==-1)
					{
						$restriction='';
					}
					else
					{
						$restriction= 'AND SessionExam=' .$sessionex.' ';
					}
					// This script retrieves records from the users table.
					require ('connect/mysqli_connect.php'); // Connect to the db.
					$q = "SELECT * FROM acteur WHERE Autorisation=0 AND codeEtablissement='".$_SESSION['CodeEtab']."' ". $restriction."ORDER BY NomAct;";	
					$result = mysqli_query ($dbcon, $q); 
					
					if ($result)
					{		   // If it ran, display the records.
						$nbrelignes = mysqli_num_rows($result);
						// Table header.
						echo '<table>
						<tr>
						<th><b>Nom</b></th>
						<th><b>Prénom</b></th>
						<th><b>Etablissement</b></th>
						<th><b>Date naissance</b></th>
						<th><b>Session exam</b></th>
						<th><b>Modif.</b></th>
						<th><b>Suppr.</b></th>
						</tr>';
						
						// Fetch and display the records:
						while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
						{
							echo '<tr>
							<td>' . $row['NomAct'] . '</td>
							<td>' . $row['PrenomAct'] . '</td>
							<td>' . $row['codeEtablissement'] . '</td>
							<td>' . $row['datenaissAct'] . '</td>
							<td>' . $row['SessionExam'] . '</td>
							<td><a class="bouton" href="prof_modif_etud.php?id='. $row['NumAct'] . '"><span class="iconic">p</span></a></td>	
							<td><a class="bouton" href="prof_supr_etud.php?id='. $row['NumAct'] . '"><span class="iconic">x</span></a></td>								
							</tr>';
							
						}
						echo '</table>'; // Close the table.
						echo '<p class="centre40"><b>'.$nbrelignes .' étudiants enregitrés </b></p>';
						mysqli_free_result ($result); // Free up the resources.
					}
					 else 
					 { // If it did not run OK.// Public message:
					
						echo '<p class="error">The current users could not be retrieved. We apologize for any inconvenience.</p>';
						// Debugging message:
						echo '<p>' . mysqli_error($dbcon) . '<br><br>Query: ' . $q . '</p>';
					}
					mysqli_close($dbcon); // Close the database connection.
				}
			?>	
			<p style="text-align: center">
				<br/>
				<a class="bouton10"  href="xx_ajout_acteur.php?">Ajouter un étudiant</a>
				<br/>
			</p>		
		</article>	
		<footer>
		<?php include ('includes/footer.inc'); ?>
	</footer>
	</body>
</html>