-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproducts.php
130 lines (106 loc) · 3.96 KB
/
products.php
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
include 'incs/header.php';
include 'classes/dbh.php';
$dbh = new Dbh();
?>
<body id=producten-body>
<?php
include 'incs/navBar.php';
?>
<?php
if (isset($_SESSION['userId']) && $userRole == "admin") {
echo "
<div id=\"admin-products-nav\">
<a href= \"products.php\" id=\"admin-nav-producten\" class= \"admin-products-nav-title\" style=\"border-bottom: 3px solid #253d84\">Producten</a>
<a href=\"categories.php\" id=\"admin-nav-categorieen\" class= \"admin-products-nav-title\" style=\"opacity: 0.3\">Categorieën</a>
</div>
";
}
?>
<form class="search-bar" methode="post" action="">
<input id="search" class="input-search" type="text" name="search" placeholder="Zoek een product">
<button type="submit" name="submit-search"><i class="fas fa-search"></i></button>
</form>
<div id="search-results"></div>
<div id=all-products>
<?php
if (isset($_SESSION['userId']) && $userRole == "admin") {
echo "
<div id=\"add-product\">
<a href=\"addProduct.php\" id=\"add-product-href\"> +<br>Product toevoegen</a>
</div>
";
}
?>
<?php
$stmtCategory = $dbh->connection()->prepare("SELECT * FROM product_category ORDER BY rand()");
$stmtCategory->execute();
$resultCategory = $stmtCategory->fetchAll();
foreach ($resultCategory as $category) {
echo "<div class=\"products-wrapper-category\">";
echo "<h2 class=\"category-title\">$category[category_name]</h2>";
$stmt = $dbh->connection()->prepare("SELECT * FROM product INNER JOIN product_category ON product.product_category = product_category.category_id INNER JOIN product_image ON product_image.product_id = product.product_id WHERE product_category = $category[category_id] ORDER BY rand();");
$stmt->execute();
$result = $stmt->fetchAll();
echo "<div id=\"products-wrapper\">";
foreach ($result as $row) {
if (isset($_SESSION['userId']) && $userRole == "admin") {
if (($row['product_quantity'] < 1) || ($row['product_availability'] != "true")) {
echo "
<div class=\"product\">
<div class=\"imgbox\">
<filter style=\"filter: grayscale(100%);\">
<img src=\"imgs/$row[image_name]\">
</filter>
</div>
<div class=\"detailsAdmin\">
<h2>$row[product_name]</h2>
<div class=\"price\">
€$row[product_price],-
</div>
<a href=\"viewProduct.php?id=$row[product_id]\">Bekijken</a>
<a href=\"editProduct.php?id=$row[product_id]\" style=\"background-color:orange\">Bewerken</a>
<a href=\"deleteProduct.php?id=$row[product_id]\" style=\"background-color:darkred\">Verwijderen</a>
</div>
</div>";
} else {
echo "
<div class=\"product\">
<div class=\"imgbox\">
<img src=\"imgs/$row[image_name]\">
</div>
<div class=\"detailsAdmin\">
<h2>$row[product_name]</h2>
<div class=\"price\">
€$row[product_price],-
</div>
<a href=\"viewProduct.php?id=$row[product_id]\">Bekijken</a>
<a href=\"editProduct.php?id=$row[product_id]\" style=\"background-color:orange\">Bewerken</a>
<a href=\"deleteProduct.php?id=$row[product_id]\" style=\"background-color:darkred\">Verwijderen</a>
</div>
</div>";
}
} elseif (($row['product_quantity'] > 0) && ($row['product_availability'] != "false")) {
echo "
<div class=\"product\">
<div class=\"imgbox\">
<img src=\"imgs/$row[image_name]\">
</div>
<div class=\"details\">
<h2>$row[product_name]<br><span>$row[category_name]</span></h2>
<div class=\"price\">
€$row[product_price],-
</div>
<a href=\"viewProduct.php?id=$row[product_id]\">Bekijken</a>
</div>
</div>";
}
}
echo "</div>";
echo "</div>";
}
?>
</div>
<?php
include 'incs/footer.php';
?>