-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflights.php
215 lines (207 loc) · 12.4 KB
/
flights.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
<?php
include 'admin/db_connect.php';
if($_SERVER['REQUEST_METHOD'] == "POST"){
foreach($_POST as $k => $v){
$$k = $v;
}
}
?>
<header class="masthead">
<div class="container h-100">
<div class="row h-100 align-items-center justify-content-center text-center">
<div class="col-lg-10 align-self-end mb-4 page-title">
<h3 class="text-white">Flights</h3>
<hr class="divider my-4" />
<div class="col-md-12 mb-2 text-left">
<div class="card">
<div class="card-body">
<form id="manage-filter" action="index.php?page=flights" method="POST">
<div class="row form-group">
<div class="col-sm-3">
<label for="" class="control-label">From</label>
<select name="departure_airport_id" id="departure_location" class="custom-select browser-default select2">
<option value=""></option>
<?php
$airport = $conn->query("SELECT * FROM airport_list order by airport asc");
while($row = $airport->fetch_assoc()):
?>
<option value="<?php echo $row['id'] ?>" <?php echo isset($departure_airport_id) && $departure_airport_id == $row['id'] ? "selected" : '' ?>><?php echo $row['location'].", ".$row['airport'] ?></option>
<?php endwhile; ?>
</select>
</div>
<div class="col-sm-3">
<label for="" class="control-label">To</label>
<select name="arrival_airport_id" id="arrival_airport_id" class="custom-select browser-default select2">
<option value=""></option>
<?php
$airport = $conn->query("SELECT * FROM airport_list order by airport asc");
while($row = $airport->fetch_assoc()):
?>
<option value="<?php echo $row['id'] ?>" <?php echo isset($arrival_airport_id) && $arrival_airport_id == $row['id'] ? "selected" : '' ?>><?php echo $row['location'].", ".$row['airport'] ?></option>
<?php endwhile; ?>
</select>
</div>
<div class="col-sm-3">
<label for="" class="control-label">Departure Date</label>
<input type="date" class="form-control input-sm datetimepicker2" name="date" autocomplete="off" value="<?php echo isset($date) && !empty($date) ? date("Y-m-d",strtotime($date)) : "" ?>">
</div>
<div class="col-sm-3" id="rdate" <?php if(isset($trip) && $trip == 1): ?> style="display: none" <?php endif; ?>>
<label for="" class="control-label">Return Date</label>
<input type="date" class="form-control input-sm datetimepicker2" name="date_return" autocomplete="off" value="<?php echo isset($date_return) && !empty($date_return) ? date("Y-m-d",strtotime($date_return)) : "" ?>">
</div>
</div>
<div class="row form-group">
<div class="col-sm-2 text-center">
<div class="form-check">
<input class="form-check-input" type="radio" name="trip" id="onewway" value="1" <?php echo isset($trip) && $trip == 1 ? "checked" : "" ?> >
<label class="form-check-label" for="onewway">
One-way
</label>
</div>
</div>
<div class="col-sm-2 text-center">
<div class="form-check">
<input class="form-check-input" type="radio" name="trip" id="rtrip" value="2" <?php echo isset($trip) && $trip == 2 ? "checked" : "" ?>>
<label class="form-check-label" for="rtrip">
Round Trip
</label>
</div>
</div>
<div class="col-sm-3 offset-sm-5">
<button class="btn btn-block btn-sm btn-primary"><i class="fa fa-plane-departure"></i> Find Flights</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</header>
<section class="page-section" id="flight" >
<div class="container">
<div class="card">
<div class="card-body">
<div class="col-lg-12">
<div class="row">
<div class="col-md-12 text-center">
<h2><b><?php echo isset($trip) && $trip == 2 ? "Departure Searched Flight results..." : ( !isset($trip)? " Flights Available " :"Searched Flight results...") ?></b></h2>
</div>
</div>
<hr class="divider">
<?php
$airport = $conn->query("SELECT * FROM airport_list ");
while($row = $airport->fetch_assoc()){
$aname[$row['id']] = ucwords($row['airport'].', '.$row['location']);
}
$where = " where date(f.departure_datetime) > '".date("Y-m-d")."' ";
if($_SERVER['REQUEST_METHOD'] == "POST" )
$where .= " and f.departure_airport_id ='$departure_airport_id' and f.arrival_airport_id = '$arrival_airport_id' and date(f.departure_datetime) = '".date('Y-m-d',strtotime($date))."' ";
$flight = $conn->query("SELECT f.*,a.airlines,a.logo_path FROM flight_list f inner join airlines_list a on f.airline_id = a.id $where order by rand()");
if($flight->num_rows > 0):
while($row=$flight->fetch_assoc()):
$booked = $conn->query("SELECT * FROM booked_flight where flight_id = ".$row['id'])->num_rows;
?>
<div class="row align-items-center">
<div class="col-md-3">
<img src="assets/img/<?php echo $row['logo_path'] ?>" alt="">
</div>
<div class="col-md-6">
<p><b><?php echo $aname[$row['departure_airport_id']].' - '.$aname[$row['arrival_airport_id']] ?></b></p>
<p><small>Airline: <b><?php echo $row['airlines'] ?></b></small></p>
<p><small>Departure: <b><?php echo date('h:i A',strtotime($row['departure_datetime'])) ?></b></small></p>
<p><small>Arrival: <b><?php echo (date('M d,Y',strtotime($row['departure_datetime'])) == date('M d,Y',strtotime($row['arrival_datetime']))) ? date('h:i A',strtotime($row['arrival_datetime'])) : date('M d,Y h:i A',strtotime($row['arrival_datetime'])) ?></b></small></p>
<p>Available Seats : <b><h4><?php echo $row['seats'] - $booked ?></h4></b></p>
</div>
<div class="col-md-3 text-center align-self-end-sm">
<h4 class="text-right"><b><?php echo number_format($row['price'],2) ?></b></h4>
<button class="btn-outline-primary btn mb-4 book_flight" type="button" data-id="<?php echo $row['id'] ?>" data-name="<?php echo $aname[$row['departure_airport_id']].' - '.$aname[$row['arrival_airport_id']] ?>" data-max="<?php echo $row['seats'] - $booked ?>">Book Now</button>
</div>
</div>
<hr class="divider" style="max-width: 60vw">
<?php endwhile; ?>
<?php else: ?>
<div class="row align-items-center">
<h5 class="text-center"><b>No result.</b></h5>
</div>
<?php endif; ?>
<?php if(isset($trip) && $trip ==2): ?>
<hr>
<div class="row">
<div class="col-md-12 text-center">
<h2><b><?php echo isset($trip) && $trip == 2 ? "Arrival Searched Flight results..." : ( !isset($trip)? " Flights Available " :"Searched Flight results...") ?></b></h2>
</div>
</div>
<hr class="divider">
<?php
$airport = $conn->query("SELECT * FROM airport_list ");
while($row = $airport->fetch_assoc()){
$aname[$row['id']] = ucwords($row['airport'].', '.$row['location']);
}
$where = " where date(f.departure_datetime) > '".date("Y-m-d")."' ";
if($_SERVER['REQUEST_METHOD'] == "POST" )
$where .= " and f.departure_airport_id ='$arrival_airport_id' and f.arrival_airport_id = '$departure_airport_id' and date(f.departure_datetime) = '".date('Y-m-d',strtotime($date_return))."' ";
$flight = $conn->query("SELECT f.*,a.airlines,a.logo_path FROM flight_list f inner join airlines_list a on f.airline_id = a.id $where order by rand()");
if($flight->num_rows > 0):
while($row=$flight->fetch_assoc()):
$booked = $conn->query("SELECT * FROM booked_flight where flight_id = ".$row['id'])->num_rows;
?>
<div class="row align-items-center">
<div class="col-md-3">
<img src="assets/img/<?php echo $row['logo_path'] ?>" alt="">
</div>
<div class="col-md-6">
<p><b><?php echo $aname[$row['departure_airport_id']].' - '.$aname[$row['arrival_airport_id']] ?></b></p>
<p><small>Airline: <b><?php echo $row['airlines'] ?></b></small></p>
<p><small>Departure: <b><?php echo date('h:i A',strtotime($row['departure_datetime'])) ?></b></small></p>
<p><small>Arrival: <b><?php echo (date('M d,Y',strtotime($row['departure_datetime'])) == date('M d,Y',strtotime($row['arrival_datetime']))) ? date('h:i A',strtotime($row['arrival_datetime'])) : date('M d,Y h:i A',strtotime($row['arrival_datetime'])) ?></b></small></p>
<p>Available Seats : <b><h4><?php echo $row['seats'] - $booked ?></h4></b></p>
</div>
<div class="col-md-3 text-center align-self-end-sm">
<h4 class="text-right"><b><?php echo number_format($row['price'],2) ?></b></h4>
<button class="btn-outline-primary btn mb-4 book_flight" type="button" data-id="<?php echo $row['id'] ?>" data-name="<?php echo $aname[$row['departure_airport_id']].' - '.$aname[$row['arrival_airport_id']] ?>" data-max="<?php echo $row['seats'] - $booked ?>">Book Now</button>
</div>
</div>
<hr class="divider" style="max-width: 60vw">
<?php endwhile; ?>
<?php else: ?>
<div class="row align-items-center">
<h5 class="text-center"><b>No result.</b></h5>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
</section>
<style>
#flight img{
max-height: 300px;
max-width: 200px;
}
#flight p{
margin: unset
}
</style>
<script>
$('.view_schedule').click(function(){
uni_modal($(this).attr('data-name')+" - Schedule","view_doctor_schedule.php?id="+$(this).attr('data-id'))
})
$('.book_flight').click(function(){
if($(this).attr('data-max') <= 0){
alert("There is no Available Seats for the selected flight");
return false;
}
uni_modal($(this).attr('data-name'),"book_flight.php?id="+$(this).attr('data-id')+"&max="+$(this).attr('data-max'),'mid-large')
})
$('[name="trip"]').on("keypress change keyup",function(){
if($(this).val() == 1){
$('#rdate').hide()
}else{
$('#rdate').show()
}
})
</script>