<!doctype html>
<html lang=fr>
	<?php											
		session_start();
		if (!isset($_SESSION['Autorisation']) or ($_SESSION['Autorisation'] != 1))
		{
		header("Location: index.php");
		exit();
		} 
	?>
	<head>
		<title>Situation pro</title>
		<meta charset=utf-8> <meta name=viewport content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="nogstyle.css">

	</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><!-- Start of the  page content. -->
			<h2>Ensemble des Situations Professionnelles</h2>	
			<form action="prof_toutesles_sp.php" method="post">
				<label class="label1" for="Nom">Session </label>
					<select name="Session" >
						<option value="-1"> Toutes
						<?php
							$annee=intval(date('Y'));
							for ($i = $annee -2; $i<= $annee+2 ; $i++)
							{
								echo '<option value="' . $i . '"';
								echo ">" . $i . "</option>";
							}
						?>
					</select>
					<input id="submit" type="submit" name="submit" value="Selection">
			</form>
			<br/>
			
			<?php
				$_SESSION['sessionex'] =-1;
				if ($_SERVER['REQUEST_METHOD'] == 'POST')
				{
					$_SESSION['sessionex'] = $_POST['Session'];
				}
				elseif($_SERVER['REQUEST_METHOD'] == 'GET')
				{
					if (isset($_GET['id']))
					$_SESSION['sessionex'] = $_GET['id'];
				}
				
				if($_SESSION['sessionex']==-1)
				{
					$restriction='';
				}
				else
				{
					$restriction= 'AND SessionExam=' .$_SESSION['sessionex'].' ';
				}	
					
				echo'	<p><i>
								Clic sur une SP --> accès à la SP
								<font color="red">(<b>Rouge</b>: SP non validées) </font><font color="green">(<b>Vert</b> : SP validées)</font>
								<br/>Clic sur le nom de l\'étudiant" --> accès au Passeport Professionnel de l\'étudiant(seules les SP validées apparaissent)
							</i></p>';
					
				/////////////////////////////////////////////////-->
				// This script retrieves records from the users table.
				require ('connect/mysqli_connect.php'); // Connect to the db.
				//REQUETE de ltoutes les SP
				$q1 = 'SELECT Numsp,IdentificationSP,Intitulesp,ValideSP, numEt 
				       FROM situationpro  ORDER BY numEt, IdentificationSP;';	
				$result1 = mysqli_query ($dbcon, $q1)or die(mysqli_error($dbcon));
				$nb_ligneSP = mysqli_num_rows($result1); //compte le nombre de lignes
				
				
				
				// REQUETE  Etudiants D'UN 1TABLISSEMENT
				$q2 ='SELECT Numact,NomAct,SessionExam FROM acteur WHERE codeEtablissement="'.$_SESSION['CodeEtab'].'" AND Autorisation=0 '. $restriction.' ORDER BY NomAct;';
				$result2 = mysqli_query ($dbcon, $q2);
				if(empty($q2))
				{
					echo '0 enregistrements retournés';
				}
					else
				{ 
					$nb_ligneEt=mysqli_num_rows($result2);
				}
				
				// tableau des SP
				$tabSP = [];
				$i=1;
				while ($row = mysqli_fetch_array($result1, MYSQLI_ASSOC))
				{
					$tabSP[$i]=$row;
					$i++;
		    	}
				
				// tableau des Etudiants
				$tabET = [];
				$i=1;
				while ($row = mysqli_fetch_array($result2, MYSQLI_ASSOC))
				{
					$tabET[$i] = $row;	
					$i++;
		    	}
				
				
				echo '<table>';
				// On génére le tableau ETudiant/SP	
				echo'<tr><th style="width:10%">Etudiant</th><th style="width:3%"></th>';
					for ($i=1;$i<=12;$i++)
					{
						echo '<th style="width:7%">'.$i.'</th>';
					}
				echo'</tr>';

				// On génére le tableau ETudiant/SP	
				for ($i=1;$i<=$nb_ligneEt;$i++)
				{
					//$colSP=3; //dans le tableau TabEt le 1er champ pour les SP est le  3eme
					echo '</tr>
							<tr>
							<td><b><a href="pass_pro.php?id='.$tabET[$i]['Numact']. '">'. $tabET[$i]['NomAct'] . '</b></a></td>';	
					echo '<td style="width:3%">'.$tabET[$i]['SessionExam'].'</td>';
					for ($j=1;$j<=$nb_ligneSP;$j++)
					{
						if($tabET[$i]['Numact']== $tabSP[$j]['numEt']) // Si le num Etudiant est trouvé dans les SP
						{
							echo ' <td style="width:7%">'; 
							if ($tabSP[$j]['ValideSP']=="Non")
							{
								echo' <a style="color:red;font-size:80%;"';
							}
							else 
							{
								echo' <a style="color:green; font-size:80%;"';
							}
							 echo' href="sp_modif.php?id='.$tabSP[$j]['Numsp']. '">'
							     .substr($tabSP[$j]['Intitulesp'],0,25).'</a> </td>';
//								$colSP++;
						}
					}
				}
				echo'</table>';
				mysqli_free_result ($result1); // Free up the resources.	
				mysqli_close($dbcon); // Close the database connection.	
			?>
			
			<br/>
			
			
		</article>			
		<footer>
			<?php include ('includes/footer.inc'); ?>
		</footer>
	</body>
</html>