-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlistings.php
334 lines (301 loc) · 13.7 KB
/
listings.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
<!DOCTYPE html>
<html lang="en" class="gr__preview_uideck_com"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" type="text/css" href="./assets/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="./assets/css/line-icons.css">
<link rel="stylesheet" type="text/css" href="./assets/css/slicknav.css">
<link rel="stylesheet" type="text/css" href="./assets/css/nivo-lightbox.css">
<link rel="stylesheet" type="text/css" href="./assets/css/animate.css">
<link rel="stylesheet" type="text/css" href="./assets/css/owl.carousel.css">
<link rel="stylesheet" type="text/css" href="./assets/css/main.css">
<link rel="stylesheet" type="text/css" href="./assets/css/responsive.css">
<link rel="stylesheet" id="colors" href="./assets/css/green.css" type="text/css"></head>
<body data-gr-c-s-loaded="true">
<?php
session_start();
$_SESSION['current_page'] = $_SERVER['REQUEST_URI'];
include "connect.php";
include 'header.php';
$page_size = 6;
$num_pages_shown = 3;
$curr_start_number = 0;
$query_params = parse_str(parse_url($url, PHP_URL_QUERY));
$page_no = 1;
if (isset($_GET['page_no'])) {
$page_no = $_GET['page_no'];
}
?>
<div id="hero-area">
<div class="overlay"></div>
<div class="container">
<div class="row">
<div class="col-md-12 col-sm-12 text-center">
<div class="contents-ctg">
<div class="search-bar">
<fieldset>
<form class="search-form" method="GET">
<div class="form-group tg-inputwithicon">
<i class="lni-tag"></i>
<input type="text" name="customword" class="form-control" placeholder="What are you looking for">
</div>
<!-- <div class="form-group tg-inputwithicon">
<i class="lni-map-marker"></i>
<div class="tg-select">
<select>
<option value="none">All Locations</option>
<option value="none">New York</option>
<option value="none">California</option>
<option value="none">Washington</option>
<option value="none">Birmingham</option>
<option value="none">Chicago</option>
<option value="none">Phoenix</option>
</select>
</div>
</div> -->
<div class="form-group tg-inputwithicon">
<i class="lni-layers"></i>
<div class="tg-select">
<select name="category">
<option value="none">Select Categories</option>
<option value="Electronics">Electronics</option>
<option value="Tools">Tools</option>
<option value="Appliances">Appliances</option>
<option value="Furniture">Furniture</option>
<option value="Books">Books</option>
<option value="Music">Music</option>
<option value="Sports">Sports</option>
</select>
</div>
</div>
<button class="btn btn-common" type="submit"><i class="lni-search"></i></button>
</form>
</fieldset>
</div>
</div>
</div>
</div>
</div>
</div>
</header>
<div class="main-container section-padding">
<div class="container">
<div class="row">
<div class="col-lg-3 col-md-12 col-xs-12 page-sidebar">
<aside>
<div class="widget categories">
<h4 class="widget-title">All Categories</h4>
<?php
$query = "SELECT type, COUNT(*) FROM item WHERE bid_end > '".date('Y/m/d H:i:s')."' GROUP BY type";
$result = pg_query($connection, $query);
for ($i = 0; $i < pg_num_rows($result); $i++) {
$row = pg_fetch_assoc($result);
${strtolower($row['type']). "_count"} = $row['count']; //dynamically assign category counts to variables
}
?>
<ul class="categories-list">
<li>
<a href="./listings.php?category=Electronics">
<i class="lni-dinner"></i>
Electronics <span class="category-counter">(<?= $electronics_count ? $electronics_count : 0 ?>)</span>
</a>
</li>
<li>
<a href="./listings.php?category=Tools">
<i class="lni-control-panel"></i>
Tools <span class="category-counter">(<?= $tools_count ? $tools_count : 0 ?>)</span>
</a>
</li>
<li>
<a href="./listings.php?category=Appliances">
<i class="lni-github"></i>
Appliances <span class="category-counter">(<?= $appliances_count ? $appliances_count : 0 ?>)</span>
</a>
</li>
<li>
<a href="./listings.php?category=Furniture">
<i class="lni-coffee-cup"></i>
Furniture <span class="category-counter">(<?= $furniture_count ? $furniture_count : 0 ?>)</span>
</a>
</li>
<li>
<a href="./listings.php?category=Books">
<i class="lni-home"></i>
Books <span class="category-counter">(<?= $books_count? $books_count : 0 ?>)</span>
</a>
</li>
<li>
<a href="./listings.php?category=Music">
<i class="lni-pencil"></i>
Music <span class="category-counter">(<?= $music_count ? $music_count : 0 ?>)</span>
</a>
</li>
<li>
<a href="./listings.php?category=Sports">
<i class="lni-display"></i>
Sports <span class="category-counter">(<?= $sports_count ? $sports_count : 0 ?>)</span>
</a>
</li>
</ul>
</div>
</aside>
</div>
<div class="col-lg-9 col-md-12 col-xs-12 page-content">
<div class="product-filter">
<div class="short-name">
<?php
if ((!isset($_GET["category"]) || $_GET["category"] == "none") && (!isset($_GET["customword"]) || $_GET["customword"] == "")) {
// if no search query param
$query = "SELECT * FROM item WHERE bid_end > '".date('Y/m/d H:i:s')."'";
$temp_result = pg_query($connection,$query);
$total_rows_from_query = pg_num_rows($temp_result);
$total_num_pages = ceil($total_rows_from_query/$page_size);
// echo $query;
// query for display; offset for pagination
$query = "SELECT * FROM item WHERE bid_end > '".date('Y/m/d H:i:s')."' ORDER BY time_created DESC OFFSET $page_size*($page_no-1)";
$result = pg_query($connection,$query);
}
else {
// user has entered search query param
$_GET["category"] == "" ? $category = "none" : $category = $_GET["category"];
$customword = $_GET["customword"];
if ($category != "none") {
$query_search = "SELECT * FROM item
WHERE type='".$category."' AND (LOWER(description) LIKE LOWER('%".$customword."%') OR LOWER(item_name) LIKE LOWER('%".$customword."%'))
AND bid_end > '".date('Y/m/d H:i:s')."'";
}
else {
$query_search = "SELECT * FROM item
WHERE LOWER(description) LIKE LOWER('%".$customword."%') OR LOWER(item_name) LIKE LOWER('%".$customword."%')
AND bid_end > '".date('Y/m/d H:i:s')."'";
}
$temp_result = pg_query($connection,$query_search);
$total_rows_from_query = pg_num_rows($temp_result);
$total_num_pages = ceil($total_rows_from_query/$page_size);
// query for display; offset for pagination
if ($category != "none") {
$query_search = "SELECT * FROM item
WHERE type='".$category."' AND (LOWER(description) LIKE LOWER('%".$customword."%') OR LOWER(item_name) LIKE LOWER('%".$customword."%'))
AND bid_end > '".date('Y/m/d H:i:s')."'
ORDER BY time_created DESC LIMIT 6 OFFSET $page_size*($page_no-1)";
}
else {
$query_search = "SELECT * FROM item
WHERE LOWER(description) LIKE LOWER('%".$customword."%') OR LOWER(item_name) LIKE LOWER('%".$customword."%')
AND bid_end > '".date('Y/m/d H:i:s')."'
ORDER BY time_created DESC LIMIT 6 OFFSET $page_size*($page_no-1)";
}
// echo $query_search;
$search_params = "customword=".$customword."&category=".$category;
$result = pg_query($connection,$query_search);
}
?>
<span>Showing (<?= min(1+($page_no-1)*$page_size, $total_rows_from_query)." - ".min($page_no*$page_size, $total_rows_from_query); ?> products of <?= $total_rows_from_query ?> products)</span>
</div>
<div class="adds-wrapper">
<div class="tab-content">
<div id="grid-view" class="tab-pane fade active show">
<div class="row">
<?php
for ($i=0; $i<min(6, pg_num_rows($result)); $i++) {
$row = pg_fetch_assoc($result);
?>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<div class="featured-box">
<figure>
<a href="./listing_detail.php?id=<?=$row['item_id']; ?>">
<img class="img-fluid" src="./assets/img/items/<?= $row['img_src']; ?>" alt="">
</a>
</figure>
<div class="feature-content">
<div class="tg-product">
<a href="./listings.php?category=<?=$row['type']; ?>"><?= $row['type']; ?></a>
</div>
<h4><a href="./listing_detail.php?id=<?=$row['item_id']; ?>"><?= $row['item_name']; ?></a></h4>
<span>Created: <?= $row['time_created']; ?></span>
<ul class="address">
<li>
<a><i class="lni-map-marker"></i><?= $row['address']; ?></a>
</li>
<li>
<a><i class="lni-alarm-clock"></i><?= $row['borrow_duration']; ?> days</a>
</li>
<li>
<a><i class="lni-user"></i><?= $row['username']; ?></a>
</li>
<!-- <li>
<a href="category.html#"><i class="lni-tag"></i> Mobile</a>
</li> -->
</ul>
<div class="btn-list">
<?php
$bid_query = "SELECT b.bid_amount FROM bid b WHERE b.bid_id='".$row['highest_bid_id']."'";
$bid_result = pg_query($connection, $bid_query);
$top_bid = pg_fetch_assoc($bid_result);
?>
<a class="btn-price">Highest Bid: $<b> <?=($top_bid['max'] === NULL ? $row['start_price'] : $top_bid['max']); ?> </b></a>
<a class="btn btn-common" href="./listing_detail.php?id=<?= $row['item_id']; ?>">
<i class="lni-list"></i>
View Details
</a>
</div>
</div>
</div>
</div>
<?php }
// to keep pagination at bottom, if odd number of listings add empty listing
if((6-min(6, pg_num_rows($result)))%2!=0) {
?>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6"> </div>
<?php } ?>
<?php $curr_start_number = $page_no - $page_no%$num_pages_shown; ?>
<div class="pagination-bar" <?php if($total_num_pages == 0) {echo 'style="display:none;"';} ?>>
<nav>
<ul class="pagination">
<li class="page-item" <?php if($page_no <= 1) {echo 'style="display:none;"';} ?>><a class="page-link"
href="<?php if ($page_no == $curr_start_number) {$curr_start_number -= $num_pages_shown; }
echo '?page_no='.($page_no-1)."&".$search_params ?>">Previous</a></li>
<li class="page-item" <?php if($curr_start_number+1 > $total_num_pages) {echo 'style="display:none;"';;} ?>><a class="page-link <?php if($page_no == $curr_start_number+1) {echo 'active';} ?>"
href="<?= '?page_no='.($curr_start_number+1)."&".$search_params ?>"><?= ($curr_start_number+1) ?></a></li>
<li class="page-item" <?php if($curr_start_number+2 > $total_num_pages) {echo 'style="display:none;"';} ?>><a class="page-link <?php if($page_no == $curr_start_number+2) {echo 'active';} ?>"
href="<?= '?page_no='.($curr_start_number+2)."&".$search_params ?>"><?= ($curr_start_number+2) ?></a></li>
<li class="page-item" <?php if($curr_start_number+3 > $total_num_pages) {echo 'style="display:none;"';} ?>><a class="page-link <?php if($page_no == $curr_start_number+3) {echo 'active';} ?>"
href="<?= '?page_no='.($curr_start_number+3)."&".$search_params ?>"><?= ($curr_start_number+3) ?></a></li>
<li class="page-item" <?php if($page_no >= $total_num_pages) {echo 'style="display:none;"';} ?>><a class="page-link"
href="<?php if (page_no == $curr_start_number+3) {$curr_start_number += $num_pages_shown; }
echo '?page_no='.($page_no+1)."&".$search_params ?>">Next</a></li>
</ul>
</nav>
</div>
</div>
</div>
</div>
</div>
</br>
</br>
</div>
</div>
</div>
</div>
</div>
<?php
include 'footer.php';
?>
<a href="category.html#" class="back-to-top" style="display: none;">
<i class="lni-chevron-up"></i>
</a>
<div id="preloader" style="display: none;">
<div class="loader" id="loader-1"></div>
</div>
<script src="./assets/js/jquery-min.js"></script>
<script src="./assets/js/popper.min.js"></script>
<script src="./assets/js/bootstrap.min.js"></script>
<script src="./assets/js/jquery.counterup.min.js"></script>
<script src="./assets/js/waypoints.min.js"></script>
<script src="./assets/js/wow.js"></script>
<script src="./assets/js/owl.carousel.min.js"></script>
<script src="./assets/js/nivo-lightbox.js"></script>
<script src="./assets/js/jquery.slicknav.js"></script>
<script src="./assets/js/main.js"></script>
<script src="./assets/js/form-validator.min.js"></script>
<script src="./assets/js/contact-form-script.min.js"></script>
</body></html>