<?php

include('include/entete.php');
include('include/entete_cfa.php');
include('config/config.inc.php');
include('config/lib.inc.php');

$maCleDeCryptage = getCleDeCryptage();

	$myIdCap = $_POST['myIdCap'];

	$query="select * from eta 
	INNER JOIN capitaines ON id_eta=num_eta
	WHERE id_eta=:num_eta AND id_cap=:myIdCap";
	$db = connect_base();
	$queryRequest = $db->prepare( $query );
	$queryRequest->bindParam( ':num_eta', $_SESSION['cfa_num'], PDO::PARAM_INT );
	$queryRequest->bindParam( ':myIdCap', $myIdCap, PDO::PARAM_INT );
	$queryRequest->execute();
	$data=$queryRequest->fetchAll();
	$count = $queryRequest->rowCount();

	if($count!=1){
		header('location:index-cfa.php');
		exit();
	}

	$nom_cap = decrypter($maCleDeCryptage,$data[0]['nom_cap']).' '.decrypter($maCleDeCryptage,$data[0]['prenom_cap']);

	//Ajout ou Modification
	if(empty($_POST['idSol'])){
		$_SESSION['msg']='Une erreur a été rencontrée pour consulter la sollicitation.';
		header('location:agenda-cfa.php#sollicitation');
		exit();
	}else	$idCoLy = $_POST['idSol'];

	
	$query="select * from sollicitations where idCoLy=:idCoLy AND (idCapitaine=:idCapitaine || idCapitaine=0) AND chxNumEta=:chxNumEta";
	$queryRequest = $db->prepare( $query );
	$queryRequest->bindParam( ':idCoLy', $idCoLy, PDO::PARAM_INT );
	$queryRequest->bindParam( ':idCapitaine', $myIdCap, PDO::PARAM_INT );
	$queryRequest->bindParam( ':chxNumEta', $_SESSION['cfa_num'], PDO::PARAM_INT );
	$queryRequest->execute();
	$countCoLy = $queryRequest->rowCount();


	if($countCoLy!=1){
		$_SESSION['msg']='Une erreur a été rencontrée pour consulter la sollicitation.';
		header('location:agenda-cfa.php#sollicitation');
		exit();
	}
	
	$dataCoLy=$queryRequest->fetchAll();
	$etaCoLy = decrypter($maCleDeCryptage,$dataCoLy[0]['etaCoLy']);
	$nomCoLy = decrypter($maCleDeCryptage,$dataCoLy[0]['nomCoLy']);
	$prenomCoLy = decrypter($maCleDeCryptage,$dataCoLy[0]['prenomCoLy']);
	$fonctionCoLy = decrypter($maCleDeCryptage,$dataCoLy[0]['fonctionCoLy']);
	$telCoLy = decrypter($maCleDeCryptage,$dataCoLy[0]['telCoLy']);
	$emlCoLy = decrypter($maCleDeCryptage,$dataCoLy[0]['emlCoLy']);
	$adresse1CoLy = decrypter($maCleDeCryptage,$dataCoLy[0]['adresse1CoLy']);
	$adresse2CoLy = decrypter($maCleDeCryptage,$dataCoLy[0]['adresse2CoLy']);
	$cpCoLy = decrypter($maCleDeCryptage,$dataCoLy[0]['cpCoLy']);
	$villeCoLy = decrypter($maCleDeCryptage,$dataCoLy[0]['villeCoLy']);
	$nbClasses = $dataCoLy[0]['nbClasses'];
	$nbEleves = $dataCoLy[0]['nbEleves'];
	$commentCoLy = decrypter($maCleDeCryptage,$dataCoLy[0]['commentCoLy']);
	$jour = MysqlToDateFr($dataCoLy[0]['chxJour']);
	$creneau = getCreneauSol($dataCoLy[0]['chxCreneau']);

	if(!empty($dataCoLy[0]['idCapitaine']))	$libTitl = 'Sollitation du capitaine '.$nom_cap;
	else	$libTitl = 'Votre sollicitation';

?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>FAFIH - DECIDAY</title>
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/fonctions.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="css/style.css" rel="stylesheet" type="text/css">
	<script>
		jQuery(document).ready(function(){
			<?php
			if(isset($_SESSION['msg']) && !empty($_SESSION['msg'])){
				?>
			alert('<?php print addslashes($_SESSION['msg']);?>');
			<?php
				$_SESSION['msg']="";
			}
			?>
		});

	</script>
	<style type="text/css">
		.frmVoir th{ font-weight: normal; }
		.frmVoir th, .frmVoir td{ padding: 5px 10px; }
	</style>
	
</head>

<body>
	
	<?php include('include/header.php');?>
	
	<div class="container contentPage">
		<div class="col-lg-2 col-md-2 col-sm-1 hidden-xs bgTitrePage"></div>
		<div class="col-lg-8 col-md-8 col-sm-10 col-xs-12 titreContenuPage">Votre espace Référent</div>
		<div class="col-lg-2 col-md-2 col-sm-1 hidden-xs bgTitrePage"></div>
		<div class="clearfix"></div>
	
		<div class="headerCap" style="text-align: center; margin:18px 0 12px;">
			<span class="ssTitreViolet"><?php echo decrypter($maCleDeCryptage,$data[0]['nom_eta']);?></span><br />
			<b>Référent : </b><?php echo decrypter($maCleDeCryptage,$data[0]['nom_ref']);?> <a href="modifier-referent.php">modifier</a><br />
			<a href="deco.php">Déconnexion</a>
		</div>
		
		<div class="menuPage">
			<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
				<a href="index-cfa.php">Vos trinômes</a>
			</div>
			<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
				<a href="bao-cfa.php">Boite à outils</a>
			</div>
			<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
				<a href="po-cfa.php">Portes ouvertes</a>
			</div>
			<div class="clearfix"></div>
		</div>
		
		<div class="col-lg-2 col-md-2 col-sm-1 hidden-xs"></div>
		<div class="col-lg-8 col-md-8 col-sm-10 col-xs-12 titreContenuPage"><?php echo $libTitl; ?></div>
		<div class="col-lg-2 col-md-2 col-sm-1 hidden-xs"></div>
		<div class="clearfix"></div>
		
		<div class="textIntro"><br/>
			<div class="clearfix"></div>
				<ul>
					<li>Jour souhaité : <b><?php echo $jour; ?></b></li>
					<li>Créneau souhaité : <b><?php echo $creneau; ?></b></li>
				</ul>
			<br /> 
			
			<table class="frmVoir">
				
				<tr><th>Etablissement : </th><td><?php echo $etaCoLy; ?></td></tr>
				<tr><th>Nom : </th><td><?php echo $nomCoLy; ?></td></tr>
				<tr><th>Prénom : </th><td><?php echo $prenomCoLy; ?></td></tr>
				<tr><th>Fonction : </th><td><?php echo $fonctionCoLy; ?></td></tr>
				<tr><th>Ligne Directe : </th><td><?php echo $telCoLy; ?></td></tr>
				<tr><th>E-mail : </th><td><?php echo $emlCoLy; ?></td></tr>
				<tr><th>Adresse 1 : </th><td><?php echo $adresse1CoLy; ?></td></tr>
				<tr><th>Adresse 2 : </th><td><?php echo $adresse2CoLy; ?></td></tr>
				<tr><th>Code Postal : </th><td><?php echo $cpCoLy; ?></td></tr>
				<tr><th>Ville : </th><td><?php echo $villeCoLy; ?></td></tr>
				<tr><th>Nombre de classes : </th><td><?php echo $nbClasses; ?></td></tr>
				<tr><th>Nombre total d'élèves concernés : </th><td><?php echo $nbEleves; ?></td></tr>
				<tr><th>Commentaires  : </th><td><?php echo nl2br($commentCoLy); ?></td></tr>
				
				</table>
				<div style="height: 20px;"></div>
				<div class="btnDeci"><a href="agenda-cfa.php?id=<?php echo $myIdCap; ?>#sollicitation">Retour</a></div>
			</form>

		</div>
		<div class="clearfix"></div>	
		
	</div>
	
	<?php include('include/footer.php');?>

</body>
</html>