<!DOCTYPE html>
<html>
    <head>
        <title>rechercher</title>
        <meta charset="utf-8" />
		<link rel="stylesheet" href="bibliotheque.css" />	
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
		<script type="text/javascript" src="afficher_cacher.js"></script>	
    </head>
    <body>
	
		<div id="criteres">
			<h1 id="criteres_titre">Critères</h1>
			
			<form method="post" action="rechercher.php">
			<ul id="recherche">
				<li class="criteres_cacher2">
				<p> Voie d'administration </p>
					<span>
						<ul>
							<label>Voie Orale :</label>
							<input type="checkbox" name="Orale[]"/> <select name="voie[]">
								<option value="4">-</option>	
								<option value="3">+</option>
								<option value="2">++</option>
								<option value="1">+++</option>
							</select>
							<br />
							<label>Voie Cutannée :</label>
							<input type="checkbox" name="Cutannee[]"/> <select name="voie2[]">
								<option value="8">-</option>	
								<option value="7">+</option>
								<option value="6">++</option>
								<option value="5">+++</option>
							</select>
							<br />		
							<label>Olfaction :</label>
							<input type="checkbox" name="Olfaction[]"/> <select name="voie3[]">
								<option value="12">-</option>	
								<option value="11">+</option>
								<option value="10">++</option>
								<option value="9">+++</option>
							</select>
							<br />
							<label>Diffusion :</label>
							<input type="checkbox" name="Diffusion[]"/> <select name="voie4[]">
								<option value="16">-</option>	
								<option value="15">+</option>
								<option value="14">++</option>
								<option value="13">+++</option>
							</select>
						</ul>
					</span>	
				</li>
				<li class="criteres_cacher3">				
					<p> Propriétés </p>
					<span>
					<ul>
							<?php	
								$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							
								$reqSante = $bdd->query('SELECT NomPropriete FROM proprietes WHERE idtype = 1 ORDER BY NomPropriete asc');
								$reqBeaute = $bdd->query('SELECT NomPropriete FROM proprietes WHERE idtype = 2 ORDER BY NomPropriete asc');
								$reqBien = $bdd->query('SELECT NomPropriete FROM proprietes WHERE idtype = 3 ORDER BY NomPropriete asc');
								
								echo '<table><tr><td colspan="2" class="sous_titre">Santé</td></tr>';
								foreach($reqSante->fetchAll() as $b){
									echo '<tr><td><input type="checkbox" name="Proprietes[]" value="'.$b['NomPropriete'].'"/></td><td>'.$b['NomPropriete'].'</td></tr>';
									
								}
								echo '<tr><td colspan="2" class="sous_titre">Beauté</td></tr>';
								foreach($reqBeaute->fetchAll() as $b){
									echo '<tr><td><input type="checkbox" name="Proprietes[]" value="'.$b['NomPropriete'].'"/></td><td>'.$b['NomPropriete'].'</td></tr>';
									
								}
								echo '<tr><td colspan="2" class="sous_titre">Bien être</td></tr>';
								foreach($reqBien->fetchAll() as $b){
									echo '<tr><td><input type="checkbox" name="Proprietes[]" value="'.$b['NomPropriete'].'"/></td><td>'.$b['NomPropriete'].'</td></tr>';
									
								}								
								echo '</table>';
							?>
						</ul>
					</span>					
				</li>
				
				<li class="criteres_cacher4">
					<p> Contre-indications </p>
					<span>
						<ul>
							<?php	
								$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							
								$reqDanger = $bdd->query('SELECT NomDanger FROM dangers');
					
								foreach($reqDanger->fetchAll() as $b){
									echo '<li><input type="checkbox" name="Danger[]" value="'.$b['NomDanger'].'"/> '.$b['NomDanger'].'</li>';
									
								}
							?>
						</ul>
					</span>					
				</li>
			</ul>
			<input type="submit" value="go" name="submit" id="bouton_recherche"/>
			</form>
		</div>
			
		<div class="fond" id="fond_rechercher">			
	
			<div class="barre_nav" id="barre_nav_fiches">
				<ul>
					<div>
						<li>
							<a href="page_accueil.php">Home</a>
						</li>
						<li>
							<a href="a_propos.php">A propos</a>
						</li>
						<li>
							<a href="fiches.php">Fiches</a>
						</li>
						<li>
							<a href="rechercher.php">Rechercher</a>
						</li>
						<li>
							<form method="post" action="barre_recherche.php" class="barre_recherche">
								<input type="text" name="requete" placeholder="votre recherche..." class="barre_recherche_texte" /><input type="submit" value="go" class="go" />
							</form>	
						</li>
					</div>
				</ul>
				
			</div>	
						
			
			<div class="sous_fond" id="sous_fond_rechercher">
				<p class="resultat">
				<?php
					
				?>
				</p>
				<p id="resultat_affichage">
				<div class="recherche_bloc">
				
				<?php
					$req=isset($_POST['submit']) ? $_POST['submit'] : NULL;
					$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
					
					if($req != NULL){
						$resultats = extract($_POST);						
						$Proprietes = array();
						$Proprietes = isset($_POST['Proprietes']) ? $_POST['Proprietes'] : NULL;
						$dangers = array();
						$dangers = isset($_POST['Danger']) ? $_POST['Danger'] : NULL;
						$orale = array();
						$orale = isset($_POST['Orale']) ? $_POST['Orale'] : NULL;
						$cutannee = array();
						$cutannee = isset($_POST['Cutannee']) ? $_POST['Cutannee'] : NULL;
						$olfaction = array();
						$olfaction = isset($_POST['Olfaction']) ? $_POST['Olfaction'] : NULL;
						$diffusion = array();
						$diffusion = isset($_POST['Diffusion']) ? $_POST['Diffusion'] : NULL;
						
						//*****************************************************************************//
						//******* Déclaration des variables utiles pour ne pas avoir de doublon *******//
						//*****************************************************************************//
						

						$tab=array();
						$tab2 = array();
						$tab3 = array();
						$tab4 = array();
						//**********************************************************************************************//
						//************ Uniquement pour Voies administration	  *****//
						//**********************************************************************************************//
						if(count($orale)>0){
							$i = 1;
							for($n=0; $n<count($orale); $n++){								
								$req = $bdd->prepare('SELECT * FROM he join est_administre using(idHE) join voie_administration using(idVoie) WHERE idVoie LIKE :Value');
								$req->execute(array(':Value'=>$voie[$n]));
								foreach($req->fetchAll() as $b){		
									$tab[$i] = $b['NomHE'];
									$i = $i+1;							
								}
							}
						}
						if(count($cutannee)>0){
							$j = 1;
							for($n=0; $n<count($cutannee); $n++){								
								$req = $bdd->prepare('SELECT * FROM he join est_administre using(idHE) join voie_administration using(idVoie) WHERE idVoie LIKE :Value');
								$req->execute(array(':Value'=>$voie2[$n]));
								foreach($req->fetchAll() as $b){		
										$tab2[$j] = $b['NomHE'];
										$j = $j+1;							
								}
							}
						}
						if(count($olfaction)>0){
							$k = 1;
							for($n=0; $n<count($olfaction); $n++){								
								$req = $bdd->prepare('SELECT * FROM he join est_administre using(idHE) join voie_administration using(idVoie) WHERE idVoie LIKE :Value');
								$req->execute(array(':Value'=>$voie3[$n]));
								foreach($req->fetchAll() as $b){		
										$tab3[$k] = $b['NomHE'];
										$k = $k+1;
								}
							}
						}
						
						if(count($diffusion)>0){
							$l = 1;
							for($n=0; $n<count($diffusion); $n++){								
								$req = $bdd->prepare('SELECT * FROM he join est_administre using(idHE) join voie_administration using(idVoie) WHERE idVoie LIKE :Value');
								$req->execute(array(':Value'=>$voie4[$n]));
								foreach($req->fetchAll() as $b){		
										$tab4[$l] = $b['NomHE'];
										$l = $l+1;							
								}
							}
						}
						
						
						
						
						
						function test_voie()
						{
							$val=0;
							$resultats = extract($_POST);						
							$Proprietes = array();
							$Proprietes = isset($_POST['Proprietes']) ? $_POST['Proprietes'] : NULL;
							$dangers = array();
							$dangers = isset($_POST['Danger']) ? $_POST['Danger'] : NULL;
							$orale = array();
							$orale = isset($_POST['Orale']) ? $_POST['Orale'] : NULL;
							$cutannee = array();
							$cutannee = isset($_POST['Cutannee']) ? $_POST['Cutannee'] : NULL;
							$olfaction = array();
							$olfaction = isset($_POST['Olfaction']) ? $_POST['Olfaction'] : NULL;
							$diffusion = array();
							$diffusion = isset($_POST['Diffusion']) ? $_POST['Diffusion'] : NULL;
							
							if(count($orale)>0 && count($cutannee)>0 && count($olfaction)>0 && count($diffusion)>0){
								$val=1;
							}
							if(count($orale)==0 && count($cutannee)>0 && count($olfaction)>0 && count($diffusion)>0){
								$val=2;
							}
							
							if(count($orale)==0 && count($cutannee)==0 && count($olfaction)>0 && count($diffusion)>0){
								$val=3;
							}

							if(count($orale)==0 && count($cutannee)==0 && count($olfaction)==0 && count($diffusion)>0){
								$val = 4;
							}
							
							if(count($orale)==0 && count($cutannee)==0 && count($olfaction)>0 && count($diffusion)==0){
								$val=5;
							}
								
							if(count($orale)==0 && count($cutannee)>0 && count($olfaction)==0 && count($diffusion)==0){
								$val=6;
							}
								
							if(count($orale)==0 && count($cutannee)>0 && count($olfaction)==0 && count($diffusion)>0){
								$val =7;
							}
									
							if(count($orale)==0 && count($cutannee)>0 && count($olfaction)>0 && count($diffusion)==0){
								$val=8;
							}
									
							if(count($orale)>0 && count($cutannee)==0 && count($olfaction)==0 && count($diffusion)==0){
								$val = 9;
							}
							
							if(count($orale)>0 && count($cutannee)==0 && count($olfaction)==0 && count($diffusion)>0){
								$val=10;
							}
							
							if(count($orale)>0 && count($cutannee)==0 && count($olfaction)>0 && count($diffusion)==0){
								$val=11;
							}
							
							if(count($orale)>0 && count($cutannee)==0 && count($olfaction)>0 && count($diffusion)>0){
								$val=12;
							}
							if(count($orale)>0 && count($cutannee)>0 && count($olfaction)==0 && count($diffusion)==0){
								$val = 13;
							}
							
							if(count($orale)>0 && count($cutannee)>0 && count($olfaction)==0 && count($diffusion)>0){
								$val=14;
							}
							
							if(count($orale)>0 && count($cutannee)>0 && count($olfaction)>0 && count($diffusion)==0){
								$val=15;
							}
							return $val;
						}
						
						
						function cas1($tab,$tab2,$tab3,$tab4)
						{
							$tout = array();
							$i=1;
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($a=1; $a<count($tab)+1; $a++){
									if($b['NomHE']==$tab[$a]){
										for($e=1; $e<count($tab2)+1; $e++){
											if($b['NomHE']==$tab2[$e]){
												for($c=1; $c<count($tab3)+1; $c++){
													if($b['NomHE']==$tab3[$c]){
														for($d=1; $d<count($tab4)+1; $d++){	
															if($b['NomHE']==$tab4[$d]){
																$tout[$i] = $b['NomHE'];
																$i = $i+1;
															}
														}
													}
												}
											}
										}
									}
								}
							}
							return $tout;
						}
						
						function cas2($tab2,$tab3,$tab4){
							$tout = array();
							$i = 1;
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($e=1; $e<count($tab2)+1; $e++){
									if($b['NomHE']==$tab2[$e]){
										for($c=1; $c<count($tab3)+1; $c++){
											if($b['NomHE']==$tab3[$c]){
												for($d=1; $d<count($tab4)+1; $d++){
													if($b['NomHE']==$tab4[$d]){
														$tout[$i] = $b['NomHE'];
														$i = $i+1;
													}
												}
											}
										}
									}
								}
									
							}
							return $tout;
						}
						
						function cas3($tab3,$tab4)
						{
							$tout = array();
							$i = 1;
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($c=1; $c<count($tab3)+1; $c++){
									if($b['NomHE']==$tab3[$c]){
										for($d=1; $d<count($tab4)+1; $d++){
											if($b['NomHE']==$tab4[$d]){
												$tout[$i] = $b['NomHE'];
												$i = $i+1;
											}
										}
									}
								}
							}
							return $tout;
						}
						
						function cas4($tab4)
						{
							$tout = array();
							$i = 1;
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($d=1; $d<count($tab4)+1; $d++){
									if($b['NomHE']==$tab4[$d]){
										$tout[$i] = $b['NomHE'];
										$i = $i+1;
									}
								}
							}
							return $tout;
						}
						
						function cas5($tab3)
						{
							$tout = array();
							$i = 1;
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($c=1; $c<count($tab3)+1; $c++){
									if($b['NomHE']==$tab3[$c]){
										$tout[$i] = $b['NomHE'];
										$i = $i+1;
									}
								}
							}
							return $tout;
						}
			
						function cas6($tab2)
						{
							$tout = array();
							$i = 1;
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($e=1; $e<count($tab2)+1; $e++){
									if($b['NomHE']==$tab2[$e]){
										$tout[$i] = $b['NomHE'];
										$i = $i+1;
									}
								}
							}
							return $tout;
						}
						
						function cas7($tab2,$tab4)
						{
							$tout = array();
							$i = 1;
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($e=1; $e<count($tab2)+1; $e++){
									if($b['NomHE']==$tab2[$e]){
										for($d=1; $d<count($tab4)+1; $d++){
											if($b['NomHE']==$tab4[$d]){
												$tout[$i] = $b['NomHE'];
												$i = $i+1;
											}
										}
									}
								}
							}
							return $tout;
						}
								
						function cas8($tab2,$tab3)
						{
							$tout = array();
							$i = 1;
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($e=1; $e<count($tab2)+1; $e++){
									if($b['NomHE']==$tab2[$e]){
										for($c=1; $c<count($tab3)+1; $c++){
											if($b['NomHE']==$tab3[$c]){
												$tout[$i] = $b['NomHE'];
												$i = $i+1;
											}
										}
									}
								}
							}
							return $tout;
						}
								
						function cas9($tab)
						{
							$tout = array();
							$i = 1;
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($a=1; $a<count($tab)+1; $a++){
									if($b['NomHE']==$tab[$a]){
										$tout[$i] = $b['NomHE'];
										$i = $i+1;
									}
								}
							}
							return $tout;
						}
						
						function cas10($tab,$tab4)
						{
							$tout = array();
							$i = 1;
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($a=1; $a<count($tab)+1; $a++){
									if($b['NomHE']==$tab[$a]){
										for($d=1; $d<count($tab4)+1; $d++){
											if($b['NomHE']==$tab4[$d]){
												$tout[$i] = $b['NomHE'];
												$i = $i+1;
											}
										}
									}
								}
							}
							return $tout;
						}
						
						function cas11($tab,$tab3){
							$tout = array();
							$i = 1;
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($a=1; $a<count($tab)+1; $a++){
									if($b['NomHE']==$tab[$a]){
										for($c=1; $c<count($tab3)+1; $c++){
											if($b['NomHE']==$tab3[$c]){
												$tout[$i] = $b['NomHE'];
												$i = $i+1;
													
											}
										}
									}
								}
							}
							return $tout;
						}
						
						function cas12($tab,$tab3,$tab4)
						{
							$tout = array();
							$i = 1;
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($a=1; $a<count($tab)+1; $a++){
									if($b['NomHE']==$tab[$a]){
										for($c=1; $c<count($tab3)+1; $c++){
											if($b['NomHE']==$tab3[$c]){
												for($d=1; $d<count($tab4)+1; $d++){
													if($b['NomHE']==$tab4[$d]){
														$tout[$i] = $b['NomHE'];
														$i = $i+1;
													}
												}
											}
										}
									}
								}
							}
							return $tout;
						}
						
						function cas13($tab,$tab2)
						{
							$tout = array();
							$i = 1;
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($a=1; $a<count($tab)+1; $a++){
									if($b['NomHE']==$tab[$a]){
										for($e=1; $e<count($tab2)+1; $e++){
											if($b['NomHE']==$tab2[$e]){
												$tout[$i] = $b['NomHE'];
												$i = $i+1;		
											}
										}
									}
								}
							}
							return $tout;
						}
						
						function cas14($tab,$tab2,$tab4)
						{
							$tout = array();
							$i = 1;
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($a=1; $a<count($tab)+1; $a++){
									if($b['NomHE']==$tab[$a]){
										for($e=1; $e<count($tab2)+1; $e++){
											if($b['NomHE']==$tab2[$e]){
												for($d=1; $d<count($tab4)+1; $d++){
													if($b['NomHE']==$tab4[$d]){
														$tout[$i] = $b['NomHE'];
														$i = $i+1;
															
													}													
												}
											}
										}
									}
								}
							}
							return $tout;
						}
						
						function cas15($tab,$tab2,$tab3)
						{
							$tout = array();
							$i = 1;
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($a=1; $a<count($tab)+1; $a++){
									if($b['NomHE']==$tab[$a]){
										for($e=1; $e<count($tab2)+1; $e++){
											if($b['NomHE']==$tab2[$e]){
												for($c=1; $c<count($tab3)+1; $c++){
													if($b['NomHE']==$tab3[$c]){
														$tout[$i] = $b['NomHE'];
														$i = $i+1;														
													}
												}
											}
										}
									}
								}
							}
							return $tout;
						}
						
						function affiche_resultat($tab)
						{
							
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$req = $bdd->query('SELECT * FROM he');
							foreach($req->fetchAll() as $b){
								for($i=1; $i<count($tab)+1; $i++){
									if($b['NomHE']==$tab[$i]){
																						
														echo '<div class=fiche_HE style="background : url('.$b['Image3'].');"> 
															<div class="fiche_HE_cacher">
															<h1> '.$b['NomHE'].' </h1>
															<h2> '.$b['NomLatin']. ' </h2>
															<a href="fiche.php?billet='.$b['idHE'].'" style="background : #'.$b['Couleur'].'"> Voir </a>
															</div>
															</div>';	
									}
								}
							}	
						}
						//******************************************************************************//
						//********** Utilisation pour quand il y a uniquement des voies cochées ********//
						//******************************************************************************//
						function switchcase($tab, $tab2,$tab3,$tab4){
							$tmp_voie = test_voie();
							$complet=array();
							switch ($tmp_voie){
								case 0 : echo 'Pas de résultat'; break;
								case 1 : $complet = cas1($tab,$tab2,$tab3,$tab4); break;
								case 2 : $complet = cas2($tab2,$tab3,$tab4); break;
								case 3 : $complet = cas3($tab3,$tab4); break;
								case 4 : $complet = cas4($tab4); break;
								case 5 : $complet = cas5($tab3); break;
								case 6 : $complet = cas6($tab2); break;
								case 7 : $complet = cas7($tab2,$tab4); break;
								case 8 : $complet = cas8($tab2,$tab3); break;
								case 9 : $complet = cas9($tab); break;
								case 10: $complet = cas10($tab,$tab4); break;
								case 11: $complet = cas11($tab,$tab3); break;
								case 12: $complet = cas12($tab,$tab3,$tab4); break;
								case 13: $complet = cas13($tab,$tab2); break;
								case 14: $complet = cas14($tab,$tab2,$tab4); break;
								case 15: $complet = cas15($tab,$tab2,$tab3); break;
								default: echo '';
							}
							return $complet;
						}
						
						if(count($Proprietes)==0 && count($dangers)==0){
							$tmp_voie = test_voie();
							$complet=array();
							$complet=switchcase($tab,$tab2,$tab3,$tab4);
							if (count($complet)==0){
								echo 'pas de resultat';
							}
							affiche_resultat($complet);
						}
						//*****************************************************************************//
						//************ Uniquement pour quand on a des proprietes de selectionnées *****//
						//*****************************************************************************//
						
						
						function Tab_Proprietes()
						{
							
							$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
							$Proprietes = array();
							$Proprietes = isset($_POST['Proprietes']) ? $_POST['Proprietes'] : NULL;
							
							$val2=array();
							$h=1;
							$val1 = array();
							$j=1;
							$tmp = 0;
							$complet = array();
							$a=1;
							
							for($i=0; $i<count($Proprietes);$i++){
								$req1 = $bdd->prepare('SELECT * FROM he join possede using(idHE) join proprietes using(idPropriete) WHERE NomPropriete LIKE :NomPropriete');
								$req1->execute(array(':NomPropriete'=>$Proprietes[$i]));
								foreach($req1->fetchAll() as $b){		
									$val2[$h] = $b['NomHE'];
									$h = $h+1;						
								}
							}
							for($i=0; $i<count($Proprietes);$i++){		
								$req1 = $bdd->prepare('SELECT * FROM he join possede using(idHE) join proprietes using(idPropriete) WHERE NomPropriete LIKE :NomPropriete');
								$req1->execute(array(':NomPropriete'=>$Proprietes[$i]));
								foreach($req1->fetchAll() as $b){	
									$compt = 0;						
									$val1[$j] = $b['NomHE'];		
									for ($k=1; $k<count($val1);$k++){	
										if ($val1[$j] == $val1[$k]){	
											$tmp=1;						
										}
									}
									if($tmp==0) 						
										{
											for($l=1; $l<count($val2)+1;$l++){	
												if($val1[$j]==$val2[$l]){
													$compt = $compt +1;		
												}
											}
											
											if($compt == count($Proprietes)){							
												$complet[$a]=$b['NomHE'];
												$a=$a+1;
											}
										}
									$tmp=0;
									$j = $j+1;	
									}
									
								}
							return $complet;
						}
						
						
						if(count($Proprietes)>0 && count($dangers)==0) {
							$recup=array();
							$recup_admi=array();
							$recup_total=array();
							$k=1;
							$recup= Tab_Proprietes();
							if(count($orale)>0 || count($cutannee)>0 || count($olfaction)>0 || count($diffusion)>0){
								$recup_admi=switchcase($tab,$tab2,$tab3,$tab4);
								for($i=1;$i<count($recup)+1;$i++){
									for($j=1;$j<count($recup_admi)+1;$j++){
										if($recup[$i]==$recup_admi[$j]){
											$recup_total[$k]=$recup[$i];
											$k=$k+1;
										}
									}
								}
								if(count($recup_total)>0){
									affiche_resultat($recup_total);
								} else { echo 'Pas de résultat'; }						
							}							
							else {
								if(count($recup)==0){
									echo 'Pas de résultat';
								}
								affiche_resultat($recup);
								
							}
						}
							
							//*****************************************************************************//
							//************ Uniquement pour quand on a des dangers de selectionnées    *****//
							//*****************************************************************************//
							
							function Tab_Dangers()
							{
								$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
								$dangers = array();
								$dangers = isset($_POST['Danger']) ? $_POST['Danger'] : NULL;
								
								$val2=array();
								$h=1;
								$val1 = array();
								$j=1;
								$tmp = 0;
								$complet = array();
								$a=1;

								
								for($i=0; $i<count($dangers);$i++){
									$req1 = $bdd->prepare('SELECT * FROM he join peut_provoquer using(idHE) join dangers using(idDanger) WHERE NomDanger LIKE :NomDanger');
									$req1->execute(array(':NomDanger'=>$dangers[$i]));
									foreach($req1->fetchAll() as $b){		
										$val2[$h] = $b['NomHE'];
										$h = $h+1;							
									}
								}
								for($i=0; $i<count($dangers);$i++){		
									$req1 = $bdd->prepare('SELECT * FROM he join peut_provoquer using(idHE) join dangers using(idDanger) WHERE NomDanger LIKE :NomDanger');
									$req1->execute(array(':NomDanger'=>$dangers[$i]));
									foreach($req1->fetchAll() as $b){	
										$compt = 0;						
										$val1[$j] = $b['NomHE'];									
										for ($k=1; $k<count($val1);$k++){	
											if ($val1[$j] == $val1[$k]){	
												$tmp=1;						
											}
										}
										if($tmp==0) 						
											{
												for($l=1; $l<count($val2)+1;$l++){	
													if($val1[$j]==$val2[$l]){
														$compt = $compt +1;		
													}
												}
												
												if($compt == count($dangers)){											
													$complet[$a]=$b['NomHE'];
													$a = $a+1;
												}
											}
										$tmp=0;
										$j = $j+1;	
										}
										
									}
								return $complet;
								
							}
							
							
							if(count($Proprietes)==0 && count($dangers)>0) {
								$recup=array();
								$recup= Tab_Dangers();
								$recup_admi=array();
								$recup_total=array();
								$k=1;								
								if(count($orale)>0 || count($cutannee)>0 || count($olfaction)>0 || count($diffusion)>0){
									$recup_admi=switchcase($tab,$tab2,$tab3,$tab4);
									for($i=1;$i<count($recup)+1;$i++){
										for($j=1;$j<count($recup_admi)+1;$j++){
											if($recup[$i]==$recup_admi[$j]){
												$recup_total[$k]=$recup[$i];
												$k=$k+1;
											}
										}
									}
										if(count($recup_total)>0){
										affiche_resultat($recup_total);
									} else { echo 'Pas de résultat'; }						
								}							
								else {
									if(count($recup)==0){
										echo 'Pas de résultat';
									}
									affiche_resultat($recup);
									
								}
							}
							
							//*****************************************************************************//
							//************ Quand il y a les deux   									  *****//
							//*****************************************************************************//							
							if(count($Proprietes)>0 && count($dangers)>0) {								
								$recup_prop = array();
								$recup_dangers= array();
								$recup_prop = Tab_Proprietes();
								$recup_dangers= Tab_Dangers();
								$recup_all = array();
								$recup_admi=array();
								$recup_total=array();
								$k=1;
								$a=1;
								for($i=1; $i<count($recup_prop)+1;$i++){
									for($j=1; $j<count($recup_dangers)+1; $j++){
										if($recup_prop[$i] == $recup_dangers[$j]){
											$recup_all[$a]=$recup_prop[$i];
											$a=$a+1;
										}
									}
								}
								if(count($orale)>0 || count($cutannee)>0 || count($olfaction)>0 || count($diffusion)>0){
									$recup_admi=switchcase($tab,$tab2,$tab3,$tab4);
									for($i=1;$i<count($recup_all)+1;$i++){
										for($j=1;$j<count($recup_admi)+1;$j++){
											if($recup_all[$i]==$recup_admi[$j]){
												$recup_total[$k]=$recup_all[$i];
												$k=$k+1;
											}
										}
									}
									if(count($recup_total)>0){
										affiche_resultat($recup_total);
									} else { echo 'Pas de résultat'; }						
								}							
								else {
									if(count($recup_all)==0){
										echo 'Pas de résultat';
									}
									affiche_resultat($recup_all);
									
								}
							}
						}
				?>
				</div>

				</p>
			</div>
			
		</div>
	
    </body>
</html>