-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
359 lines (316 loc) · 15 KB
/
index.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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<?php
require 'assets/partials/_functions.php';
$conn = db_connect();
if(!$conn)
die("Connection Failed");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bus Ticket Bookings</title>
<!-- google fonts -->
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@100;200;300;400;500&display=swap" rel="stylesheet">
<!-- Font-awesome -->
<script src="https://kit.fontawesome.com/d8cfbe84b9.js" crossorigin="anonymous"></script>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<!-- CSS -->
<?php
require 'assets/styles/styles.php'
?>
</head>
<body>
<?php
if(isset($_GET["booking_added"]) && !isset($_POST['pnr-search']))
{
if($_GET["booking_added"])
{
echo '<div class="my-0 alert alert-success alert-dismissible fade show" role="alert">
<strong>Successful!</strong> Booking Added, your PNR is <span style="font-weight:bold; color: #272640;">'. $_GET["pnr"] .'</span>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
else{
// Show error alert
echo '<div class="my-0 alert alert-danger alert-dismissible fade show" role="alert">
<strong>Error!</strong> Booking already exists
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
}
if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["pnr-search"]))
{
$pnr = $_POST["pnr"];
$sql = "SELECT * FROM bookings WHERE booking_id='$pnr'";
$result = mysqli_query($conn, $sql);
$num = mysqli_num_rows($result);
if($num)
{
$row = mysqli_fetch_assoc($result);
$route_id = $row["route_id"];
$customer_id = $row["customer_id"];
$customer_name = get_from_table($conn, "customers", "customer_id", $customer_id, "customer_name");
$customer_phone = get_from_table($conn, "customers", "customer_id", $customer_id, "customer_phone");
$customer_route = $row["customer_route"];
$booked_amount = $row["booked_amount"];
$booked_seat = $row["booked_seat"];
$booked_timing = $row["booking_created"];
$dep_date = get_from_table($conn, "routes", "route_id", $route_id, "route_dep_date");
$dep_time = get_from_table($conn, "routes", "route_id", $route_id, "route_dep_time");
$bus_no = get_from_table($conn, "routes", "route_id", $route_id, "bus_no");
?>
<div class="alert alert-dark alert-dismissible fade show" role="alert">
<h4 class="alert-heading">Booking Information!</h4>
<p>
<button class="btn btn-sm btn-success"><a href="assets/partials/_download.php?pnr=<?php echo $pnr; ?>" class="link-light">Download</a></button>
<button class="btn btn-danger btn-sm" id="deleteBooking" data-bs-toggle="modal" data-bs-target="#deleteModal" data-pnr="<?php echo $pnr;?>" data-seat="<?php echo $booked_seat;?>" data-bus="<?php echo $bus_no; ?>">
Delete
</button>
</p>
<hr>
<p class="mb-0">
<ul class="pnr-details">
<li>
<strong>PNR : </strong>
<?php echo $pnr; ?>
</li>
<li>
<strong>Customer Name : </strong>
<?php echo $customer_name; ?>
</li>
<li>
<strong>Customer Phone : </strong>
<?php echo $customer_phone; ?>
</li>
<li>
<strong>Route : </strong>
<?php echo $customer_route; ?>
</li>
<li>
<strong>Bus Number : </strong>
<?php echo $bus_no; ?>
</li>
<li>
<strong>Booked Seat Number : </strong>
<?php echo $booked_seat; ?>
</li>
<li>
<strong>Departure Date : </strong>
<?php echo $dep_date; ?>
</li>
<li>
<strong>Departure Time : </strong>
<?php echo $dep_time; ?>
</li>
<li>
<strong>Booked Timing : </strong>
<?php echo $booked_timing; ?>
</li>
</p>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php }
else{
echo '<div class="my-0 alert alert-danger alert-dismissible fade show" role="alert">
<strong>Error!</strong> Record Doesnt Exist
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
?>
<?php }
// Delete Booking
if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["deleteBtn"]))
{
$pnr = $_POST["id"];
$bus_no = $_POST["bus"];
$booked_seat = $_POST["booked_seat"];
$deleteSql = "DELETE FROM `bookings` WHERE `bookings`.`booking_id` = '$pnr'";
$deleteResult = mysqli_query($conn, $deleteSql);
$rowsAffected = mysqli_affected_rows($conn);
$messageStatus = "danger";
$messageInfo = "";
$messageHeading = "Error!";
if(!$rowsAffected)
{
$messageInfo = "Record Doesn't Exist";
}
elseif($deleteResult)
{
$messageStatus = "success";
$messageInfo = "Booking Details deleted";
$messageHeading = "Successfull!";
// Update the Seats table
$seats = get_from_table($conn, "seats", "bus_no", $bus_no, "seat_booked");
// Extract the seat no. that needs to be deleted
$booked_seat = $_POST["booked_seat"];
$seats = explode(",", $seats);
$idx = array_search($booked_seat, $seats);
array_splice($seats,$idx,1);
$seats = implode(",", $seats);
$updateSeatSql = "UPDATE `seats` SET `seat_booked` = '$seats' WHERE `seats`.`bus_no` = '$bus_no';";
mysqli_query($conn, $updateSeatSql);
}
else{
$messageInfo = "Your request could not be processed due to technical Issues from our part. We regret the inconvenience caused";
}
// Message
echo '<div class="my-0 alert alert-'.$messageStatus.' alert-dismissible fade show" role="alert">
<strong>'.$messageHeading.'</strong> '.$messageInfo.'
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
?>
<header>
<nav>
<div>
<a href="#" class="nav-item nav-logo">SBTBS</a>
<!-- <a href="#" class="nav-item">Gallery</a> -->
</div>
<ul>
<li><a href="#" class="nav-item">Home</a></li>
<li><a href="#about" class="nav-item">About</a></li>
<li><a href="#contact" class="nav-item">Contact</a></li>
</ul>
<div>
<a href="#" class="login nav-item" data-bs-toggle="modal" data-bs-target="#loginModal"><i class="fas fa-sign-in-alt" style="margin-right: 0.4rem;"></i>Login</a>
<a href="#pnr-enquiry" class="pnr nav-item">PNR Enquiry</a>
</div>
</nav>
</header>
<!-- Login Modal -->
<?php require 'assets/partials/_loginModal.php';
require 'assets/partials/_getJSON.php';
$routeData = json_decode($routeJson);
$busData = json_decode($busJson);
$customerData = json_decode($customerJson);
?>
<section id="home">
<div id="route-search-form">
<h1>Simple Bus Ticket Booking System</h1>
<p class="text-center">Welcome to Simple Bus Ticket Booking System. Login now to manage bus tickets and much more. OR, simply scroll down to check the Ticket status using Passenger Name Record (PNR number)</p>
<center>
<button class="btn btn-danger " data-bs-toggle="modal" data-bs-target="#loginModal">Administrator Login</button>
</center>
<br>
<center>
<a href="#pnr-enquiry"><button class="btn btn-primary">Scroll Down <i class="fa fa-arrow-down"></i></button></a>
</center>
</div>
</section>
<div id="block">
<section id="info-num">
<figure>
<img src="assets/img/route.svg" alt="Bus Route Icon" width="100px" height="100px">
<figcaption>
<span class="num counter" data-target="<?php echo count($routeData); ?>">999</span>
<span class="icon-name">routes</span>
</figcaption>
</figure>
<figure>
<img src="assets/img/bus.svg" alt="Bus Icon" width="100px" height="100px">
<figcaption>
<span class="num counter" data-target="<?php echo count($busData); ?>">999</span>
<span class="icon-name">bus</span>
</figcaption>
</figure>
<figure>
<img src="assets/img/customer.svg" alt="Happy Customer Icon" width="100px" height="100px">
<figcaption>
<span class="num counter" data-target="<?php echo count($customerData); ?>">999</span>
<span class="icon-name">happy customers</span>
</figcaption>
</figure>
<figure>
<img src="assets/img/ticket.svg" alt="Instant Ticket Icon" width="100px" height="100px">
<figcaption>
<span class="num"><span class="counter" data-target="20">999</span> SEC</span>
<span class="icon-name">Instant Tickets</span>
</figcaption>
</figure>
</section>
<section id="pnr-enquiry">
<div id="pnr-form">
<h2>PNR ENQUIRY</h2>
<form action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="POST">
<div>
<input type="text" name="pnr" id="pnr" placeholder="Enter PNR">
</div>
<button type="submit" name="pnr-search">Submit</button>
</form>
</div>
</section>
<section id="about">
<div>
<h1>Database Management Project - Bus Management System</h1>
<h4>Team Members - </h4>
<p>
Satya Vani - RA1911030010056<br>
Mayank Gokhale - RA1911030010057<br>
Sidhant Singh Rana - RA1911030010065
</p>
</div>
</section>
<section id="contact">
<div id="contact-form">
<h1>Contact Us</h1>
<form action="">
<div>
<label for="name">Name</label>
<input type="text" name="name" id="name">
</div>
<div>
<label for="email">Email Address</label>
<input type="email" name="email" id="email">
</div>
<div>
<label for="message">Message</label>
<textarea name="message" id="message" cols="30" rows="10"></textarea>
</div>
<div></div>
</form>
</div>
</section>
<footer>
<p>
<i class="far fa-copyright"></i> <?php echo date('Y');?> - Simple Bus Ticket Booking System
</p>
</footer>
</div>
<!-- Delete Booking Modal -->
<div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"><i class="fas fa-exclamation-circle"></i></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<h2 class="text-center pb-4">
Are you sure?
</h2>
<p>
Do you really want to delete your booking? <strong>This process cannot be undone.</strong>
</p>
<!-- Needed to pass pnr -->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" id="delete-form" method="POST">
<input id="delete-id" type="hidden" name="id">
<input id="delete-booked-seat" type="hidden" name="booked_seat">
<input id="delete-booked-bus" type="hidden" name="bus">
</form>
</div>
<div class="modal-footer">
<button type="submit" form="delete-form" class="btn btn-primary btn-danger" name="deleteBtn">Delete</button>
</div>
</div>
</div>
</div>
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
<!-- External JS -->
<script src="assets/scripts/main.js"></script>
</body>
</html>