-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser_listings.php
342 lines (292 loc) · 18.2 KB
/
user_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
335
336
337
338
339
340
341
342
<!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" class="modal-open-header">
<?php
session_start();
$_SESSION['current_page'] = $_SERVER['REQUEST_URI'];
include "connect.php";
if (!isset($_SESSION['key'])) {
header("Location: ./login.php");
}
$uname = $_SESSION['key'];
$input_user = pg_escape_string($connection, $_GET['user']);
$find_user = "SELECT full_name FROM account WHERE username='$input_user'";
$result = pg_query($connection, $find_user);
if (pg_num_rows($result) == 0) {
header("Location: ./user_listings.php?show=" . $_GET['show'] . "&user=" . $_SESSION['key']);
}
$full_name = pg_fetch_assoc($result)['full_name'];
if ($uname == $input_user) {
$is_owner = true;
} else {
$is_owner = false;
$uname = $input_user;
};
include "header.php";
?>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$delete_item = "DELETE FROM item WHERE item_id=" . $_POST['delete_id'];
$delete = pg_query($connection, $delete_item);
if ($delete) {
$flash = "<div class='alert alert-success text-center' role='alert'>Deletion successful!</div>";
} else {
$flash = "<div class='alert alert-danger text-center' role='alert'>Unable to delete item!</div>";
}
}
?>
<div class="page-header" style="background: url(assets/img/banner1.jpg);">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="breadcrumb-wrapper">
<h2 class="product-title"><?= $is_owner ? "My" : $full_name ?> Listings</h2>
<ol class="breadcrumb">
<li><a href="./index.php">Home /</a></li>
<li class="current"><?= $is_owner ? "My" : $full_name ?> Listings</li>
</ol>
</div>
</div>
</div>
</div>
</div>
<div id="content" class="section-padding">
<div class="container">
<div class="row">
<?php
include "user_sidebar.php";
?>
<div class="col-sm-12 col-md-8 col-lg-9">
<div style="width:950px">
<div class="inner-box">
<?= $flash ?>
<div class="dashboard-box">
<h2 class="dashbord-title"><?= $is_owner ? "My" : $full_name ?> Listings</h2>
</div>
<div class="dashboard-wrapper">
<nav class="nav-table">
<?php
date_default_timezone_set('Asia/Singapore');
$time_now = date('Y/m/d H:i:s');
$query = "SELECT item_id FROM item WHERE username='$uname'";
$all_ids = pg_fetch_all(pg_query($connection, $query));
$all_count = $all_ids ? count($all_ids) : 0;
$query = "SELECT item_id FROM item WHERE username='$uname' AND bid_end >'$time_now'";
$active_ids = pg_fetch_all(pg_query($connection, $query));
$active_count = $active_ids ? count($active_ids) : 0;
$query = "SELECT DISTINCT i.item_id FROM item i " .
"WHERE i.username='$uname' AND i.bid_end <'$time_now' AND i.highest_bid_id IS NULL";
$closed_ids = pg_fetch_all(pg_query($connection, $query));
$closed_count = $closed_ids ? count($closed_ids) : 0;
$query = "SELECT DISTINCT i.item_id FROM item i " .
"WHERE i.username='$uname' AND i.bid_end <'$time_now' AND i.highest_bid_id IS NOT NULL";
$rented_ids = pg_fetch_all(pg_query($connection, $query));
$rented_count = $rented_ids ? count($rented_ids) : 0;
?>
<ul>
<li<?= empty($_GET['show']) ? " class=\"active\"" : "" ?>><a
href="user_listings.php?user=<?= $uname ?>">All Listings
(<?= $all_count ?>) </a></li>
<li<?= $_GET['show'] == "active" ? " class=\"active\"" : "" ?>><a
href="user_listings.php?show=active&user=<?= $uname ?>">Active
(<?= $active_count ?>) </a>
</li>
<li<?= $_GET['show'] == "closed" ? " class=\"active\"" : "" ?>><a
href="user_listings.php?show=closed&user=<?= $uname ?>">Closed
(<?= $closed_count ?>) </a>
</li>
<li<?= $_GET['show'] == "rented" ? " class=\"active\"" : "" ?>><a
href="user_listings.php?show=rented&user=<?= $uname ?>">Rented
(<?= $rented_count ?>) </a>
</li>
</ul>
</nav>
<table class="table dashboardtable tablemyads">
<thead>
<tr>
<th>Photo</th>
<th>Title</th>
<th>Category</th>
<th>Ad Status</th>
<th>Price</th>
<th>Bidders</th>
<th style="padding-left: 40px">Action</th>
<?php if ($is_owner) { ?>
<th>Highest Bidder</th>
<?php } ?>
</tr>
</thead>
<tbody>
<tr data-category="active">
<?php
switch ($_GET['show']) {
case "active":
$target_ids = array_map('current', $active_ids);
break;
case "closed":
$target_ids = array_map('current', $closed_ids);
break;
case "rented":
$target_ids = array_map('current', $rented_ids);
break;
default:
$target_ids = array_map('current', $all_ids);
}
$query = "SELECT i.img_src, i.item_name, i.type, i.start_price, i.item_id, i.bid_end, COUNT(b.bid_id) as bidders, b1.bid_amount as highest_bid, b1.username as highest_bidder " .
"FROM item i LEFT OUTER JOIN bid b on i.item_id=b.item_id LEFT OUTER JOIN bid b1 on i.highest_bid_id=b1.bid_id " .
"WHERE i.item_id in (" . implode(",", $target_ids) . ") " .
"GROUP BY i.img_src, i.item_name, i.type, i.start_price, i.item_id, b1.username, b1.bid_amount " .
"ORDER BY i.time_created";
$result = pg_query($connection, $query);
for ($i = 0; $i < pg_num_rows($result); $i++) {
$row = pg_fetch_assoc($result);
$row['bidders'] = $row['bidders'] ? $row['bidders'] : 0;
?>
<td class="photo"><img class="img-fluid"
src="./assets/img/items/<?= $row['img_src'] ?>" alt=""></td>
<td data-title="Title">
<h3><?= $row['item_name'] ?></h3>
</td>
<td data-title="Category"><span class="adcategories"><?= $row['type'] ?></span></td>
<td data-title="Ad Status">
<?php
if (date('Y/m/d H:i:s', strtotime($row['bid_end'])) > $time_now) {
echo "<span class=\"adstatus adstatussold\">active</span>";
} elseif ($row['bidders'] == 0) {
echo "<span class=\"adstatus adstatusdeleted\">closed</span>";
} else {
echo "<span class=\"adstatus adstatusactive\">rented</span>";
}
?>
</td>
<td data-title="Price">
<h3>
$<?= ($row['highest_bid'] > $row['start_price']) ? $row['highest_bid'] : $row['start_price'] ?></h3>
</td>
<td data-title="Bidders">
<h3><?= $row['bidders'] ?></h3>
</td>
<td data-title="Action">
<div class="btns-actions">
<a class="btn-action btn-view" title="View Listing"
href="./listing_detail.php?id=<?= $row['item_id']; ?>"><i
class="lni-eye"></i></a>
<?php
if ((date('Y/m/d H:i:s', strtotime($row['bid_end'])) > $time_now) && $is_owner) {
?>
<form method="POST" action="user_listings.php?show=<?= $_GET['show'] ?>">
<input type="hidden" name="delete_id" value="<?= $row['item_id'] ?>"/>
<button class="btn-action btn-delete lni-trash shadow-none"
style="border-style: none; cursor: pointer"
title="Delete Listing"></button>
</form>
<?php } ?>
</div>
</td>
<?php if ($is_owner) { ?>
<td data-title="Highest">
<?php if (isset($row['highest_bidder'])) {
?>
<!-- User Contact Information Modal -->
<div class="modal fade" id="bidwinner<?php echo $i;?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<?php
$winner_username = pg_escape_string($row['highest_bidder']);
$query = "SELECT full_name, email, phone FROM account where username='" . $winner_username . "'";
$query_result = pg_query($connection, $query) or die('Query unsuccessful:' . pg_last_error());
$details = pg_fetch_assoc($query_result);
?>
<div class="modal-dialog h-100 d-flex flex-column justify-content-center my-0" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<span class="modal-title w-100 font-weight-bold" style="font-size: larger">Contact Information</span>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body mx-3">
<div class="form-group">
<div class="input-icon">
<i class="lni-user">
</i>
<label class="control-label">Name</label>
<input type="text" id="username" name="username" class="form-control"
value="<?php echo $details['full_name']?>" readonly>
</div>
</div>
<div class="form-group">
<div class="input-icon">
<i class="lni-envelope">
</i>
<label class="control-label">Email</label>
<input type="text" class="form-control"
value="<?php echo $details['email']?>" readonly>
</div>
</div>
<div class="form-group">
<div class="input-icon">
<i class="lni-phone">
</i>
<label class="control-label">Phone</label>
<input type="text" class="form-control"
value="<?php echo $details['phone']?>" readonly>
</div>
</div>
</div>
</div>
</div>
</div>
<span style="margin-left: -5px" class="tg-btn" data-toggle="modal" data-target="#bidwinner<?php echo $i;?>">
<i class="lni-phone-handset"></i><?= $row['highest_bidder'] ?></span>
<?php } ?>
</td>
<?php } ?>
</tr>
<?php } ?>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
include "footer.php";
?>
<a href="/user_bids.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>