<?php
session_start();
include("/../../config.php");
include('email.php');
		include('matricule.php');
		include('/../../chiffrement.php');
		$chiffrer=new chiffrement();
		
		//$connecter = new email($chiffrer->decrypt($_POST['nom']),$chiffrer->decrypt($_POST['prenom']), $chiffrer->decrypt($_POST['email']), $_POST['Id_personne']);
		//	$connecter->felicitation();
		$matricul= new matricule();
		$_SESSION['fiche']=$_POST['Id_personne'];
		
		$verif1=$bdd->prepare('SELECT * FROM preselectionner WHERE nom=:nom AND prenom=:prenom AND datenaissance=:date AND email=:email');
$verif1->execute(array(
'nom' => $_POST['nom'],
 'prenom' =>$_POST['prenom'],
 'date' => $_POST['datenaissance'],
 'email' => $_POST['email'])) or die(print_r($verif1->errorInfo()));
		$verif2=$bdd->prepare('SELECT * FROM stagiaire WHERE nom=:nom AND prenom=:prenom AND naissance=:date AND email=:email');
$verif2->execute(array(
'nom' => $_POST['nom'],
 'prenom' =>$_POST['prenom'], 
 'date' => $_POST['datenaissance'], 
 'email' => $_POST['email'])) or die(print_r($verif2->errorInfo()));
		$verif3=$bdd->prepare('SELECT * FROM rejeter WHERE nom=:nom AND prenom=:prenom AND datenaissance=:date AND email=:email');
$verif3->execute(array(
'nom' => $_POST['nom'], 
'prenom' =>$_POST['prenom'], 
'date' => $_POST['datenaissance'],
'email' => $_POST['email'])) or die(print_r($verif3->errorInfo()));
		$cond1=$verif1->fetch();
	$cond2=$verif2->fetch();
	$cond3=$verif3->fetch();
	if((isset($cond1) and !empty($cond1)) or (isset($cond2) and !empty($cond2)) or (isset($cond3) and !empty($cond3)))
{
	if(isset($cond1) and !empty($cond1)){$identifiant=$chiffrer->decrypt($cond1['matricule']);}
	else if(isset($cond2) and !empty($cond2)){$identifiant=$chiffrer->decrypt($cond2['matricule']);}
	else {$identifiant=$chiffrer->decrypt($cond3['matricule']);}
}
else
{	
			$identifiant=$matricul->matricules('stagiaire',$_POST['Id_personne'], $_POST['pro']);}
			
			
		$connecter = new email($_POST['nom'],$_POST['prenom'], $_POST['email'],$_POST['Id_personne'], $identifiant);
			$connecter->felicitation();
			/*$matricul= new matricule('stagiaire', $chiffrer->decrypt($data['Id_personne']), $chiffrer->decrypt($data['promotion']));
			$identifiant=$matricul->matricules();*/
	$deplacer=$bdd->prepare('INSERT INTO preselectionner(nom, prenom, email, telephone, datenaissance, universite, id_personne, matricule, Photo, promotion) VALUES(:nom, :prenom, :email, :telephone, :datenaissance, :universite, :id_personne, :matricule, :photo, :promotion)');
			$deplacer->execute(array(
			'nom'=>$_POST['nom'],
			'prenom'=> $_POST['prenom'],
			'email'=>$_POST['email'],
			'telephone'=>$_POST['telephone'],
			'datenaissance'=>$_POST['datenaissance'],
			'universite'=>$_POST['universite'],
			'id_personne'=>$_POST['Id_personne'],
			'matricule'=>$chiffrer->encrypt($identifiant),
			'photo'=>$_POST['photo'],
			'promotion'=>$_POST['pro']));
$bdd->exec('DELETE FROM presentation WHERE Id_personne='.$_POST['Id_personne'].'');
header('Location:../../admin.php');

?>