aboutsummaryrefslogtreecommitdiff
path: root/public/cart.php
blob: f9538804241e7e8469ef7c0cb9a2e00074637c39 (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
<!DOCTYPE html>
<?php require "../lib/db.php" ?>
<?php require "../lib/login.php" ?>
<?php if_logged_in(false, "/login.php", true) ?>
<?php
do {
	if ($_SERVER['REQUEST_METHOD'] !== 'POST') break;
	if (!$_POST['product_id']) break;

	// TODO: add product to cart
	// $statement = $cursor->prepare("select id, image, price, name, description from webs.product where id = ?");
	// $statement->bind_param("i", $_GET['id']);
	// if (!$statement->execute()) refuse();
	// $res = $statement->get_result();
	// if (!mysqli_num_rows($res)) refuse();
	// $product = $res->fetch_object();


	// if all guards passed, successful login occurred
	cookie_redir($_POST['username'], $_POST['password']);
} while (false);
?>
<?php 
function item_template($item) {
	$image_path = $item->image ? "/img/product/$item->id-thumb.jpg" : "/img/placeholder.png";
	echo <<<"EOF"
	<div class="product">
		<img src="$image_path" alt="productafbeelding">
		<span class="name">$item->name</span>
		<label for="$item->id-count">hoeveelheid:</label>
		<input type="number" value="$item->count" min="1" max="20" id="$item->id-count">
		<button id="$item->id-delete">weghalen</button>
		<span class="price">$item->price</span>
	</div>
EOF;
}
?>
<html>
<head>
	<?php include 'head.php' ?>
	<title>mand</title>
	<link rel="stylesheet" href="cart.css">
</head>
<body>
	<?php include 'navbar.php' ?>
	<div class="main limwidth">
	<h2>dingen in de mand van <?php echo $username ?></h2>
		<div class="products">
			<?php do {
				global $username;
				$statement = $cursor->prepare("select product.id, product.name, product.price, product.image, cart.count from cart join customer on customer.id = cart.customer join product on product.id = cart.product where customer.name = ?");
				$statement->bind_param("s", $username);
				if (!$statement->execute()) break;
				$res = $statement->get_result();
				if (!mysqli_num_rows($res)) {
					echo "mandje leeg";
					break;
				}
				while ($product = $res->fetch_object()) item_template($product);
			} while (false); ?>
		</div>
	</div>
	<?php include 'footer.php' ?>
</body>
</html>