<?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']);

?>
<!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 type="text/javascript" src="js/jquery.tablesorter.js"></script>
<script>
jQuery(document).ready(function(){
	<?php
	if(isset($_SESSION['msg']) && !empty($_SESSION['msg'])){
	?>
		alert('<?php print addslashes($_SESSION['msg']);?>');
	<?php
		$_SESSION['msg']="";
	}
	?>
	
	$("#myTablePro").tablesorter({
		sortList: [[0,0], [1,0]] ,
		cssAsc: 'up',
        cssDesc: 'down' 
	});
	
	$('#btnSlidePro').click(function(){
		$(".lstPro").slideDown();
	});
	
	
});
function valid_en(){
	
	var a1 = 0;
	var a2 = 0;
	var p1 = 0;
	var p2 = 0;
	
	document.frmEn.nom_eleve.value=trim(document.frmEn.nom_eleve.value);
	document.frmEn.prenom_eleve.value=trim(document.frmEn.prenom_eleve.value);
	document.frmEn.nom_pro.value=trim(document.frmEn.nom_pro.value);
	document.frmEn.prenom_pro.value=trim(document.frmEn.prenom_pro.value);
	
	if(document.frmEn.nom_eleve.value!="")		a1 = 1;
	if(document.frmEn.prenom_eleve.value!="")	a2 = 1;
	if(document.frmEn.nom_pro.value!="")		p1 = 1;
	if(document.frmEn.prenom_pro.value!="")	p2 = 1;
	
	
	if(a1==0 && a2==1){
		alert('Merci de renseigner le nom de l\'apprenant.');
		document.frmCo.nom_eleve.focus();
		return false;
	}
	if(a1==1 && a2==0){
		alert('Merci de renseigner le prénom de l\'apprenant.');
		document.frmCo.prenom_eleve.focus();
		return false;
	}
	if(!verifmail('document.frmEn.eml_eleve',0))	return false;
	if(!checkFormTel('document.frmEn.tel_eleve','T','Le téléphone de l\'apprenant',0))	return false;
	
	if(p1==0 && p2==1){
		alert('Merci de renseigner le nom du professionnel.');
		document.frmCo.nom_pro.focus();
		return false;
	}
	if(p1==1 && p2==0){
		alert('Merci de renseigner le prénom du professionnel.');
		document.frmCo.prenom_pro.focus();
		return false;
	}
	if(!verifmail('document.frmEn.eml_pro',0))	return false;
	if(!checkFormTel('document.frmEn.tel_pro','T','Le téléphone du professionnel',0))	return false;
			
	return true;
}	
function test_en(){
	if(valid_en()) document.frmEn.submit();
}
	
</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">Votre trinôme</div>
		<div class="col-lg-2 col-md-2 col-sm-1 hidden-xs"></div>
		<div class="clearfix"></div>
		
		<div class="textIntro"><br/>Identifiez ici les membres de votre trinôme 
			<div class="clearfix"></div>
		</div>
		<div class="clearfix"></div>
	
	<?php
	$query="select * from equipes where num_capitaine=:num_cap";
	$db = connect_base();
	$queryRequest = $db->prepare( $query );
	$queryRequest->bindParam( ':num_cap', $_SESSION['cap_num'], PDO::PARAM_INT );
	$queryRequest->execute();
	if($queryRequest->rowCount()>0){
		$data=$queryRequest->fetchAll();
	?>
		<form name="frmEn" id="frmEn" method="post" action="traitement-cap.php">
			
			<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
			
				<div style="margin-bottom: 20px;">
					<b>Apprenant : </b><br />
					<input type="text" name="prenom_eleve" id="prenom_eleve" value="<?php echo decrypter($maCleDeCryptage,$data[0]['prenom_eleve']);?>" placeholder="Prénom" /><br />
					<input type="text" name="nom_eleve" id="nom_eleve" value="<?php echo decrypter($maCleDeCryptage,$data[0]['nom_eleve']);?>" placeholder="Nom" /> <br />
					<input type="text" name="eml_eleve" id="eml_eleve" value="<?php echo decrypter($maCleDeCryptage,$data[0]['eml_eleve']);?>" placeholder="Email" /> <br />
					<input type="text" name="tel_eleve" id="tel_eleve" value="<?php echo decrypter($maCleDeCryptage,$data[0]['tel_eleve']);?>" placeholder="Téléphone" />
				</div>
			
			</div>
			<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
			
				<div style="margin-bottom: 20px;">
					<b>Professionnel : </b><br />
					<input type="text" name="prenom_pro" id="prenom_pro" value="<?php echo decrypter($maCleDeCryptage,$data[0]['prenom_pro']);?>" placeholder="Prénom" /> <br />
					<input type="text" name="nom_pro" id="nom_pro" value="<?php echo decrypter($maCleDeCryptage,$data[0]['nom_pro']);?>" placeholder="Nom" /> <br />
					<input type="text" name="eml_pro" id="eml_pro" value="<?php echo decrypter($maCleDeCryptage,$data[0]['eml_pro']);?>" placeholder="Email" /> <br />
					<input type="text" name="tel_pro" id="tel_pro" value="<?php echo decrypter($maCleDeCryptage,$data[0]['tel_pro']);?>" placeholder="Téléphone" />
					<div><a href="#" id="btnSlidePro">Trouver un professionnel</a></div>
				</div>
				
			</div>
			
			<div class="clearfix"></div>
			
			<div style="margin-bottom: 20px;">&nbsp;</div>
			
			<input type="hidden" name="action" value="go_en" />
			<div class="btnDeci"><a href="javascript:void(0);" onClick="test_en()">Enregistrer</a></div>
		
		</form>
		
		<?php
		
		//if($data[0]['num_eta']==399 || $data[0]['num_eta']==402){
		
		//LISTE DES PROFESSIONNELS
			
			echo '<div class="lstPro">';
			
			echo '<br /><br />';

			echo '<div class="col-lg-2 col-md-2 col-sm-1 hidden-xs"></div>'."\r\n";
			echo '<div class="col-lg-8 col-md-8 col-sm-10 col-xs-12 titreContenuPage">Liste des professionnels</div>'."\r\n";
			echo '<div class="col-lg-2 col-md-2 col-sm-1 hidden-xs"></div>'."\r\n";
			echo '<div class="clearfix"></div>'."\r\n";

			$queryPro="SELECT * FROM inscriptions_pro WHERE statut = 1 AND faireEquipe = 1";
				$queryRequestPro = $db->prepare( $queryPro );
				$queryRequestPro->execute();
				$countSol = $queryRequestPro->rowCount();
			
				if($countSol>0){
					
					$dataSol = $queryRequestPro->fetchAll();
					
					echo '<table id="myTablePro" class="tablesorter">'."\r\n";
					
					echo '<thead><tr><th>Etablissement</th><th>Nom</th><th>Prénom</th><th>CP</th><th>Ville</th><th class="sorter-false">Mobile</th><th class="sorter-false">Fixe</th><th class="sorter-false">Email</th></tr></thead>'."\r\n";
					echo '<tbody>'."\r\n";
					foreach($dataSol as $key=>$val){
						
						
						echo '<tr>'."\r\n";
							echo '<td>'.mb_strtoupper(decrypter($maCleDeCryptage,$val['etablissement_pro'])).'</td>'."\r\n";
							echo '<td>'.mb_strtoupper(decrypter($maCleDeCryptage,$val['nom_pro'])).'</td>'."\r\n";
							echo '<td>'.decrypter($maCleDeCryptage,$val['prenom_pro']).'</td>'."\r\n";
							echo '<td>'.decrypter($maCleDeCryptage,$val['cp_pro']).'</td>'."\r\n";
							echo '<td>'.mb_strtoupper(decrypter($maCleDeCryptage,$val['ville_pro'])).'</td>'."\r\n";
							echo '<td>'.decrypter($maCleDeCryptage,$val['mobile_pro']).'</td>'."\r\n";
							echo '<td>'.decrypter($maCleDeCryptage,$val['fixe_pro']).'</td>'."\r\n";
							echo '<td>'.decrypter($maCleDeCryptage,$val['email_pro']).'</td>'."\r\n";
						echo '</tr>'."\r\n";
						
						
					}
					echo '</tbody>'."\r\n";
					echo '</table>'."\r\n";
				}else{
					echo '<div align="center">Aucun professionnel pour l\'instant</div>';
				}
			
				echo '</div>';
				

			
			
		//}
		
		?>
		

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

</body>
</html>