-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadmin_page.php
More file actions
262 lines (197 loc) · 10.5 KB
/
admin_page.php
File metadata and controls
262 lines (197 loc) · 10.5 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
<?php
require "includes/db_connect.php";
require "includes/auth.php";
// Initialize the session.
session_start();
// NB: This below will no longer be necessary if you won't be displaying the new article link page for non-login users
if (!isLoggedIn()){
die("Unauthorized. You must be logged in first." . PHP_EOL . "<a href='index.php'>Back To Homepage</a>");
}
// connect to the database server
$conn = connectDB();
// READING FROM THE DATABASE AND CHECKING FOR ERRORS
$sql = "SELECT *
FROM passengers_record
ORDER BY booking_date, booking_time DESC;";
$results = mysqli_query($conn, $sql);
if ($results === false)
echo mysqli_error($conn);
else
$all_data = mysqli_fetch_all($results, MYSQLI_ASSOC);
//print_r($all_data); prints an associative array
// Check if the "Clear All" button was clicked
if(isset($_POST['clear_all'])) {
// SQL query to delete all data from the table
// $sql = DELETE FROM rooms_record
$sql = "TRUNCATE TABLE passengers_record";
// Execute the SQL query
mysqli_query($conn, $sql);
header("Location: http://localhost/flight_booking-app/admin_page.php");
exit;
}
// INDEX FORM INSERTION BELOW (COPIED FROM INDEX PAGE)
// Defining the variables in the global
$name = ''; $email = ''; $phone_no = ''; $crew = ''; $to = ''; $time = ''; $date = ''; $airline = '';
$fare = ''; $seat = ''; $message = '';
// Check if a new form is submitted and its not empty, then add it to the database
if ($_SERVER["REQUEST_METHOD"] == "POST"){
if (isset($_POST['save'])){
$customer_name = trim(htmlspecialchars($_POST['name']));
$booking_date = trim($_POST['date']);
$booking_time = trim($_POST['time']);
$location_to = trim($_POST['to']);
$customer_message = trim(htmlspecialchars($_POST['message']));
$phone_no = trim(htmlspecialchars($_POST['phone_no']));
$email = trim(htmlspecialchars($_POST['email']));
$seat = trim($_POST['seat']);
$airline = trim($_POST['airline']);
$fare = trim($_POST['fare']);
$crew = trim($_POST['crew']);
if (!empty($customer_name) && !empty($booking_date) && !empty($booking_time) && !empty($location_to) && !empty($phone_no) && !empty($email) && !empty($seat)
&& !empty($airline) && !empty($fare) && !empty($crew)){
// makes the message field "null" if not filled
if ($customer_message == ''){
$customer_message = null;
}
// connect to the database server
$conn = connectDB();
// inserts the data into the database server
$sql = "INSERT INTO passengers_record (customer_name, email, phone_no, crew, location_to, booking_time, booking_date, airline, fare, seat, customer_message)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
// Prepares an SQL statement for execution
$stmt = mysqli_prepare($conn, $sql);
if ($stmt === false){
echo mysqli_error($conn);
} else {
// i - integer, d - double, s - string
// Bind variables for the parameter markers in the SQL statement prepared
mysqli_stmt_bind_param($stmt, "sssssssssss", $customer_name, $email, $phone_no, $crew, $location_to, $booking_time, $booking_date, $airline, $fare, $seat, $customer_message);
// Executes a prepared statement
$results = mysqli_stmt_execute($stmt);
// checking for errors, if none, then redirect the user to the new article page
if ($results === false){
echo mysqli_stmt_error($stmt);
} else {
//Returns the value generated for an AUTO_INCREMENT column by the last query
$id = mysqli_insert_id($conn);
// it is more advisable to use absolute paths below than relative path
header("Location: http://localhost/flight_booking-app/admin_page.php");
exit;
}
}
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>FLIGHT BOOKING APP</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
</head>
<body style="background-color: rebeccapurple">
<div class="container">
<!--Introduction header-->
<h1 class="text-center my-4 py-4" style="font-family: Tahoma, Verdana, Segoe, sans-serif; color: white">AeroLux Airline Booking System</h1>
<div class="container text-center">
<div class="row">
<!-- GRID 1 -->
<div class="col">
<!-- Button trigger modal -->
<div align="right">
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#staticBackdrop">
Reserve Now!
</button>
</div>
<!-- Modal -->
<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<form action="" method="POST" autocomplete="off">
<div class="modal-content" style="background-color: gray">
<div class="modal-header">
<h1 class="modal-title fs-5" id="staticBackdropLabel" style="color: white">Book a Flight Now</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="w-55 m-auto">
<!--HTML form-->
<?php require "./includes/admin_form.php"; ?>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="save">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- GRID 2 -->
<div class="col" align="left">
<form action="" method="POST">
<button type="submit" class="btn btn-secondary" name="clear_all">Clear Lists</button>
</form>
</div>
</div>
</div>
<br>
<!--Horizontal line demacation-->
<hr class="bg-dark w-50 m-auto">
<!-- Table class="w-50 m-auto"-->
<div class="container-fluid">
<div style="margin: 25px 50px 25px 50px; background-color: black; color: white; border-radius:20px">
<h1 align="center">Booking Database Table</h1>
</div>
<table class="table table-dark table-hover">
<thead align="center">
<tr>
<!--<th scope="col" class="table-secondary">#ID</th>-->
<th scope="col" class="table-secondary">NAME</th>
<th scope="col" class="table-secondary">EMAIL</th>
<th scope="col" class="table-secondary">PHONE NO.</th>
<th scope="col" class="table-secondary">CREW</th>
<th scope="col" class="table-secondary">DESTINATION</th>
<th scope="col" class="table-secondary">BOOKING TIME</th>
<th scope="col" class="table-secondary">BOOKING DATE</th>
<th scope="col" class="table-secondary">AIRLINE</th>
<th scope="col" class="table-secondary">FARE</th>
<th scope="col" class="table-secondary">SEAT</th>
<th scope="col" class="table-secondary">MESSAGE</th>
<th scope="col" class="table-secondary">ACTION</th>
</tr>
</thead>
<?php if (!empty($all_data)): ?>
<tbody align="center">
<?php foreach ($all_data as $index => $data): ?>
<tr>
<!--<td>AIR<= $data["id"]; ?></td> -->
<td><?= htmlspecialchars($data["customer_name"]) ?></td>
<td><?= htmlspecialchars($data["email"]) ?></td>
<td><?= htmlspecialchars($data["phone_no"]) ?></td>
<td><?= htmlspecialchars($data["crew"]) ?></td>
<td><?= htmlspecialchars($data["location_to"]) ?></td>
<td><?= htmlspecialchars($data["booking_time"]) ?></td>
<td><?= htmlspecialchars($data["booking_date"]) ?></td>
<td><?= htmlspecialchars($data["airline"]) ?></td>
<td><?= htmlspecialchars($data["fare"]) ?></td>
<td><?= htmlspecialchars($data["seat"]) ?></td>
<td><?= htmlspecialchars($data["customer_message"]) ?></td>
<td><a class="btn btn-primary" href="edit_data.php?id=<?= $data["id"]; ?>">Edit</a> <a class="btn btn-danger" href="delete_data.php?id=<?= $data['id']; ?>">Delete</a></td>
</tr>
<?php endforeach; ?>
</tbody>
<?php else: ?>
<p style="color: white;">No articles found.</p>
<?php endif; ?>
</table>
<div align="center">
<i><a class="btn btn-link" href="index.php" role="button" style="color: white">Back to Homepage</a></i>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script>
</body>
</html>