<?php
	if (isset($_POST['username']) && isset($_POST['password']))
	{
		$formulaire = '';
		$erreur = '';

		include 'connexion.php';
		include 'user-class.php';
		session_start();

		// si on recoit le nom d'usager et le mot de pass en POST
		if(isset($_POST['username']) && isset($_POST['password']))
		{
			// on va chercher les informations de l'usager
			$requete = 'SELECT * FROM isoactif_t_usager_ecole WHERE u_login = \'' . escapeValue($_POST['username']) . '\' AND u_pwd = \'' . escapeValue($_POST['password']) . '\'';
			$resultat = $connexion->query($requete);

			if ($resultat->num_rows == 0)
				header('Location: ../index.php?error=login');
			else
			{
				$ligne = $resultat->fetch_assoc();

				$user = new Usager();
				$user->creerusager($ligne['u_id'], $ligne['u_prenom'], $ligne['u_nom'], $ligne['u_e_id_fk'], $ligne['u_g_prisec']);
				$_SESSION['usagerEcoleIsoActif'] =  $user;

				header('Location: ../index.php');
			}
		}

		$connexion->close();
	}
?>
