1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This class is part of FlightAirmap. It's used to retrieve schedules |
4
|
|
|
* |
5
|
|
|
* Copyright (c) Ycarus (Yannick Chabanois) at Zugaina <[email protected]> |
6
|
|
|
* Licensed under AGPL license. |
7
|
|
|
* For more information see: https://www.flightairmap.com/ |
8
|
|
|
*/ |
9
|
|
|
require_once(dirname(__FILE__).'/libs/simple_html_dom.php'); |
10
|
|
|
require_once(dirname(__FILE__).'/settings.php'); |
11
|
|
|
require_once(dirname(__FILE__).'/class.Connection.php'); |
12
|
|
|
require_once(dirname(__FILE__).'/class.Translation.php'); |
13
|
|
|
require_once(dirname(__FILE__).'/class.Spotter.php'); |
14
|
|
|
require_once(dirname(__FILE__).'/class.Common.php'); |
15
|
|
|
require_once(dirname(__FILE__).'/libs/uagent/uagent.php'); |
16
|
|
|
|
17
|
|
|
class Schedule { |
18
|
|
|
protected $cookies = array(); |
19
|
|
|
public $db; |
20
|
|
|
|
21
|
|
|
/* |
22
|
|
|
* Initialize connection to DB |
23
|
|
|
*/ |
24
|
|
|
public function __construct($dbc = null) { |
25
|
|
|
$Connection = new Connection($dbc); |
26
|
|
|
$this->db = $Connection->db(); |
27
|
|
|
if ($this->db === null) die('Error: No DB connection.'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Add schedule data to database |
32
|
|
|
* @param String $ident aircraft ident |
33
|
|
|
* @param String $departure_airport_icao departure airport icao |
34
|
|
|
* @param String $departure_airport_time departure airport time |
35
|
|
|
* @param String $arrival_airport_icao arrival airport icao |
36
|
|
|
* @param String $arrival_airport_time arrival airport time |
37
|
|
|
/ @param String $source source of data |
38
|
|
|
*/ |
39
|
|
|
public function addSchedule($ident,$departure_airport_icao,$departure_airport_time,$arrival_airport_icao,$arrival_airport_time,$source = 'website') { |
40
|
|
|
date_default_timezone_set('UTC'); |
41
|
|
|
$date = date("Y-m-d H:i:s",time()); |
42
|
|
|
//if ($departure_airport_time == '' && $arrival_airport_time == '') exit; |
43
|
|
|
//$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident"; |
44
|
|
|
$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident"; |
45
|
|
|
$query_values = array(':ident' => $ident); |
46
|
|
|
try { |
47
|
|
|
$sth = $this->db->prepare($query); |
48
|
|
|
$sth->execute($query_values); |
49
|
|
|
} catch(PDOException $e) { |
50
|
|
|
return "error : ".$e->getMessage(); |
51
|
|
|
} |
52
|
|
|
if ($sth->fetchColumn() > 0) { |
53
|
|
|
if ($departure_airport_time == '' && $arrival_airport_time == '') { |
54
|
|
|
$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao"; |
55
|
|
|
$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao); |
56
|
|
|
} elseif ($arrival_airport_time == '') { |
57
|
|
|
$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao"; |
58
|
|
|
$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao); |
59
|
|
|
} elseif ($departure_airport_time == '') { |
60
|
|
|
$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time"; |
61
|
|
|
$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time); |
62
|
|
|
} else { |
63
|
|
|
//$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time"; |
64
|
|
|
$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time"; |
65
|
|
|
$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time); |
66
|
|
|
} |
67
|
|
|
try { |
68
|
|
|
$sth = $this->db->prepare($query); |
69
|
|
|
$sth->execute($query_values); |
70
|
|
|
} catch(PDOException $e) { |
71
|
|
|
return "error : ".$e->getMessage(); |
72
|
|
|
} |
73
|
|
|
if ($sth->fetchColumn() == 0) { |
74
|
|
|
//$query = 'UPDATE schedule SET departure_airport_icao = :departure_airport_icao, departure_airport_time = :departure_airport_time, arrival_airport_icao = :arrival_airport_icao, arrival_airport_time = :arrival_airport_time, date_modified = :date, source = :source WHERE ident = :ident'; |
75
|
|
|
if ($departure_airport_time == '' && $arrival_airport_time == '') { |
76
|
|
|
$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
77
|
|
|
$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source); |
78
|
|
|
} elseif ($arrival_airport_time == '') { |
79
|
|
|
$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
80
|
|
|
$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source); |
81
|
|
|
} elseif ($departure_airport_time == '') { |
82
|
|
|
$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
83
|
|
|
$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
84
|
|
|
} else { |
85
|
|
|
$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
86
|
|
|
$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
87
|
|
|
} |
88
|
|
|
try { |
89
|
|
|
$sth = $this->db->prepare($query); |
90
|
|
|
$sth->execute($query_values); |
91
|
|
|
} catch(PDOException $e) { |
92
|
|
|
return "error : ".$e->getMessage(); |
93
|
|
|
} |
94
|
|
|
} else { |
95
|
|
|
//$query = 'UPDATE schedule SET date_lastseen = :date WHERE ident = :ident'; |
96
|
|
|
$query = 'UPDATE routes SET date_lastseen = :date WHERE CallSign = :ident'; |
97
|
|
|
$query_values = array(':ident' => $ident,':date' => $date); |
98
|
|
|
try { |
99
|
|
|
$sth = $this->db->prepare($query); |
100
|
|
|
$sth->execute($query_values); |
101
|
|
|
} catch(PDOException $e) { |
102
|
|
|
return "error : ".$e->getMessage(); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} else { |
106
|
|
|
$query = 'INSERT INTO routes (CallSign,FromAirport_ICAO, FromAirport_Time, ToAirport_ICAO, ToAirport_Time,date_added,source) VALUES (:ident,:departure_airport_icao,:departure_airport_time,:arrival_airport_icao,:arrival_airport_time,:date,:source)'; |
107
|
|
|
$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
108
|
|
|
try { |
109
|
|
|
$sth = $this->db->prepare($query); |
110
|
|
|
$sth->execute($query_values); |
111
|
|
|
} catch(PDOException $e) { |
112
|
|
|
return "error : ".$e->getMessage(); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/* |
118
|
|
|
* Get schedule data by ident |
119
|
|
|
* @param String $ident Flight ident |
120
|
|
|
* @return Array Schedules info |
121
|
|
|
*/ |
122
|
|
|
public function getSchedule($ident) { |
123
|
|
|
$Translation = new Translation($this->db); |
124
|
|
|
$operator = $Translation->checkTranslation($ident,false); |
125
|
|
|
if ($ident != $operator) { |
126
|
|
|
$query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :operator OR CallSign = :ident LIMIT 1"; |
127
|
|
|
$query_values = array(':ident' => $ident,'operator' => $operator); |
128
|
|
|
} else { |
129
|
|
|
$query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :ident LIMIT 1"; |
130
|
|
|
$query_values = array(':ident' => $ident); |
131
|
|
|
} |
132
|
|
|
try { |
133
|
|
|
$sth = $this->db->prepare($query); |
134
|
|
|
$sth->execute($query_values); |
135
|
|
|
} catch(PDOException $e) { |
136
|
|
|
return "error : ".$e->getMessage(); |
|
|
|
|
137
|
|
|
} |
138
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
139
|
|
|
$sth->closeCursor(); |
140
|
|
|
if (count($row) > 0) { |
141
|
|
|
return $row; |
142
|
|
|
} else return array(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/* |
146
|
|
|
* Check if there is schedule info for an ident |
147
|
|
|
* @param String $ident Flight ident |
148
|
|
|
* @return Integer 1 if result, 0 if no results |
149
|
|
|
*/ |
150
|
|
|
public function checkSchedule($ident) { |
151
|
|
|
global $globalDBdriver; |
152
|
|
|
//$query = "SELECT COUNT(*) as nb FROM schedule WHERE ident = :ident AND date_added > DATE_SUB(CURDATE(), INTERVAL 8 DAY) - 8 LIMIT 1"; |
153
|
|
|
if ($globalDBdriver == 'mysql') { |
154
|
|
|
$query = "SELECT COUNT(*) as nb FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :ident AND ((date_added BETWEEN DATE(DATE_SUB(CURDATE(), INTERVAL 1 MONTH)) AND DATE(NOW()) and date_modified IS NULL) OR (date_modified BETWEEN DATE(DATE_SUB(CURDATE(), INTERVAL 15 DAY)) AND DATE(NOW()))) LIMIT 1"; |
155
|
|
|
} else { |
156
|
|
|
$query = "SELECT COUNT(*) as nb FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :ident |
157
|
|
|
AND ((date_added::timestamp BETWEEN CURRENT_TIMESTAMP - INTERVAL '1 MONTH' AND CURRENT_TIMESTAMP) and date_modified::timestamp IS NULL) |
158
|
|
|
OR (date_modified::timestamp BETWEEN CURRENT_TIMESTAMP - INTERVAL '1 MONTH' AND CURRENT_TIMESTAMP) LIMIT 1"; |
159
|
|
|
} |
160
|
|
|
$query_values = array(':ident' => $ident); |
161
|
|
|
try { |
162
|
|
|
$sth = $this->db->prepare($query); |
163
|
|
|
$sth->execute($query_values); |
164
|
|
|
} catch(PDOException $e) { |
165
|
|
|
return "error : ".$e->getMessage(); |
166
|
|
|
} |
167
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
168
|
|
|
$sth->closeCursor(); |
169
|
|
|
return $row['nb']; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Get flight info from Air France |
174
|
|
|
* @param String $callsign The callsign |
175
|
|
|
* @param String $date date we want flight number info |
176
|
|
|
* @param String $carrier IATA code |
177
|
|
|
* @return Flight departure and arrival airports and time |
178
|
|
|
*/ |
179
|
|
|
public function getAirFrance($callsign, $date = 'NOW',$carrier = 'AF') { |
180
|
|
|
$Common = new Common(); |
181
|
|
|
$check_date = new Datetime($date); |
182
|
|
|
$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
183
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
184
|
|
|
$url = "http://www.airfrance.fr/cgi-bin/AF/FR/fr/local/resainfovol/infovols/detailsVolJson.do?codeCompagnie[0]=".$carrier."&numeroVol[0]=".$numvol."&dayFlightDate=".$check_date->format('d')."&yearMonthFlightDate=".$check_date->format('Ym'); |
185
|
|
|
$json = $Common->getData($url); |
186
|
|
|
var_dump($json); |
|
|
|
|
187
|
|
|
$parsed_json = json_decode($json); |
188
|
|
|
if (property_exists($parsed_json,'errors') === false) { |
189
|
|
|
//$originLong = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originLong'}; |
190
|
|
|
$originShort = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originShort'}; |
191
|
|
|
//$departureDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'departureDateMedium'}; |
192
|
|
|
$departureTime = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'departureTime'}; |
193
|
|
|
//$destinationLong = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'destinationLong'}; |
194
|
|
|
$destinationShort = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'destinationShort'}; |
195
|
|
|
//$arrivalDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalDateMedium'}; |
196
|
|
|
$arrivalTime = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalTime'}; |
197
|
|
|
|
198
|
|
|
preg_match('/\((.*?)\)/',$originShort,$originiata); |
199
|
|
|
$DepartureAirportIata = $originiata[1]; |
200
|
|
|
preg_match('/\((.*?)\)/',$destinationShort,$destinationiata); |
201
|
|
|
$ArrivalAirportIata = $destinationiata[1]; |
202
|
|
|
|
203
|
|
|
/* |
204
|
|
|
date_default_timezone_set('Europe/Paris'); |
205
|
|
|
$departureTime = gmdate('H:i',strtotime($departureTime)); |
206
|
|
|
$arrivalTime = gmdate('H:i',strtotime($arrivalTime)); |
207
|
|
|
*/ |
208
|
|
|
|
209
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airfrance'); |
210
|
|
|
} else return array(); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Get flight info from EasyJet |
215
|
|
|
* @param String $callsign The callsign |
216
|
|
|
* @param String $date date we want flight number info |
217
|
|
|
* @return Flight departure and arrival airports and time |
218
|
|
|
*/ |
219
|
|
|
private function getEasyJet($callsign, $date = 'NOW') { |
220
|
|
|
global $globalTimezone; |
221
|
|
|
$Common = new Common(); |
222
|
|
|
date_default_timezone_set($globalTimezone); |
223
|
|
|
$check_date = new Datetime($date); |
224
|
|
|
$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
225
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
226
|
|
|
$url = "http://www.easyjet.com/ft/api/flights?date=".$check_date->format('Y-m-d')."&fn=".$callsign; |
227
|
|
|
$json = $Common->getData($url); |
228
|
|
|
$parsed_json = json_decode($json); |
229
|
|
|
|
230
|
|
|
$flights = $parsed_json->{'flights'}; |
231
|
|
|
if (count($flights) > 0) { |
232
|
|
|
$DepartureAirportIata = $parsed_json->{'flights'}[0]->{'airports'}->{'pda'}->{'iata'}; //name |
233
|
|
|
$ArrivalAirportIata = $parsed_json->{'flights'}[0]->{'airports'}->{'paa'}->{'iata'}; //name |
234
|
|
|
$departureTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fstd'}; |
235
|
|
|
$arrivalTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fsta'}; |
236
|
|
|
|
237
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_easyjet'); |
238
|
|
|
} else return array(); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Get flight info from Ryanair |
243
|
|
|
* @param String $callsign The callsign |
244
|
|
|
* @return Flight departure and arrival airports and time |
245
|
|
|
*/ |
246
|
|
|
private function getRyanair($callsign) { |
247
|
|
|
$Common = new Common(); |
248
|
|
|
$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
249
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
250
|
|
|
$url = "http://www.ryanair.com/fr/api/2/flight-info/0/50/"; |
251
|
|
|
$post = '{"flight":"'.$numvol.'","minDepartureTime":"00:00","maxDepartureTime":"23:59"}'; |
252
|
|
|
$headers = array('Content-Type: application/json','Content-Length: ' . strlen($post)); |
253
|
|
|
$json = $Common->getData($url,'post',$post,$headers); |
254
|
|
|
$parsed_json = json_decode($json); |
255
|
|
|
if (isset($parsed_json->{'flightInfo'})) { |
256
|
|
|
$flights = $parsed_json->{'flightInfo'}; |
257
|
|
|
if (count($flights) > 0) { |
258
|
|
|
$DepartureAirportIata = $parsed_json->{'flightInfo'}[0]->{'departureAirport'}->{'iata'}; //name |
259
|
|
|
$ArrivalAirportIata = $parsed_json->{'flightInfo'}[0]->{'arrivalAirport'}->{'iata'}; //name |
260
|
|
|
$departureTime = $parsed_json->{'flightInfo'}[0]->{'departureTime'}; |
261
|
|
|
$arrivalTime = $parsed_json->{'flightInfo'}[0]->{'arrivalTime'}; |
262
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair'); |
263
|
|
|
} else return array(); |
264
|
|
|
} else return array(); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* Get flight info from Swiss |
269
|
|
|
* @param String $callsign The callsign |
270
|
|
|
* @return Flight departure and arrival airports and time |
271
|
|
|
*/ |
272
|
|
|
private function getSwiss($callsign) { |
273
|
|
|
$Common = new Common(); |
274
|
|
|
$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
275
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
276
|
|
|
$url = "http://www.world-of-swiss.com/fr/routenetwork.json"; |
277
|
|
|
$json = $Common->getData($url); |
278
|
|
|
$parsed_json = json_decode($json); |
279
|
|
|
|
280
|
|
|
|
281
|
|
|
$flights = $parsed_json->{'flights'}; |
282
|
|
|
if (count($flights) > 0) { |
283
|
|
|
$departureTime = ''; |
284
|
|
|
$arrivalTime = ''; |
285
|
|
|
foreach ($flights as $flight) { |
286
|
|
|
if ($flight->{'no'} == "Vol LX ".$numvol) { |
287
|
|
|
$DepartureAirportIata = $flight->{'from'}->{'code'}; //city |
288
|
|
|
$ArrivalAirportIata = $flight->{'to'}->{'code'}; //city |
289
|
|
|
$departureTime = substr($flight->{'from'}->{'hour'},0,5); |
290
|
|
|
$arrivalTime = substr($flight->{'to'}->{'hour'},0,5); |
291
|
|
|
} |
292
|
|
|
} |
293
|
|
|
if (isset($DepartureAirportIata) && isset($ArrivalAirportIata)) { |
294
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_swiss'); |
295
|
|
|
} else return array(); |
296
|
|
|
} else return array(); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Get flight info from British Airways API |
301
|
|
|
* @param String $callsign The callsign |
302
|
|
|
* @param String $date date we want flight number info |
303
|
|
|
* @return Flight departure and arrival airports and time |
304
|
|
|
*/ |
305
|
|
|
public function getBritishAirways($callsign, $date = 'NOW') { |
306
|
|
|
global $globalBritishAirwaysKey; |
307
|
|
|
$Common = new Common(); |
308
|
|
|
$check_date = new Datetime($date); |
309
|
|
|
$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign)); |
310
|
|
|
if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array(); |
311
|
|
|
if ($globalBritishAirwaysKey == '') return array(); |
312
|
|
|
$url = "https://api.ba.com/rest-v1/v1/flights;flightNumber=".$numvol.";scheduledDepartureDate=".$check_date->format('Y-m-d').".json"; |
313
|
|
|
$headers = array('Client-Key: '.$globalBritishAirwaysKey); |
314
|
|
|
$json = $Common->getData($url,'get','',$headers); |
315
|
|
|
if ($json == '') return array(); |
316
|
|
|
$parsed_json = json_decode($json); |
317
|
|
|
$flights = $parsed_json->{'FlightsResponse'}; |
318
|
|
|
if (count($flights) > 0) { |
319
|
|
|
$DepartureAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'DepartureAirport'}; |
320
|
|
|
$ArrivalAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ArrivalAirport'}; |
321
|
|
|
$departureTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'})); |
322
|
|
|
$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'})); |
323
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_britishairways'); |
324
|
|
|
} else return array(); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* Get flight info from Lutfhansa API |
329
|
|
|
* @param String $callsign The callsign |
330
|
|
|
* @param String $date date we want flight number info |
331
|
|
|
* @return Flight departure and arrival airports and time |
332
|
|
|
*/ |
333
|
|
|
public function getLufthansa($callsign, $date = 'NOW') { |
334
|
|
|
global $globalLufthansaKey; |
335
|
|
|
$Common = new Common(); |
336
|
|
|
$check_date = new Datetime($date); |
337
|
|
|
$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign)); |
338
|
|
|
if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array(); |
339
|
|
|
if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') return array(); |
340
|
|
|
$url = "https://api.lufthansa.com/v1/oauth/token"; |
341
|
|
|
$post = array('client_id' => $globalLufthansaKey['key'],'client_secret' => $globalLufthansaKey['secret'],'grant_type' => 'client_credentials'); |
342
|
|
|
$data = $Common->getData($url,'post',$post); |
343
|
|
|
$parsed_data = json_decode($data); |
344
|
|
|
if (!isset($parsed_data->{'access_token'})) return array(); |
345
|
|
|
$token = $parsed_data->{'access_token'}; |
346
|
|
|
|
347
|
|
|
$url = "https://api.lufthansa.com/v1/operations/flightstatus/LH".$numvol."/".$check_date->format('Y-m-d'); |
348
|
|
|
$headers = array('Authorization: Bearer '.$token,'Accept: application/json'); |
349
|
|
|
$json = $Common->getData($url,'get','',$headers); |
350
|
|
|
if ($json == '') return array(); |
351
|
|
|
$parsed_json = json_decode($json); |
352
|
|
|
if (isset($parsed_json->{'FlightStatusResource'}) && count($parsed_json->{'FlightStatusResource'}) > 0) { |
353
|
|
|
$DepartureAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'AirportCode'}; |
354
|
|
|
$departureTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'ScheduledTimeLocal'}->{'DateTime'})); |
355
|
|
|
$ArrivalAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'AirportCode'}; |
356
|
|
|
$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'})); |
357
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa'); |
358
|
|
|
} else return array(); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* Get flight info from Transavia API |
363
|
|
|
* @param String $callsign The callsign |
364
|
|
|
* @param String $date date we want flight number info |
365
|
|
|
* @return Flight departure and arrival airports and time |
366
|
|
|
*/ |
367
|
|
|
public function getTransavia($callsign, $date = 'NOW') { |
368
|
|
|
global $globalTransaviaKey; |
369
|
|
|
$Common = new Common(); |
370
|
|
|
$check_date = new Datetime($date); |
371
|
|
|
$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign)); |
372
|
|
|
if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array(); |
373
|
|
|
if ($globalTransaviaKey == '') return array(); |
374
|
|
|
$url = "https://tst.api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol; |
375
|
|
|
//$url = "https://api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol; |
376
|
|
|
$headers = array('apikey: '.$globalTransaviaKey); |
377
|
|
|
$json = $Common->getData($url,'get','',$headers); |
378
|
|
|
//echo 'result : '.$json; |
379
|
|
|
if ($json == '') return array(); |
380
|
|
|
$parsed_json = json_decode($json); |
381
|
|
|
|
382
|
|
|
if (isset($parsed_json->{'data'}[0])) { |
383
|
|
|
$DepartureAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'departureAirport'}->{'locationCode'}; |
384
|
|
|
$departureTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'departureDateTime'})); |
385
|
|
|
$ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'}; |
386
|
|
|
$arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'})); |
387
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia'); |
388
|
|
|
} else return array(); |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* Get flight info from Tunisair |
393
|
|
|
* @param String $callsign The callsign |
394
|
|
|
* @return Flight departure and arrival airports and time |
395
|
|
|
*/ |
396
|
|
|
public function getTunisair($callsign) { |
397
|
|
|
$Common = new Common(); |
398
|
|
|
$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
399
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
400
|
|
|
$url = "http://www.tunisair.com/site/publish/module/Volj/fr/Flight_List.asp"; |
401
|
|
|
$data = $Common->getData($url); |
402
|
|
|
$table = $Common->table2array($data); |
403
|
|
|
foreach ($table as $flight) { |
404
|
|
|
if (isset($flight[1]) && $flight[1] == "TU ".sprintf('%04d',$numvol)) { |
405
|
|
|
return array('DepartureAirportIATA' => $flight[2],'DepartureTime' => str_replace('.',':',$flight[5]),'ArrivalAirportIATA' => $flight[3],'ArrivalTime' => str_replace('.',':',$flight[6]),'Source' => 'website_tunisair'); |
406
|
|
|
} |
407
|
|
|
} |
408
|
|
|
return array(); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* Get flight info from Vueling |
413
|
|
|
* @param String $callsign The callsign |
414
|
|
|
* @return Flight departure and arrival airports and time |
415
|
|
|
*/ |
416
|
|
|
public function getVueling($callsign,$date = 'NOW') { |
417
|
|
|
$Common = new Common(); |
418
|
|
|
$check_date = new Datetime($date); |
419
|
|
|
$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
420
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
421
|
|
|
$final_date = str_replace('/','%2F',$check_date->format('d/m/Y')); |
422
|
|
|
$url = "http://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=FlightStatusResult&searchBy=bycode&date=".$final_date."&flightNumber=".$numvol."&idioma=en-GB"; |
423
|
|
|
$data = $Common->getData($url); |
424
|
|
|
$data=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$data)); |
425
|
|
|
if ($data != '') { |
426
|
|
|
preg_match('/flightOri=[A-Z]{3}/',$data,$result); |
427
|
|
|
$DepartureAirportIata = str_replace('flightOri=','',$result[0]); |
428
|
|
|
preg_match('/flightDest=[A-Z]{3}/',$data,$result); |
429
|
|
|
$ArrivalAirportIata = str_replace('flightDest=','',$result[0]); |
430
|
|
|
if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling'); |
431
|
|
|
else return array(); |
432
|
|
|
} |
433
|
|
|
return array(); |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* Get flight info from Iberia |
438
|
|
|
* @param String $callsign The callsign |
439
|
|
|
* @param String $date date we want flight number info |
440
|
|
|
* @return Flight departure and arrival airports and time |
441
|
|
|
*/ |
442
|
|
|
public function getIberia($callsign, $date = 'NOW') { |
443
|
|
|
$Common = new Common(); |
444
|
|
|
$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
445
|
|
|
$check_date = new Datetime($date); |
446
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
447
|
|
|
$url = "https://www.iberia.com/web/flightDetail.do"; |
448
|
|
|
$post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB'); |
449
|
|
|
$data = $Common->getData($url,'post',$post); |
450
|
|
|
if ($data != '') { |
451
|
|
|
$table = $Common->table2array($data); |
452
|
|
|
//print_r($table); |
453
|
|
|
if (count($table) > 0) { |
454
|
|
|
$flight = $table; |
455
|
|
|
preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch); |
456
|
|
|
preg_match('/([A-Z]{3})/',$flight[5][0],$ArrivalAirportIataMatch); |
457
|
|
|
$DepartureAirportIata = $DepartureAirportIataMatch[0]; |
458
|
|
|
$ArrivalAirportIata = $ArrivalAirportIataMatch[0]; |
459
|
|
|
$departureTime = substr(trim(str_replace(' lunes','',str_replace(' ','',$flight[3][2]))),0,5); |
460
|
|
|
$arrivalTime = trim(str_replace(' lunes','',str_replace(' ','',$flight[5][1]))); |
461
|
|
|
if ($arrivalTime == 'Hora estimada de llegada') { |
462
|
|
|
$arrivalTime = substr(trim(str_replace(' lunes','',str_replace(' ','',$flight[5][2]))),0,5); |
463
|
|
|
} else $arrivalTime = substr($arrivalTime,0,5); |
464
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia'); |
465
|
|
|
} |
466
|
|
|
} |
467
|
|
|
return array(); |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* Get flight info from Star Alliance |
472
|
|
|
* @param String $callsign The callsign |
473
|
|
|
* @param String $date date we want flight number info |
474
|
|
|
* @return Flight departure and arrival airports and time |
475
|
|
|
*/ |
476
|
|
|
|
477
|
|
|
private function getStarAlliance($callsign, $date = 'NOW',$carrier = '') { |
478
|
|
|
$Common = new Common(); |
479
|
|
|
$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
480
|
|
|
$check_date = new Datetime($date); |
481
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
482
|
|
|
$url = "http://www.staralliance.com/flifoQueryAction.do?myAirline=&airlineCode=".$carrier."&flightNo=".$numvol."&day=".$check_date->format('d')."&month=".$check_date->format('m')."&year=".$check_date->format('Y')."&departuredate=".$check_date->format('d-M-Y'); |
483
|
|
|
$data = $Common->getData($url); |
484
|
|
|
if ($data != '') { |
485
|
|
|
$table = $Common->table2array($data); |
486
|
|
|
if (count($table) > 0) { |
487
|
|
|
$flight = $table; |
488
|
|
|
//print_r($table); |
489
|
|
|
if (isset($flight[25]) && isset($flight[29])) { |
490
|
|
|
preg_match('/([A-Z]{3})/',$flight[25][1],$DepartureAirportIataMatch); |
491
|
|
|
preg_match('/([A-Z]{3})/',$flight[25][3],$ArrivalAirportIataMatch); |
492
|
|
|
$DepartureAirportIata = $DepartureAirportIataMatch[0]; |
493
|
|
|
$ArrivalAirportIata = $ArrivalAirportIataMatch[0]; |
494
|
|
|
$departureTime = substr(trim(str_replace('Scheduled: ','',$flight[29][0])),0,5); |
495
|
|
|
$arrivalTime = substr(trim(str_replace('Scheduled: ','',$flight[29][1])),0,5); |
496
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_staralliance'); |
497
|
|
|
} else return array(); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
|
501
|
|
|
} |
502
|
|
|
return array(); |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* Get flight info from Alitalia |
508
|
|
|
* @param String $callsign The callsign |
509
|
|
|
* @param String $date date we want flight number info |
510
|
|
|
* @return Flight departure and arrival airports and time |
511
|
|
|
*/ |
512
|
|
|
private function getAlitalia($callsign, $date = 'NOW') { |
513
|
|
|
$Common = new Common(); |
514
|
|
|
$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
515
|
|
|
$check_date = new Datetime($date); |
516
|
|
|
$url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y'); |
517
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
518
|
|
|
$data = $Common->getData($url); |
519
|
|
|
if ($data != '') { |
520
|
|
|
$table = $Common->text2array($data); |
521
|
|
|
$DepartureAirportIata = ''; |
522
|
|
|
$ArrivalAirportIata = ''; |
523
|
|
|
$departureTime = $table[4]; |
524
|
|
|
$arrivalTime = $table[5]; |
525
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_alitalia'); |
526
|
|
|
} |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
/** |
530
|
|
|
* Get flight info from Brussels airlines |
531
|
|
|
* @param String $callsign The callsign |
532
|
|
|
* @param String $date date we want flight number info |
533
|
|
|
* @return Flight departure and arrival airports and time |
534
|
|
|
*/ |
535
|
|
|
private function getBrussels($callsign, $date = 'NOW') { |
536
|
|
|
$Common = new Common(); |
537
|
|
|
$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
538
|
|
|
$check_date = new Datetime($date); |
539
|
|
|
$url= "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302"; |
540
|
|
|
//http://www.brusselsairlines.com/fr-fr/informations-pratiques/statut-de-votre-vol/resultat.aspx?flightnumber=".$numvol."&date=".$check_date->format('d/m/Y')."&lookup=flightnumber"; |
541
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
542
|
|
|
$data = $Common->getData($url); |
543
|
|
|
if ($data != '') { |
544
|
|
|
//echo $data; |
545
|
|
|
$parsed_json = json_decode($data,true); |
546
|
|
|
if (isset($parsed_json[0]['FromAirportCode'])) { |
547
|
|
|
$DepartureAirportIata = $parsed_json[0]['FromAirportCode']; |
548
|
|
|
$ArrivalAirportIata = $parsed_json[0]['ToAirportCode']; |
549
|
|
|
$departureTime = date('H:i',strtotime($parsed_json[0]['ScheduledDepatureDate'])); |
550
|
|
|
$arrivalTime = date('H:i',strtotime($parsed_json[0]['ScheduledArrivalDate'])); |
551
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_brussels'); |
552
|
|
|
} |
553
|
|
|
} |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
/** |
557
|
|
|
* Get flight info from FlightRadar24 |
558
|
|
|
* @param String $callsign The callsign |
559
|
|
|
* @param String $date date we want flight number info |
560
|
|
|
* @return Flight departure and arrival airports and time |
561
|
|
|
*/ |
562
|
|
|
/* |
563
|
|
|
public function getFlightRadar24($callsign, $date = 'NOW') { |
564
|
|
|
$Common = new Common(); |
565
|
|
|
$url= "http://arn.data.fr24.com/zones/fcgi/feed.js?flight=".$callsign; |
566
|
|
|
$data = $Common->getData($url); |
567
|
|
|
if ($data != '') { |
568
|
|
|
$parsed_json = get_object_vars(json_decode($data)); |
569
|
|
|
if (count($parsed_json) > 2) { |
570
|
|
|
$info = array_splice($parsed_json,2,1); |
571
|
|
|
$fr24id = current(array_keys($info)); |
572
|
|
|
$urldata = "http://krk.data.fr24.com/_external/planedata_json.1.4.php?f=".$fr24id; |
573
|
|
|
$datapl = $Common->getData($urldata); |
574
|
|
|
if ($datapl != '') { |
575
|
|
|
$parsed_jsonpl = json_decode($datapl); |
576
|
|
|
if (isset($parsed_jsonpl->from_iata)) { |
577
|
|
|
$DepartureAirportIata = $parsed_jsonpl->from_iata; |
578
|
|
|
$ArrivalAirportIata = $parsed_jsonpl->to_iata; |
579
|
|
|
$departureTime = date('H:i',$parsed_jsonpl->dep_schd); |
580
|
|
|
$arrivalTime = date('H:i',$parsed_jsonpl->arr_schd); |
581
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightradar24'); |
582
|
|
|
} |
583
|
|
|
} |
584
|
|
|
} |
585
|
|
|
} |
586
|
|
|
return array(); |
587
|
|
|
} |
588
|
|
|
*/ |
589
|
|
|
/** |
590
|
|
|
* Get flight info from Lufthansa |
591
|
|
|
* @param String $callsign The callsign |
592
|
|
|
* @param String $date date we want flight number info |
593
|
|
|
* @return Flight departure and arrival airports and time |
594
|
|
|
*/ |
595
|
|
|
|
596
|
|
|
/* private function getLufthansa($callsign, $date = 'NOW') { |
597
|
|
|
$Common = new Common(); |
598
|
|
|
*/ |
599
|
|
|
//$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
600
|
|
|
/* |
601
|
|
|
$url= "http://www.lufthansa.com/fr/fr/Arrivees-Departs-fonction"; |
602
|
|
|
$check_date = new Datetime($date); |
603
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
604
|
|
|
|
605
|
|
|
$post = array('flightNumber' => $numvol, 'date' => $check_date->format('Y-m-d'),'time' => '12:00','timezoneOffset' => '0','selection' => '0','arrivalDeparture' => 'D'); |
606
|
|
|
$data = $Common->getData($url,'post',$post); |
607
|
|
|
if ($data != '') { |
608
|
|
|
$table = $Common->table2array($data); |
609
|
|
|
$departureTime = trim(str_replace($check_date->format('d.m.Y'),'',$table[25][3])); |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
$post = array('flightNumber' => $numvol, 'date' => $check_date->format('Y-m-d'),'time' => '12:00','timezoneOffset' => '0','selection' => '0','arrivalDeparture' => 'A'); |
613
|
|
|
$data = $Common->getData($url,'post',$post); |
614
|
|
|
if ($data != '') { |
615
|
|
|
$table = $Common->table2array($data); |
616
|
|
|
$arrivalTime = trim(str_replace($check_date->format('d.m.Y'),'',$table[25][3])); |
617
|
|
|
} |
618
|
|
|
return array('DepartureAirportIATA' => '','DepartureTime' => $departureTime,'ArrivalAirportIATA' => '','ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa'); |
619
|
|
|
} |
620
|
|
|
*/ |
621
|
|
|
/** |
622
|
|
|
* Get flight info from flytap |
623
|
|
|
* @param String $callsign The callsign |
624
|
|
|
* @return Flight departure and arrival airports and time |
625
|
|
|
*/ |
626
|
|
|
private function getFlyTap($callsign) { |
627
|
|
|
$Common = new Common(); |
628
|
|
|
$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
629
|
|
|
$url= "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees"; |
630
|
|
|
//$check_date = new Datetime($date); |
631
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
632
|
|
|
$post = array('arrivalsdepartures_content' => 'number','arrivalsdepartures_tp' => $numvol,'arrivalsdepartures_trk' => 'ARR','arrivalsdepartures_date_trk' => '1','aptCode' => '','arrivalsdepartures' => 'DEP','arrivalsdepartures_date' => '1','aptCodeFrom' => '','aptCodeTo' => '','arrivalsdepartures2' => 'DEP','arrivalsdepartures_date2' => '1'); |
633
|
|
|
$data = $Common->getData($url,'post',$post); |
634
|
|
|
if ($data != '') { |
635
|
|
|
$table = $Common->table2array($data); |
636
|
|
|
$departureTime = trim(substr($table[15][0],0,5)); |
637
|
|
|
$arrivalTime = trim(substr($table[35][0],0,5)); |
638
|
|
|
preg_match('/([A-Z]{3})/',$table[11][0],$DepartureAirportIataMatch); |
639
|
|
|
preg_match('/([A-Z]{3})/',$table[31][0],$ArrivalAirportIataMatch); |
640
|
|
|
$DepartureAirportIata = $DepartureAirportIataMatch[0]; |
641
|
|
|
$ArrivalAirportIata = $ArrivalAirportIataMatch[0]; |
642
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flytap'); |
643
|
|
|
} |
644
|
|
|
return array(); |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
/** |
648
|
|
|
* Get flight info from flightmapper |
649
|
|
|
* @param String $callsign The callsign |
650
|
|
|
* @return Flight departure and arrival airports and time |
651
|
|
|
*/ |
652
|
|
|
public function getFlightMapper($callsign) { |
653
|
|
|
$Common = new Common(); |
654
|
|
|
$airline_icao = ''; |
655
|
|
|
if (!is_numeric(substr($callsign, 0, 3))) |
656
|
|
|
{ |
657
|
|
|
if (is_numeric(substr(substr($callsign, 0, 3), -1, 1))) { |
658
|
|
|
$airline_icao = substr($callsign, 0, 2); |
659
|
|
|
} elseif (is_numeric(substr(substr($callsign, 0, 4), -1, 1))) { |
660
|
|
|
$airline_icao = substr($callsign, 0, 3); |
661
|
|
|
} |
662
|
|
|
} |
663
|
|
|
if ($airline_icao == '') return array(); |
664
|
|
|
$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
665
|
|
|
$url= "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol; |
666
|
|
|
//$check_date = new Datetime($date); |
667
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
668
|
|
|
$data = $Common->getData($url); |
669
|
|
|
if ($data != '') { |
670
|
|
|
$table = $Common->table2array($data); |
671
|
|
|
if (isset($table[5][0])) { |
672
|
|
|
$sched = $table[5][0]; |
673
|
|
|
$dhour = ''; |
674
|
|
|
$darr = ''; |
675
|
|
|
$ahour = ''; |
676
|
|
|
$aarr = ''; |
677
|
|
|
$n = sscanf($sched,'%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])',$dhour,$darr,$ahour,$aarr); |
678
|
|
|
if ($n == 7) { |
679
|
|
|
$departureTime = $dhour; |
680
|
|
|
$arrivalTime = $ahour; |
681
|
|
|
$DepartureAirportIata = str_replace(array('(',')'),'',$darr); |
682
|
|
|
$ArrivalAirportIata = str_replace(array('(',')'),'',$aarr); |
683
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper'); |
684
|
|
|
} |
685
|
|
|
} |
686
|
|
|
} |
687
|
|
|
return array(); |
688
|
|
|
} |
689
|
|
|
|
690
|
|
|
/** |
691
|
|
|
* Get flight info from flightaware |
692
|
|
|
* @param String $callsign The callsign |
693
|
|
|
* @return Flight departure and arrival airports and time |
694
|
|
|
*/ |
695
|
|
|
public function getFlightAware($callsign) { |
696
|
|
|
global $globalFlightAwareUsername, $globalFlightAwarePassword; |
697
|
|
|
date_default_timezone_set('UTC'); |
698
|
|
|
$Common = new Common(); |
699
|
|
|
/* |
700
|
|
|
if (!is_numeric(substr($callsign, 0, 3))) |
701
|
|
|
{ |
702
|
|
|
if (is_numeric(substr(substr($callsign, 0, 3), -1, 1))) { |
703
|
|
|
$airline_icao = substr($callsign, 0, 2); |
704
|
|
|
} elseif (is_numeric(substr(substr($callsign, 0, 4), -1, 1))) { |
705
|
|
|
$airline_icao = substr($callsign, 0, 3); |
706
|
|
|
} |
707
|
|
|
} |
708
|
|
|
*/ |
709
|
|
|
//$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
710
|
|
|
//if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
711
|
|
|
if ($globalFlightAwareUsername != '' && $globalFlightAwarePassword != '') { |
712
|
|
|
$url = 'http://'.$globalFlightAwareUsername.':'.$globalFlightAwarePassword.'@flightxml.flightaware.com/json/FlightXML3/FlightInfoStatus?ident='.$callsign; |
713
|
|
|
$data = $Common->getData($url); |
714
|
|
|
if ($data != '') { |
715
|
|
|
$result = json_decode($data,true); |
716
|
|
|
$flight = $result['FlightInfoStatusResult']['flights'][0]; |
717
|
|
|
if (isset($flight['origin'])) { |
718
|
|
|
return array( |
719
|
|
|
'DepartureAirportIATA' => $flight['origin']['alternate_ident'], |
720
|
|
|
'DepartureTime' => $flight['filed_departure_time']['time'], |
721
|
|
|
'ArrivalAirportIATA' => $flight['destination']['alternate_ident'], |
722
|
|
|
'ArrivalTime' => $flight['filed_arrival_time']['time'], |
723
|
|
|
'Source' => 'website_flightaware'); |
724
|
|
|
} |
725
|
|
|
} |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
$url= "http://flightaware.com/live/flight/".$callsign; |
729
|
|
|
$data = $Common->getData($url); |
730
|
|
|
if ($data != '') { |
731
|
|
|
preg_match(':<script>var trackpollBootstrap = (.*?);</script>:',$data,$result); |
732
|
|
|
$flights = json_decode($result[1],true); |
733
|
|
|
$flight = reset($flights['flights']); |
734
|
|
|
if (isset($flight['activityLog']['flights'][0]['origin'])) { |
735
|
|
|
return array( |
736
|
|
|
'DepartureAirportIATA' => $flight['activityLog']['flights'][0]['origin']['iata'], |
737
|
|
|
'DepartureTime' => date('H:i',$flight['activityLog']['flights'][0]['takeoffTimes']['scheduled']), |
738
|
|
|
'ArrivalAirportIATA' => $flight['activityLog']['flights'][0]['destination']['iata'], |
739
|
|
|
'ArrivalTime' => date('H:i',$flight['activityLog']['flights'][0]['landingTimes']['scheduled']), |
740
|
|
|
'Source' => 'website_flightaware'); |
741
|
|
|
} |
742
|
|
|
} |
743
|
|
|
return array(); |
744
|
|
|
} |
745
|
|
|
|
746
|
|
|
/** |
747
|
|
|
* Get flight info from CostToTravel |
748
|
|
|
* @param String $callsign The callsign |
749
|
|
|
* @return Flight departure and arrival airports and time |
750
|
|
|
*/ |
751
|
|
|
public function getCostToTravel($callsign) { |
752
|
|
|
$Common = new Common(); |
753
|
|
|
$url= "http://www.costtotravel.com/flight-number/".$callsign; |
754
|
|
|
//$check_date = new Datetime($date); |
755
|
|
|
//if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
756
|
|
|
$data = $Common->getData($url); |
757
|
|
|
if ($data != '') { |
758
|
|
|
$table = $Common->table2array($data); |
759
|
|
|
if (isset($table[11][1])) { |
760
|
|
|
if (is_numeric(substr($table[11][1],0,1))) $departureTime = substr($table[11][1],0,5); |
761
|
|
|
else $departureTime = ''; |
762
|
|
|
if (is_numeric(substr($table[17][1],0,1))) $arrivalTime = substr($table[17][1],0,5); |
763
|
|
|
else $arrivalTime = ''; |
764
|
|
|
$DepartureAirportIata = substr($table[13][1],0,3); |
765
|
|
|
$ArrivalAirportIata = substr($table[15][1],0,3); |
766
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_costtotravel'); |
767
|
|
|
} |
768
|
|
|
} |
769
|
|
|
return array(); |
770
|
|
|
} |
771
|
|
|
|
772
|
|
|
/** |
773
|
|
|
* Get flight info from Air Canada |
774
|
|
|
* @param String $callsign The callsign |
775
|
|
|
* @param String $date date we want flight number info |
776
|
|
|
* @return Flight departure and arrival airports and time |
777
|
|
|
*/ |
778
|
|
|
private function getAirCanada($callsign,$date = 'NOW') { |
779
|
|
|
$Common = new Common(); |
780
|
|
|
if (class_exists("DomDocument") === FALSE) return array(); |
781
|
|
|
date_default_timezone_set('UTC'); |
782
|
|
|
$check_date = new Datetime($date); |
783
|
|
|
$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
784
|
|
|
$url= "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249"; |
785
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
786
|
|
|
$data = $Common->getData($url); |
787
|
|
|
$dom = new DomDocument(); |
788
|
|
|
$dom->loadXML($data); |
789
|
|
|
if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) return array(); |
790
|
|
|
$departure = $dom->getElementsByTagName('DepartureStationInfo')->item(0); |
791
|
|
|
if (isset($departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue)) { |
792
|
|
|
$DepartureAirportIata = $departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue; |
793
|
|
|
$departureTime = date('H:i',strtotime($departure->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue)); |
794
|
|
|
$arrival = $dom->getElementsByTagName('ArrivalStationInfo')->item(0); |
795
|
|
|
$ArrivalAirportIata = $arrival->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue; |
796
|
|
|
$arrivalTime = date('H:i',strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue)); |
797
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_aircanada'); |
798
|
|
|
} else return array(); |
799
|
|
|
} |
800
|
|
|
|
801
|
|
|
/** |
802
|
|
|
* Get flight info from Vietnam Airlines |
803
|
|
|
* @param String $callsign The callsign |
804
|
|
|
* @param String $date date we want flight number info |
805
|
|
|
* @return Flight departure and arrival airports and time |
806
|
|
|
*/ |
807
|
|
|
private function getVietnamAirlines($callsign, $date = 'NOW') { |
808
|
|
|
$Common = new Common(); |
809
|
|
|
$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
810
|
|
|
$check_date = new Datetime($date); |
811
|
|
|
$url= "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&"; |
812
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
813
|
|
|
$data = $Common->getData($url); |
814
|
|
|
if ($data != '') { |
815
|
|
|
$table = $Common->table2array($data); |
816
|
|
|
$flight = $table; |
817
|
|
|
preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch); |
818
|
|
|
preg_match('/([A-Z]{3})/',$flight[21][0],$ArrivalAirportIataMatch); |
819
|
|
|
$DepartureAirportIata = $DepartureAirportIataMatch[0]; |
820
|
|
|
$ArrivalAirportIata = $ArrivalAirportIataMatch[0]; |
821
|
|
|
$departureTime = $flight[5][1]; |
822
|
|
|
$arrivalTime = $flight[23][1]; |
823
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_vietnamairlines'); |
824
|
|
|
} |
825
|
|
|
} |
826
|
|
|
|
827
|
|
|
/** |
828
|
|
|
* Get flight info from Air Berlin |
829
|
|
|
* @param String $callsign The callsign |
830
|
|
|
* @param String $date date we want flight number info |
831
|
|
|
* @param String $carrier airline code |
832
|
|
|
* @return Flight departure and arrival airports and time |
833
|
|
|
*/ |
834
|
|
|
private function getAirBerlin($callsign, $date = 'NOW',$carrier = 'AB') { |
835
|
|
|
$Common = new Common(); |
836
|
|
|
date_default_timezone_set('UTC'); |
837
|
|
|
//AB = airberlin, HG/NLY = NIKI, 4T/BHP = Belair |
838
|
|
|
$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
839
|
|
|
$check_date = new Datetime($date); |
840
|
|
|
$url= "http://www.airberlin.com/en-US/site/aims.php"; |
841
|
|
|
if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
842
|
|
|
$post = array('type' => 'departure','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => $carrier); |
843
|
|
|
$data = $Common->getData($url,'post',$post); |
844
|
|
|
//echo $data; |
845
|
|
|
$DepartureAirportIata = ''; |
846
|
|
|
$ArrivalAirportIata = ''; |
847
|
|
|
|
848
|
|
|
if ($data != '') { |
849
|
|
|
$table = $Common->table2array($data); |
850
|
|
|
$flight = $table; |
851
|
|
|
if (isset($flight[5][4])) $departureTime = $flight[5][4]; |
852
|
|
|
else $departureTime = ''; |
853
|
|
|
if (isset($flight[5][2])) $departureAirport = $flight[5][2]; |
854
|
|
|
else $departureAirport = ''; |
855
|
|
|
} else return array(); |
856
|
|
|
$post = array('type' => 'arrival','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB'); |
857
|
|
|
$data = $Common->getData($url,'post',$post); |
858
|
|
|
if ($data != '') { |
859
|
|
|
$table = $Common->table2array($data); |
860
|
|
|
$flight = $table; |
861
|
|
|
if (isset($flight[5][4])) { |
862
|
|
|
$arrivalTime = $flight[5][4]; |
863
|
|
|
$arrivalAirport = $flight[5][3]; |
864
|
|
|
} else { |
865
|
|
|
$arrivalTime = ''; |
866
|
|
|
$arrivalAirport = ''; |
867
|
|
|
} |
868
|
|
|
} else return array(); |
869
|
|
|
$url = 'http://www.airberlin.com/en-US/site/json/suggestAirport.php?searchfor=departures&searchflightid=0&departures%5B%5D=&suggestsource%5B0%5D=activeairports&withcountries=0&withoutroutings=0&promotion%5Bid%5D=&promotion%5Btype%5D=&routesource%5B0%5D=airberlin&routesource%5B1%5D=partner'; |
870
|
|
|
$json = $Common->getData($url); |
871
|
|
|
if ($json == '') return array(); |
872
|
|
|
$parsed_json = json_decode($json); |
873
|
|
|
$airports = $parsed_json->{'suggestList'}; |
874
|
|
|
if (count($airports) > 0) { |
875
|
|
|
foreach ($airports as $airinfo) { |
876
|
|
|
if ($airinfo->{'name'} == $departureAirport) { |
877
|
|
|
$DepartureAirportIata = $airinfo->{'code'}; |
878
|
|
|
} |
879
|
|
|
if ($airinfo->{'name'} == $arrivalAirport) { |
880
|
|
|
$ArrivalAirportIata = $airinfo->{'code'}; |
881
|
|
|
} |
882
|
|
|
} |
883
|
|
|
} |
884
|
|
|
if (isset($DepartureAirportIata)) { |
885
|
|
|
return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airberlin'); |
886
|
|
|
} else return array(); |
887
|
|
|
} |
888
|
|
|
|
889
|
|
|
/* |
890
|
|
|
* Fetch schedules from ident |
891
|
|
|
* @param String $ident Flight ident |
892
|
|
|
* @param String $date Date |
893
|
|
|
* @return Array Schedules info |
894
|
|
|
*/ |
895
|
|
|
public function fetchSchedule($ident,$date = 'NOW') { |
896
|
|
|
global $globalSchedulesSources, $globalSchedulesFetch, $globalOffline; |
897
|
|
|
//$Common = new Common(); |
898
|
|
|
if ($globalSchedulesFetch === FALSE || (isset($globalOffline) && $globalOffline === TRUE)) return array(); |
899
|
|
|
$airline_icao = ''; |
900
|
|
|
if (!is_numeric(substr($ident, 0, 3))) |
901
|
|
|
{ |
902
|
|
|
if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) { |
903
|
|
|
$airline_icao = substr($ident, 0, 2); |
904
|
|
|
} elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) { |
905
|
|
|
$airline_icao = substr($ident, 0, 3); |
906
|
|
|
} |
907
|
|
|
} |
908
|
|
|
if ($airline_icao != '') { |
909
|
|
|
switch ($airline_icao) { |
910
|
|
|
/* |
911
|
|
|
// Adria Airways |
912
|
|
|
case "ADR": |
913
|
|
|
case "JP": |
914
|
|
|
return Schedule->getStarAlliance($ident,$date,'JP'); |
915
|
|
|
break; |
916
|
|
|
// Aegean Airlines |
917
|
|
|
case "AEE": |
918
|
|
|
case "A3": |
919
|
|
|
return Schedule->getStarAlliance($ident,$date,'A3'); |
920
|
|
|
break; |
921
|
|
|
// Air Canada |
922
|
|
|
case "ACA": |
923
|
|
|
case "AC": |
924
|
|
|
return Schedule->getStarAlliance($ident,$date,'AC'); |
925
|
|
|
break; |
926
|
|
|
// Air China |
927
|
|
|
case "CCA": |
928
|
|
|
case "CA": |
929
|
|
|
return Schedule->getStarAlliance($ident,$date,'CA'); |
930
|
|
|
break; |
931
|
|
|
// Air India |
932
|
|
|
case "AIC": |
933
|
|
|
case "AI": |
934
|
|
|
return Schedule->getStarAlliance($ident,$date,'AI'); |
935
|
|
|
break; |
936
|
|
|
// Air New Zealand |
937
|
|
|
case "ANZ": |
938
|
|
|
case "NZ": |
939
|
|
|
return Schedule->getStarAlliance($ident,$date,'NZ'); |
940
|
|
|
break; |
941
|
|
|
// All Nippon Airways |
942
|
|
|
case "ANA": |
943
|
|
|
case "NH": |
944
|
|
|
return Schedule->getStarAlliance($ident,$date,'NH'); |
945
|
|
|
break; |
946
|
|
|
// Asiana Airlines |
947
|
|
|
case "AAR": |
948
|
|
|
case "OZ": |
949
|
|
|
return Schedule->getStarAlliance($ident,$date,'OZ'); |
950
|
|
|
break; |
951
|
|
|
// Austrian |
952
|
|
|
case "AUA": |
953
|
|
|
case "OS": |
954
|
|
|
return Schedule->getStarAlliance($ident,$date,'OS'); |
955
|
|
|
break; |
956
|
|
|
// Avianca |
957
|
|
|
case "AVA": |
958
|
|
|
case "AV": |
959
|
|
|
return Schedule->getStarAlliance($ident,$date,'AV'); |
960
|
|
|
break; |
961
|
|
|
*/ |
962
|
|
|
// Brussels Airlines |
963
|
|
|
case "BEL": |
964
|
|
|
case "SN": |
965
|
|
|
return $this->getBrussels($ident,$date); |
966
|
|
|
/* |
967
|
|
|
// Copa Airlines |
968
|
|
|
case "CMP": |
969
|
|
|
case "CM": |
970
|
|
|
return Schedule->getStarAlliance($ident,$date,'CM'); |
971
|
|
|
break; |
972
|
|
|
// Croatia Airlines |
973
|
|
|
case "CTN": |
974
|
|
|
case "OU": |
975
|
|
|
return Schedule->getStarAlliance($ident,$date,'OU'); |
976
|
|
|
break; |
977
|
|
|
// Egyptair |
978
|
|
|
case "MSR": |
979
|
|
|
case "MS": |
980
|
|
|
return Schedule->getStarAlliance($ident,$date,'MS'); |
981
|
|
|
break; |
982
|
|
|
// Ethiopian Airlines |
983
|
|
|
case "ETH": |
984
|
|
|
case "ET": |
985
|
|
|
return Schedule->getStarAlliance($ident,$date,'ET'); |
986
|
|
|
break; |
987
|
|
|
// Eva Air |
988
|
|
|
case "EVA": |
989
|
|
|
case "BR": |
990
|
|
|
return Schedule->getStarAlliance($ident,$date,'BR'); |
991
|
|
|
break; |
992
|
|
|
// LOT Polish Airlines |
993
|
|
|
case "LOT": |
994
|
|
|
case "LO": |
995
|
|
|
return Schedule->getStarAlliance($ident,$date,'LO'); |
996
|
|
|
break; |
997
|
|
|
// Scandinavian Airlines |
998
|
|
|
case "SAS": |
999
|
|
|
case "SK": |
1000
|
|
|
return Schedule->getStarAlliance($ident,$date,'SK'); |
1001
|
|
|
break; |
1002
|
|
|
// Shenzhen Airlines |
1003
|
|
|
case "CSZ": |
1004
|
|
|
case "ZH": |
1005
|
|
|
return Schedule->getStarAlliance($ident,$date,'ZH'); |
1006
|
|
|
break; |
1007
|
|
|
// Singapore Airlines |
1008
|
|
|
case "SIA": |
1009
|
|
|
case "SQ": |
1010
|
|
|
return Schedule->getStarAlliance($ident,$date,'SQ'); |
1011
|
|
|
break; |
1012
|
|
|
// South African Airways |
1013
|
|
|
case "SAA": |
1014
|
|
|
case "SA": |
1015
|
|
|
return Schedule->getStarAlliance($ident,$date,'SA'); |
1016
|
|
|
break; |
1017
|
|
|
*/ |
1018
|
|
|
// SWISS |
1019
|
|
|
case "SWR": |
1020
|
|
|
case "LX": |
1021
|
|
|
return $this->getSwiss($ident); |
1022
|
|
|
|
1023
|
|
|
/* |
1024
|
|
|
// TAP Portugal |
1025
|
|
|
case "TAP": |
1026
|
|
|
case "TP": |
1027
|
|
|
return $this->getFlyTap($ident,$date); |
1028
|
|
|
break; |
1029
|
|
|
*/ |
1030
|
|
|
/* |
1031
|
|
|
// Thai Airways International |
1032
|
|
|
case "THA": |
1033
|
|
|
case "TG": |
1034
|
|
|
return Schedule->getStarAlliance($ident,$date,'TG'); |
1035
|
|
|
break; |
1036
|
|
|
// Turkish Airlines |
1037
|
|
|
case "THY": |
1038
|
|
|
case "TK": |
1039
|
|
|
return Schedule->getStarAlliance($ident,$date,'TK'); |
1040
|
|
|
break; |
1041
|
|
|
// United |
1042
|
|
|
case "UAL": |
1043
|
|
|
case "UA": |
1044
|
|
|
return Schedule->getStarAlliance($ident,$date,'UA'); |
1045
|
|
|
break; |
1046
|
|
|
*/ |
1047
|
|
|
// Air France |
1048
|
|
|
/* |
1049
|
|
|
case "AF": |
1050
|
|
|
case "AFR": |
1051
|
|
|
return $this->getAirFrance($ident,$date,'AF'); |
1052
|
|
|
*/ |
1053
|
|
|
// HOP |
1054
|
|
|
/* |
1055
|
|
|
case "A5": |
1056
|
|
|
case "HOP": |
1057
|
|
|
return $this->getAirFrance($ident,$date,'A5'); |
1058
|
|
|
*/ |
1059
|
|
|
// EasyJet |
1060
|
|
|
case "U2": |
1061
|
|
|
case "DS": |
1062
|
|
|
case "EZY": |
1063
|
|
|
case "EZS": |
1064
|
|
|
return $this->getEasyJet($ident,$date); |
1065
|
|
|
// Ryanair |
1066
|
|
|
case "FR": |
1067
|
|
|
case "RYR": |
1068
|
|
|
return $this->getRyanair($ident); |
1069
|
|
|
// British Airways |
1070
|
|
|
case "BA": |
1071
|
|
|
case "SHT": |
1072
|
|
|
case "BAW": |
1073
|
|
|
return $this->getBritishAirways($ident); |
1074
|
|
|
// Tunisair |
1075
|
|
|
case "TUI": |
1076
|
|
|
case "TAR": |
1077
|
|
|
case "TU": |
1078
|
|
|
return $this->getTunisair($ident); |
1079
|
|
|
// Vueling |
1080
|
|
|
case "VLG": |
1081
|
|
|
case "VY": |
1082
|
|
|
return $this->getVueling($ident); |
1083
|
|
|
// Alitalia |
1084
|
|
|
/* |
1085
|
|
|
case "AZ": |
1086
|
|
|
case "AZA": |
1087
|
|
|
return $this->getAlitalia($ident); |
1088
|
|
|
*/ |
1089
|
|
|
// Air Canada |
1090
|
|
|
case "ACA": |
1091
|
|
|
case "AC": |
1092
|
|
|
return $this->getAirCanada($ident); |
1093
|
|
|
// Lufthansa |
1094
|
|
|
case "DLH": |
1095
|
|
|
case "LH": |
1096
|
|
|
return $this->getLufthansa($ident); |
1097
|
|
|
/* |
1098
|
|
|
// Transavia |
1099
|
|
|
case "TRA": |
1100
|
|
|
case "HV": |
1101
|
|
|
return $this->getTransavia($ident); |
1102
|
|
|
break; |
1103
|
|
|
*/ |
1104
|
|
|
/* |
1105
|
|
|
case "DLH": |
1106
|
|
|
case "LH": |
1107
|
|
|
return $this->getStarAlliance($ident,$date,'LH'); |
1108
|
|
|
break; |
1109
|
|
|
*/ |
1110
|
|
|
// Iberia |
1111
|
|
|
case "IBE": |
1112
|
|
|
case "IB": |
1113
|
|
|
return $this->getIberia($ident); |
1114
|
|
|
// Vietnam Airlines |
1115
|
|
|
case "HVN": |
1116
|
|
|
return $this->getVietnamAirlines($ident,$date); |
1117
|
|
|
// Air Berlin |
1118
|
|
|
case "AB": |
1119
|
|
|
case "BER": |
1120
|
|
|
return $this->getAirBerlin($ident,$date,'AB'); |
1121
|
|
|
// NIKI |
1122
|
|
|
case "HG": |
1123
|
|
|
case "NLY": |
1124
|
|
|
return $this->getAirBerlin($ident,$date,'HG'); |
1125
|
|
|
// BelAir |
1126
|
|
|
case "4T": |
1127
|
|
|
case "BHP": |
1128
|
|
|
return $this->getAirBerlin($ident,$date,'4T'); |
1129
|
|
|
default: |
1130
|
|
|
if (strlen($airline_icao) == 3) { |
1131
|
|
|
$Spotter = new Spotter($this->db); |
1132
|
|
|
$airline_info = $Spotter->getAllAirlineInfo($airline_icao); |
1133
|
|
|
if (isset($airline_info[0]['iata'])) $airline_icao = $airline_info[0]['iata']; |
1134
|
|
|
} |
1135
|
|
|
// Randomly use a generic function to get hours |
1136
|
|
|
if (strlen($airline_icao) == 2) { |
1137
|
|
|
if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper','costtotravel','flightaware'); |
1138
|
|
|
if (count($globalSchedulesSources) > 0) { |
1139
|
|
|
$rand = mt_rand(0,count($globalSchedulesSources)-1); |
1140
|
|
|
$source = $globalSchedulesSources[$rand]; |
1141
|
|
|
if ($source == 'flightmapper') return $this->getFlightMapper($ident); |
1142
|
|
|
elseif ($source == 'costtotravel') return $this->getCostToTravel($ident); |
1143
|
|
|
//elseif ($source == 'flightradar24') return $this->getFlightRadar24($ident,$date); |
1144
|
|
|
elseif ($source == 'flightaware') return $this->getFlightAware($ident); |
1145
|
|
|
} |
1146
|
|
|
} |
1147
|
|
|
} |
1148
|
|
|
} |
1149
|
|
|
return array(); |
1150
|
|
|
} |
1151
|
|
|
} |
1152
|
|
|
|
1153
|
|
|
|
1154
|
|
|
//$Schedule = new Schedule(); |
1155
|
|
|
|
1156
|
|
|
//print_r($Schedule->fetchSchedule('HV5661')); |
1157
|
|
|
//print_r($Schedule->getCostToTravel('AB8788')); |
1158
|
|
|
//print_r($Schedule->getBritishAirways('BAW551')); |
1159
|
|
|
//print_r($Schedule->getLufthansa('LH551')); |
1160
|
|
|
//print_r($Schedule->getTunisair('TU203')); |
1161
|
|
|
//print_r($Schedule->getTransavia('TRA598')); |
1162
|
|
|
//print_r($Schedule->getSkyTeam('AF7669')); |
1163
|
|
|
|
1164
|
|
|
?> |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.