<?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 (){
		$(this).click(function() {
			var target = $(this).attr('data-target');
			$('#'+target).modal('show');
		});
		
	});
	$("#export").click(function(e){
		e.preventDefault;
		window.location.href='export-suivi-jpo-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 JPO</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 eta
			LEFT JOIN jpo ON jpo.id_eta = eta.id_eta";
	$db = connect_base();
	$queryRequest = $db->prepare( $query );
	$queryRequest->execute();
	if($queryRequest->rowCount()>0){
		$data=$queryRequest->fetchAll();
/*		echo '<pre>';
		var_dump($data);
		echo '</pre>';die();*/
		echo '<table cellpadding="0" cellspacing="0" class="table tabAdm">';
			echo "<tr><th>Etablissement</th><th>CP / Ville</th><th>Email du référent</th><th>JPO</th><th>Détails</th></tr>";
			foreach($data as $key => $val){
				$count=0;
				echo "<tr><td>".decrypter($maCleDeCryptage,$val['nom_eta'])."</td>";
				echo "<td>".decrypter($maCleDeCryptage,$val['cp'])." ".decrypter($maCleDeCryptage,$val['ville'])."</td>";
				echo "<td>".decrypter($maCleDeCryptage,$val['email_ref'])."</td>";
				if(!is_null($val['id_jpo'])) echo "<td align=\"center\">oui</td>"."<td align=\"center\"><a href=\"#\" data-toggle=\"modal\" data-target=\"m$key\" class=\"comLien\">Détail</a></td>";
				else echo "<td align=\"center\">non</td>"."<td>&nbsp;</td>";
				echo "</tr>";
			}
		echo '</table>';
		foreach($data as $key => $val){
			if(!is_null($val['id_jpo'])) {
				echo '
			<!-- Modal -->
			<div class="modal fade" id="m'.$key.'" tabindex="-1" role="dialog" aria-labelledby="m'.$key.'" aria-hidden="true">
			  <div class="modal-dialog modal-dialog-centered" role="document">
				<div class="modal-content">
				  <div class="modal-header">
					<h5 class="modal-title" id="m'.$key.'Title">JPO de '.decrypter($maCleDeCryptage,$val['nom_eta']).' </h5>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					  <span aria-hidden="true">&times;</span>
					</button>
				  </div>
				  <div class="modal-body">'
					. nl2br(utf8_decode(decrypter($maCleDeCryptage,$val['details_jpo']))) .
				  '</div>
				  <div class="modal-footer">
					<button type="button" class="btn btn-secondary" data-dismiss="modal">Fermer</button>
				  </div>
				</div>
			  </div>
			</div>';	
			}
		}
	}
	?>
		<br /><div class="btnDeci"><a href="index-adm.php">Retour</a></div>		
	</div>
	
	<?php include('include/footer.php');?>

</body>
</html>