<?php
	session_start();
	
	if (isset($_SESSION['usagerConsultIsoActif']) && isset($_POST['idEcole']))
	{
		include 'connexion.php';
		include 'escape_valeur.php';
		
		$requeteUser = 'SELECT * FROM isoactif_t_usager_ecole where u_e_id_fk = ' . escape_valeur($_POST['idEcole']);
		if(!$resultatUser = $connexion->query($requeteUser)){ die('There was an error running the query [' . $connexion->error . ']'); }
		$ligneUser = $resultatUser->fetch_assoc();
		
		$tableLevel = '';
		
		if ($ligneUser['u_g_prisec'] == 'P')
		{
			$requete = 'UPDATE isoactif_t_form_p SET fp_complet = \'non\' WHERE fp_u_id_fk = ' . escape_valeur($ligneUser['u_id']);
			if(!$resultat = $connexion->query($requete)){ die('There was an error running the query [' . $connexion->error . ']'); }
		}
		else
		{
			$requete = 'UPDATE isoactif_t_form_s SET fs_complet = \'non\' WHERE fs_u_id_fk = ' . escape_valeur($ligneUser['u_id']);
			if(!$resultat = $connexion->query($requete)){ die('There was an error running the query [' . $connexion->error . ']'); }
		}
		
		$connexion->close();
		
		if (isset($_POST['idRegion']))
			header ("Location: ../index.php?p=tableauEcoles&unlockedForm=" . $_POST['idEcole'] . '&sltQuelleRegion=' . $_POST['idRegion']);
		else
			header ("Location: ../index.php?p=tableauEcoles&unlockedForm=" . $_POST['idEcole']);
	}
?>