aboutsummaryrefslogtreecommitdiff
path: root/public/index.php
blob: 0fd0ff2e54f6e31d6bd9e39d7cea690e45f1f02f (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
<!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">
		<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>