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

if(!isset($_GET['id']) || empty($_GET['id'])){
	header('location:index-cfa.php');
	exit();
}

$id=$_GET['id'];
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();
}


include('config/lib.inc.php');
$maCleDeCryptage = getCleDeCryptage();
$data=$queryRequest->fetchAll();
$nom_cap=decrypter($maCleDeCryptage,$data[0]['nom_cap']);
$prenom_cap=decrypter($maCleDeCryptage,$data[0]['prenom_cap']);
$email_cap=decrypter($maCleDeCryptage,$data[0]['email_cap']);


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

?>
<!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_cap.value==""){
		alert('Merci de renseigner le nom.');
		document.frmCo.nom_cap.focus();
		return false;
	}
	if(document.frmAj.prenom_cap.value==""){
		alert('Merci de renseigner le prénom.');
		document.frmCo.prenom_cap.focus();
		return false;
	}
	if(!verifmail('document.frmAj.email_cap',1)){
		return false;
	}
	return true;
}	
function test_aj(){
	if(valid_aj()) document.frmAj.submit();
}
jQuery(document).ready(function(){
	document.frmAj.nom_cap.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 les coordonnées du capitaine</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_cap" id="nom_cap"  value="<?php echo $nom_cap;?>"/><br />
			<div class="labFrm">Prénom :</div>
			<input type="text" name="prenom_cap" id="prenom_cap" value="<?php echo $prenom_cap;?>" /><br />
			<div class="labFrm">Email :</div>
			<input type="text" name="email_cap" id="email_cap" value="<?php echo $email_cap;?>" /><br />
			<input type="hidden" name="id_cap" id="id_cap" value="<?php echo $id;?>" />
			<input type="hidden" name="action" value="go_mo" />
			<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>