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

$maCleDeCryptage = getCleDeCryptage();	

	$query="select * from eta where id_eta=:num_eta";
	$db = connect_base();
	$queryRequest = $db->prepare( $query );
	$queryRequest->bindParam( ':num_eta', $_SESSION['cfa_num'], PDO::PARAM_INT );
	$queryRequest->execute();
	$data=$queryRequest->fetchAll();

	//Affichage sollicitations capitaines
	$querySolRef="select * FROM sollicitations WHERE idCapitaine=0 AND traitement=0 AND chxNumEta=:chxNumEta";
	$queryRequestSolRef = $db->prepare( $querySolRef );
	$queryRequestSolRef->bindParam( ':chxNumEta', $_SESSION['cfa_num'], PDO::PARAM_INT );
	$queryRequestSolRef->execute();
	$countSolRef=$queryRequestSolRef->rowcount();

?>
<!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>
</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 />
			<span style="font-size: 0.9em;">
			<?php 
				echo decrypter($maCleDeCryptage,$data[0]['adresse1']); 
				if(!empty($data[0]['adresse2']))	echo ' - '.decrypter($maCleDeCryptage,$data[0]['adresse2']); 
				echo ' - '.decrypter($maCleDeCryptage,$data[0]['cp']).' '.decrypter($maCleDeCryptage,$data[0]['ville']); 
			?>
			</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">Vos trinômes</div>
		<div class="col-lg-2 col-md-2 col-sm-1 hidden-xs"></div>
		<div class="clearfix"></div>
		
		<div class="textIntro"><br/>
			<?php 
				if($countSolRef==0)	echo 'Vous n\'avez aucune sollicitation refusée.<br />';
				elseif($countSolRef==1)	echo '<b>Vous avez '.$countSolRef.' sollicitation refusée.</b><br />';
				elseif($countSolRef>1)	echo '<b>Vous avez '.$countSolRef.' sollicitations refusées.</b><br />';
			?>
			Suivez les sollicitations des collèges et lycées dans l'agenda de vos capitaines.<br /><br />
			Créez et suivez vos trinômes dans l'organisation de Deciday !
		</div>
		<div class="clearfix"></div>
		
		<div style="text-align: center;"><a href="ajouter-ref.php">Créer un trinôme</a></div>
	<?php
	$query="select * from capitaines where num_eta=:num_eta";
	$db = connect_base();
	$queryRequest = $db->prepare( $query );
	$queryRequest->bindParam( ':num_eta', $_SESSION['cfa_num'], PDO::PARAM_INT );
	$queryRequest->execute();
	if($queryRequest->rowCount()>0){
		$data=$queryRequest->fetchAll();
		echo '<table cellpadding="0" cellspacing="0" class="tabAdm">';
			echo "<tr><th>Capitaine</th><th>Apprenant</th><th>Professionnel</th><th>Rendez-vous</th><th>Sollicitations</th><th colspan='2' style='text-align:center'>Actions</th></tr>";
			foreach($data as $val){
				//Affichage noms apprenant et pro
				$query2="select * from equipes where num_capitaine=:num_cap";
				$db2 = connect_base();
				$queryRequest2 = $db2->prepare( $query2 );
				$queryRequest2->bindParam( ':num_cap', $val['id_cap'], PDO::PARAM_INT );
				$queryRequest2->execute();
				$data2=$queryRequest2->fetchAll();
				//Affichage rendez-vous capitaines
				$query3="select * FROM agenda WHERE numCap=:num_cap AND statut= 'reserve' AND numEta=:numEta";
				$db3 = connect_base();
				$queryRequest3 = $db3->prepare( $query3 );
				$queryRequest3->bindParam( ':numEta', $_SESSION['cfa_num'], PDO::PARAM_INT );
				$queryRequest3->bindParam( ':num_cap', $val['id_cap'], PDO::PARAM_INT );
				$queryRequest3->execute();
				$countRdv=$queryRequest3->rowcount();
				//Affichage sollicitations capitaines
				$query4="select * FROM sollicitations WHERE idCapitaine=:num_cap AND traitement=0 AND chxNumEta=:chxNumEta";
				$db4 = connect_base();
				$queryRequest4 = $db4->prepare( $query4 );
				$queryRequest4->bindParam( ':chxNumEta', $_SESSION['cfa_num'], PDO::PARAM_INT );
				$queryRequest4->bindParam( ':num_cap', $val['id_cap'], PDO::PARAM_INT );
				$queryRequest4->execute();
				$countSol=$queryRequest4->rowcount();
				
				echo '<tr><td>'.decrypter($maCleDeCryptage,$val['prenom_cap']).' '.decrypter($maCleDeCryptage,$val['nom_cap']).'</td>';
				if(!empty($data2[0]['nom_eleve']) && !empty($data2[0]['prenom_eleve'])) echo '<td>'.decrypter($maCleDeCryptage,$data2[0]['nom_eleve']).' '.decrypter($maCleDeCryptage,$data2[0]['prenom_eleve']).'</td>';
				else echo '<td>&nbsp;</td>';
				if(!empty($data2[0]['nom_pro']) && !empty($data2[0]['prenom_pro']))  echo '<td>'.decrypter($maCleDeCryptage,$data2[0]['nom_pro']).' '.decrypter($maCleDeCryptage,$data2[0]['prenom_pro']).'</td>';
				else echo '<td>&nbsp;</td>';
				echo "<td align=\"center\">".$countRdv."</td>";
				echo "<td align=\"center\">".$countSol."</td>";
				echo '<td><a href="modifier-ref.php?id='.$val['id_cap'].'">Modifier</a></td>';
				echo '<td><a href="agenda-cfa.php?id='.$val['id_cap'].'">Agenda</a></td>';
				echo '</tr>';
			
			}
		echo '</table>';
	}
	?>
	</div>
	
	<?php include('include/footer.php');?>

</body>
</html>