-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader.php
375 lines (355 loc) · 10.2 KB
/
header.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
<?php
// FIXME: At the moment, I've allowed these values to be set manually.
// But eventually, with a database, these should be set automatically
// ONLY after the user's login credentials have been verified via a
// database query.
session_start();
//$_SESSION['logged_in'] = false;
//$_SESSION['account_type'] = 'seller';
?>
<?php require("database.php")?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap and FontAwesome CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Custom CSS file -->
<link rel="stylesheet" href="css/custom.css">
<title>Group 11 Auction Site</title>
</head>
<body>
<!-- Navbars -->
<nav class="navbar navbar-expand-lg navbar-light bg-light mx-2">
<a class="navbar-brand" href="#">Group 11 Auction Site</a>
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown">
<?php
// Displays either login or logout on the right, depending on user's
// current status (session).
if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == true) {
echo "<a class='nav-link dropdown-toggle' href='#' id='navbarDropdown' role='button' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>User</a>".
"<div class='dropdown-menu dropdown-menu-right' aria-labelledby='navbarDropdown'>".
"<a class='dropdown-item' href='#'>User Name: ".$_SESSION['username']."</a>".
"<a class='dropdown-item' href='#'>Email: ".$_SESSION['email']."</a>".
"<a class='dropdown-item' href='#'>User Group: ".$_SESSION['account_type']."</a>".
"<div class='dropdown-divider'></div>".
"<a class='dropdown-item' href='logout.php'>Logout</a>";
//echo $_SESSION['logged_in'];
}
else {
echo '<button type="button" class="btn nav-link" data-toggle="modal" data-target="#loginModal">Login</button>';
//echo $_SESSION['logged_in'];
}
?>
</div>
</li>
</ul>
</nav>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<ul class="navbar-nav align-middle">
<li class="nav-item mx-1">
<a class="nav-link" href="browse.php">Browse</a>
</li>
<?php
if (isset($_SESSION['account_type']) && $_SESSION['account_type'] == 'buyer') {
echo('
<li class="nav-item mx-1">
<a class="nav-link" href="mybids.php">My Bids</a>
</li>
<li class="nav-item mx-1">
<a class="nav-link" href="recommendations.php">Recommended</a>
</li>');
}
if (isset($_SESSION['account_type']) && $_SESSION['account_type'] == 'seller') {
echo('
<li class="nav-item mx-1">
<a class="nav-link" href="mylistings.php">My Listings</a>
</li>
<li class="nav-item ml-3">
<a class="nav-link btn border-light" href="create_auction.php">+ Create auction</a>
</li>');
}
?>
</ul>
</nav>
<?php
if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == true) {
if (isset($_SESSION['account_type']) && $_SESSION['account_type'] == 'buyer') {
/*Notification for outbid */
$querryOutbid = <<<QUERRYTEXT
SELECT *
FROM
(
SELECT
a.AuctionID,
a.ItemName,
a.StartingPrice,
MAX(b.BidPrice) AS 'bidPrice',
IF(
MAX(bidPrice) IS NULL,
a.StartingPrice,
MAX(bidPrice)
) AS 'CurrentPrice'
FROM
auctions a
LEFT JOIN bids b ON a.AuctionID = b.AuctionID
WHERE
(a.EndingTime - CURRENT_TIMESTAMP) > 0
AND a.AuctionID IN (
SELECT
AuctionID
FROM
bids
WHERE
UserName = '{$_SESSION['username']}'
GROUP BY
AuctionID
)
GROUP BY
a.AuctionID,
a.ItemName,
a.ItemDescription,
a.StartingPrice,
a.EndingTime
) MaxPriceGlobal
INNER JOIN (
SELECT
AuctionID,
MAX(BidPrice) AS UserMax
FROM
bids
WHERE
UserName = '{$_SESSION['username']}'
GROUP BY
AuctionID
) MaxPriceUser ON MaxPriceGlobal.AuctionID = MaxPriceUser.AuctionID
WHERE
MaxPriceGlobal.CurrentPrice != MaxPriceUser.UserMax
ORDER BY
MaxPriceGlobal.AuctionID
QUERRYTEXT;
//echo $querryOutbid;
$resultOutbid = mysqli_query($connectionView, $querryOutbid);
//echo $querryOutbid;
if ($resultOutbid->num_rows > 0) {
echo <<<TABLEPARTS
<div class="alert alert-primary alert-dismissible fade show" role="alert">
<strong>Some of the items you bidded is being outbidded by other user!</strong>
<table class="table">
<thead>
<tr>
<th scope="col">Auction ID</th>
<th scope="col">Name Of Item</th>
<th scope="col">Current Bid Price (£)</th>
<th scope="col">Your Bid (£)</th>
</tr>
</thead>
<tbody>
TABLEPARTS;
while ($rowOutbid = mysqli_fetch_array($resultOutbid)){
echo <<<ROWPARTS
<tr>
<th scope="row">{$rowOutbid['AuctionID']}</th>
<td>{$rowOutbid['ItemName']}</td>
<td>{$rowOutbid['CurrentPrice']}</td>
<td>{$rowOutbid['UserMax']}</td>
</tr>
ROWPARTS;
}
echo <<<TABLEPARTS
</tbody>
</table>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
TABLEPARTS;
}
/*Extracting variable for the WatchList*/
$querryWatchList = <<<QUERRYTEXT
SELECT
a.AuctionID,
a.ItemName,
a.StartingPrice,
MAX(b.BidPrice) AS 'bidPrice',
IF(
MAX(bidPrice) IS NULL,
a.StartingPrice,
MAX(bidPrice)
) AS 'CurrentPrice'
FROM
auctions a
LEFT JOIN bids b ON a.AuctionID = b.AuctionID
WHERE
b.BidTime > CURDATE() - INTERVAL 1 DAY
AND b.Bidtime < CURDATE()
AND a.AuctionID IN (
SELECT
AuctionID
FROM
watchlist
WHERE
UserName = '{$_SESSION['username']}'
)
GROUP BY
a.AuctionID,
a.ItemName,
a.ItemDescription,
a.StartingPrice,
a.EndingTime
ORDER BY
a.AuctionID
QUERRYTEXT;
//echo $querryWatchList;
//echo $querryWatchList;
$resultWatchList = mysqli_query($connectionView, $querryWatchList);
//echo $querryOutbid;
if ($resultWatchList->num_rows > 0) {
echo <<<TABLEPARTS
<div class="alert alert-secondary alert-dismissible fade show" role="alert">
<strong>Update for your watchlist</strong>
<table class="table">
<thead>
<tr>
<th scope="col">Auction ID</th>
<th scope="col">Name Of Item</th>
<th scope="col">Current Bid Price (£)</th>
</tr>
</thead>
<tbody>
TABLEPARTS;
while ($rowWatchList = mysqli_fetch_array($resultWatchList)){
echo <<<ROWPARTS
<tr>
<th scope="row">{$rowWatchList['AuctionID']}</th>
<td>{$rowWatchList['ItemName']}</td>
<td>{$rowWatchList['CurrentPrice']}</td>
</tr>
ROWPARTS;
}
echo <<<TABLEPARTS
</tbody>
</table>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
TABLEPARTS;
}
}
/* Finished Auction */
/* Fetching Auction ending today */
$querryTodayAuctionFinish = <<<QUERRYTEXT
SELECT
a.AuctionID,
a.UserName,
u.Email,
a.ItemName,
a.ReservePrice
FROM
auctions a
JOIN users u
ON u.UserName = a. UserName
WHERE
EndingTime > CURDATE() - INTERVAL 1 DAY
AND EndingTime < CURDATE()
QUERRYTEXT;
$resultTodayAuctionFinish = mysqli_query($connectionView, $querryTodayAuctionFinish);
if ($resultTodayAuctionFinish->num_rows > 0) {
echo <<<TABLEPARTS
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Auction Just Ended</strong>
<table class="table">
<thead>
<tr>
<th scope="col">Auction ID</th>
<th scope="col">Name Of Item</th>
<th scope="col">Final Price (£)</th>
<th scope="col">Buyer</th>
<th scope="col">Buyer Email</th>
<th scope="col">Seller</th>
<th scope="col">Seller Email</th>
</tr>
</thead>
<tbody>
TABLEPARTS;
while ($rowFinAuction = mysqli_fetch_array($resultTodayAuctionFinish)){
$Auction_ID = $rowFinAuction['AuctionID'];
$Item_Name = $rowFinAuction['ItemName'];
$Seller = $rowFinAuction['UserName'];
$Seller_Email = $rowFinAuction['Email'];
$Reserve_Price = $rowFinAuction['ReservePrice'];
$querryWinner = <<<QUERRYTEXT
SELECT
b.UserName,
b.bidPrice,
u.Email
FROM
bids b
JOIN users u
ON b.UserName = u.Username
WHERE
b.AuctionID = {$Auction_ID}
ORDER BY
b.BidPrice DESC,
b.BidTime ASC;
QUERRYTEXT;
$resultWinner = mysqli_query($connectionView, $querryWinner);
$rowWinner = mysqli_fetch_array($resultWinner);
$Final_Price = $rowWinner['bidPrice'];
$Buyer = $rowWinner['UserName'];
$Buyer_Email = $rowWinner['Email'];
if ($Final_Price >= $Reserve_Price) {
echo <<<ROWPARTS
<tr>
<th scope="row">{$Auction_ID}</th>
<td>{$Item_Name}</td>
<td>{$Final_Price}</td>
<td>{$Buyer}</td>
<td>{$Buyer_Email}</td>
<td>{$Seller}</td>
<td>{$Seller_Email}</td>
</tr>
ROWPARTS;
}
}
echo <<<TABLEPARTS
</tbody>
</table>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
TABLEPARTS;
}
}
?>
<!-- Login modal -->
<div class="modal fade" id="loginModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Login</h4>
</div>
<!-- Modal body -->
<div class="modal-body">
<form method="POST" action="login_result.php">
<div class="form-group">
<label for="Username">Username</label>
<input type="text" class="form-control" name="Username" placeholder="Username">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name="password" placeholder="Password">
</div>
<button type="submit" class="btn btn-primary form-control">Sign in</button>
</form>
<div class="text-center">or <a href="register.php">create an account</a></div>
</div>
</div>
</div>
</div> <!-- End modal -->