-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.php
222 lines (194 loc) · 9.22 KB
/
routes.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
<?php
require 'assets/partials/_functions.php';
$conn = db_connect();
if(!$conn)
die("Connection Failed");
if(!$_SERVER["REQUEST_METHOD"] == "POST" || !isset($_POST["search"]))
{
header("location: index.php");
exit;
}
$source = strtoupper($_POST["source"]);
$destination = strtoupper($_POST["destination"]);
$dep_date = $_POST["departure"];
$destination_state = strtoupper($_POST["destination_state"]);
$sql = "SELECT * FROM routes WHERE route_dep_date='$dep_date'";
$result = mysqli_query($conn, $sql);
$no_results = mysqli_num_rows($result);
$count = 0;
while($row = mysqli_fetch_assoc($result))
{
$citiesArr = explode(",",$row["route_cities"]);
// Search the tables if we have any routes thats matches the form details
if(!in_array($source, $citiesArr) || !in_array($destination, $citiesArr) || !(array_search($source, $citiesArr) < array_search($destination, $citiesArr)))
continue;
$count++;
}
$sql = "SELECT * FROM routes WHERE route_dep_date='$dep_date'";
$result = mysqli_query($conn, $sql);
$no_results = mysqli_num_rows($result);
?>
<!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>Routes Search Page</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/search_routes.php'?>
</head>
<body>
<div id="covidInfo">
</div>
<header>
<nav id="navbar">
<div>
<a href="#" class="nav-item nav-logo">GOBUS</a>
<a href="#" class="nav-item">Gallery</a>
</div>
<ul>
<li><a href="index.php" 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>
</nav>
</header>
<main id="container">
<section id="searched-route">
<ul>
<li class="searched-route-item" id="">Total Results : <span id="result-num">
<?php
echo $count;
?>
</span></li>
<li class="searched-route-item"><?php echo $source; ?> <span class="arrow">→</span> <?php echo $destination; ?>
<li class="searched-route-item" id="date">
<?php
// Changing format from yyyy-mm-dd to dd-mm-yyyy
$dep_date = implode("-",(array_reverse(explode("-", $dep_date))));
echo $dep_date;
?></li>
</ul>
</section>
<section id="searched-results">
<?php
if(!$count)
{?>
<div class="container mt-4">
<div id="noRoutes" class="alert alert-dark " role="alert">
<h1 class="alert-heading">No Routes Found!!</h1>
<p class="fw-light">
Currently there are no services for the specified route
</p>
<hr>
<div id="addCustomerAlert" class="alert alert-success" role="alert">
We will soon make this route available for service
</div>
</div>
</div>
<?php }
while($row = mysqli_fetch_assoc($result))
{
$citiesArr = explode(",",$row["route_cities"]);
// Search the tables if we have any routes that matches the form details
if(!in_array($source, $citiesArr) || !in_array($destination, $citiesArr) || !(array_search($source, $citiesArr) < array_search($destination, $citiesArr)))
continue;
$route_id = $row["route_id"];
$route_dep_time = $row["route_dep_time"];
$route_stepCost = $row["route_step_cost"];
$bus_no = $row["bus_no"];
$source_idx = array_search($source, $citiesArr);
$dest_idx = array_search($destination, $citiesArr);
$viaCities = false;
if($source_idx + 1 != $dest_idx)
{
$viaCities = implode(",", array_slice($citiesArr, $source_idx + 1, $dest_idx - $source_idx));
}
$booking_amount = ($dest_idx - $source_idx) * $route_stepCost;
$booked_seats = get_from_table($conn,"seats", "bus_no", $bus_no, "seat_booked");
$booked_seatsArr = [];
if($booked_seats)
$booked_seatsArr = explode(",", $booked_seats);
$no_available_seats = 38 - count($booked_seatsArr);
?>
<div class="searched-container">
<div class="searched-result-item">
<div class="route-id">
<p>
<?php echo $route_id; ?>
</p>
</div>
<div class="timing">
<p>
<?php
echo $route_dep_time;
?>
</p>
</div>
<div class="route-desc" data-dest="<?php echo $destination_state; ?>">
<p class="main-route">
<span class="source-route">
<?php
echo $source;
?>
</span>
<span class="arrow">→</span>
<span class="dest-route">
<?php
echo $destination;
?>
</span>
</p>
<p class="cities">
<?php if($viaCities){ ?>
<span class="via">Via</span>
<?php
echo $viaCities;
}
else{ ?>
<span class="via">Direct</span>
<?php }
?>
</p>
</div>
<div class="seats-desc">
<div>
<span class="num-seats">
<!-- Total or taken?? -->
<?php
echo $no_available_seats;
?>
</span> seats
</div>
</div>
<div class="booking-desc">
<p class="price"><i class="fas fa-rupee-sign"></i>
<?php
echo $booking_amount;
?></p>
<button class="book-seat-btn" data-busno="<?php
echo $bus_no;?>" data-seats="<?php echo $booked_seats; ?>" data-routeid="<?php echo $route_id; ?>" data-amount="<?php echo $booking_amount; ?>" data-source="<?php echo $source; ?>" data-destination="<?php echo $destination; ?>">
Select Seats
</button>
</div>
</div>
<!-- Book Row -->
<div class="bookContainer">
</div>
</div>
<?php }?>
</section>
</main>
<script src="assets/scripts/booking.js"></script>
<!-- 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>
</body>
</html>