<!doctype html>
<html lang=fr>

	<?php	
		session_start(); // On récupére les données de la session
		if (!isset($_SESSION['Autorisation']) or ($_SESSION['Autorisation'] != 1) )
		{
		header("Location: index.php"); // Si l'acteur de la session n'est pas un prof on retourne à l'accueil'
		exit();
		}
	?>
	
	<head>
		<title>Validation inscription Etudiant</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 content for the delete page -->
			<h2>Validation inscription Etudiant</h2>
			<?php 
				// Check for a valid user ID, through GET or POST:
				if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) 
				{ 	// From prof liste etudiant.php
					$id = $_GET['id'];
				}
				elseif( (isset($_POST['id'])) && (is_numeric($_POST['id'])) )
				{ // id issu du formulaire.
					$id = $_POST['id'];
				}
				else 
				{ // If no valid ID, stop the script.
					echo '<p class="error">This page has been accessed in error.</p>';
					exit();
				}
				
				require ('connect/mysqli_connect.php');
				// Check if the form has been submitted:
				if ($_SERVER['REQUEST_METHOD'] == 'POST') {
					if ($_POST['sure'] == 'Oui')
					{ // on met à jour l'autorisation de 99 à 0
						$q = "UPDATE acteur SET Autorisation=0 WHERE NumAct='$id'";
						$result = @mysqli_query ($dbcon, $q);
						if (mysqli_affected_rows($dbcon) == 1) 
						{// If it ran OK
							 echo'<h3>Mise à jour effectuée
								<a class="bouton10" href="prof_valid_temp.php"?>OK</a>
								</h3>';
						}
						else
						{ // If the query did not run OK.
							echo '<p class="error">The record could not be deleted.<br>Probably because it does not exist or due to a system error.</p>'; // Public message.
							echo '<p>' . mysqli_error($dbcon ) . '<br />Query: ' . $q . '</p>'; // Debugging message.
						}
					} 
					else 
					{ 	// No confirmation of deletion.
						echo '<h3>Annulation de l\'inscription
									<a class="bouton10" href="prof_valid_temp.php"?>OK</a>
								</h3>';	
					}
				} 
				else 
				{ // Show the form.
					// Retrieve the user's information:
					$q = "SELECT CONCAT(NomAct, ' ',PrenomAct) FROM acteur WHERE NumAct=$id";
					$result = @mysqli_query ($dbcon , $q);
					if (mysqli_num_rows($result) == 1)
					{ // Valid user ID, show the form.
						// Get the user's information:
						$row = mysqli_fetch_array ($result, MYSQLI_NUM);
						// Display the record being deleted:
						echo "<h3>INSCRIRE $row[0]?</h3>";
						// Create the form:
						echo '<form action="prof_valid_temp_ok.php" method="post">
						<p class="centre">
							<br/>
							<input id="submit-yes" type="submit" name="sure" value="Oui"> 
							<input id="submit-no" type="submit" name="sure" value="Non">					
							<input type="hidden" name="id" value="' . $id . '">
							<br/>
						</p>
						</form>';
					} 
					else
					{ // Not a valid user ID.
						echo '<p class="error">This page has been accessed in error.</p>';
						echo '<p>&nbsp;</p>';
					}
				} // End of the main submission conditional.
				mysqli_close($dbcon );
				echo '<p>&nbsp;</p>';
			?>
	</article>
	<footer>
		<?php include ('includes/footer.inc'); ?>
	</footer>
	</body>
</html>