<?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-suivi-pro-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 professionnels</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 tabPro" 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 inscriptions_pro";
	$db = connect_base();
	$queryRequest = $db->prepare( $query );
	$queryRequest->execute();
	if($queryRequest->rowCount()>0){
		$n=0;
		$commentaire = null;
		$data=$queryRequest->fetchAll();
		echo '<table cellpadding="0" cellspacing="0" class="table tabAdm tabPro">';
			echo "<tr><th>Etablissement</th><th>SIRET</th><th>Nom<br/>prénom</th><th>Coordonnées</th><th>Mobile/Fixe</th><th>Email</th><th>Commentaire</th><th>Déciday!</th><th>stage 3ème</th><th>Rdv étudiant</th><th>Date inscription</th><th>Statut</th><th>Action</th></tr>";
			foreach($data as $val){
				$commentaire = decrypter($maCleDeCryptage,$val['comment_pro']);
				echo "<tr>";
				echo "<td>".decrypter($maCleDeCryptage,$val['etablissement_pro'])."</td>";
				echo "<td>".decrypter($maCleDeCryptage,$val['siret_pro'])."</td>";
				echo "<td>".decrypter($maCleDeCryptage,$val['nom_pro'])."<br/>".decrypter($maCleDeCryptage,$val['prenom_pro'])."</td>";
				echo "<td>".decrypter($maCleDeCryptage,$val['adr1_pro'])." ".decrypter($maCleDeCryptage,$val['adr2_pro'])." ".decrypter($maCleDeCryptage,$val['cp_pro'])."  ".decrypter($maCleDeCryptage,$val['ville_pro'])."</td>";
				echo "<td>".decrypter($maCleDeCryptage,$val['mobile_pro'])."/".decrypter($maCleDeCryptage,$val['fixe_pro'])."</td>";
				echo "<td>".decrypter($maCleDeCryptage,$val['email_pro'])."</td>";
//				echo "<td>".$val['flyers']."</td>";
				if (!empty($commentaire)) {
					echo "<td>"."<a href=\"#\" data-toggle=\"modal\" data-target=\"mCommentaire$n\" class=\"comLien\">Détail</a>"."</td>";
					$n++;
				} else echo "<td>&nbsp;</td>";
				// echo "<td>".nl2br(decrypter($maCleDeCryptage,$val['comment_pro']))."</td>";
				if($val['faireEquipe']==1) echo "<td>Oui</td>";
				else echo "<td>Non</td>";
				if($val['recevoirStage']==1) echo "<td>Oui</td>";
				else echo "<td>Non</td>";
				if($val['recevoirJeunes']==1) echo "<td>Oui</td>";
				else echo "<td>Non</td>";
				echo "<td>".MysqlToDateFr($val['date_insert'])."</td>";
				if($val['statut']==1) echo "<td>Validé</td>";
				else if($val['statut']==2) echo "<td>Refusé</td>";
				else echo "<td>En attente</td>";
				echo "<td>"; 
				if($val['statut'] ==0  ) echo "<a href='valid_pro.php?id=".$val['id_pro']."'>Valider</a>/<a href='refuse_pro.php?id=".$val['id_pro']."'>Refuser</a>";
				else if($val['statut']==1) echo "<a href='refuse_pro.php?id=".$val['id_pro']."'>Refuser</a>";
				else echo "<a href='valid_pro.php?id=".$val['id_pro']."'>Valider</a>";
				echo "</td>";
			}
		echo '</table>';
		
		$n=0;
			foreach($data as $val){
				$pro = decrypter($maCleDeCryptage,$val['etablissement_pro']);
				$commentaires = nl2br(htmlspecialchars(decrypter($maCleDeCryptage,$val['comment_pro'])));
				if(!empty($commentaires)){
			?>
		
		
		<!-- Modal -->
		<div class="modal fade" id="mCommentaire<?=$n?>" tabindex="-1" role="dialog" aria-labelledby="mCommentaire<?=$n?>" 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="mCommentaire<?=$n?>Title">Commentaire - <?=$pro ?> </h5>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
				  <span aria-hidden="true">&times;</span>
				</button>
			  </div>
			  <div class="modal-body">
				<?=$commentaires ?>
			  </div>
			  <div class="modal-footer">
				<button type="button" class="btn btn-secondary" data-dismiss="modal">Fermer</button>
			  </div>
			</div>
		  </div>
		</div>
		<?php
				$n++;
				}}		
	}
	?>
		<br /><div class="btnDeci"><a href="index-adm.php">Retour</a></div>		
	</div>
	
	<?php include('include/footer.php');?>

</body>
</html>