<?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();


	// Récupération des sollicitations pour vérifier si au moins 1 RDV pour permettre l'ajout des dates des JPO
	$q="SELECT `statut`
		FROM `agenda`
		WHERE `numEta`=:num_eta";
	$db2 = connect_base();
	$qR = $db2->prepare($q);
	$qR->bindParam( ':num_eta', $_SESSION['cfa_num'], PDO::PARAM_INT );
	$qR->execute();
	$creneauxCount = $qR->rowCount();
	$creneauxData = $qR->fetchAll();
	$rdv = 0;
	if ($creneauxCount>0 ) {
		foreach($creneauxData as $key => $value){
			if($value['statut'] == "reserve") $rdv++;
		}
	}

?>
<!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>
	<script type="text/javascript" src="js/wysiwyg.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="css/style.css" rel="stylesheet" type="text/css">
	<style>
#editeur{
    width: 100%;
    height: 200px; 
    border: 1px solid black; 
    padding: 5px;
    overflow: auto;
}
		.contentPage form input {margin-bottom: 2px !important;}
	</style>
	
	<script>
	
jQuery(document).ready(function(){
	<?php
	if(isset($_SESSION['msg']) && !empty($_SESSION['msg'])){
		?>
	alert('<?php print addslashes($_SESSION['msg']);?>');
	<?php
		$_SESSION['msg']="";
	}
	?>
	
	var submitBtnJpo = $('#btnSubJpoForm'), editJpo = $('#editJpo'), textareaJpo = $('#textareaJpo');
	
	editJpo.click(function(e) {
		e.preventDefault();
		textareaJpo.removeAttr("disabled");
		submitBtnJpo.removeClass("hidden");
		
	});
	
});
</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">Portes ouvertes</div>
		<div class="col-lg-2 col-md-2 col-sm-1 hidden-xs"></div>
		<div class="clearfix"></div>
		
		
		
		<?php
		// Afficher le contenu JPO + pouvoir modifier

		$query="select * from jpo where id_eta=:num_eta";
		$db = connect_base();
		$queryRequest = $db->prepare( $query );
		$queryRequest->bindParam( ':num_eta', $_SESSION['cfa_num'], PDO::PARAM_INT );
		$queryRequest->execute();
		$jpoCount = $queryRequest->rowCount();
		$jpoData = $queryRequest->fetchAll();
		
		if($rdv>0 && $jpoCount<1)
		{
			echo '<br/><div style="text-align: center;"><a href="ajouter-jpo.php">Ajouter vos journées portes ouvertes</a></div>';
		} else if ($rdv == 0){
			echo '<div class="textIntro"><br/><div class="alert alert-warning" role="alert">';
				echo "Au moins un rendez-vous doit-être pris par l'une de vos équipes pour pouvoir renseigner les dates de vos prochaines Journées Portes Ouvertes.";
			echo '</div></div>';
		}
		
		if($jpoCount>0){
			foreach($jpoData as $key => $value){
			?>

			<br/>
			<div class="col-lg-12">
				<form name="jpo-form" id="jpo-form" method="post" action="traitement-jpo.php" onsubmit="return getContent()" style="text-align: left!important;">
					<input type="button" value="G" style="font-weight:bold;" onClick="commande('bold');" title="Gras" /> 
	    			<input type="button" value="I" style="font-style:italic;" onClick="commande('italic');" title="Italique" /> 
					<input type="button" value="S" style="text-decoration:underline;" onClick="commande('underline');" title="Souligné" />  
					<div id="editeur"  class="form-control" required contentEditable style="width: 100%;"><?=utf8_decode(decrypter($maCleDeCryptage,$value['details_jpo']));?></div>
					<textarea id="detailsJpo" name="detailsJpo" class="hidden" ></textarea>
					<input type="hidden" name="action" value="mo_jpo" />
					<input type="hidden" name="id_jpo" value="<?=$value['id_jpo']?>"/>
					<br/><br/>
					<div class="col-lg-4 col-lg-offset-8">
						<p>
							Date de dernière modification : <?=MysqlToDateFr($value['date_create_jpo']);?><br/>
						</p>
						<button class="btn btn-block" id="btnSubJpoForm" type="submit">Envoyer</button>
					</div>
				</form>
			</div>

		<?php

			}
				
		}
		?>
		
		
		
		
	</div>
	
	<?php include('include/footer.php');?>

</body>
</html>