/
buy.php
499 lines (416 loc) · 18.8 KB
/
buy.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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
<?php
if (!isset($_SESSION)) {
session_start();
}
$connect = mysqli_connect("localhost", "root", "", "carena");
$orderX = '';
$orderIn = '';
if ($_SESSION['loginStatus'] == 1) {
$viewerShip = 'privacy IN(0,1)';
} else {
$viewerShip = 'privacy=0';
}
function getProduct($connect, $viewerShip)
{
$query = "SELECT * FROM product WHERE $viewerShip";
$result = mysqli_query($connect, $query);
return $result;
}
function setProductCard($connect, $orderX, $orderIn, $viewerShip)
{
$output = '';
$count = 0;
$result = getProduct($connect, $viewerShip);
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total = mysqli_num_rows($result);
$no_of_pages = ceil($total / $no_of_records_per_page);
$display_sql = "SELECT * FROM product WHERE $viewerShip ORDER BY $orderX $orderIn LIMIT $offset, $no_of_records_per_page";
$display_result = mysqli_query($connect, $display_sql);
$flag = 0;
$output .= '<div class="row">';
while ($row = mysqli_fetch_array($display_result)) {
$output .= '
<div class="col-md-4 mb-5">
<div class="productCard">
<img src="' . $row["image"] . '" class="d-block w-100">';
if ($row["privacy"] == 1 && $_SESSION['loginStatus']) {
$output .= '<span class="premiumLabel align-self-end">Premium</span>';
}
$output .= '
<div class="mt-4">
<a href="product_details.php?product_id=' . $row["product_id"] . '">
<h5 class="card-title">' . $row["maker"] . ' ' . $row["model"] . '</h5></a>
<p class="text-justify">' . $row["car_desc"] . '</p>
</div>
<p class=\'text-danger font-weight-bold\'> $' . $row["price"] . ' </p>
<div class=\'row p-2\'>
<div class="col-md-4 border align-content-center">
<i class=\'fa fa-cogs fa-1x text-center\'> ' . $row["fuel"] . '</i>
</div>
<div class="col-md-4 border align-content-center">
<i class="fa fa-calendar text-center"> ' . $row["year_mfg"] . '</i>
</div>
<div class="col-md-4 border align-content-center">
<i class=\'fa fa-tachometer text-center\'> ' . $row["mileage"] . '</i>
</div>
</div>
</div>
</div>
';
$count = $count + 1;
}
$output .= '
</div>
<div class="row p-4">
<div class="col-md">
<nav aria-label="pagination">
<ul class="pagination justify-content-center">';
if ($pageno > 1) {
$output .= '<li class="page-item">';
} else {
$output .= '<li class="page-item disabled">';
}
$output .= '<a class="page-link" href="?pageno=' . ($pageno - 1) . '">Previous</a>
</li>';
for ($i = 1; $i <= $no_of_pages; $i++) {
$output .= '
<li class="page-item"><a class="page-link" href="?pageno=' . $i . '"> ' . $i . '</a></li>';
}
if ($pageno < $no_of_pages) {
$output .= '<li class="page-item">';
} else {
$output .= '<li class="page-item disabled">';
}
$output .= '
<a class="page-link " href="?pageno=' . ($pageno + 1) . '">Next</a>
</li>
</ul>
</nav>
</div>
</div>
';
return $output;
}
function setProductCardByFilter($connect, $orderX, $orderIn, $maker, $priceRange, $year_mfg, $body_type, $viewerShip)
{
$output = '';
$count = 0;
$result = getProduct($connect, $viewerShip);
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
$no_of_records_per_page = 12;
$offset = 0;
$display_sql = "SELECT * FROM product WHERE $viewerShip AND maker='$maker' and price $priceRange AND year_mfg=$year_mfg AND body_type='$body_type' ORDER BY $orderX $orderIn LIMIT $offset, $no_of_records_per_page";
$display_result = mysqli_query($connect, $display_sql);
$total = mysqli_num_rows($display_result);
$no_of_pages = ceil($total / $no_of_records_per_page);
$flag = 0;
$output .= '<div class="row">';
if ($total > 0) {
while ($row = mysqli_fetch_array($display_result)) {
$output .= '
<div class="col-sm-4 mb-5">
<div class="productCard">
<img src="' . $row["image"] . '" class="d-block w-100">';
if ($row["privacy"] == 1 && $_SESSION['loginStatus']) {
$output .= '<span class="premiumLabel align-self-end">Premium</span>';
}
$output .= '
<div class="mt-4">
<a href="product_details.php?product_id=' . $row["product_id"] . '">
<h5 class="card-title">' . $row["maker"] . ' ' . $row["model"] . '</h5></a>
<p class="text-justify">' . $row["car_desc"] . '</p>
</div>
<p class=\'text-danger font-weight-bold\'> $' . $row["price"] . ' </p>
<div class=\'row p-2\'>
<div class="col-md-4 border align-content-center">
<i class=\'fa fa-cogs\'> ' . $row["fuel"] . '</i>
</div>
<div class="col-md-4 border align-content-center">
<i class="fa fa-calendar"> ' . $row["year_mfg"] . '</i>
</div>
<div class="col-md-4 border align-content-center">
<i class=\'fa fa-tachometer\'> ' . $row["mileage"] . '</i>
</div>
</div>
</div>
</div>
';
$count = $count + 1;
}
} else {
echo "<script type='text/javascript'>alert('Sorry!No car found!')</script>";
}
$output .= '
</div>
<div class="row p-4">
<div class="col-md">
<nav aria-label="pagination">
<ul class="pagination justify-content-center">';
if ($pageno < $no_of_pages) {
$output .= '<li class="page-item">';
} else {
$output .= '<li class="page-item disabled">';
}
$output .= '
<a class="page-link disabled" href="?pageno=' . ($pageno + 1) . '">Previous</a>
</li>';
for ($i = 1; $i <= $no_of_pages; $i++) {
$output .= '
<li class="page-item"><a class="page-link" href="?pageno=' . $i . '"> ' . $i . '</a></li>';
}
if ($pageno < $no_of_pages) {
$output .= '<li class="page-item">';
} else {
$output .= '<li class="page-item disabled">';
}
$output .= '
<a class="page-link disabled" href="?pageno=' . ($pageno + 1) . '">Next</a>
</li>';
return $output;
}
function setProductCardBySearch($connect, $item, $viewerShip)
{
$output = '';
$count = 0;
$result = getProduct($connect, $viewerShip);
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
$no_of_records_per_page = 12;
$offset = 0;
$what = explode(' ', $item);
$q = count($what);
$display_sql = "SELECT * FROM product WHERE $viewerShip AND ((maker LIKE '%" . $item . "%') OR (model LIKE '%" . $item . "%') OR (CONCAT(maker,' ',model) LIKE '%" . $item . "%')) LIMIT $offset, $no_of_records_per_page";
$display_result = mysqli_query($connect, $display_sql);
$total = mysqli_num_rows($display_result);
$no_of_pages = ceil($total / $no_of_records_per_page);
$flag = 0;
$output .= '<div class="row">';
if ($total > 0) {
while ($row = mysqli_fetch_array($display_result)) {
$output .= '
<div class="col-sm-4 mb-5">
<div class="productCard">
<img src="' . $row["image"] . '" class="d-block w-100">';
if($row["privacy"]==1 && $_SESSION['loginStatus']){
$output.='<span class="premiumLabel align-self-end">Premium</span>';
}
$output.='<div class="mt-4">
<a href="product_details.php?product_id=' . $row["product_id"] . '">
<h5 class="card-title">' . $row["maker"] . ' ' . $row["model"] . '</h5></a>
<p class="text-justify">' . $row["car_desc"] . '</p>
</div>
<p class=\'text-danger font-weight-bold\'> $' . $row["price"] . ' </p>
<div class=\'row p-2\'>
<div class="col-md-4 border align-content-center">
<i class=\'fa fa-cogs\'> ' . $row["fuel"] . '</i>
</div>
<div class="col-md-4 border align-content-center">
<i class="fa fa-calendar"> ' . $row["year_mfg"] . '</i>
</div>
<div class="col-md-4 border align-content-center">
<i class=\'fa fa-tachometer\'> ' . $row["mileage"] . '</i>
</div>
</div>
</div>
</div>
';
$count = $count + 1;
}
} else {
echo "<script type='text/javascript'>alert('Sorry!No car found!')</script>";
}
$output .= '
</div>
<div class="row p-4">
<div class="col-md">
<nav aria-label="pagination">
<ul class="pagination justify-content-center">';
if ($pageno < $no_of_pages) {
$output .= '<li class="page-item">';
} else {
$output .= '<li class="page-item disabled">';
}
$output .= '
<a class="page-link disabled" href="?pageno=' . ($pageno + 1) . '">Previous</a>
</li>';
for ($i = 1; $i <= $no_of_pages; $i++) {
$output .= '
<li class="page-item"><a class="page-link" href="?pageno=' . $i . '"> ' . $i . '</a></li>';
}
if ($pageno < $no_of_pages) {
$output .= '<li class="page-item">';
} else {
$output .= '<li class="page-item disabled">';
}
$output .= '
<a class="page-link disabled" href="?pageno=' . ($pageno + 1) . '">Next</a>
</li>';
return $output;
}
function show_details($connect)
{
if (isset($_GET['product_id'])) {
$product_id = $_GET['id'];
echo $product_id;
} else {
echo "failed";
}
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<link rel="stylesheet" href="css/main.css"/>
<link rel="stylesheet" type="text/css" href="css/buy.css"/>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css"
integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">
</head>
<body>
<?php
include 'header.php'
?>
<div class="container">
<!-- Example single danger button -->
<div class="row carListingHeader justify-content-center">
<p class="hdr">Buy Your Dream Car...</p>
</div>
<div class="row pt-5">
<div class="col-md-2 bg-light h-100">
<div class="row">
<p class="filterBar">Filter By</p>
<div class="row">
<div class="col-md-12 ml-2">
<form class="form-group" method="post">
<label>By Maker:</label>
<ul class="list-unstyled ml-3">
<li><input type="radio" name="vendor" value="." checked hidden></li>
<?php
$query = "SELECT distinct maker FROM product order by maker";
$result = mysqli_query($connect, $query);
$i = 0;
while ($row = mysqli_fetch_array($result)) {
echo "
<li><input type=\"radio\" class=\"form-check-inline\" name=\"vendor\" value=" . $row["maker"] . ">" . $row["maker"] . "</li>";
$i++;
}
?>
</ul>
<label>Price Range</label>
<select name="priceRange" class="" required>
<option value="between 500000 AND 1000000">5-10 Lakh</option>
<option value="between 1000000 and 2500000">10-25 Lakh</option>
<option value="between 2500000 and 5000000">25-50 Lakh</option>
<option value=">=5000000">50 Lakh&Higher</option>
</select>
<label class="mt-2">Year of MFG</label>
<input type="number" value="2018" name="year_mfg" class="d-block w-75" required>
<label class="mt-2 mb-2">Body Type</label>
<ul class="list-unstyled ml-3">
<li><input type="radio" name="body_type" value="." checked hidden></li>
<?php
$query = "SELECT distinct body_type FROM product order by body_type";
$result = mysqli_query($connect, $query);
$i = 0;
while ($row = mysqli_fetch_array($result)) {
echo "
<li><input type=\"radio\" name='body_type' class=\"form-check-inline\" value=" . $row["body_type"] . ">" . $row["body_type"] . "</li>";
$i++;
}
?>
</ul>
<button type="submit" class="btn btn-info rounded-0 ml-2" name="filterBtn">Filter</button>
<button type="reset" class="btn btn-secondary rounded-0 ml-4" name="resetBtn">Reset</button>
</form>
</div>
</div>
</div>
</div>
<div class="col-md-10 pl-4">
<div class="row sortbar">
<form class="form-group form-inline" method="post">
<label><strong>Sort By:</strong></label>
<select class="ml-3 form-control rounded-0" name="selectVendor">
<option>Maker</option>
<option>Price</option>
<option>Capacity</option>
<option value="year_mfg">Year of Mfg.</option>
<option>Transmission</option>
<option>Fuel</option>
</select>
<select class="ml-2 form-control rounded-0" name="selectOrder">
<option>ASC</option>
<option>DESC</option>
</select>
<button type="submit" class="btn btn-info ml-3 pl-4 pr-4 rounded-0" name="sortBtn">Sort</button>
</form>
<form class="form-group form-inline ml-auto pr-2" method="post">
<input type="text" class="form-control rounded-0" name="searchItem"
placeholder="search by maker/model">
<button type="submit" class="btn btn-danger rounded-0 ml-3 pl-4 pr-4" name="searchBtn">Search
</button>
</form>
</div>
<?php
if (isset($_POST['sortBtn'])) {
$X = $_POST['selectVendor'];
$Y = $_POST['selectOrder'];
} else {
$X = 'maker';
$Y = 'ASC';
}
if (isset($_POST['searchBtn'])) {
$item = $_POST['searchItem'];
if ($item == '') {
echo "<script type='text/javascript'>alert('Enter a valid search!')</script>";
echo setProductCard($connect, $X, $Y, $viewerShip);
} else {
echo setProductCardBySearch($connect, $item, $viewerShip);
}
}
if (isset($_POST['filterBtn'])) {
$maker = $_POST['vendor'];
$priceRange = $_POST['priceRange'];
$year_mfg = $_POST['year_mfg'];
$body_type = $_POST['body_type'];
if ($maker !== '.' && $priceRange != '' && $year_mfg != '' && $body_type != '.') {
echo setProductCardByFilter($connect, $X, $Y, $maker, $priceRange, $year_mfg, $body_type, $viewerShip);
} else {
echo setProductCard($connect, $X, $Y, $viewerShip);
echo "<script type='text/javascript'>alert('All parameters are required!')</script>";
}
}
if (!(isset($_POST['searchBtn']) || isset($_POST['filterBtn']) || isset($_POST['sorthBtn']))) {
echo setProductCard($connect, $X, $Y, $viewerShip);
}
?>
</div>
</div>
</div>
<?php
include 'footer.php'
?>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="js/jquery.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>