diff --git a/Cocktails.php b/Cocktails.php index e6d028e9c02ffa5c800877b85c4814bd1bc6d729..eb8df4e6baa67a3b0ae58324fec186bd9b8af02d 100644 --- a/Cocktails.php +++ b/Cocktails.php @@ -11,16 +11,30 @@ <ul> <?php - include "scripts/Functions.php"; - $ar = getRecipes(['Malibu'], [], 10, true, true); + include "Donnees.inc.php"; + $ar = $Recettes; - foreach($ar as $r) + for($i = 0; $i < count($ar); $i++) { - echo '<li>' . $r['recipe']['titre'] . ' (unsatisfied ingredients = ' . $r['score'] . ')' . '</li>'; + echo '<li onclick="notifyParent(' . $i . ');">' . $ar[$i]['titre'] . '</li>'; } ?> </ul> + + <script> + + function notifyParent(e) // Send a message to the parent window, asking to display the recipe #e + { + var data = { + event: 'recipeselect', + value: Number(e) + }; + window.top.postMessage(data, [data.event, data.value]); + } + + </script> + </body> </html> \ No newline at end of file diff --git a/Hierarchy.php b/Hierarchy.php index b0439e7357e48efdbda1b061ec09fe2c69bd685a..4b1c1f2723193e1d4842678f247643f6316b60eb 100644 --- a/Hierarchy.php +++ b/Hierarchy.php @@ -10,34 +10,17 @@ <body id="body"> - <ul id="origin_list"></ul> + <!-- HTML --> + + <!-- JAVASCRIPT --> - <script> - let n_list_origin = document.getElementById('origin_list'); - //let ingredients = getIngredients(); + <script> + - function detailIngredients() - { - let d = document.getElementsByClassName('detailed'); - let ud = document.getElementsByClassName('undetailed'); - for(let el in ud) - { - while (el.firstChild) { - el.removeChild(el.firstChild); - } - } - for(let el in d) - { - let c = getIngredients(el.value, function (data, status) - { - - }); - } - } - function notifyParent(e) + function notifyParent(e) // Send a message to the parent window, asking to display the recipe #e { var data = { event: 'recipeselect', diff --git a/Home.php b/Home.php index 4bca3865488785d7dcaa575f1d0cb55c5db7000b..2702c225156a5e5f482114f735309f2d5a8a8bb9 100644 --- a/Home.php +++ b/Home.php @@ -60,12 +60,12 @@ wraper.disabled = false; } - function showRecipe(id) + function showRecipe(id) // Show the Recipe with the id 'id' in the file 'Donnees.inc.php' { embed.setAttribute('src','RecipeView.php?id_recipe=' + id); - wrapper.classList.add('active'); - content.classList.add('blur'); + wrapper.classList.add('active'); // Set the RecipeView wrapper active + content.classList.add('blur'); // Blurs the original content of the page wrapper.disabled = true; embed.focus(); diff --git a/scripts/Functions.php b/scripts/Functions.php index 0a92146763063dcc98a58b22146bad67d9f0149e..efde0974766fe66a2f1807d40d490b4d4a93fc7a 100644 --- a/scripts/Functions.php +++ b/scripts/Functions.php @@ -59,13 +59,16 @@ function getRecipes($wanted_ingredients, $unwanted_ingredients, $max_unsatisfied function getIngredients($parent_category) { include "../Donnees.inc.php"; - $res = ''; - $ingredients = $Hierarchie[$parent_category]['sous-categorie']; - foreach($ingredients as $i) + if(isset($Hierarchie[$parent_category])) { - $res .= $i . '|'; + $ingredients = $Hierarchie[$parent_category]['sous-categorie']; + + foreach($ingredients as $i) + { + $res .= $i . '|'; + } } return $res;