forked from Nayar/web-tech
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecipes.php
61 lines (50 loc) · 1.65 KB
/
recipes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Authors: JOOLFOO Nayar (1118369)
* DILJORE Humeira (1110539)
* GAUZEE Basheera (1115178)
*/
require "inc/core.php";
// See if listing is to be done usign category
if(isset($_GET['cat_id'])) {
$recipes = $Recipes->get_multiple("WHERE recipes.cat_id = '{$_GET['cat_id']}'");
}
// Or name
elseif(isset($_GET['name'])) {
$recipes = $Recipes->get_multiple("WHERE recipes.name LIKE '%{$_GET['name']}%'");
}
elseif(isset($_GET['geniuscook'])) {
foreach($_POST['ingredient'] as $key=>$value){
if($value == '') {
unset($_POST['ingredient'][$key]);
}
}
// We get a string in which the ingredient names are separated by commas
$ingredients = implode('%" OR ingredients.ingr_name LIKE "%',$_POST['ingredient']);
// Need to rework Query <------------------------------------------------
$recipes = $Recipes->get_multiple('WHERE recipes.recipe_id IN
(
SELECT recipe_id
FROM recipes_ingr_qty
LEFT JOIN ingredients on recipes_ingr_qty.ingr_id = ingredients.ingr_id
WHERE ingredients.ingr_name LIKE "%'.$ingredients.'%"
GROUP BY recipe_id
HAVING count(ingredients.ingr_id) >= 2
ORDER BY count(ingredients.ingr_id) DESC
)');
}
// Else we display all the recipes in chronological order
else {
$recipes = $Recipes->get_multiple("ORDER BY timeposted DESC");
}
$recipelist = "";
foreach($recipes as $recipe) {
eval("\$recipelist .= \"".$templates->simple_get("gallery_recipe")."\";");
}
if($recipelist == "") {
$recipelist = "No recipe found as per your search";
}
eval("\$contents = \"".$templates->get_page("gallery_page")."\";");
eval("\$headerincludes = \"".$headerincludes."\";");
$templates->output_page($contents);
?>