-
Notifications
You must be signed in to change notification settings - Fork 0
/
show-flight.php
129 lines (118 loc) · 5.64 KB
/
show-flight.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
<?php
session_start();
if (!isset($_SESSION['user_type'])) {
header('location: login.php');
}
require_once('includes/showMessage.php');
require 'includes/functions.php';
displaySessionMessage();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Deleting Flight</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>Flight List</h2>
<table class="table table-striped">
<thead class="table-dark">
<tr>
<th>Airline</th>
<th>Departure Airport</th>
<th>Arrival Airport</th>
<th>Departure</th>
<th>Arrival</th>
<th>Seats</th>
<th>Price</th>
<th>Flight Class</th> <!-- New Column -->
<th>Airline Email</th> <!-- New Column -->
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
include("connection.php");
// Delete Flight Operation
if (isset($_POST["confirm_delete_flight"])) {
$deleteFlightId = $_POST["delete_flight_id"];
$deleteSql = "DELETE FROM flight WHERE id = '$deleteFlightId'";
if ($con->query($deleteSql) === TRUE) {
setSessionMessage("Flight deleted successfully");
header('location: show-flight.php');
} else {
echo "<script>showModal('errorModal', 'Error deleting flight: " . $con->error . "');</script>";
}
}
// Displaying flights in the table
$sqlFlights = "SELECT * FROM flight";
$resultFlights = $con->query($sqlFlights);
if ($resultFlights->num_rows > 0) {
while ($rowFlight = $resultFlights->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $rowFlight["airline_name"] . "</td>";
echo "<td>" . $rowFlight["dep_airport"] . "</td>";
echo "<td>" . $rowFlight["arr_airport"] . "</td>";
echo "<td>" . $rowFlight["source_date"] . " " . $rowFlight["source_time"] . "</td>";
echo "<td>" . $rowFlight["dest_date"] . " " . $rowFlight["dest_time"] . "</td>";
echo "<td>" . $rowFlight["seats"] . "</td>";
echo "<td>" . $rowFlight["price"] . "</td>";
echo "<td>" . $rowFlight["flight_class"] . "</td>"; // New Column
echo "<td>" . $rowFlight["airline_email"] . "</td>"; // New Column
echo "<td>";
echo "<button class='btn btn-danger btn-sm delete-flight' data-id='" . $rowFlight["id"] . "' data-toggle='modal' data-target='#deleteFlightModal'>Delete</button>";
echo "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='10' class='text-center'><h3>No flights available</h3></td></tr>";
}
?>
</tbody>
</table>
<!-- Delete Flight Form -->
<form action="" method="POST">
<input type="hidden" name="delete_flight_id" id="delete_flight_id" value="">
<div class="modal fade" id="deleteFlightModal" tabindex="-1" role="dialog"
aria-labelledby="deleteFlightModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteFlightModalLabel">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 flight?
</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_flight">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-flight", function () {
var deleteFlightId = $(this).data('id');
$('#delete_flight_id').val(deleteFlightId);
});
</script>
</body>
</html>