-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_meal.php
176 lines (156 loc) · 6.18 KB
/
edit_meal.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
require("connect-db.php");
require('meals.php');
require('foods.php');
session_start();
$foodID = "default";
// if user is not logged in or doesn't own the mealm redirect
if($_SESSION["userID"] == 0) {
header("Location: login_form.php");
}
if($_POST["copyMeal"]) {
$_POST["mealID"] = copyMealToUser($_SESSION["userID"], $_POST["mealID"]);
}
$mealID = $_GET["mealID"] ? $_GET["mealID"] : $_POST["mealID"];
if(!$mealID || !madeMeal($mealID, $_SESSION["userID"])) {
header("Location: designed_meals.php");
}
if($_SERVER["REQUEST_METHOD"] == "POST") {
if($_POST["updateMeal"]) {
updateMeal($mealID, $_POST["name"], $_POST["num_of_servings"], $_POST["prep_time"], $_POST["calorie_count"], $_POST["time_of_day"]);
} else if($_POST["deleteMeal"]) {
deleteMeal($mealID);
header("Location: designed_meals.php");
} else if($_POST["addFood"]) {
$foodID = getFoodId($_POST['name']);
if ($foodID){
addFoodToMeal(getFoodId($_POST["name"]), $_POST["mealID"], $_POST["quantity"]); }
else {
$foodID = "";
}
} else if($_POST["deleteFood"]) {
deleteFoodFromMeal($_POST["foodID"], $mealID);
}
else if (!empty($_POST['addBtn']) && ($_POST['addBtn'] == "Add Food")){
addFoodCaloriesTempGroup($_POST['entered-food-name'], $_POST['cooked-status'], $_POST['calories'], $_POST['ideal_storage_temp'], $_POST['food_group']);
addFoodToMeal(getFoodId($_POST["entered-food-name"]), $_POST["mealID"], $_POST["quantity"]);
}
}
$meal = getMeal($mealID);
$foods = getFoodsOfMeal($mealID);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php include("common-header.php"); ?>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<?php include("navbar.php"); ?>
<div class="jumbotron feature" style = "margin-bottom: 10px;">
<div class="container">
<h1>Edit Meals</h1>
<p>Choose which foods you want in this meal</p>
</div>
</div>
<div class = "outer-container-edit-meals" id = "outer-container-edit-meals">
<div class = "container-edit-meals" id = "container-edit-meals">
<h1>Edit Meal</h1>
<form name="editMeal" action="edit_meal.php" method="post">
<div class="row mb-3 mx-3"> Name of meal:
<input type="text" class="form-control" name="name" value="<?php echo $meal["name"]; ?>" required />
</div>
<div class="row mb-3 mx-3">Number of servings:
<input type="number" class="form-control" value="<?php echo $meal["num_of_servings"]; ?>" name="num_of_servings"/>
</div>
<div class="row mb-3 mx-3">Prep time (min):
<input type="number" class="form-control" value="<?php echo $meal["prep_time"]; ?>" name="prep_time" />
</div>
<div class="row mb-3 mx-3">Calorie count:
<input type="number" class="form-control" value="<?php echo $meal["calorie_count"]; ?>" name="calorie_count" />
</div>
<div class="row mb-3 mx-3">Time of day:
<input type="text" class="form-control" value="<?php echo $meal["time_of_day"]; ?>" name="time_of_day" />
</div>
<div class="row mb-3 mx-3">
<input type="hidden" name="mealID" value=<?php echo $mealID ?>>
<input class="btn btn-primary" type="submit" name="updateMeal" value="Update" style = "margin-bottom:10px;"/>
<input class="btn btn-danger" type="submit" name="deleteMeal" value="Delete" />
</div>
</form>
</div>
<div class = "container-edit-meals-add-food" id = "container-edit-meals-add-food">
<h1>Add food</h1>
<form name="addFood" action="edit_meal.php" method="post">
<div class="row mb-3 mx-3"> Name:
<input type="text" class="form-control" name="name" required />
</div>
<div class="row mb-3 mx-3">Servings:
<input type="number" class="form-control" name="quantity" required />
</div>
<div class="row mb-3 mx-3">
<input type="hidden" name="mealID" value=<?php echo $mealID ?>>
<input class="btn btn-primary" type="submit" name="addFood" value="Add Food" />
</div>
</form>
</div>
</div>
<div class="container">
<div class="modal" id="addFoodModal" tabindex="-1" role="dialog" aria-labelledby="addFoodModalLabel" aria-hidden="true" display = "none;">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addFoodModalLabel">Add Food Before Adding to Meal!</h5>
<button type="button" class="close close_btn" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form id="foodForm" action="edit_meal.php" method="post" class="form-border">
<input type="hidden" name="mealID" value=<?php echo $mealID ?>>
<input type="hidden" name="quantity" value=<?php echo $_POST['quantity'] ?>>
<?php include("new_food_modal_form.php"); ?>
</form>
</div>
</div>
</div>
<div class="row justify-content-center">
<table class="w3-table w3-bordered w3-card-4 center" style="width:70%">
<thead>
<tr style="background-color:#B0B0B0">
<th width="20%"> Name
<th width="20%"> Servings
<th width="20%"> Delete
</tr>
</thead>
<?php foreach ($foods as $item): ?>
<?php
?>
<tr>
<td><?php echo $item['name']; ?></td>
<td><?php echo $item['quantity']; ?></td>
<td>
<form action="edit_meal.php" method="post">
<input type="submit" name="deleteFood" value="Delete" class="btn btn-danger btn-sm" />
<input type="hidden" name="foodID", value="<?php echo $item['foodID']; ?>" />
<input type="hidden" name="mealID", value="<?php echo $mealID; ?>" />
</form>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
</body>
</html>
<script>
$(document).ready(function() {
$(".close_btn").click(function() {
$("#addFoodModal").hide();
});
console.log("<?php echo $foodID; ?>");
if ("<?php echo $foodID; ?>" === "") {
$("#addFoodModal").show();
} else {
$("#addFoodModal").hide();
}
});
</script>