-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetail_lelang.php
More file actions
488 lines (423 loc) · 21 KB
/
detail_lelang.php
File metadata and controls
488 lines (423 loc) · 21 KB
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
<?php
session_start();
include 'connect.php';
include 'buat_notifikasi.php';
// Get auction ID from URL
$auction_id = isset($_GET['id']) ? mysqli_real_escape_string($conn, $_GET['id']) : '';
if (empty($auction_id)) {
header("Location: index.php");
exit;
}
// Query to get auction and car details
$sql = "SELECT a.auction_id, a.start_time, a.end_time, a.current_highest_bid, a.winner_id,
c.foto1, c.foto2, c.foto3, c.model, c.year, c.type, c.description
FROM auctions a
JOIN cars c ON a.car_id = c.car_id
WHERE a.auction_id = '$auction_id'";
$result = mysqli_query($conn, $sql);
if (!$result || mysqli_num_rows($result) == 0) {
header("Location: index.php");
exit;
}
$auction = mysqli_fetch_assoc($result);
// Calculate remaining time
$end_time = strtotime($auction['end_time']);
$now = time();
$time_left = $end_time - $now;
// Format remaining time
$days = floor($time_left / (24 * 3600));
$hours = floor(($time_left % (24 * 3600)) / 3600);
$minutes = floor(($time_left % 3600) / 60);
$time_display = "";
if ($days > 0) {
$time_display = $days . " hari " . $hours . " jam " . $minutes . " menit";
} else if ($hours > 0) {
$time_display = $hours . " jam " . $minutes . " menit";
} else {
$time_display = $minutes . " menit";
}
// Process bid submission via AJAX
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit_bid'])) {
$response = array();
$bid_amount = mysqli_real_escape_string($conn, $_POST['bid_amount']);
$bidder_id = $_SESSION['user_id'];
if ($bid_amount <= $auction['current_highest_bid']) {
$response['status'] = 'error';
$response['message'] = "Penawaran harus lebih tinggi dari penawaran tertinggi saat ini";
} else {
mysqli_begin_transaction($conn);
try {
$insert_bid = "INSERT INTO bids (auction_id, bidder_id, bid_amount) VALUES (?, ?, ?)";
$stmt = mysqli_prepare($conn, $insert_bid);
mysqli_stmt_bind_param($stmt, "iid", $auction_id, $bidder_id, $bid_amount);
mysqli_stmt_execute($stmt);
$update_auction = "UPDATE auctions SET current_highest_bid = ?, winner_id = ? WHERE auction_id = ?";
$stmt = mysqli_prepare($conn, $update_auction);
mysqli_stmt_bind_param($stmt, "dii", $bid_amount, $bidder_id, $auction_id);
mysqli_stmt_execute($stmt);
mysqli_commit($conn);
createBidNotifications($conn, $auction_id, $bidder_id, $bid_amount);
// Get updated auction data
$result = mysqli_query($conn, $sql);
$updated_auction = mysqli_fetch_assoc($result);
$response['status'] = 'success';
$response['message'] = "Penawaran berhasil diajukan!";
$response['new_bid'] = number_format($updated_auction['current_highest_bid'], 0, ',', '.');
$response['is_winner'] = true;
} catch (Exception $e) {
mysqli_rollback($conn);
$response['status'] = 'error';
$response['message'] = "Terjadi kesalahan saat mengajukan penawaran";
}
}
header('Content-Type: application/json');
echo json_encode($response);
exit;
}
// Check if current user is the highest bidder
$is_highest_bidder = isset($_SESSION['user_id']) && $auction['winner_id'] == $_SESSION['user_id'];
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Detail Lelang - <?php echo htmlspecialchars($auction['model']); ?></title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="icon" type="image/png" sizes="32x32" href="assets/logo2.png">
<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@200;300;400;500;600;700;800&display=swap" rel="stylesheet">
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: {
body: ['Plus Jakarta Sans']
},
colors: {
primary: '#1b9af5',
secondary: '#bcedff',
tertiary: '#1767b6',
accent: '#143557',
},
},
}
}
</script>
</head>
<body class="bg-gray-50 font-body">
<?php require_once 'navbar.php'; ?>
<div class="container mx-auto px-4 py-8">
<!-- Breadcrumb -->
<div class="flex items-center gap-2 text-sm mb-8">
<a href="index.php" class="text-gray-500 hover:text-primary">Home</a>
<span class="text-gray-400">/</span>
<span class="text-primary">Detail Lelang</span>
</div>
<!-- Main Content Grid -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-8">
<!-- Left Column - Images -->
<div class="space-y-4">
<div data-aos="zoom-in" data-aos-duration="1500" class="bg-white p-4 rounded-lg shadow-md">
<!-- Carousel Container -->
<div class="relative h-[400px] overflow-hidden rounded-lg">
<!-- Slides -->
<div class="slide absolute w-full h-full transition-opacity duration-1000 opacity-100">
<img src="<?php echo htmlspecialchars($auction['foto1']); ?>"
alt="<?php echo htmlspecialchars($auction['model']); ?>"
class="w-full h-full object-cover">
</div>
<?php if (!empty($auction['foto2'])): ?>
<div class="slide absolute w-full h-full transition-opacity duration-1000 opacity-0">
<img src="<?php echo htmlspecialchars($auction['foto2']); ?>"
alt="<?php echo htmlspecialchars($auction['model']); ?>"
class="w-full h-full object-cover">
</div>
<?php endif; ?>
<?php if (!empty($auction['foto3'])): ?>
<div class="slide absolute w-full h-full transition-opacity duration-1000 opacity-0">
<img src="<?php echo htmlspecialchars($auction['foto3']); ?>"
alt="<?php echo htmlspecialchars($auction['model']); ?>"
class="w-full h-full object-cover">
</div>
<?php endif; ?>
<!-- Navigation Buttons -->
<button onclick="moveSlide(-1)"
class="absolute left-4 top-1/2 -translate-y-1/2 bg-black/50 text-white p-2 rounded-full hover:bg-black/75 transition-colors z-10">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
</svg>
</button>
<button onclick="moveSlide(1)"
class="absolute right-4 top-1/2 -translate-y-1/2 bg-black/50 text-white p-2 rounded-full hover:bg-black/75 transition-colors z-10">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
</svg>
</button>
<!-- Dots -->
<div class="absolute bottom-4 left-1/2 -translate-x-1/2 flex space-x-2 z-10">
<button onclick="currentSlide(0)"
class="w-2 h-2 rounded-full bg-primary transition-colors"></button>
<?php if (!empty($auction['foto2'])): ?>
<button onclick="currentSlide(1)"
class="w-2 h-2 rounded-full bg-white transition-colors"></button>
<?php endif; ?>
<?php if (!empty($auction['foto3'])): ?>
<button onclick="currentSlide(2)"
class="w-2 h-2 rounded-full bg-white transition-colors"></button>
<?php endif; ?>
</div>
</div>
</div>
<!-- Thumbnails -->
<div data-aos="fade-up" data-aos-duration="1500" class="grid grid-cols-3 gap-4">
<img src="<?php echo htmlspecialchars($auction['foto1']); ?>"
onclick="currentSlide(0)"
class="w-full h-32 object-cover rounded-lg cursor-pointer hover:opacity-75 transition-opacity">
<?php if (!empty($auction['foto2'])): ?>
<img src="<?php echo htmlspecialchars($auction['foto2']); ?>"
onclick="currentSlide(1)"
class="w-full h-32 object-cover rounded-lg cursor-pointer hover:opacity-75 transition-opacity">
<?php endif; ?>
<?php if (!empty($auction['foto3'])): ?>
<img src="<?php echo htmlspecialchars($auction['foto3']); ?>"
onclick="currentSlide(2)"
class="w-full h-32 object-cover rounded-lg cursor-pointer hover:opacity-75 transition-opacity">
<?php endif; ?>
</div>
</div>
<!-- Right Column - Details -->
<div class="space-y-6">
<!-- Car Info -->
<div data-aos="fade-down" data-aos-duration="1500" class="bg-white p-6 rounded-lg shadow-md">
<h1 class="text-3xl font-bold text-accent mb-2">
<?php echo htmlspecialchars($auction['model']); ?>
</h1>
<div class="grid grid-cols-2 gap-4 mt-4">
<div>
<p class="text-gray-600">Tahun</p>
<p class="font-semibold"><?php echo htmlspecialchars($auction['year']); ?></p>
</div>
<div>
<p class="text-gray-600">Tipe</p>
<p class="font-semibold"><?php echo htmlspecialchars($auction['type']); ?></p>
</div>
</div>
</div>
<!-- Auction Info -->
<div data-aos="fade-up" data-aos-duration="1500" class="bg-white p-6 rounded-lg shadow-md">
<div class="space-y-4">
<div>
<p class="text-gray-600">Penawaran Tertinggi Saat Ini</p>
<p class="text-2xl font-bold text-primary" id="current-bid">
Rp. <?php echo number_format($auction['current_highest_bid'], 0, ',', '.'); ?>
</p>
<?php if ($is_highest_bidder): ?>
<p class="text-green-600 mt-2">Anda saat ini merupakan penawar dengan harga tertinggi</p>
<?php endif; ?>
</div>
<div>
<p class="text-gray-600">Sisa Waktu</p>
<p class="font-semibold text-red-500" id="countdown">
<?php echo $time_display; ?>
</p>
</div>
<div>
<h2 class="text-xl font-semibold text-accent">Deskripsi</h2>
<p class="text-gray-700 mt-2">
<?php echo nl2br(htmlspecialchars($auction['description'])); ?>
</p>
</div>
</div>
<!-- Bid Button -->
<?php if (isset($_SESSION['user_id'])): ?>
<button onclick="openBidModal()"
class="w-full bg-primary text-white px-6 py-3 rounded-md hover:bg-tertiary transition-colors mt-6">
Ikuti Lelang
</button>
<?php else: ?>
<div class="mt-6 text-center">
<p class="text-gray-600 mb-4">Login untuk mengajukan penawaran</p>
<a href="login.php" class="inline-block bg-primary text-white px-6 py-2 rounded-md hover:bg-tertiary transition-colors">
Login
</a>
</div>
<?php endif; ?>
</div>
</div>
</div>
<!-- Bid Modal -->
<div id="bidModal" class="hidden fixed inset-0 bg-black bg-opacity-50 z-50">
<div class="fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white rounded-lg p-6 max-w-md w-full">
<button onclick="closeBidModal()" class="absolute right-4 top-4 text-gray-500 hover:text-gray-700">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
<h2 class="text-2xl font-bold text-accent mb-4">Ajukan Penawaran</h2>
<div id="bid-message" class="hidden mb-4"></div>
<form id="bidForm" class="space-y-4">
<div>
<label class="block text-gray-700 mb-2">Penawaran Saat Ini</label>
<p class="text-xl font-bold text-primary" id="modal-current-bid">
Rp. <?php echo number_format($auction['current_highest_bid'], 0, ',', '.'); ?>
</p>
</div>
<div>
<label for="bid_amount" class="block text-gray-700 mb-2">Jumlah Penawaran Anda</label>
<input type="number"
name="bid_amount"
id="bid_amount"
class="w-full border rounded-md px-4 py-2 focus:outline-none focus:ring-2 focus:ring-primary"
min="<?php echo $auction['current_highest_bid'] + 1000; ?>"
step="1000"
required>
<p class="text-sm text-gray-500 mt-1">
Minimal penawaran: Rp. <?php echo number_format($auction['current_highest_bid'] + 1000, 0, ',', '.'); ?>
</p>
</div>
<button type="submit"
name="submit_bid"
class="w-full bg-primary text-white px-6 py-3 rounded-md hover:bg-tertiary transition-colors">
Ajukan Penawaran
</button>
</form>
</div>
</div>
</div>
</main>
<?php include 'footer.php'; ?>
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
<script>
AOS.init();
</script>
<script>
let slideIndex = 0;
const slides = document.getElementsByClassName("slide");
const dots = document.querySelectorAll(".absolute.bottom-4 button");
// Modal functions
function openBidModal() {
document.getElementById('bidModal').classList.remove('hidden');
}
function closeBidModal() {
document.getElementById('bidModal').classList.add('hidden');
}
// Close modal when clicking outside
window.onclick = function(event) {
const modal = document.getElementById('bidModal');
if (event.target == modal) {
modal.classList.add('hidden');
}
}
// Slider functions
function moveSlide(n) {
slideIndex += n;
if (slideIndex >= slides.length) {
slideIndex = 0;
}
if (slideIndex < 0) {
slideIndex = slides.length - 1;
}
showSlides();
}
function currentSlide(n) {
slideIndex = n;
showSlides();
}
function showSlides() {
for (let i = 0; i < slides.length; i++) {
slides[i].style.opacity = "0";
if (dots[i]) {
dots[i].classList.remove("bg-primary");
dots[i].classList.add("bg-white");
}
}
slides[slideIndex].style.opacity = "1";
if (dots[slideIndex]) {
dots[slideIndex].classList.remove("bg-white");
dots[slideIndex].classList.add("bg-primary");
}
}
// Countdown timer
const endTime = <?php echo $end_time * 1000; ?>;
function updateCountdown() {
const now = new Date().getTime();
const timeLeft = endTime - now;
if (timeLeft <= 0) {
document.getElementById('countdown').textContent = 'Lelang telah berakhir';
return;
}
const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
let display = '';
if (days > 0) {
display = `${days} hari ${hours} jam ${minutes} menit`;
} else if (hours > 0) {
display = `${hours} jam ${minutes} menit`;
} else {
display = `${minutes} menit`;
}
document.getElementById('countdown').textContent = display;
}
// Update countdown every minute
setInterval(updateCountdown, 60000);
function showMessage(type, message) {
const messageDiv = document.getElementById('bid-message');
messageDiv.className = `p-4 rounded ${type === 'success' ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700'}`;
messageDiv.textContent = message;
messageDiv.classList.remove('hidden');
}
$(document).ready(function() {
$('#bidForm').on('submit', function(e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: window.location.href,
data: $(this).serialize() + '&submit_bid=1',
dataType: 'json',
success: function(response) {
if (response.status === 'success') {
showMessage('success', response.message);
$('#current-bid, #modal-current-bid').text('Rp. ' + response.new_bid);
if (response.is_winner) {
// Add highest bidder message if not exists
if ($('.text-green-600').length === 0) {
$('#current-bid').after('<p class="text-green-600 mt-2">Anda saat ini merupakan penawar dengan harga tertinggi</p>');
}
}
// Clear form
$('#bidForm')[0].reset();
// Close modal after 2 seconds
setTimeout(closeBidModal, 2000);
} else {
showMessage('error', response.message);
}
},
error: function() {
showMessage('error', 'Terjadi kesalahan. Silakan coba lagi.');
}
});
});
});
// Format bid amount input with thousand separator
const bidInput = document.getElementById('bid_amount');
bidInput.addEventListener('input', function(e) {
// Remove non-numeric characters
let value = this.value.replace(/\D/g, '');
// Format with thousand separator
if (value.length > 3) {
let formattedValue = new Intl.NumberFormat('id-ID').format(value);
document.querySelector('.text-sm.text-gray-500').textContent =
'Jumlah penawaran: Rp. ' + formattedValue;
}
});
// Auto-advance slides every 5 seconds
setInterval(function() {
moveSlide(1);
}, 5000);
</script>
</body>
</html>
<?php mysqli_close($conn); ?>