<?php
require($_SERVER['DOCUMENT_ROOT'].'/espace_personnel/inc/head-ee.php');
require($_SERVER['DOCUMENT_ROOT'].'/espace_personnel/inc/sidebar-entreprises.php');


// FILTRES 

$_SELECT['search']['niveau_diplome']		= str_replace('value="'.$_GET['niveau_diplome'].'"', 'value="'.$_GET['niveau_diplome'].'" selected ', $_SELECT['search']['niveau_diplome']);
$_SELECT['search']['specialite_diplome']	= str_replace('value="'.$_GET['specialite_diplome'].'"', 'value="'.$_GET['specialite_diplome'].'" selected ', $_SELECT['search']['specialite_diplome']);
$_SELECT['search']['langue']				= str_replace('value="'.$_GET['langue'].'"', 'value="'.$_GET['langue'].'" selected ', $_SELECT['search']['langue']);
$_SELECT['search']['pratique']				= str_replace('value="'.$_GET['pratique'].'"', 'value="'.$_GET['pratique'].'" selected ', $_SELECT['search']['pratique']);
$_SELECT['search']['secteur_activite']		= str_replace('value="'.$_GET['secteur_activite'].'"', 'value="'.$_GET['secteur_activite'].'" selected ', $_SELECT['search']['secteur_activite']);
$_SELECT['search']['csp']					= str_replace('value="'.$_GET['csp'].'"', 'value="'.$_GET['csp'].'" selected ', $_SELECT['search']['csp']);
$_SELECT['search']['duree_experience']		= str_replace('value="'.$_GET['duree_experience'].'"', 'value="'.$_GET['duree_experience'].'" selected ', $_SELECT['search']['duree_experience']);



?>
	<style>
		label{width:140px;;font-size:1em}
		.filtres{background:#f5f5f5;margin-bottom:50px;font-size:0.8em;line-height:2.5em;padding-bottom:10px}
		.filtres h1{margin-bottom:5px;display:block;width:100%;border-bottom:1px dotted #c1002a;}
		.filtres select,.filtres label{width:45%}
		.filtres div{display:inline-block;width:45%;padding:10px;vertical-align:top;}
		input[type=text],select {width:150px;}
	</style>

	<div class="alert">
		Vous avez la possibilité de rechercher un CV
	</div>

	<div class="filtres">

		<form>
			<div>
				<h1>Diplômes</h1>

				<label>Diplômes : </label>
					<?php echo $_SELECT['search']['niveau_diplome'];?>

				<label>Spécialité : </label>
					<?php echo $_SELECT['search']['specialite_diplome'];?>

				<label>Validation : </label>
					<select name="validation">
						<option value="null">Indifférent</option>
						<option value="1" <?php if($_GET['validation'] == '1') echo 'selected';?>>Obtenu</option>
						<option value="0" <?php if($_GET['validation'] == '0') echo 'selected';?>>En cours</option>
					</select>
				
				<br><br>
				<h1>Langues étrangères pratiquées</h1>
				<label>Langue : </label>
					<?php echo $_SELECT['search']['langue'];?>

				<label>Niveau de pratique : </label>
					<?php echo $_SELECT['search']['pratique'];?>
			</div>


			<div>
				<h1>Expériences professionnelles</h1>

				<label>Secteur d'activité : </label>
					<?php echo $_SELECT['search']['secteur_activite'];?>
				
				<label>CSP : </label>
					<?php echo $_SELECT['search']['csp'];?><br>
				
				<label>Durée d'expérience : </label>
					<select name="duree_experience">
						<option value="null">Indifférent</option>
						<option value="24">2 ans et plus</option>
						<option value="60">5 ans et plus</option>
					</select>
				<br><br>
				<h1>Transport</h1>
				<label>Véhicule : </label>
					<select name="vehicule">
						<option value="null">Indifférent</option>
						<option value="1" <?php if($_GET['vehicule'] == '1') echo 'selected';?>>Oui</option>
						<option value="0" <?php if($_GET['vehicule'] == '0') echo 'selected';?>>Non</option>
					</select>

				<label>Permis B : </label>
					<select name="permis_b">
						<option value="null">Indifférent</option>
						<option value="1" <?php if($_GET['permis_b'] == '1') echo 'selected';?>>Oui</option>
						<option value="0" <?php if($_GET['permis_b'] == '0') echo 'selected';?>>Non</option>
						<option value="autre_permis" <?php if($_GET['permis_b'] == 'autre_permis') echo 'selected';?>>Autre permis</option>
					</select>

				<label></label>
					
			</div>
			<input type="submit" class="btn-red" style="display:block;margin:0 auto;margin-bottom:10px;" value="Lancer la recherche">
			
		</form>

	</div>
	

<?php
// REQUETE + TABLEAU RESULTAT
	
	$where_cv	= " WHERE 1 = 1 ";
	$where_exp	= " WHERE 1 = 1 ";
	$where_dip	= " WHERE 1 = 1 ";
	
	
	// DUREE EXPERIENCE
	if		($_GET['duree_experience'] == '24')								$where_exp .= " AND duree_experience >= '24' ";
	elseif	($_GET['duree_experience'] == '60')								$where_exp .= " AND duree_experience >= '60' ";

	
	// KEYWORD
	/*
	if( isset($_GET['k']) AND strlen($_GET['k']) > 2 ){
		$_KEYWORD = explode(" ",$_GET['k']);
		foreach($_KEYWORD as $key => $value){
			if( strlen($value) > 2)
				$where .= " AND ( intitule LIKE \"%$value%\" OR descriptif LIKE \"%$value%\" OR objectifs LIKE \"%$value%\" OR missions LIKE \"%$value%\" ) ";

		}
	}
	*/
	
	$where = "WHERE a.id_cv = e.id_cv AND a.id_cv = d.id_cv ";

	if( isset($_GET['niveau_diplome'])		&& $_GET['niveau_diplome'] <> "null" )		$where	.= " AND d.niveau_diplome		= '".$_GET['niveau_diplome']."' ";
	if( isset($_GET['specialite_diplome'])	&& $_GET['specialite_diplome'] <> "null" )	$where	.= " AND d.specialite_diplome	= '".$_GET['specialite_diplome']."' ";
	if( isset($_GET['secteur_activite'])	&& $_GET['secteur_activite'] <> "null" )	$where	.= " AND e.secteur_activite		= '".$_GET['secteur_activite'] ."' ";
	if( isset($_GET['csp'])					&& $_GET['csp'] <> "null" )					$where	.= " AND e.csp					= '".$_GET['csp'] ."' ";
	if( isset($_GET['permis_b'])			&& $_GET['permis_b'] <> "null" )			$where	.= " AND a.permis_b				= '".$_GET['permis_b'] ."' ";
	if( isset($_GET['permis_b'])			&& $_GET['permis_b'] <> "autre_permis" )	$where	.= " AND a.autre_permis			<> '' ";
	if( isset($_GET['vehicule'])			&& $_GET['vehicule'] <> "null" )			$where	.= " AND a.vehicule				= '".$_GET['vehicule'] ."' ";
	
	if( isset($_GET['langue'])				&& $_GET['langue'] <> "null" )	{
		$where .= " AND ( langue1 = '".$_GET['langue']."' OR langue2 = '".$_GET['langue']."' OR langue3 = '".$_GET['langue']."' )";
	}
	if( isset($_GET['pratique'])				&& $_GET['langue'] <> "null" )	{
		$where .= " AND ( pratique1 = '".$_GET['pratique']."' OR pratique2 = '".$_GET['pratique']."' OR pratique3 = '".$_GET['pratique']."' )";
	}
	



	$q = "SELECT * FROM cv_auditeurs a,cv_experiences e,cv_diplomes d ".$where." GROUP BY a.id_cv";
	
	$sql = dbquery($q);
		
	$resultats_tableau	= ""; 
	
	if(dbnumrows($sql)>0){
		for($i=0;$i<dbnumrows($sql);$i++){
			$id_cv					= dbresult($sql,$i,"a.id_cv");
			$id_auditeur			= dbresult($sql,$i,"id_auditeur");
			$langue1				= dbresult($sql,$i,"langue1");
			$pratique1				= dbresult($sql,$i,"pratique1");
			$langue2				= dbresult($sql,$i,"langue2");
			$pratique2				= dbresult($sql,$i,"pratique2");
			$langue3				= dbresult($sql,$i,"langue3");
			$pratique3				= dbresult($sql,$i,"pratique3");
			
			//echo $id_cv."<br>";
			

			// Diplôme le + élevé
			
			//echo $d = "SELECT * FROM cv_diplomes WHERE id_cv = '".$id_cv."' ORDER BY id_niveau_diplome DESC LIMIT 1";

			$sql_d = dbquery("SELECT * FROM cv_diplomes WHERE id_cv = '".$id_cv."' ORDER BY id_niveau_diplome DESC LIMIT 1");

			$intitule			= dbresult($sql_d,0,"intitule");
			$specialite			= dbresult($sql_d,0,"specialite");


			// Exp.pro la + significative

			//$sql_e = dbquery("SELECT * FROM cv_experiences WHERE id_cv = '".$id_cv."' AND first = '1' LIMIT 1");

			$sql_e = dbquery("SELECT * FROM cv_experiences WHERE id_cv = '".$id_cv."' AND affichage_recherche = '1' LIMIT 1");

			$fonction			= dbresult($sql_e,0,"fonction");
			$secteur_activite	= dbresult($sql_e,0,"secteur_activite");
			$duree_experience	= dbresult($sql_e,0,"duree_experience");

			$resultats_tableau .='
					<tr>
						<td>'.$id_cv.'</td>
						<td class="left">'.$intitule.' - <i>'.$_TAB['specialite_diplome'][$specialite].'</i></td>
						<td class="left" >'.$fonction.' - '.$_TAB['secteur_activite'][$secteur_activite].'</td>
						<td>'.$duree_experience.' mois</td>
						<td><a class="overlay-ajax" rel="#overlay" href="/espace_personnel/overlay/apercu/cv/full.php?id_cv='.$id_cv.'"><img src="/espace_personnel/images/page_search.png"/></a></td>
					</tr>
				';


		}

	//echo $q = "SELECT * FROM site_offres ".$where;
	
	//$sql_cv = dbquery("SELECT * FROM cv_auditeurs a,cv_experiences e,cv_diplomes d ".$where_cv." ");
		
	//$resultats_nb		= 0 ;

	
	$resultats_tableau .= '</tbody></table>';

?>

		<table class="tablesorter">
		<thead>
			<tr>
				<th style="width:5%">N°</th>
				<th class="left" style="width:35%">Diplôme le plus élevé</th>
				<th class="left" style="width:35%">Expérience professionnelle</th>
				<th style="width:20%">Durée d'expérience</th>
				<th style="width:5%">Détails</th>
			</tr>
		</thead>
		<tbody>	
<?php
		echo $resultats_tableau;
	}
	else
		echo '<i>Aucun résultat</i>';
?>
</div>

<div class="apple_overlay" id="overlay" style="max-height:70%;overflow:auto;" >	
	<div class="contentWrap"></div>
</div>

<script>
// TABLESORTER
	$(document).ready(function() 
    { 
        $(".tablesorter").tablesorter({
			headers: { 1: { sorter: false}, 2: {sorter: false}, 4: {sorter: false} }
		}); 
    } 
	);
</script>

</div>

<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/espace_personnel/inc/end.php');
?>
