-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookings.php
84 lines (74 loc) · 2.47 KB
/
bookings.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
<?php
require_once 'includes/database.php';
require_once 'includes/session.php';
require_once 'includes/util.php';
$successMsg = null;
if ($loggedIn) {
$pageName = 'Bookings';
if (isset($_GET['booked'])) {
$eventId = $_GET['booked'];
$statement = $mysqli->prepare('SELECT `name` FROM `events` WHERE id = ?;');
$statement->bind_param('i', $eventId);
$statement->bind_result($eventName);
$statement->execute();
if ($statement->fetch()) {
$successMsg = "Congratulations $firstName, you're going to <strong>$eventName</strong>.";
}
$statement->close();
}
} else {
$pageName = 'Access Denied';
}
?>
<!DOCTYPE html>
<html lang="en">
<?php include('includes/head.php'); ?>
<body>
<?php include('includes/menu.php'); ?>
<div class="container">
<?php if ($loggedIn): ?>
<h2>Bookings</h2>
<?php if ($successMsg != null): ?>
<div class="alert alert-success"><?= $successMsg ?></div>
<?php endif; ?>
<?php
$statement = $mysqli->prepare('SELECT id, `name`, `time`, venue FROM `events`, bookings
WHERE events.id = bookings.eventId
AND bookings.userId = ?;');
$statement->bind_param('i', $userId);
$statement->bind_result($eventId, $name, $isoDateTime, $venue);
$statement->execute();
$statement->store_result();
?>
<?php if ($statement->num_rows > 0): ?>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Date/Time</th>
<th>Venue</th>
<th></th>
</tr>
</thead>
<tbody>
<?php while ($statement->fetch()): ?>
<tr>
<td><?= $name ?></td>
<td><?= formatDateTime(new DateTime($isoDateTime)) ?></td>
<td><?= $venue ?></td>
<td><a href="view_event.php?id=<?= $eventId ?>">View Event</a></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php else: ?>
<p>You are not booked into any events.</p>
<?php endif; ?>
<?php $statement->close(); ?>
<?php else: ?>
<div class="alert alert-danger">You must be logged in to view this.</div>
<?php endif; ?>
</div>
<?php include 'includes/footer.php' ?>
</body>
</html>