<!doctype html>
<html lang=fr>

	<?php									
		session_start(); // On récupére les données de la seession
		if (!isset($_SESSION['Autorisation']) or ($_SESSION['Autorisation'] != 0) )
		{
			header("Location: index.php"); // Si l'acteur de la session n'est pas un étudiant on retourne à l'accueil'
			exit();
		}
	?>

	<head>
		<title>Supprimer une situation professionnelle</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">
			p { text-align:center; }
			form { text-align:center;}
			input.fl-left { float:left;}
			#submit-yes { float:left; margin-left:220px;}
			#submit-no { float:left; margin-left:20px; }
			</style>
			
			-->
	</head>
	
	<body>
	
		<header>
			<?php
				include('includes/header_simple.inc'); 
				echo'<h3>'.$_SESSION['PrenomAct'].' '.$_SESSION['NomAct'].'&nbsp;-&nbsp; '.$_SESSION['NomEtab'].'</h3>';
				include('includes/menu_etudiant.inc');
			 ?>
		</header>
			
		<article><!-- Start of content for the delete page -->
			<h2>Supprimer une situation professionnelle</h2>
			<?php 
				// On verifie la validité du num de la SP à supprimer
				if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) 
				{
					$numsp=$_GET['id'];
				}
				elseif (isset($_POST['id']) && (is_numeric($_POST['id'])))
				{ // Form submission.
					$numsp = $_POST['id'];
				}
				else
				{ // If no valid ID, stop the script.
					echo '<p class="error">SP non valide.</p>';
					//exit();
				}
				require ('connect/mysqli_connect.php');
				// Check if the form has been submitted:
				if ($_SERVER['REQUEST_METHOD'] == 'POST')
				{
					if ($_POST['sure'] == 'Oui') 
					{ // Delete the record.
						// Make the query:
						$q = "DELETE FROM situationpro WHERE NumSP=$numsp;";
						$result = @mysqli_query ($dbcon, $q)or exit('Erreur SQL ! '.$q. '<br />'.mysql_error($dbcon));	
						if (mysqli_affected_rows($dbcon ) == 1) 
						{ // If it ran OK.
							// Print a message:
							echo '<h3>La situation professionnelle a été détruite.</h3>';	
							header("Location: sp_liste.php?");		
						} 
						else 
						{ 	// If the query did not run OK.
							echo '<p class="error">L\'enrerigistrment ne peut être détruit.<br> Il n\'existe pas </p>'; // Public message.
							echo '<p>' . mysqli_error($dbcon ) . '<br />Query: ' . $q . '</p>'; // Debugging message.
						}
					}
					else 
					{		 // No confirmation of deletion.
						echo '<div class="alert echec"><p>La SP n\'a pas été suppprimée</p><br/>';
						echo'<a class="bouton10"  href="sp_liste.php?" class="bouton">&nbsp;&nbsp;OK&nbsp;&nbsp;</a></p></div>';						
					}
				}
				else 
				{ // Show the form.
					// Retrieve the user's information:
					$q = "SELECT NumSP FROM situationpro WHERE NumSP=$numsp ;";
					$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>Voulez vous supprimer la situation professionnelle $row[0]?</h3>";
						// Create the form:
						echo '<form action="sp_suppr.php" method="post">
						<center>
							<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="' . $numsp . '">
						</center>
						</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>';
				//	include ('footer.php');
			?>
		</article>
	</body>
</html>