-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_recipe.php
executable file
·128 lines (108 loc) · 4 KB
/
view_recipe.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
session_start();
require_once 'classes/Recipe.php';
require_once 'classes/Category.php';
require_once 'classes/Util.php';
$util = new Util();
$category = new Category();
$categories = $category->getAllCategories();
$recipe = new Recipe();
$recipeDetails = array();;
$tags = array();
$recipeId = "";
if (isset($_GET['recipe_id'])) {
$recipeId = $util->decryptPK($_GET['recipe_id']);
$recipeDetails = $recipe->getRecipeOnly($recipeId);
if (!empty($recipeDetails)) {
$recipeAndTags = $recipe->getRecipeAndTags($recipeId);
$tags = array_column($recipeAndTags, 'tag_name');
} else {
$_SESSION['error_message'] = "The page you are looking for does not exist!";
header("Location:index.php");
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>View Recipe - Recipes of the World</title>
<?php include_once('meta.php'); ?>
</head>
<body>
<?php include_once('header.php'); ?>
<section id="section1">
<?php include_once('_logout.php'); ?>
</section>
<section id="section4">
<?php include_once('_tag_pop_up.php'); ?>
<form method="post" action="" id="add-recipe-form">
<table width="30%" cellpadding="5" cellspacing="5" border="0">
<tr>
<td></td>
<td>
<?php
$image = "default.png";
if (isset($recipeDetails['photo'])) {
$image = $recipeDetails['photo'];
}
?>
<img src="image_uploads/<?php echo $image; ?>" width="200" height="200">
</td>
</tr>
<tr>
<td>Country</td>
<td><?php echo $recipeDetails['country']; ?></td>
</tr>
<tr>
<td>Name</td>
<td>
<?php echo $recipeDetails['name']; ?>
</td>
</tr>
<tr>
<td>
Description (How to?)
</td>
<td>
<?php echo $recipeDetails['description']; ?>
</td>
</tr>
<tr>
<td>Tag (s)</td>
<td>
<?php echo implode(", ", $tags); ?>
</td>
</tr>
<tr>
<td>
<?php if ($_SESSION['admin'] == 1 || $_SESSION['user_id'] == $recipeDetails['userID']) {
?>
<a onclick="return validateDelete(<?php echo $util->encryptPK($recipeId);?>)">
<button type="button">Delete Recipe</button>
</a>
</td>
<?php
} ?>
<?php if ($_SESSION['user_id'] == $recipeDetails['userID']) {
?>
<td>
<a href="edit_recipe.php?recipe_id=<?php echo $util->encryptPK($recipeId);?>">
<button type="button">Edit Recipe</button>
</a>
</td>
<?php
}?>
</tr>
</table>
</form>
</section>
</body>
</html>
<script>
function validateDelete(recipeId) {
if (!confirm('Are you sure you want to delete this item permanently?')) {
return false;
}
window.location = 'delete_recipe.php?recipe_id=' + recipeId;
}
</script>