This repository was archived by the owner on Mar 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategory.php
More file actions
212 lines (181 loc) · 10 KB
/
Copy pathcategory.php
File metadata and controls
212 lines (181 loc) · 10 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
session_start();
include_once('./lib/csrf.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://bootswatch.com/5/minty/bootstrap.min.css" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-dark-5@1.1.3/dist/css/bootstrap-dark.min.css" media="(prefers-color-scheme: dark)" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" crossorigin="anonymous">
<link rel="stylesheet" href="./main.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="icon" type="image/x-icon" href="favicon.ico">
<title>IERG4210 Phase 5</title>
</head>
<body>
<nav class="fixed-top navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container-fluid">
<a class="navbar-brand" href="./index.php">IERG4210 Store</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="./index.php">Home</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link active dropdown-toggle" href="#" id="navbarDropdown" role="button"
data-bs-toggle="dropdown" aria-expanded="false">
Categories
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<?php
require __DIR__.'/admin/lib/db.inc.php';
$res = ierg4210_cat_fetchall();
$res2 = ierg4210_prod_fetchall();
foreach ($res as $cat){
echo '<li>';
echo '<a class="dropdown-item" href="category.php?catid=' . $cat["CATID"] . '">' . $cat["NAME"] . '</a>';
echo '</li>';
}
?>
</ul>
</li>
<li class="nav-item">
<a tabindex="0" class="nav-link active d-none d-lg-block" href="#" data-bs-toggle="popover"
data-bs-trigger="hover" type="button" data-bs-placement="bottom" data-bs-html="true"
data-content-id="shoppingcart">Shopping Cart <i class="bi bi-cart"></i></a>
<a tabindex="0" class="nav-link d-lg-none" href="#">Shopping Cart <i class="bi bi-cart"></i></a>
</li>
<?php
if ($_SESSION['admin_token']||$_SESSION['user_token'])
echo '<li class="nav-item">
<form action = "../auth-process.php?action=logout" id="logout" method="post">
<a type="submit" class = "nav-link active" onclick="document.getElementById(\'logout\').submit()" >Logout</a>
<input type="hidden" name="nonce" value="' . csrf_getNonce("logout"). '"/>
</form>
</li>';
else
echo '<li class="nav-item">
<a href="../login.php" class = "nav-link active">Login</a>
</li><li class="nav-item"><a href="../changepw.php" class = "nav-link active">Change Password</a></li>';
?>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="./recentorders.php">Recent Orders</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="position-relative overflow-hidden p-3 p-md-5 m-md-3 text-center bg-light">
<div class="col-md-6 p-lg-6 mx-auto my-5">
<?php
$catname = ierg4210_cat_fetchOne($_GET["catid"]);
if ($catname == null) {
header("Location: ./404.php");
exit();
};
echo '<p class="display-4 font-weight-normal">'. htmlspecialchars($catname[0]["NAME"]) .'</p>';
?>
</div>
<div class="product-device box-shadow d-none d-md-block"></div>
<div class="product-device product-device-2 box-shadow d-none d-md-block"></div>
</div>
<div class="container">
<div class="row">
<span class="navbar-brand"> Hey there,
<?php
if ($_SESSION['username']) {echo htmlspecialchars($_SESSION['username']);} else {echo "Guest";};
?>!
<nav class="navbar navbar-light p-3 d-flex justify-content-start">
<div><span class="navbar-brand">You are now at:</span></div>
<div><a class="nav-link" href="./index.php">Home</a></div>
<div><span class="navbar-text">></span></div>
<?php
echo '<div><a class="nav-link active" href="#">'. htmlspecialchars($catname[0]["NAME"]) .'</a></div>';
?>
</nav>
</div>
</div>
<div class="container mb-5">
<div class="row">
<div class="d-none d-md-block col-md-2 navbar navbar-light">
<ul class="navbar-nav flex-column">
<li class="nav-item mb-2">
<a class="navbar-brand">Categories:</a>
</li>
<?php
foreach ($res as $cat){
echo '<li class="nav-item">';
echo '<a class="nav-link active" href="category.php?catid=' . $cat["CATID"] . '">' . htmlspecialchars($cat["NAME"]) . '</a>';
echo '</li>';
}
?>
</ul>
</div>
<div class="col-md-10">
<div class="album py-3 ">
<div class="container">
<div class="row">
<?php
foreach ($res2 as $prodkey => $prod){
if ($prod["CATID"] != $_GET["catid"]) unset($res2[$prodkey]);
}
if ($_GET["page"] == null) {$page = 1;} else {$page = $_GET["page"];};
foreach (array_chunk($res2, 12)[$page - 1] as $prod){
echo '<div class="col-md-6 col-lg-4 col-xl-3 row-eq-height">';
echo '<div class="card mb-4 box-shadow">';
echo '<a href="product.php?pid='.$prod["PID"].' " >';
echo '<div class="image"><img id="thumbnail" class="card-img-top" src="../admin/lib/images/' . htmlspecialchars($prod["FILENAME"]) . '"></div>';
echo '</a>';
echo '<div class="card-body d-flex align-items-end flex-column">';
echo '<a class="card-text me-auto" href="product.php?pid='.$prod["PID"].' " >$' . $prod["PRICE"] .' '. htmlspecialchars($prod["NAME"]) . '</a>';
echo '<div class="btn-group mt-auto me-auto py-2">';
echo '<a class="btn btn-sm btn-secondary" href="product.php?pid='.$prod["PID"].' " >View</a>';
echo '<button type="button" onclick="addtocart(' . $prod["PID"] . ');" class="btn btn-sm btn-secondary">Add to cart</button>';
echo '</div>';
echo '</div></div></div>';
}
?>
</div>
<nav class="mt-3 d-flex justify-content-center" aria-label="Page navigation example">
<ul class="pagination">
<?php
echo '<li class="page-item"><a class="page-link" href="category.php?catid=' .$_GET["catid"]. '&page=';
if ($page > 1) {echo $page - 1;} else {echo $page;};
echo '">Previous</a></li>';
for ($x = 1; $x <= sizeof(array_chunk($res2, 12)); $x++) {
echo '<li class="page-item"><a class="page-link" href="category.php?catid=' .$_GET["catid"]. '&page=' . $x . '">' . $x . '</a></li>';
}
echo '<li class="page-item"><a class="page-link" href="category.php?catid=' .$_GET["catid"]. '&page=';
if ($page < sizeof(array_chunk($res2, 12))) {echo $page + 1;} else {echo $page;};
echo '">Next</a></li>';
?>
</ul>
</nav>
</div>
</div>
</div>
</div>
</div>
<div class="d-none" id="shoppingcart">
<?php include 'shoppinglist.php';?>
</div>
</body>
<footer class="static-bottom mt-5 text-muted bg-light container-fluid">
<div class="container py-3 d-flex align-items-start">
<div><p>SID: 1155127347 Name: Lau Long Ching</p></div>
<div class="ms-auto">
<a href="#">Back to top</a>
</div>
</div>
</footer>
<script src="./popover.js"></script> <!--- Bootstrap Popover Function, enabled with JQuery for the on-hover shopping cart window. --->
</html>