-
Notifications
You must be signed in to change notification settings - Fork 0
/
customer-dashboard.php
182 lines (165 loc) · 8.23 KB
/
customer-dashboard.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
<?php
session_start();
if (!isset($_SESSION['user_type'])) {
header('location: login.php');
}
require_once('includes/showMessage.php');
require 'includes/functions.php';
displaySessionMessage();
include("navOptions/customer-dashboard-nav-options.php");
// Get the user_email from the session
$user_email = $_SESSION['email'];
//fetch the name
require_once 'connection.php';
$sql = "SELECT first_name, last_name FROM customer WHERE email = '$user_email'";
$result = $con->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$customer_name = $row['first_name'] . ' ' . $row['last_name']; // Use dots for concatenation
} else {
$customer_name = "Guest"; // Default if no name found
}
?>
<!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" />
<link rel="stylesheet" type="text/css" href="css/general.css">
</head>
<body>
<header>
</header>
<nav>
<a class="logo" href="index.php"> <img src="images/Easyfly.png" alt="site-logo"> </a>
<?php include('navOptions/nav.php') ?>
</nav>
<div class="user-info">
<p style="text-align: right; font-size: 24px;">
<span style="font-weight: light; color: #999; margin-bottom: 10px; margin-right: 10px"><em style="font-style: italic;">user:</em></span>
<span style="font-size: 20pt; color: #333; margin-right: 35px"><?php echo $customer_name; ?></span>
</p>
</div>
<div class="container mt-5">
<h2>Your Booked Flights</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> Price</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: customer-dashboard.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,
CASE
WHEN f.flight_class = 'Economy' THEN 0.6 * f.price
WHEN f.flight_class = 'Business' THEN 0.8 * f.price
WHEN f.flight_class = 'First Class' THEN f.price
ELSE 0.0 -- Handle other cases if necessary
END AS price
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>" . $rowBooking["price"] . "</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 flight booked Yet! :( <br><a href = 'booking-form.php'> Book Now :)</a></h3></td></tr>";
}
?>
</tbody>
</table>
<!-- 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>
<footer>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="aboutUs.php">About Us</a></li>
<li><a href="aboutUs.php#targeting-contact">Contact</a></li>
<li><a href="booking-form.php">Services</a></li>
</ul>
<p>© 2023 EASYFLY, all right reserved</p>
</footer>
</body>
</html>