-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmylistings.php
189 lines (154 loc) · 4.93 KB
/
mylistings.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
<?php include_once("header.php")?>
<?php require("utilities.php")?>
<?php require("database.php")?>
<div class="container">
<h2 class="my-3">My listings</h2>
<div id="searchSpecs">
<!-- When this form is submitted, this PHP page is what processes it.
Search/sort specs are passed to this page through parameters in the URL
(GET method of passing data to a page). -->
<form method="get" action="mylistings.php">
<div class="col-md-3 pr-0">
<div class="form-inline">
<label class="mx-2" for="order_by">Sort by:</label>
<select type = "submit" id="order_by" name="order_by" onchange="this.form.submit();">
<option selected value="ORDER BY CurrentPrice ASC">Price (low to high)</option>
<option value="ORDER BY CurrentPrice DESC">Price (high to low)</option>
<option value="ORDER BY (a.EndingTime - CURRENT_TIMESTAMP) ASC">Soonest expiry</option>
</select>
</div>
</div>
</form>
</div> <!-- end search specs bar -->
</div>
<?php
if (!isset($_GET['order_by'])) {
// TODO: Define behavior if an order_by value has not been specified.
$ordering = "";
}
else {
$ordering = $_GET['order_by'];
}
if (!isset($_GET['page'])) {
$curr_page = 1;
}
else {
$curr_page = $_GET['page'];
}
if (isset($_SESSION['username']) != true){
echo "Log in to view your bids";
}
else if ($_SESSION['account_type'] != 'seller'){
echo "log into seller sccount to view your listing";
}
$results_per_page = 10;
$querryItemList = <<<QUERRYTEXT
SELECT
a.AuctionID,
a.ItemName,
a.ItemDescription,
a.StartingPrice,
a.EndingTime,
COUNT(b.BidID) AS 'CountBids',
MAX(b.BidPrice) AS 'bidPrice',
IF(
MAX(bidPrice) IS NULL,
a.StartingPrice,
MAX(bidPrice)
) AS 'CurrentPrice',
a.StartingPrice
FROM
auctions a
LEFT JOIN bids b ON a.AuctionID = b.AuctionID
WHERE
a.UserName = '{$_SESSION['username']}'
GROUP BY
a.AuctionID,
a.ItemName,
a.ItemDescription,
a.StartingPrice,
a.EndingTime {$ordering}
QUERRYTEXT;
//echo $querryItemList;
$limiter = " LIMIT ".strval(($curr_page-1)*$results_per_page).", ".strval($results_per_page);
$querryWithLimitItemPerPage = $querryItemList.$limiter;
$resultforCounting = mysqli_query($connectionView, $querryItemList);
//echo mysqli_error($connectionview)
if ($resultforCounting)
{
// it return number of rows in the table.
$num_results = mysqli_num_rows($resultforCounting);
}
$max_page = ceil($num_results / $results_per_page);
?>
<div class="container mt-5">
<!-- TODO: If result set is empty, print an informative message. Otherwise... -->
<ul class="list-group">
<?php
// Demonstration of what listings will look like using dummy data.
$search_query_result = mysqli_query($connectionView, $querryWithLimitItemPerPage);
while ($row = mysqli_fetch_array($search_query_result)){
$item_id = $row['AuctionID'];
$title = $row['ItemName'];
$description = $row['ItemDescription'];
$current_price = $row['CurrentPrice'];
$num_bids = $row['CountBids'];
$end_date = new DateTime($row['EndingTime']);
// This uses a function defined in utilities.php
print_listing_li($item_id, $title, $description, $current_price, $num_bids, $end_date);
}
?>
<!-- Pagination for results listings -->
<nav aria-label="Search results pages" class="mt-5">
<ul class="pagination justify-content-center">
<?php
// Copy any currently-set GET variables to the URL.
$querystring = "";
foreach ($_GET as $key => $value) {
if ($key != "page") {
$querystring .= "$key=$value&";
}
}
$high_page_boost = max(3 - $curr_page, 0);
$low_page_boost = max(2 - ($max_page - $curr_page), 0);
$low_page = max(1, $curr_page - 2 - $low_page_boost);
$high_page = min($max_page, $curr_page + 2 + $high_page_boost);
if ($curr_page != 1) {
echo('
<li class="page-item">
<a class="page-link" href="mybids.php?' . $querystring . 'page=' . ($curr_page - 1) . '" aria-label="Previous">
<span aria-hidden="true"><i class="fa fa-arrow-left"></i></span>
<span class="sr-only">Previous</span>
</a>
</li>');
}
for ($i = $low_page; $i <= $high_page; $i++) {
if ($i == $curr_page) {
// Highlight the link
echo('
<li class="page-item active">');
}
else {
// Non-highlighted link
echo('
<li class="page-item">');
}
// Do this in any case
echo('
<a class="page-link" href="mybids.php?' . $querystring . 'page=' . $i . '">' . $i . '</a>
</li>');
}
if ($curr_page != $max_page) {
echo('
<li class="page-item">
<a class="page-link" href="mybids.php?' . $querystring . 'page=' . ($curr_page + 1) . '" aria-label="Next">
<span aria-hidden="true"><i class="fa fa-arrow-right"></i></span>
<span class="sr-only">Next</span>
</a>
</li>');
}
?>
</ul>
</nav>
</div>
<?php include_once("footer.php")?>