-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlisting_detail.php
219 lines (173 loc) · 8.19 KB
/
listing_detail.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
<!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();
include "connect.php";
$_SESSION['current_page'] = $_SERVER['REQUEST_URI'];
if (!isset($_SESSION['key'])) {
header("Location: ./login.php");
}
$query_item = "SELECT * FROM item WHERE item_id=" . $_GET['id'];
$item_result = pg_query($connection, $query_item);
$row = pg_fetch_assoc($item_result);
if (!pg_num_rows($item_result)) {
header("Location: ./listings.php");
}
include "header.php";
?>
<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">Item Details</h2>
<ol class="breadcrumb">
<li><a href="./index.php">Home /</a></li>
<li class="current">Item Details</li>
</ol>
</div>
</div>
</div>
</div>
</div>
<?php
$query_bids = "SELECT MAX(bid_amount) AS max_bid FROM bid where item_id=" . $_GET['id'];
$bid_result = pg_query($connection, $query_bids);
$bids = pg_fetch_assoc($bid_result);
$curr_min_bid = empty($bids['max_bid']) ? $row['start_price'] : $bids[max_bid];
?>
<?php
$flash = "";
date_default_timezone_set('Asia/Singapore');
$now = date('Y-m-d H:i:s');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (empty($_POST['bid_amt'])) {
// Empty bid
$flash = "<div class='alert alert-danger text-center' role='alert'>Bid amount not indicated</div>";
} else {
$insert_bid = "INSERT INTO bid VALUES(DEFAULT,'" . $now . "'," . $_POST['bid_amt'] . ",'" . $_SESSION['key'] . "'," . $_GET['id'] . ")";
$write = pg_query($connection, $insert_bid);
if ($write) {
$flash = "<div class='alert alert-success text-center' role='alert'>Bid of $" . $_POST['bid_amt'] . " submitted!</div>";
} else {
preg_match("/:.+/",pg_last_error($connection),$match);
$error_msg = ltrim($match[0], ':');
$flash = "<div class='alert alert-danger text-center' role='alert'>$error_msg</div>";
}
}
}
?>
<?php
$query_bid_count = "SELECT COUNT(*) AS count FROM bid where item_id=" . $_GET['id'];
$count_result = pg_query($connection, $query_bid_count);
$count = pg_fetch_assoc($count_result);
?>
<div class="section-padding">
<div class="container">
<?= $flash ?>
<div class="product-info row">
<div class="col-lg-7 col-md-12 col-xs-12">
<div class="details-box ads-details-wrapper">
<div id="owl-demo" class="owl-carousel owl-theme" style="opacity: 1; display: block;">
<div class="owl-wrapper-outer">
<div class="owl-wrapper" style="width: 3810px; left: 0px; display: block;">
<div class="owl-item" style="width: 635px;">
<div class="item">
<div class="product-img">
<img class="img-fluid" src="./assets/img/items/<?= $row['img_src'] ?>"
alt="">
</div>
<span class="price">$<?= $curr_min_bid+1 ?></span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-5 col-md-12 col-xs-12">
<div class="details-box">
<div class="ads-details-info">
<h2><?= $row['item_name'] ?></h2>
<div class="details-meta">
<span><i class="lni-alarm-clock"></i> <?= $row['borrow_duration'] ?> <?= $row['borrow_duration'] == 1 ? day : days ?></span>
<span><i class="lni-map-marker"></i> <?= $row['address'] ?></span>
<span><i class="lni-eye"></i> <?= $count['count'] ?> bids</span>
</div>
<ul class="advertisement mb-4">
<li><strong>Opening bid: </strong><?= $row['bid_start'] ?></li>
<li><strong>Closing bid: </strong><?= explode(" ",$row['bid_end'])[0] ?></li>
</ul>
</div>
<div class="advertisement mb-4">
<p><?= $row['description'] ?></p>
</div>
<div class="advertisement mb-2">
<form method="POST" action="listing_detail.php?id=<?= $row['item_id'] ?>">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">$</span>
</div>
<input name="username" type="hidden" value="<?= $row['username'] ?>"/>
<input name="bid_amt" type="number" class="form-control"
min=<?= floor($curr_min_bid + 1) ?> placeholder="<?= floor($curr_min_bid + 1) ?>
onwards">
<span class="input-group-btn">
<?php
if (date('Y/m/d H:i:s', strtotime($row['bid_end'])) < date('Y/m/d H:i:s')) {
echo "<button class=\"btn btn-common btn-secondary\" type=\"submit\" disabled>Closed!</button>";
} else {
echo "<button class=\"btn btn-common btn-reply\" type=\"submit\">Bid It!</button>";
}
?>
</span>
</div><!-- /input-group -->
</form>
</div>
<div class="advertisement mb-2">
<strong>more from </strong><a
href="user_listings.php?user=<?= $row['username'] ?>"><?= $row['username'] ?></a><strong>?</strong>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
include "./footer.php";
?>
<a href="/ads-details.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>
<script src="./assets/js/summernote.js"></script>
</body>
</html>