Skip to content

Commit 6d7fb19

Browse files
committed
Merge branch 'change_order_state'
2 parents ed38b54 + 0710c6b commit 6d7fb19

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
function updateRestaurantInfo($db,$orderID,$state) {
3+
$stmt = $db->prepare(
4+
'UPDATE FoodOrder
5+
SET state = :state
6+
WHERE orderID = :id'
7+
);
8+
$stmt->bindParam(':id', $orderID);
9+
$stmt->bindParam(':state', $state);
10+
11+
$stmt->execute();
12+
}
13+
?>

php/actions/edit-order-state.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
require_once('../../database/db-connection.php');
3+
require_once('../../database/data-fetching/user.php');
4+
require_once('../../database/data-fetching/restaurants.php');
5+
require_once('../../database/data-insertion/update-order-info.php');
6+
7+
session_start();
8+
$db = getDatabaseConnection('../../database/restaurants.db');
9+
$user_info = getUserbyID($db, $_SESSION['userID']);
10+
$restaurant_info = getRestaurantInfo($db, $_GET['restaurantID']);
11+
$ownerID = $restaurant_info['ownerID'];
12+
13+
if ($_SESSION['userID'] === NULL) {
14+
header('Location: ../../register-page.php');
15+
} else if ($user_info['owner'] === 0 || $user_info['userID'] !== $ownerID) {
16+
header('Location: ../../restaurant-orders-page.php');
17+
}
18+
19+
updateRestaurantInfo($db,$_GET['orderID'],$_GET['state']);
20+
header('Location: ../../restaurant-orders-page.php?restaurantID=' . $_GET['restaurantID']);
21+
22+
?>

php/output-functions/draw-restaurant-orders.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ function outputRestaurantOrders() {
2929
?>
3030
</div>
3131
<p class="orderState"><?=$order['state']?></p>
32-
<button class="button">Change State</button> <!-- TODO: mudar para dropdown -->
32+
<form action="php/actions/edit-order-state.php" methode="get">
33+
<select name="state">
34+
<option value="Received">Received</option>
35+
<option value="Preparing">Preparing</option>
36+
<option value="Ready">Ready</option>
37+
</select>
38+
<input type="hidden" value="<?=$order['orderID']?>" name="orderID">
39+
<input type="hidden" value="<?=$_GET['restaurantID']?>" name="restaurantID">
40+
<input class="button" type="submit" value="Change State">
41+
</form>
3342
<?php
3443
} ?>
3544
</section>

0 commit comments

Comments
 (0)