Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/projects/slutprojekt/logged_in/
dashboard.php
orders.php
restaurant.php
restaurant.php
79 lines UTF-8 Windows (CRLF)
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
<?php
session_start();
if (!$_SESSION["permission"]) {
echo "Du är inte inloggad med korrekt behörighet";
die();
}
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard</title>
<link rel="stylesheet" href="../css/style.css">
</head>
<body>
<?php
include __DIR__ . '/../incl/elements/nav.php';
?>
<div class="big-flex">
<?php
require_once __DIR__ . '/../../../dbconnect.php';
$stmt = $dbconn->prepare("SELECT id, item_name, item_description, item_price, item_image FROM slutprojekt_menu_items WHERE restaurant_id=? AND item_enabled=?");
$stmt->execute([$_GET["restaurant_id"], true]);
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
?>
<div class="flex-item">
<img src="../img/menu-items/<?php echo $res['item_image']; ?>" class="img-block" alt="Logotyp: <?php echo $res["item_name"]; ?>">
<h2>
<?php echo $res["item_name"]; ?>
</h2>
<p>
<?php echo $res["item_description"]; ?>
</p>
<button class="btn-order" id="button-order-<?php echo $res['id']; ?>" onclick="sendOrder(<?php echo $res['id']; ?>)">Beställ</button>
</div>
<?php
}
?>
</div>
<script>
function sendOrder(itemId) {
// Skapa ett FormData-objekt och lägg in alla key-value-par
const formData = new FormData();
formData.append('item_id', itemId);
// Skicka POST-förfrågan med fetch
const url = '../endpoints/order-handling/register-order.php';
fetch(url, {
method: 'POST',
body: formData
})
.then(response => response.text())
.then(result => {
console.log('Svar från servern:', result);
if (result.trim() === "success") {
const orderButton = document.getElementById('button-order-' + itemId);
orderButton.innerText = "Beställning mottagen";
orderButton.classList.remove('btn-order');
orderButton.classList.add('btn-order-placed');
orderButton.setAttribute('disabled', "true")
}
})
.catch(error => {
console.error('Fel vid förfrågan:', error);
});
}
</script>
</body>
</html>