-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp.php
132 lines (122 loc) · 5.73 KB
/
temp.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
<?php
session_start();
if (!isset($_SESSION['user_type'])) {
header('location: login.php');
}
require_once('includes/showMessage.php');
require 'includes/functions.php';
displaySessionMessage();
// Get the user_email from the session
$user_email = $_SESSION['email'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Managing Bookings</title>
<link rel="stylesheet" href="css/style.css" />
<!-- Fontawesome CDN Link -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" />
</head>
<body>
<?php include('includes/admin-nav.php'); ?>
<div class="container mt-5">
<h2>Booking List</h2>
<table class="table table-striped">
<thead class = "table-dark">
<tr>
<th>Customer Email</th>
<th>Airline</th>
<th>Departure Airport</th>
<th>Arrival Airport</th>
<th>Departure</th>
<th>Arrival</th>
<th>Class</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<!-- Displaying bookings in the table with joined data for the user_email -->
<?php
include("connection.php");
// Delete Booking Operation
if (isset($_POST["confirm_delete_booking"])) {
$deleteBookingId = $_POST["delete_booking_id"];
$deleteSql = "DELETE FROM booked WHERE id = '$deleteBookingId'";
if ($con->query($deleteSql) === TRUE) {
setSessionMessage("Booking deleted successfully");
header('location: booked-flight.php');
} else {
echo "<script>showModal('errorModal', 'Error deleting booking: " . $con->error . "');</script>";
}
}
// Displaying bookings in the table with joined data for the user_email
$sqlBookings = "SELECT b.id, b.customer_email, f.airline_name, a1.airport_name as dep_airport, a2.airport_name as arr_airport,
f.source_date, f.source_time, f.dest_date, f.dest_time, f.flight_class
FROM booked b
INNER JOIN flight f ON b.flight_id = f.id
INNER JOIN customer c ON b.customer_email = c.email
INNER JOIN airport a1 ON f.dep_airport_id = a1.airport_id
INNER JOIN airport a2 ON f.arr_airport_id = a2.airport_id
WHERE c.email = '$user_email'"; // Filter by user_email
$resultBookings = $con->query($sqlBookings);
if ($resultBookings->num_rows > 0) {
while ($rowBooking = $resultBookings->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $rowBooking["customer_email"] . "</td>";
echo "<td>" . $rowBooking["airline_name"] . "</td>";
echo "<td>" . $rowBooking["dep_airport"] . "</td>";
echo "<td>" . $rowBooking["arr_airport"] . "</td>";
echo "<td>" . $rowBooking["source_date"] . "</td>";
echo "<td>" . $rowBooking["dest_date"] . "</td>";
echo "<td>" . $rowBooking["flight_class"] . "</td>";
echo "<td>";
echo "<button class='btn btn-danger btn-sm delete-booking' data-id='" . $rowBooking["id"] . "' data-toggle='modal' data-target='#deleteBookingModal'>Delete</button>";
echo "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='8' class='text-center'><h3>No bookings available</h3></td></tr>";
}
?>
<!-- Delete Booking Form -->
<form action="" method="POST">
<input type="hidden" name="delete_booking_id" id="delete_booking_id" value="">
<div class="modal fade" id="deleteBookingModal" tabindex="-1" role="dialog"
aria-labelledby="deleteBookingModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteBookingModalLabel">Confirm Delete</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Are you sure you want to delete this booking?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-danger" name="confirm_delete_booking">Delete</button>
</div>
</div>
</div>
</div>
</form>
</div>
<!-- Bootstrap and jQuery Scripts -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@1.16.1/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!-- JavaScript to handle modals -->
<script>
// Click event handler for delete buttons
$(document).on("click", ".delete-booking", function () {
var deleteBookingId = $(this).data('id');
$('#delete_booking_id').val(deleteBookingId);
});
</script>
</body>
</html>