-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_trip.php
171 lines (164 loc) · 9.75 KB
/
search_trip.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
<?php
require_once("admin/configs/config.php");
$source_id = $_GET['source_id'];
$destination_id = $_GET['destination_id'];
$departureDate = $_GET['departureDate'];
$no_of_seat = $_GET['no_of_seat'];
$search_query = "SELECT schedule.s_id,schedule.departure_time,schedule.arrival_time,schedule.price,route_find.route_id,bus.type,bus.no_of_seat,bus_operator.bus_operator_name,bus_operator.email,bus_operator.phone_no,route.title,route_find.c_name AS route_city_detail
FROM (
SELECT route_detail.route_id,
GROUP_CONCAT(city.c_name ORDER BY route_detail.location ASC SEPARATOR '-') AS c_name,
GROUP_CONCAT(city.c_id ORDER BY route_detail.location ASC SEPARATOR '-') AS c_id,
GROUP_CONCAT(route_detail.location ORDER BY route_detail.location ASC SEPARATOR '-') AS location
FROM route_detail
INNER JOIN (
SELECT route_detail.route_id,route_detail.location,route_detail.city_id
FROM route_detail
INNER JOIN (
SELECT route_detail.route_id,route_detail.location,route_detail.city_id AS source_id
FROM route_detail WHERE route_detail.city_id = '$source_id'
) AS A
ON A.route_id = route_detail.route_id AND A.location < route_detail.location
AND route_detail.city_id = '$destination_id'
) AS route_detail_new
ON route_detail.route_id = route_detail_new.route_id
INNER JOIN city ON city.c_id = route_detail.city_id
GROUP BY route_detail.route_id
) as route_find
INNER JOIN route ON route.r_id = route_find.route_id
INNER JOIN schedule ON schedule.route_id = route.r_id
INNER JOIN bus ON bus.bus_id = schedule.bus_id
INNER JOIN bus_operator ON bus_operator.bus_operator_id = bus.bus_operator_id
";
$result_search = mysqli_query($conn, $search_query);
$result_city = mysqli_query($conn, "SELECT * FROM city");
$city_list = array();
while ($city_row = mysqli_fetch_assoc($result_city))
array_push($city_list, $city_row);
?>
<?php
$title = "Search Trip";
require_once "header.php";
?>
<div class="container" style="margin-top:2%;">
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<h5 class="card-title">Search Trip</h5>
<form action="search_trip.php" method="get">
<div class="form-row align-items-end">
<div class="form-group col-md-3">
<label for="source_id">Leaving From</label>
<select class="form-control selectpicker" data-live-search="true"
title="Select a location" name="source_id" required>
<?php foreach ($city_list as $city): ?>
<?php if ($city['c_id'] == $source_id): ?>
<option selected data-tokens="<?php echo $city['c_name'] ?>"
value="<?php echo $city['c_id'] ?>"><?php echo $city['c_name'] ?></option>
<?php else: ?>
<option data-tokens="<?php echo $city['c_name'] ?>"
value="<?php echo $city['c_id'] ?>"><?php echo $city['c_name'] ?></option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-md-3">
<label for="destination_id">Going To</label>
<select class="form-control selectpicker" data-live-search="true"
title="Select a location" name="destination_id" required>
<?php foreach ($city_list as $city): ?>
<?php if ($city['c_id'] == $destination_id): ?>
<option selected data-tokens="<?php echo $city['c_name'] ?>"
value="<?php echo $city['c_id'] ?>"><?php echo $city['c_name'] ?></option>
<?php else: ?>
<option data-tokens="<?php echo $city['c_name'] ?>"
value="<?php echo $city['c_id'] ?>"><?php echo $city['c_name'] ?></option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-md-2">
<label for="departureDate">Departure Date</label>
<input type="text" id="departureDate" name="departureDate"
class="form-control datepicker"
placeholder="Pick a date" value="<?php echo $departureDate ?>" required>
</div>
<div class="form-group col-md-2">
<label for="no_of_seat">Number of Seats</label>
<select class="form-control selectpicker" title="Select Seat" name="no_of_seat"
required>
<?php for ($i = 1; $i < 6; $i++): ?>
<?php if ($i == $no_of_seat): ?>
<option value="<?php echo $i ?>" selected><?php echo $i ?></option>
<?php else: ?>
<option value="<?php echo $i ?>"><?php echo $i ?></option>
<?php endif; ?>
<?php endfor; ?>
</select>
</div>
<div class="form-group col-md-2">
<input type="submit" class="form-control btn btn-primary" name="search_now"
id="search_now" value="Search Now">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="row justify-content-center" style="margin-top: 2%;margin-bottom: 10%;" id="trip_list">
<?php
while ($search_row = mysqli_fetch_assoc($result_search)):
$departure_date_time = new DateTime($departureDate.' '.$search_row['departure_time']);
$arrival_date_time = new DateTime($departureDate.' '.$search_row['arrival_time']);
$departure_time_am_pm = $departure_date_time->format('M d, h:i A');
$arrival_time_am_pm = $arrival_date_time->format('M d, h:i A');
$duration = $arrival_date_time->diff($departure_date_time)->format('%h');
?>
<div class="col-md-12" style="margin-bottom: 2%;">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-6">
<h5 class="card-title"><?php echo $departure_time_am_pm ?> - <?php echo $search_row['type'] ?></h5>
<p class="card-text font-italic"><?php echo $search_row['route_city_detail'] ?></p>
<p class="card-text font-weight-light">Departs: <span class="text-primary font-italic"><?php echo $departure_time_am_pm ?></span></p>
<p class="card-text font-weight-light">Arrives: <span class="text-primary font-italic"><?php echo $arrival_time_am_pm ?></span> Duration: <?php echo $duration?> Hours</p>
</div>
<div class="col-md-6">
<div class="row align-items-center">
<div class="col">
<h5 class="card-title"><?php echo $search_row['bus_operator_name'] ?></h5>
</div>
<div class="col text-right">
<h5 class="card-title text-danger"><?php echo $search_row['price']*$no_of_seat ?> MMK</h5>
<div class="card-text text-danger"><?php echo $no_of_seat ?> Seat x <?php echo $search_row['price'] ?> MMK</div>
<br>
<a href="seat_list.php?s_id=<?php echo $search_row['s_id'] ?>&no_of_seat=<?php echo $no_of_seat?>&departureDate=<?php echo $departureDate?>" class="btn btn-primary">Select Seat</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endwhile;?>
</div>
<div class="modal fade" id="alertModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Please select pick date</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php require_once "footer.php";?>