-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearchresults.php
437 lines (404 loc) · 22.7 KB
/
searchresults.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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
<?php
session_start();
include_once './dist/php/connection.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">
<title>TroliMart Search Results</title>
<link rel="stylesheet" href="dist/css/homepage.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<script type="text/javascript">
window.history.forward();
</script>
</head>
<body class="text-dark">
<!-- upper navbar -->
<header>
<nav class="navbar navbar-expand-lg navbar-dark nav-bg m-0">
<div class="container-fluid">
<!-- upperleft logo -->
<div class="navbar-brand p-0 me-2" >
<a href="homepage.php">
<img src="images/trolimart rect2.png" width="180" alt="">
</a>
</div>
<div class="align-items-center w-50">
<form class="input-group align-items-center w-auto" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
<input name='search-query' type="search" class="align-self-center form-control border rounded w-50"
placeholder="Search for groceries..." aria-label="Search" aria-describedby="button-addon2">
<button class="align-items-center btn search-btn" type="submit" id="button-addon2">
<a class="navbar-brand m-0" href="#">
<img src="./images/search.png" width="35" height="35" alt="">
</a>
</button>
</form>
</div>
<ul class="navbar-nav">
<li class="nav-item text-light">
<?php
$uname = $_SESSION['user_name'];
$uid = $_SESSION['user_id'];
$sql = "SELECT * FROM account WHERE (user_id='$uid')";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
if ($uname == $row['First name']) {
$firstName = $row["First name"];
$lastName = $row["Last name"];
$email = $row["Email"];
$password = $row["Password"];
$birthdate = $row["Birth date"];
$gender = $row["Gender"];
$photo = $row["Account_picture"];
}
}
echo '<img src="data:image/jpeg;base64,' . base64_encode($photo) . '" width="30" height="30" alt="" class="mr-2" data-toggle="modal" data-target="#profile" style="cursor: pointer;">';
?>
<!-- <img src="./images/user.png" width="30" height="30" alt="" class="mr-2" data-toggle="modal" data-target="#profile" style="cursor: pointer;"> -->
</li>
<!-- Modal -->
<div class="modal fade" id="profile" tabindex="-1" role="dialog" aria-labelledby="userprofile" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="userprofile">User Profile</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<?php
$uname = $_SESSION['user_name'];
$uid = $_SESSION['user_id'];
$sql = "SELECT * FROM account WHERE (user_id='$uid')";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
if($uname == $row['First name']){
$firstName = $row["First name"];
$lastName = $row["Last name"];
$email = $row["Email"];
$password = $row["Password"];
$birthdate = $row["Birth date"];
$gender = $row["Gender"];
$photo = $row["Account_picture"];
}
}
?>
<div class="row">
<div class="col-md-6">
<?php echo '<img style=\'height: 9em;\' src="data:image/jpeg;base64,' . base64_encode($photo) . '"/><br>'; ?>
</div>
<div class="col-md-6 user-mod">
<h5>First Name: <?php echo $firstName ?></h5>
<h5>Last Name: <?php echo $lastName ?></h5>
<h5>Email: <?php echo $email ?></h5>
<h5>Birth date: <?php echo $birthdate ?></h5>
<h5>Gender: <?php echo $gender ?></h5>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<!-- <button type="button" class="btn btn-primary">Save changes</button> -->
</div>
</div>
</div>
</div>
<li class="nav-item text-light dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdownProfile" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<!-- <img src="images/user.png" width="30" height="30" alt="" class="mr-2"> -->
Hello <?php if (isset($_SESSION['user_name'])) {
print_r($_SESSION['user_name']);
} ?>
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="editprofiletest.php">Edit Profile</a>
<a class="dropdown-item" href="logout.php">Logout</a>
</div>
</li>
<li class="nav-item text-light ml-5">
<a class="view-cart navbar-brand" href="#" onclick="return toggleCart()">
<img src="images/shopping-cart.png" width="30" height="30" alt="">
<p class="view-cart-text">View List</p>
</a>
</li>
</ul>
</div>
</nav>
</header>
<?php if(isset($_SESSION['logged_in'])){ ?>
<div class="main-content">
<!-- sidebar -->
<div class="wrapper">
<nav id="sidebar" class=" category-bg ">
<div class="sidebar-header ">
<br>
<h3>All Categories</h3>
<div class="categories overflow-auto">
<ul class="list-unstyled components">
<li>
<?php $product='beverages'; echo "<a href='content.php?category=$product' >Beverages</a>"; ?>
</li>
<li>
<?php $product='bread'; echo "<a href='content.php?category=$product' >Bread/Bakery</a>"; ?>
</li>
<li>
<?php $product='canned'; echo "<a href='content.php?category=$product' >Canned/Jarred Goods</a>"; ?>
</li>
<li>
<?php $product='dairy'; echo "<a href='content.php?category=$product' >Dairy</a>"; ?>
</li>
<li>
<?php $product='baking'; echo "<a href='content.php?category=$product' >Dry/Baking Goods</a>"; ?>
</li>
<li>
<?php $product='frozen'; echo "<a href='content.php?category=$product' >Frozen Foods</a>"; ?>
</li>
<li>
<?php $product='meat'; echo "<a href='content.php?category=$product' >Meats</a>"; ?>
</li>
<li>
<?php $product='fruit'; echo "<a href='content.php?category=$product' >Fruits</a>"; ?>
</li>
<li>
<?php $product='vegetable'; echo "<a href='content.php?category=$product' >Vegetables</a>"; ?>
</li>
<li>
<?php $product='cleaner'; echo "<a href='content.php?category=$product' >Cleaners</a>"; ?>
</li>
<li>
<?php $product='personalcare'; echo "<a href='content.php?category=$product' >Personal Care</a>"; ?>
</li>
</ul>
</div>
</div>
<div class="sidebar-header">
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
<h3>Search Filter</h3>
<div class="price-range">
<h5>Price Range</h5>
<div class="price-range-selector">
<input name='min-price' type="text" class='price-range-input' placeholder="RM MIN" required>
<div class="price-range-line"></div>
<input name='max-price' type="text" class='price-range-input' placeholder="RM MAX" required>
</div>
<button class="price-range-button btn btn-success">APPLY</button>
</div>
</form>
</div>
</nav>
</div>
<!-- end of sidebar -->
<div class="content">
<div id="carouselIndicators" class="carousel slide mt-3" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselIndicators" data-slide-to="1"></li>
<li data-target="#carouselIndicators" data-slide-to="2"></li>
<li data-target="#carouselIndicators" data-slide-to="3"></li>
</ol>
<div class="carousel-inner" id="carouselinnerhomepage">
<div class="carousel-item active">
<img class="d-block align-items-center" src="./images/trolimart rectangle.png" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block align-items-center" src="./images/banner5.jpg" alt="Second slide"
style="object-fit:cover; object-position: 50% 30%;">
</div>
<div class="carousel-item">
<img class="d-block align-items-center" src="./images/banner3.jpg" alt="Third slide"
style="object-fit:cover; object-position: 50% 35%;">
</div>
<div class="carousel-item">
<img class="d-block align-items-center" src="./images/banner4.jpg" alt="Third slide"
style="object-fit:cover; object-position: 50% 35%;">
</div>
<a class="carousel-control-next" href="#carouselIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
<!-- <div class="categories categories-content row d-flex"> -->
<?php
include_once './dist/php/connection.php';
if (isset($_POST['search-query'])) {
global $searchQuery;
$searchQuery = $_POST['search-query'];
$sql = "SELECT * FROM products WHERE product_name LIKE '%$searchQuery%'";
$result = $conn->query($sql);
?>
<h3 class="categories-header">Search Results for <?php echo $searchQuery; ?></h3>
<?php
if ($result->num_rows > 0) {
?>
<div class="categories categories-content row d-flex">
<?php
while ($row = $result->fetch_assoc()) {
$product_name = $row['product_name'];
$product_image = $row['product_image'];
$product_price = $row['product_price'];
// print_r($row);
?>
<div class="card card-block mx-2 text-center">
<?php echo '<img class=\'card-img-top\' style=\'height: 9em;\' src="data:image/jpeg;base64,'.base64_encode( $product_image ).'"/><br>'; ?>
<h6 class="card-title"><?php echo $product_name ?></h6>
<p class="card-text">RM<?php echo $product_price ?></p>
<button class="add-to-cart-button btn btn-success align-self-end">Add to List</button>
</div>
<?php
}
?>
</div>
<?php
} else {
echo '<div class="alert alert-danger mt-3" style="width: 1120px;"role="alert">
Item not found!
</div>';
}
} else if ($_POST['min-price'] && $_POST['max-price']) {
global $minPrice, $maxPrice;
$minPrice = $_POST['min-price'];
$maxPrice = $_POST['max-price'];
?>
<h3 class="categories-header">Search Results for items in range RM<?php echo $minPrice; ?> and RM<?php echo $maxPrice; ?></h3>
<div class="categories categories-content row d-flex">
<?php
$sql = "SELECT * FROM products WHERE product_price >= '$minPrice' AND product_price <= '$maxPrice' ORDER BY product_price ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$product_name = $row['product_name'];
$product_image = $row['product_image'];
$product_price = $row['product_price'];
// print_r($row);
?>
<div class="card card-block mx-2 text-center">
<?php echo '<img class=\'card-img-top\' style=\'height: 9em;\' src="data:image/jpeg;base64,'.base64_encode( $product_image ).'"/><br>'; ?>
<h6 class="card-title"><?php echo $product_name ?></h6>
<p class="card-text">RM<?php echo $product_price ?></p>
<button class="add-to-cart-button btn btn-success align-self-end">Add to List</button>
</div>
<?php
}
}
?>
</div>
<?php
} else {
echo '<div class="alert alert-danger" role="alert">
Item not found!
</div>';
}
?>
<!-- </div> -->
<!-- cart -->
<div class="cart">
<h3 class='cart-header text-center'>📝 List 📝</h3>
<div>
<ul id="testnav" class="nav nav-tabs justify-content-center">
<li class="" id="initialtab"><a class="nav-link active" data-toggle="tab" aria-current="page" href="#tabdiv1"
onclick="whatiscurrenttab('list_itemstab1')">List 1 <button class="delete-list-btn"
onclick="return deletedefaulttab('tabdiv1','initialtab');">❌</button></a></li>
<li id="addtab"><a class="nav-link px-0px py-0px" href="#"><button class="add-tab-btn"
onclick="return addlist()"> ➕ </button></a></li>
</ul>
</div>
<!-- inside the list -->
<div id="contentd" class="tab-content">
<div id="tabdiv1" class="tab-pane in active ml-15px overflow-block">
<div class="cart-items">
<ol id="list_itemstab1" class='list-group list-group-flush '>
</ol>
</div>
<div id="calculatedprice" class="row total-price-container">
<div class="col">
Total Price: <span>RM </span> <span class="spantotalprice" id="list_itemstab1-total-price-value">0.00</span>
</div>
</div>
</div>
<!-- NEW DIV HERE -->
</div>
</div>
</div>
</div>
<footer class="text-center font-italic p-3 pb-4 mt-3 text-light" style="background-color: #0c143c;">
<div class="container">
<div class="row">
<div class="col-sm">
<p type="button" data-toggle="collapse" data-target="#collapseContactUs" aria-expanded="false" aria-controls="collapseExample">
<u>Contact Us</u>
</p>
<div class="collapse" id="collapseContactUs">
<div class="fs-6 fw-lighter text-left">
<ul>
<li>Call us at <p style="color:#3385ff;">03-5657 5432</p></li>
<li>Email us at <a href="mailto:[email protected]">[email protected]</a></li>
</ul>
</div>
</div>
</div>
<div class="col-sm">
<p type="button" data-toggle="collapse" data-target="#collapseAboutUs" aria-expanded="false" aria-controls="collapseExample">
<u>About Us</u>
</p>
<div class="collapse" id="collapseAboutUs">
<div class="fs-6 fw-lighter text-left">
<p>TroliMart system is intended to help the consumers to manage grocery shopping list before going to the shop to purchase the products.
</p>
</div>
</div>
</div>
<div class="col-sm">
<p type="button" data-toggle="collapse" data-target="#collapseFollowUs" aria-expanded="false" aria-controls="collapseExample">
<u>Follow Us</u>
</p>
<div class="collapse" id="collapseFollowUs">
<div class="fs-6 fw-lighter text-left">
<ul>
<li>
<nav class="navbar navbar-light">
<a class="navbar-brand text-primary" href="https://www.facebook.com/">
<img src="images/fb.png" width="30" height="30" alt="" class="d-inline-block align-top">
Facebook
</a>
</nav>
</li>
<li>
<nav class="navbar navbar-light">
<a class="navbar-brand text-primary" href="https://www.instagram.com/">
<img src="images/insta.png" width="30" height="30" alt="" class="d-inline-block align-top">
Instagram
</a>
</nav>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<p>
Copyright © 2021 TroliMart Co. <br>
</p>
</footer>
<script src="dist/js/file.js"></script>
<script src="dist/js/modal.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns"
crossorigin="anonymous"></script>
</body>
</html>
<?php }
else{
echo "<h1 style='color:red; font-size:300px;'>Session is destroyed</h1>";
echo "<a href='index.php' style='font-size:100px;'>Click here to login back!</a>";
}
?>