Hierarchy.php 2.40 KiB
<!DOCTYPE html>
<html>
<head>
<title>Drinkpedia</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/Hierarchy.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="scripts/DataQuery.js"></script>
</head>
<body id="body">
<!-- PHP -->
<?php
// DEBUT DES ACTIONS SUR LA PAGE :
include "scripts/Functions.php";
if(!isset($_GET['element'])) {
// Si on ouvre la Hiérachie pour la première fois, on part de 'Vin effervescent'
$aliment = 'Aliment';
} else {
// Sinon on récupère l'aliment en cours
$aliment = $_GET['element'];
$aliment = trim($aliment, '"');
}
$sup_cat = get_super_categories($aliment);
$sous_cat = get_sous_categories($aliment);
// Crée la disposition de la hiérarchie
echo '<div class="hierarchy_view">';
// On affiche les Super-Catégories, s'il y'en a :
if($sup_cat != null) {
echo '<div class="category-view">';
echo '<h1> Super-catégories de '.$aliment.' </h1>';
if($sup_cat != null) foreach($sup_cat as $cat) {
echo '<li><button onclick="notifyParent('."'".$cat."'".');">'.$cat.'</button></li>';
}
echo '</div>';
}
// On affiche les sous-catégories, s'il y'en a :
if($sous_cat != null) {
echo '<div class="category-view">';
echo '<h1> Sous-catégories de '.$aliment.' </h1>';
if($sous_cat != null) foreach($sous_cat as $cat) {
//echo '<li><button onclick="notifyParent('.$cat.');">'.$cat.'</button></li>';
echo '<li><button onclick="notifyParent('."'".$cat."'".');">'.$cat.'</button></li>';
}
echo '</div>';
}
echo '</div>';
?>
<!-- JAVASCRIPT -->
<script>
function notifyParent($aliment) // Send a message to the parent window, asking to change to page $aliment
{
var data = {
event: 'hierarchyDisplay',
value: $aliment
};
window.top.postMessage(data, [data.event, data.value]);
}
</script>
</body>
</html>