<?php
include('include/entete.php');
include('include/entete_cap.php');
include('config/config.inc.php');
include('config/lib.inc.php');

$maCleDeCryptage = getCleDeCryptage();	

$query="select * from eta,capitaines where id_eta=num_eta and id_cap=:id_cap";
$db = connect_base();
$queryRequest = $db->prepare( $query );
$queryRequest->bindParam( ':id_cap', $_SESSION['cap_num'], PDO::PARAM_INT );
$queryRequest->execute();
$data=$queryRequest->fetchAll();
$capitaine=decrypter($maCleDeCryptage,$data[0]['prenom_cap'])." ".decrypter($maCleDeCryptage,$data[0]['nom_cap']);

$nom_cap=decrypter($maCleDeCryptage,$data[0]['nom_cap']);
$prenom_cap=decrypter($maCleDeCryptage,$data[0]['prenom_cap']);
$email_cap=decrypter($maCleDeCryptage,$data[0]['email_cap']);
$num_eta=$data[0]['num_eta'];

?>
<!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']="";
	}
	?>
});

function valid_upcap(){
	if(document.frmUpcap.nom_cap.value==""){
		alert('Merci de renseigner le nom.');
		document.frmUpcap.nom_cap.focus();
		return false;
	}
	if(document.frmUpcap.prenom_cap.value==""){
		alert('Merci de renseigner le prénom.');
		document.frmUpcap.prenom_cap.focus();
		return false;
	}
	if(!verifmail('document.frmUpcap.email_cap',1)){
		return false;
	}
	
	if(document.frmUpcap.email_cap.value!='<?php echo $email_cap; ?>'){
		if(!window.confirm('Vous transmettez vos prérogatives de Capitaine à 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_upcap(){
	if(valid_upcap()) document.frmUpcap.submit();
}
jQuery(document).ready(function(){
	document.frmUpcap.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 Capitaine</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 />
			<b>Capitaine : </b><?php echo $capitaine;?> <a href="modifier-cap.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-cap.php">Votre trinôme</a>
			</div>
			<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
				<a href="agenda-cap.php">Votre agenda</a>
			</div>
			<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
				<a href="bao-cap.php">Boite à outils</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 capitaine</div>
		<div class="col-lg-2 col-md-2 col-sm-1 hidden-xs"></div>
		<div class="clearfix"></div>
		<form name="frmUpcap" id="frmUpcap" method="post" action="traitement-cap.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 $_SESSION['cap_num']; ?>" />
			<input type="hidden" name="num_eta" id="num_eta" value="<?php echo $num_eta; ?>" />
			<input type="hidden" name="action" value="go_moCap" />
			<div class="btnDeci"><a href="javascript:void(0);" onClick="test_upcap()">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>