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

$maCleDeCryptage = getCleDeCryptage();	


?>
<!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']="";
	}
	?>
	
	$('.comLien').each(function (index){
		$(this).click(function() {
			$('#mCommentaire'+index).modal('show');
		});
		index = index++;
	});
	$("#export").click(function(e){
		e.preventDefault;
		window.location.href='export-reservations-adm.php';
	})
	
});	
</script>
</head>

<body>
	
	<?php include('include/header.php');?>
	
	<div class="container contentPage">
		
		<?php include('include/admin-header.php');?>
		
		<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">Suivi des réservations</div>
		<div class="col-lg-2 col-md-2 col-sm-1 hidden-xs bgTitrePage"></div>
		<div class="clearfix"></div>
		<br/><br/>
		<button type="button" class="btn btn-default btn-lg" id="export" title="Télécharger le fichier Excel">
  			<span class="glyphicon glyphicon-save-file" aria-hidden="true"></span> Export Excel
		</button>	

	<?php
	$query="SELECT *
			FROM `agenda`
			INNER JOIN eta 
			ON eta.id_eta = agenda.numEta
			WHERE `statut` = 'reserve' AND (
			`numEta` <> 399
			AND  `numEta` <> 400
			AND  `numEta` <> 402
			AND  `numEta` <> 403) ";
	$db = connect_base();
	$queryRequest = $db->query($query);
	$queryRequest->execute();
	
		
	
	if($queryRequest->rowCount()>0){
		$data=$queryRequest->fetchAll();
		
/*		echo '<pre>';
		var_dump($data);
		echo '</pre>';*/
		
		$coLy_tmp = array();
		$coLy_fullDetail = array();
		
		
		foreach($data as $key => $value){
			$coLy_tmp[] = array(
				"id_college_lycee" 	=> $value['numCoLy'],
				"jour_reserve"		=> mysqlToDateFr($value['jour']),
				"creneau"			=> getCreneauPlus($value['creneau']),
				"nom_cfa_lp"		=> decrypter($maCleDeCryptage, $value['nom_eta']),
				"localite_cfa_lp" 	=> decrypter($maCleDeCryptage, $value['cp']). "<br/>" . decrypter($maCleDeCryptage, $value['ville'])
			);
		}

		
		foreach($coLy_tmp as $key => $value){
			
			$db = connect_base();
			$query = $db->prepare("SELECT * FROM `collegelycee` WHERE `idCoLy` =:idCoLy");
			$query->bindParam( ':idCoLy', $value['id_college_lycee'], PDO::PARAM_INT );
			$query->execute();
			
			$result[] = $query->fetchAll();	
			$result[$key][0]['chxJour'] = $value['jour_reserve'];
			$result[$key][0]['chxCreneau'] = $value['creneau'];
			$result[$key][0]['nom_cfa_lp'] = $value['nom_cfa_lp'];
			$result[$key][0]['localite_cfa_lp'] = $value['localite_cfa_lp'];
			
		}
		
		

		echo '<table cellpadding="0" cellspacing="0" class="tabAdm">';
			echo "<tr><th>Etablissement</th><th>Coordonnées</th><th>Classes/Elèves</th><th>Date Réservation</th><th>Créneaux</th><th>Nom CFA/LP</th><th>Localité CFA/LP</th></tr>";
		
			foreach($result as $k => $v){
				
				// Définition des coordonnées de l'établissement
				$add1 = decrypter($maCleDeCryptage,$v[0]['adresse1CoLy']);
				$add2 = decrypter($maCleDeCryptage,$v[0]['adresse2CoLy']);
				$cp = decrypter($maCleDeCryptage,$v[0]['cpCoLy']);
				$ville = decrypter($maCleDeCryptage,$v[0]['villeCoLy']);
				$coordonnees = $add1;
				if(!empty($add2)){
					$coordonnees = $coordonnees . "<br/>" . $add2;
				}
				$coordonnees = $coordonnees . "<br/>" . $cp . " " . $ville;	
					
				
				
				echo "<tr>";
				echo "<td>".decrypter($maCleDeCryptage,$v[0]['etaCoLy'])."</td>";
				echo "<td>".$coordonnees."</td>";
				echo "<td>".$v[0]['nbClasses']."/".$v[0]['nbEleves']."</td>";
				echo "<td>".$v[0]['chxJour']."</td>";
				echo "<td>".$v[0]['chxCreneau']."</td>";	
				echo "<td>".$v[0]['nom_cfa_lp']."</td>";	
				echo "<td>".$v[0]['localite_cfa_lp']."</td>";	
			}
		echo '</table>';
		
	}
			?>
		
		
		
		<br /><div class="btnDeci"><a href="index-adm.php">Retour</a></div>
		
	</div>
	
	<?php include('include/footer.php');?>
</body>
</html>