-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect_seat.php
More file actions
409 lines (375 loc) · 12.1 KB
/
Copy pathselect_seat.php
File metadata and controls
409 lines (375 loc) · 12.1 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
<?php
session_start();
include 'config/db.php';
if (!isset($_GET['id'])) {
die("Event ID missing.");
}
$event_id = intval($_GET['id']);
if (!isset($_SESSION['user_id'])) {
header('Location: login.php'); exit();
}
$user_id = $_SESSION['user_id'];
// Get event details for price
$event_stmt = $conn->prepare("SELECT id, title, price FROM events WHERE id = ?");
$event_stmt->execute([$event_id]);
$event = $event_stmt->fetch(PDO::FETCH_ASSOC);
if (!$event) {
die("Event not found.");
}
// Get List of Already Booked Seats
$booked_seats = [];
$stmt = $conn->prepare("SELECT seat_number FROM bookings WHERE event_id = ? AND payment_status IN ('Paid', 'Pending')");
$stmt->execute([$event_id]);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$booked_seats[] = $row['seat_number'];
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="assets/css/style.css">
<title>Select Seats - <?php echo htmlspecialchars($event['title']); ?></title>
<style>
body {
font-family: sans-serif;
background-color: #111827;
color: #e5e7eb;
padding: 20px;
}
.container {
max-width: 900px;
margin: 0 auto;
}
h1 {
text-align: center;
color: #e5e7eb;
margin-bottom: 10px;
}
.event-info {
background: #1F2937;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
text-align: center;
}
.event-info p {
margin: 5px 0;
color: #9CA3AF;
}
.screen {
background: #333;
color: white;
text-align: center;
padding: 15px;
margin-bottom: 30px;
border-radius: 8px;
font-weight: bold;
font-size: 18px;
}
.seat-grid {
display: grid;
grid-template-columns: repeat(10, 1fr);
gap: 10px;
margin-bottom: 30px;
background: #1F2937;
padding: 20px;
border-radius: 8px;
}
.seat {
padding: 15px;
text-align: center;
border: 2px solid #22d3ee;
background-color: #10b981;
cursor: pointer;
border-radius: 5px;
color: white;
font-weight: bold;
transition: all 0.3s ease;
}
.seat:hover {
background-color: #059669;
transform: scale(1.05);
}
.seat.booked {
background-color: #ef4444;
border-color: #dc2626;
cursor: not-allowed;
opacity: 0.6;
}
.seat.selected {
background-color: #8B5CF6;
border-color: #7c3aed;
box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
transform: scale(1.1);
}
.legend {
display: flex;
justify-content: center;
gap: 30px;
margin-bottom: 20px;
flex-wrap: wrap;
}
.legend-item {
display: flex;
align-items: center;
gap: 10px;
}
.legend-box {
width: 30px;
height: 30px;
border-radius: 4px;
border: 2px solid;
}
.legend-available {
background-color: #10b981;
border-color: #22d3ee;
}
.legend-booked {
background-color: #ef4444;
border-color: #dc2626;
}
.legend-selected {
background-color: #8B5CF6;
border-color: #7c3aed;
}
.summary {
background: #1F2937;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
}
.summary h3 {
color: #e5e7eb;
margin-top: 0;
}
.selected-seats {
background: #111827;
padding: 10px;
border-radius: 4px;
margin-bottom: 15px;
min-height: 40px;
}
.selected-seats p {
margin: 0 0 10px 0;
color: #9CA3AF;
}
.seats-list {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.seat-badge {
background: #6366f1;
color: white;
padding: 5px 10px;
border-radius: 4px;
font-size: 14px;
}
.price-info {
background: #064e3b;
padding: 10px;
border-radius: 4px;
margin-bottom: 15px;
color: #86efac;
}
.button-group {
display: flex;
gap: 10px;
justify-content: center;
flex-wrap: wrap;
}
button {
padding: 12px 30px;
border: none;
border-radius: 6px;
cursor: pointer;
font-weight: bold;
font-size: 16px;
transition: all 0.3s;
}
#confirm-btn {
background: linear-gradient(135deg, #6366f1, #22d3ee);
color: #040025;
flex: 1;
min-width: 150px;
}
#confirm-btn:hover:not(:disabled) {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}
#confirm-btn:disabled {
background: #6b7280;
cursor: not-allowed;
opacity: 0.6;
}
#clear-btn {
background: #6b7280;
color: white;
flex: 1;
min-width: 150px;
}
#clear-btn:hover {
background: #4b5563;
}
.back-btn {
background: #6b7280;
color: white;
flex: 1;
min-width: 150px;
text-decoration: none;
display: inline-block;
text-align: center;
}
.back-btn:hover {
background: #4b5563;
}
.error-message {
background: #7f1d1d;
color: #fecaca;
padding: 10px;
border-radius: 4px;
margin-bottom: 15px;
border: 1px solid #dc2626;
}
</style>
</head>
<body>
<div class="container">
<h1>🎫 Select Your Seats</h1>
<div class="event-info">
<p><strong>Event:</strong> <?php echo htmlspecialchars($event['title']); ?></p>
<p><strong>Price per Seat:</strong> ₹<?php echo number_format($event['price'], 2); ?></p>
</div>
<div class="legend">
<div class="legend-item">
<div class="legend-box legend-available"></div>
<span>Available</span>
</div>
<div class="legend-item">
<div class="legend-box legend-booked"></div>
<span>Booked</span>
</div>
<div class="legend-item">
<div class="legend-box legend-selected"></div>
<span>Selected</span>
</div>
</div>
<div class="screen">🎬 STAGE / SCREEN</div>
<div class="seat-grid" id="seatGrid">
<?php
// Generate 50 Seats (5 rows of 10)
for ($i = 1; $i <= 50; $i++) {
$isBooked = in_array($i, $booked_seats);
$bookedClass = $isBooked ? 'booked' : '';
$seatId = 'seat-' . $i;
echo "<div class='seat $bookedClass' id='$seatId' data-seat='$i'" .
($isBooked ? " disabled" : " onclick='toggleSeat($i)'") .
">$i</div>";
}
?>
</div>
<div class="summary">
<h3>📋 Your Selection</h3>
<div class="selected-seats">
<p>Selected Seats:</p>
<div class="seats-list" id="selectedList">
<span style="color: #6b7280; font-style: italic;">No seats selected</span>
</div>
</div>
<div class="price-info">
<strong>Total Price:</strong> ₹<span id="totalPrice">0.00</span>
<span style="margin-left: 20px;">(<span id="seatCount">0</span> seat<span id="seatPlural">s</span>)</span>
</div>
<div class="button-group">
<button id="confirm-btn" onclick="confirmSelection()" disabled>
✓ Confirm & Proceed to Payment
</button>
<button id="clear-btn" onclick="clearSelection()">
✕ Clear Selection
</button>
<a href="view_event.php?id=<?php echo $event_id; ?>" class="back-btn">
← Back to Event
</a>
</div>
</div>
</div>
<script>
const pricePerSeat = <?php echo $event['price']; ?>;
const eventId = <?php echo $event_id; ?>;
let selectedSeats = [];
function toggleSeat(seatNumber) {
const seatElement = document.getElementById('seat-' + seatNumber);
// Check if seat is booked
if (seatElement.classList.contains('booked')) {
return;
}
// Toggle selection
if (selectedSeats.includes(seatNumber)) {
selectedSeats = selectedSeats.filter(s => s !== seatNumber);
seatElement.classList.remove('selected');
} else {
selectedSeats.push(seatNumber);
seatElement.classList.add('selected');
}
// Sort seats numerically
selectedSeats.sort((a, b) => a - b);
updateSummary();
}
function updateSummary() {
const count = selectedSeats.length;
const totalPrice = count * pricePerSeat;
// Update selected seats display
const selectedList = document.getElementById('selectedList');
if (count === 0) {
selectedList.innerHTML = '<span style="color: #6b7280; font-style: italic;">No seats selected</span>';
} else {
const badges = selectedSeats.map(s => `<span class="seat-badge">Seat ${s}</span>`).join('');
selectedList.innerHTML = badges;
}
// Update price
document.getElementById('totalPrice').textContent = totalPrice.toFixed(2);
document.getElementById('seatCount').textContent = count;
document.getElementById('seatPlural').textContent = count === 1 ? '' : 's';
// Enable/disable confirm button
const confirmBtn = document.getElementById('confirm-btn');
confirmBtn.disabled = count === 0;
}
function clearSelection() {
// Remove selected class from all seats
selectedSeats.forEach(seatNumber => {
const seatElement = document.getElementById('seat-' + seatNumber);
seatElement.classList.remove('selected');
});
// Clear array
selectedSeats = [];
updateSummary();
}
function confirmSelection() {
if (selectedSeats.length === 0) {
alert('Please select at least one seat!');
return;
}
// Create form and submit
const form = document.createElement('form');
form.method = 'POST';
form.action = 'buy_ticket.php';
// Add hidden fields
const eventIdInput = document.createElement('input');
eventIdInput.type = 'hidden';
eventIdInput.name = 'event_id';
eventIdInput.value = eventId;
form.appendChild(eventIdInput);
const seatsInput = document.createElement('input');
seatsInput.type = 'hidden';
seatsInput.name = 'seats';
seatsInput.value = JSON.stringify(selectedSeats);
form.appendChild(seatsInput);
// Submit form
document.body.appendChild(form);
form.submit();
}
// Initialize summary on page load
updateSummary();
</script>
</body>
</html>