aboutsummaryrefslogtreecommitdiff
path: root/public/products.php
blob: ce0ada5616632d92081b39a2403f0ebaa8488c62 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<?php require "../lib/db.php"; ?>
<?php require "../lib/login.php"; ?>
<?php 
function product_template($product) {
	$image_path = $product->image ? "/img/product/$product->id-thumb.jpg" : "/img/placeholder.png";
	echo <<<"EOF"
	<a href="/product.php?id=$product->id" class="product nolinkstyle">
		<img src="$image_path" alt="">
		<span class="price">$product->price</span>
		<span class="name">$product->name</span>
	</a>
EOF;
}
?>
<?php $cat_id = $_GET['c']; ?>
<?php function categories_recursive($id = null) {
	global $cursor, $cat_id;
	if ($id === null) {
		$res = $cursor->query("select id, name, parent from category where parent is null");
	} else {
		$statement = $cursor->prepare("select id, name, parent from category where parent = ?");
		$statement->bind_param("i", $id);
		$statement->execute();
		$res = $statement->get_result();
	}
	if (!mysqli_num_rows($res)) return;
	echo '<div class="sub">';
	$categories = $res->fetch_all(MYSQLI_ASSOC);
	foreach ($categories as $category) {
		// php is een hele mooie programmeertaal die heel fijn werkt
		echo "<a href='?c=";
		echo $category["id"];
		echo "' class='";
		echo "category ";
		if ($category["id"] == $cat_id) echo "current ";
		echo "'>";
		echo $category["name"];
		echo "</a>";
		categories_recursive($category["id"]);
	}
	echo '</div>';
} ?>
<html>
<head>
	<?php include 'head.php' ?>
	<title>producten</title>
	<link rel='stylesheet' type='text/css' media='screen' href='products.css'>
</head>
<body>
	<?php include 'navbar.php' ?>
	<div class="main limwidth">
		<div class="twocolumn">
			<div class="left">
				<h2>Filters</h2>
				<h3>Categorieën</h3>
				<div class="categories">
					<a href="?">Reset</a>
					<?php categories_recursive() ?>
				</div>
			</div>
			<div class="right">
				<?php
					$id = $_GET['c'];
					echo "<h2>Producten";
					if ($id !== null) echo " in categorie $id";
					echo "</h2>";
				?>
				<?php do {
					if (($user_privileges & PRIVILEGE_ADMIN) == 0) break;
					echo <<<"EOF"
						<div class="center">
							<form action="/admin-product.php" method="get" class="d-ib">
								<input type="submit" value="Nieuw product toevoegen" class="button filled">
							</form>
							<form action="/admin-category.php" method="get" class="d-ib">
								<input type="submit" value="Nieuwe categorie toevoegen" class="button filled">
							</form>
						</div>
					EOF;
				} while (false); ?>
				<div class="products">
					<?php
						if ($id === null) {
							$res = $cursor->query("select id, image, price, name from webs.product");
						} else {
							$statement = $cursor->prepare("select id, image, price, name from webs.product where category = ?");
							$statement->bind_param("i", $id);
							$statement->execute();
							$res = $statement->get_result();
						}
						while ($product = $res->fetch_object()) product_template($product);
					?>
				</div>
			</div>
		</div>
	</div>
	<?php include 'footer.php' ?>
</body>
</html>