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

include('config/config.inc.php');
/*
$query="select * from capitaines where id_cap=:id_cap";
$db = connect_base();
$queryRequest = $db->prepare( $query );
$queryRequest->bindParam( ':id_cap', $id, PDO::PARAM_INT );
$queryRequest->execute();
if($queryRequest->rowCount()==0){
	header('location:index-cfa.php');
	exit();
}
*/

$id =  $_SESSION['cfa_num'];

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

$nom_ref=decrypter($maCleDeCryptage,$data[0]['nom_ref']);
$tel_ref=decrypter($maCleDeCryptage,$data[0]['tel_ref']);
$email_ref=decrypter($maCleDeCryptage,$data[0]['email_ref']);

?>
<!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>
function valid_aj(){
	if(document.frmAj.nom_ref.value==""){
		alert('Merci de renseigner le nom.');
		document.frmCo.nom_ref.focus();
		return false;
	}
	if(!checkFormTel('document.frmAj.tel_ref','T','Le téléphone',1))	return false;
	if(!verifmail('document.frmAj.email_ref',1)){
		return false;
	}
	if(document.frmAj.email_ref.value!='<?php echo $email_ref; ?>'){
		if(!window.confirm('Vous transmettez vos prérogatives de Référent à une autre personne.\r\nÊtes-vous sûr ?\r\nSi oui, vous serez déconnecté après la modification.'))	return false;
	}
	return true;
}	
function test_aj(){
	if(valid_aj()) document.frmAj.submit();
}
jQuery(document).ready(function(){
	document.frmAj.nom_ref.focus();
});
	
</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">Modifier Votre profil Référent</div>
		<div class="col-lg-2 col-md-2 col-sm-1 hidden-xs"></div>
		<div class="clearfix"></div>
		<form name="frmAj" id="frmAj" method="post" action="traitement-cfa.php">
	
			<div class="labFrm">Nom :</div>
			<input type="text" name="nom_ref" id="nom_ref" value="<?php echo $nom_ref;?>"/><br />
			<div class="labFrm">Téléphone :</div>
			<input type="text" name="tel_ref" id="tel_ref" value="<?php echo $tel_ref;?>" /><br />
			<div class="labFrm">Email :</div>
			<input type="text" name="email_ref" id="email_ref" value="<?php echo $email_ref;?>" /><br />
			<input type="hidden" name="id_eta" id="id_eta" value="<?php echo $id;?>" />
			<input type="hidden" name="action" value="go_mo_ref" />
			<div class="btnDeci"><a href="javascript:void(0);" onClick="test_aj()">Modifier</a></div>
			<div style="height: 20px;"></div>
			<div class="btnDeci"><a href="index-cap.php">Retour</a></div>						
		</form>
	</div>
	
	<?php include('include/footer.php');?>

</body>
</html>