aboutsummaryrefslogtreecommitdiff
path: root/public/index.php
blob: fecf624a6e16275cc9b4effd0eb4cedb22cd6de2 (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
<!DOCTYPE html>
<?php require "../lib/db.php"; ?>
<?php
function promobuff2str($price_buff, $count_buff) {
	if ($count_buff == 1) return ((1-$price_buff)*100)."% korting";
	if ($count_buff <= 4) {
		for ($i = $count_buff-1; $i > 0; $i--)
			if (abs((($i/$count_buff)-$price_buff)/$price_buff) < 0.001)
				return $i."+".($count_buff - $i)." gratis";
	}
	return ((1-$price_buff)*100)."% korting per ".$count_buff."-pack";
}
?>
<html>
<head>
	<?php include 'head.php' ?>
	<title>webshop</title>
	<link rel='stylesheet' type='text/css' media='screen' href='home.css'>
</head>
<body>
	<?php include 'navbar.php' ?>
	<div class="main limwidth">
		<?php do {
			if (($user_privileges & PRIVILEGE_ADMIN) == 0) break;
			echo <<<"EOF"
				<div class="center">
					<form action="/admin-promo.php" method="get" class="d-ib">
						<input type="submit" value="Aanbiedingen beheren" class="button filled">
					</form>
				</div>
			EOF;
		} while (false); ?>
		<div class="s1">
			<h1>hier zijn de aanbiedingen</h1>
			<ul>
				<?php
					$res = $cursor->query("select product.id, product.name as name, promotion.count_buff, promotion.price_buff from promotion join product on product.id = promotion.product");
					while ($product = $res->fetch_object()) {
						echo "<li><a href=\"/product.php?id=$product->id\">$product->name</a>: ";
						echo promobuff2str($product->price_buff, $product->count_buff);
						echo "</li>";
					}
				?>
			</ul>
		</div>
	</div>
	<?php include 'footer.php' ?>
</body>
</html>