<?php 
$bdd = new PDO('mysql:host=localhost;dbname=bibliotheque;charset=utf8','root','');
$req1 = $bdd->prepare('SELECT NomHE, NomLatin, Image1, Image2, Description, Famille, Origine, Partie_distille, Composition, Couleur FROM he WHERE idHE = ?');
$req1->execute(array($_GET['billet']));

?>

<!DOCTYPE html>
<html>
    <head>
        <title>	<?php 
		$req2 = $bdd->prepare('SELECT NomHE, NomLatin, Image1, Image2, Description, Famille, Origine, Partie_distille, Composition, Couleur FROM he WHERE idHE = ?');
		$req2->execute(array($_GET['billet']));
		foreach($req2->fetchAll() as $ligne){echo $ligne['NomHE'];} ?></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>		

    </head>
    <body>
	<?php							
		foreach($req1->fetchAll() as $ligne){
	?>
		<div class="fond" id="fond_fiche">
	
			<div class="barre_nav" id="barre_nav_fiche">
				<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_fiche">
				<div class="arborescence">
					<a href="fiches.php">
						fiches
					</a>
					>				
					<span>
						<?php 
						$req2 = $bdd->prepare('SELECT NomHE, NomLatin, Image1, Image2, Description, Famille, Origine, Partie_distille, Composition, Couleur FROM he WHERE idHE = ?');
						$req2->execute(array($_GET['billet']));
						foreach($req2->fetchAll() as $ligne){
								echo $ligne['NomHE'];
						} 
						?>			
					</span>
				</div>			
		
			<div class="image">
				<img src="<?php	echo $ligne['Image1'];?>"/>
			</div>		
			<h2>
				<?php echo $ligne['NomHE']; ?>
			</h2>
			<h4>
				<?php echo $ligne['NomLatin']; ?>				
			</h4>
			<h3>Caractéristiques</h3>
			<div class="caracteristiques">
				<div class="caracteristiques_texte">
					<?php echo $ligne['Description']; ?>		
				</div>
				<div class="caracteristiques_infos">
					<h5>
						Infos Generales
					</h5>
					<ul>
						<li>
							Famille : <?php echo $ligne['Famille']; ?>		
						</li>
						<li>
							Origine : <?php	echo $ligne['Origine']; ?>	
						</li>
						<li>
							Partie utilisee : <?php echo $ligne['Partie_distille']; ?>	
						</li>
					</ul>
				</div>
					
				<div class="composition">
					<h5>
						Composition
					</h5>
					<p>
						<?php echo nl2br($ligne['Composition']); ?>
					</p>
				</div>
			</div>
			
			<h3>Propriétés</h3>
			<div class="proprietes">
				<div id="sante" class="propriete">
					<div class="proprietes_cacher" id="sante_cacher">
					<ul>
						<?php	
							$reqSante = $bdd->prepare('SELECT NomPropriete FROM possede join proprietes using(idPropriete) join type using(idType) WHERE NomType like "sante" and idHE = ? ORDER BY NomPropriete asc');
							$reqSante->execute(array($_GET['billet']));							
							foreach($reqSante->fetchAll() as $b){
								echo '<li>'.$b['NomPropriete'].'</li>';							
							}
						?>
					<ul>
					</div>
				</div>
					<div id="beaute" class="propriete">
					<div class="proprietes_cacher" id="beaute_cacher">
					<ul>
						<?php		
							$reqBeaute = $bdd->prepare('SELECT NomPropriete FROM possede join proprietes using(idPropriete) join type using(idType) WHERE NomType like "beaute" and idHE = ? ORDER BY NomPropriete asc');
							$reqBeaute->execute(array($_GET['billet']));
							foreach($reqBeaute->fetchAll() as $b){
								echo '<li>'.$b['NomPropriete'].'</li>';
							}
						?>
					<ul>
					</div>
				</div>
				<div id="bien_etre" class="propriete">
					<div class="proprietes_cacher" id="bien_etre_cacher">
					<ul>
						<?php			
							$reqBien = $bdd->prepare('SELECT NomPropriete FROM possede join proprietes using(idPropriete) join type using(idType) WHERE NomType like "bien_etre" and idHE = ? ORDER BY NomPropriete asc');
							$reqBien->execute(array($_GET['billet']));					
							foreach($reqBien->fetchAll() as $b){
								echo '<li>'.$b['NomPropriete'].'</li>';
							}
						?>
					<ul>
					</div>
				</div>				
			</div>
			
			<h3>Voie Administration</h3>
			<div class="voie">
				<?php
					$i =0;
					$j =0;
					$reqVoie = $bdd->prepare('SELECT NomVoie, Valeur FROM he join est_administre using(idHE) join voie_administration using(idVoie) WHERE idHE = ?');
					$reqVoie->execute(array($_GET['billet']));					
					foreach($reqVoie->fetchAll() as $b){
						$i=$i+1;
						$j=$j+1;
				?>
				<div class="<?php echo $j; ?>">
					<span>				
						<?php echo $b['NomVoie']; ?>
					</span>
				
					<p id="<?php echo $i; ?>">
						<?php echo $b['Valeur']; ?>
					</p>
				</div>		
				<script type="text/javascript">

					$voie = <?php echo $b['Valeur'];?>;
			
					if($voie == 0){
						$('.<?php echo $j; ?> span').addClass('voie2');
						$('#<?php echo $i; ?>').css('color', '#b43b3b');
						}else{
						$('.<?php echo $j; ?> span').addClass('voie1');
						$('#<?php echo $i; ?>').css('color', '#b4aa3b');
					}
						if($voie == 0){
							$('#<?php echo $i; ?>').html('-');	
						}							
						if($voie == 1){
							$('#<?php echo $i; ?>').html('+');
						}if($voie == 2){
							$('#<?php echo $i; ?>').html('++');
						}if($voie == 3){
							$('#<?php echo $i; ?>').html('+++');
						}					
			
				</script>
				<?php
					}
				?>											
			
			</div>	

			<h3>Dangers et précautions d'utilisation</h3>
			<div class="dangers">
				<?php			
					$reqDangers = $bdd->prepare('SELECT NomDanger, TexteDanger FROM he join peut_provoquer using(idHE) join dangers using(idDanger) WHERE idHE = ? ORDER BY NomDanger asc');
					$reqDangers->execute(array($_GET['billet']));					
					foreach($reqDangers->fetchAll() as $b){
				?>
				<h5>			
					<?php echo $b['NomDanger']; ?>
				</h5>
				<p>
					<?php echo $b['TexteDanger']; ?>
				</p>
								
				<?php
					}
				?>					
			</div>
			
		</div>
		

		
		<script type="text/javascript">
			$image = "url('<?php echo $ligne['Image2'];?>')";
			$couleur = "#<?php echo $ligne['Couleur'];?>";
			$('#sous_fond_fiche h3').css('background', $couleur);
			$('#sous_fond_fiche h2').css('color', $couleur);
			$('#sous_fond_fiche h4').css('color', $couleur);
			$('.arborescence a').css('color', $couleur);
			$('.caracteristiques_infos').css('backgroundImage', $image);
		</script>
		
		<?php
		}
		?>
		
    </body>
</html>