aboutsummaryrefslogtreecommitdiff
path: root/public/admin-order.php
blob: debde66571bf698bf9c2b133ba4d8ccf607f15fe (plain)
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
<!DOCTYPE html>
<?php require "../lib/login.php"; ?>
<?php if_privileged(PRIVILEGE_ADMIN, "/") ?>
<?php do {
	if ($_SERVER['REQUEST_METHOD'] !== 'POST') break;
	$order_id = $_POST['id'];
	$new_status = $_POST['status'];
	if (!$order_id) break;
	if (!$new_status) break;

	$statement = $cursor->prepare("update `order` set status = ? where id = ?");
	$statement->bind_param("ii", $new_status, $order_id);
	$statement->execute();
} while (false); ?>
<?php
function order_template($order) {
	echo <<<"EOF"
		<form method="post">
			<input type="hidden" name="id" value="$order->id">
			<tr>
				<td>$order->id</td>
				<td>$order->user_name</td>
				<td>$order->product_count</td>
				<td>
					<select name="status">
	EOF;
	$stages = array(
		1 => "in winkelwagen",
		"besteld",
		"onderweg",
		"afgeleverd",
	);
	foreach ($stages as $id => $name) {
		$selected = $id == $order->status ? ' selected' : '';
		echo "<option value=\"{$id}\"{$selected}>{$name}</option>";
	}
	echo <<<"EOF"
					</select>
				</td>
				<td>
					<input type="submit" value="bijwerken">
				</td>
			</tr>
		</form>
	EOF;
}
?>

<html>
<head>
	<?php include 'head.php' ?>
	<title>orders</title>
	<link rel="stylesheet" href="admin.css">
</head>
<body>
	<?php include 'navbar.php' ?>
	<div class="main limwidth">
		<h2>bestellingen</h2>
		<p>hier kun je bestellingen zien en de status aanpassen. wijzigingen kunnen doorgevoegd worden door op de 'bijwerken'-knop te drukken na het aanpassen van de status. maar één bestellingen kan aangepast worden per update!!</p>
		<table>
			<tr>
				<th>ID</th>
				<th>besteller</th>
				<th>aantal producten</th>
				<th>status</th>
				<th>update</th>
			</tr>
			<?php
				$res = $cursor->query("select `order`.id as id, sum(orderproduct.count) as product_count, user.name as user_name, `order`.status from orderproduct join `order` on `order`.id = orderproduct.`order` join user on user.id = `order`.user where status > 1 group by orderproduct.`order` order by status asc");
				while ($order = $res->fetch_object()) order_template($order);
			?>
		</table>
	</div>
	<?php include 'footer.php' ?>
</body>
</html>