Completed
Push — master ( cd1e29...4e1bb4 )
by Yannick
07:06
created

Spotter::getAllSourceName()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 16
nc 8
nop 1
dl 0
loc 26
rs 8.5806
c 0
b 0
f 0
1
<?php
2
require_once(dirname(__FILE__).'/class.Scheduler.php');
3
require_once(dirname(__FILE__).'/class.ACARS.php');
4
require_once(dirname(__FILE__).'/class.Image.php');
5
$global_query = "SELECT spotter_output.* FROM spotter_output";
6
7
class Spotter{
8
	public $db;
9
	
10
	function __construct($dbc = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
11
		$Connection = new Connection($dbc);
12
		$this->db = $Connection->db();
13
	}
14
	
15
	/**
16
	* Executes the SQL statements to get the spotter information
17
	*
18
	* @param String $query the SQL query
19
	* @param Array $params parameter of the query
20
	* @param String $limitQuery the limit query
21
	* @return Array the spotter information
22
	*
23
	*/
24
	public function getDataFromDB($query, $params = array(), $limitQuery = '')
25
	{
26
		global $globalSquawkCountry, $globalIVAO, $globalVATSIM, $globalphpVMS;
27
		$Image = new Image($this->db);
28
		$Schedule = new Schedule($this->db);
29
		$ACARS = new ACARS($this->db);
30
		if (!isset($globalIVAO)) $globalIVAO = FALSE;
31
		if (!isset($globalVATSIM)) $globalVATSIM = FALSE;
32
		if (!isset($globalphpVMS)) $globalphpVMS = FALSE;
33
		date_default_timezone_set('UTC');
34
		
35
		if (!is_string($query))
36
		{
37
			return false;
38
		}
39
		
40
		if ($limitQuery != "")
41
		{
42
			if (!is_string($limitQuery))
43
			{
44
				return false;
45
			}
46
		}
47
48
		
49
		try {
50
			$sth = $this->db->prepare($query.$limitQuery);
51
			$sth->execute($params);
52
		} catch (PDOException $e) {
53
			printf("Invalid query : %s\nWhole query: %s\n",$e->getMessage(), $query.$limitQuery);
54
			exit();
55
		}
56
		
57
	//	$num_rows = count($sth->fetchAll());
58
		$num_rows = 0;
59
60
		$spotter_array = array();
61
		$temp_array = array();
0 ignored issues
show
Unused Code introduced by
$temp_array is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
62
		
63
64
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
65
		{
66
			$num_rows++;
67
			$temp_array = array();
68
			if (isset($row['spotter_live_id'])) {
69
				//$temp_array['spotter_id'] = $row['spotter_live_id'];
70
				$temp_array['spotter_id'] = $this->getSpotterIDBasedOnFlightAwareID($row['flightaware_id']);
71
			} elseif (isset($row['spotter_archive_id'])) {
72
				$temp_array['spotter_id'] = $row['spotter_archive_id'];
73
			} elseif (isset($row['spotter_archive_output_id'])) {
74
				$temp_array['spotter_id'] = $row['spotter_archive_output_id'];
75
			} elseif (isset($row['spotter_id'])) {
76
				$temp_array['spotter_id'] = $row['spotter_id'];
77
			} else {
78
				$temp_array['spotter_id'] = '';
79
			}
80
			$temp_array['flightaware_id'] = $row['flightaware_id'];
81
			if (isset($row['modes'])) $temp_array['modes'] = $row['modes'];
82
			$temp_array['ident'] = $row['ident'];
83
			if (isset($row['registration']) && $row['registration'] != '') {
84
				$temp_array['registration'] = $row['registration'];
85
			} elseif (isset($temp_array['modes'])) {
86
				$temp_array['registration'] = $this->getAircraftRegistrationBymodeS($temp_array['modes']);
87
			} else $temp_array['registration'] = '';
88
			$temp_array['aircraft_type'] = $row['aircraft_icao'];
89
			
90
			$temp_array['departure_airport'] = $row['departure_airport_icao'];
91
			$temp_array['arrival_airport'] = $row['arrival_airport_icao'];
92
			if (isset($row['real_arrival_airport_icao']) && $row['real_arrival_airport_icao'] != NULL) $temp_array['real_arrival_airport'] = $row['real_arrival_airport_icao'];
93
			$temp_array['latitude'] = $row['latitude'];
94
			$temp_array['longitude'] = $row['longitude'];
95
			/*
96
			if (Connection->tableExists('countries')) {
97
				$country_info = $this->getCountryFromLatitudeLongitude($temp_array['latitude'],$temp_array['longitude']);
98
				if (is_array($country_info) && isset($country_info['name']) && isset($country_info['iso2'])) {
99
				    $temp_array['country'] = $country_info['name'];
100
				    $temp_array['country_iso2'] = $country_info['iso2'];
101
				}
102
			}
103
			*/
104
			$temp_array['waypoints'] = $row['waypoints'];
105
			$temp_array['format_source'] = $row['format_source'];
106
			if (isset($row['route_stop'])) {
107
				$temp_array['route_stop'] = $row['route_stop'];
108
				if ($row['route_stop'] != '') {
109
					$allroute = explode(' ',$row['route_stop']);
110
			
111
					foreach ($allroute as $route) {
112
						$route_airport_array = $this->getAllAirportInfo($route);
113
						if (isset($route_airport_array[0]['name'])) {
114
							$route_stop_details['airport_name'] = $route_airport_array[0]['name'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$route_stop_details was never initialized. Although not strictly required by PHP, it is generally a good practice to add $route_stop_details = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
115
							$route_stop_details['airport_city'] = $route_airport_array[0]['city'];
116
							$route_stop_details['airport_country'] = $route_airport_array[0]['country'];
117
							$route_stop_details['airport_icao'] = $route_airport_array[0]['icao'];
118
							$temp_array['route_stop_details'][] = $route_stop_details;
119
						}
120
					}
121
				}
122
			}
123
			$temp_array['altitude'] = $row['altitude'];
124
			$temp_array['heading'] = $row['heading'];
125
			$heading_direction = $this->parseDirection($row['heading']);
126
			if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
127
			$temp_array['ground_speed'] = $row['ground_speed'];
128
			$temp_array['image'] = "";
129
			$temp_array['image_thumbnail'] = "";
130
			$temp_array['image_source'] = "";
131
			$temp_array['image_copyright'] = "";
132
 
133
			if (isset($row['highlight'])) {
134
				$temp_array['highlight'] = $row['highlight'];
135
			} else $temp_array['highlight'] = '';
136
			
137
			$dateArray = $this->parseDateString($row['date']);
138
			if ($dateArray['seconds'] < 10)
139
			{
140
				$temp_array['date'] = "a few seconds ago";
141
			} elseif ($dateArray['seconds'] >= 5 && $dateArray['seconds'] < 30)
142
			{
143
				$temp_array['date'] = "half a minute ago";
144
			} elseif ($dateArray['seconds'] >= 30 && $dateArray['seconds'] < 60)
145
			{
146
				$temp_array['date'] = "about a minute ago";
147
			} elseif ($dateArray['minutes'] < 5)
148
			{
149
				$temp_array['date'] = "a few minutes ago";
150
			} elseif ($dateArray['minutes'] >= 5 && $dateArray['minutes'] < 60)
151
			{
152
				$temp_array['date'] = "about ".$dateArray['minutes']." minutes ago";
153
			} elseif ($dateArray['hours'] < 2)
154
			{
155
				$temp_array['date'] = "about an hour ago";
156
			} elseif ($dateArray['hours'] >= 2 && $dateArray['hours'] < 24)
157
			{
158
				$temp_array['date'] = "about ".$dateArray['hours']." hours ago";
159
			} else {
160
				$temp_array['date'] = date("M j Y, g:i a",strtotime($row['date']." UTC"));
161
			}
162
			$temp_array['date_minutes_past'] = $dateArray['minutes'];
163
			$temp_array['date_iso_8601'] = date("c",strtotime($row['date']." UTC"));
164
			$temp_array['date_rfc_2822'] = date("r",strtotime($row['date']." UTC"));
165
			$temp_array['date_unix'] = strtotime($row['date']." UTC");
166
			
167
			if (isset($row['aircraft_name']) && $row['aircraft_name'] != '' && isset($row['aircraft_shadow']) && $row['aircraft_shadow'] != '') {
168
				$temp_array['aircraft_name'] = $row['aircraft_name'];
169
				$temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer'];
170
				if (isset($row['aircraft_shadow'])) {
171
					$temp_array['aircraft_shadow'] = $row['aircraft_shadow'];
172
				}
173
			} else {
174
				$aircraft_array = $this->getAllAircraftInfo($row['aircraft_icao']);
175
				if (count($aircraft_array) > 0) {
176
					$temp_array['aircraft_name'] = $aircraft_array[0]['type'];
177
					$temp_array['aircraft_manufacturer'] = $aircraft_array[0]['manufacturer'];
178
				
179
					if ($aircraft_array[0]['aircraft_shadow'] != NULL) {
180
						$temp_array['aircraft_shadow'] = $aircraft_array[0]['aircraft_shadow'];
181
					} else $temp_array['aircraft_shadow'] = 'default.png';
182
                                } else {
183
                            		$temp_array['aircraft_shadow'] = 'default.png';
184
					$temp_array['aircraft_name'] = 'N/A';
185
					$temp_array['aircraft_manufacturer'] = 'N/A';
186
                            	}
187
			}
188
			if (!isset($row['airline_name']) || $row['airline_name'] == '') {
189
				$airline_array = array();
0 ignored issues
show
Unused Code introduced by
$airline_array is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
190
				if (!is_numeric(substr($row['ident'], 0, 3))) {
191
					if (is_numeric(substr($row['ident'], 2, 1))) {
192
						$airline_array = $this->getAllAirlineInfo(substr($row['ident'], 0, 2));
193
					} elseif (is_numeric(substr($row['ident'], 3, 1))) {
194
						$airline_array = $this->getAllAirlineInfo(substr($row['ident'], 0, 3));
195
					} else {
196
						$airline_array = $this->getAllAirlineInfo('NA');
197
					}
198
				} else {
199
					$airline_array = $this->getAllAirlineInfo('NA');
200
				}
201
				if (count($airline_array) > 0) {
202
					$temp_array['airline_icao'] = $airline_array[0]['icao'];
203
					$temp_array['airline_iata'] = $airline_array[0]['iata'];
204
					$temp_array['airline_name'] = $airline_array[0]['name'];
205
					$temp_array['airline_country'] = $airline_array[0]['country'];
206
					$temp_array['airline_callsign'] = $airline_array[0]['callsign'];
207
					$temp_array['airline_type'] = $airline_array[0]['type'];
208
				}
209
			} else {
210
				$temp_array['airline_icao'] = $row['airline_icao'];
211
				if (isset($row['airline_iata'])) $temp_array['airline_iata'] = $row['airline_iata'];
212
				else $temp_array['airline_iata'] = '';
213
				$temp_array['airline_name'] = $row['airline_name'];
214
				$temp_array['airline_country'] = $row['airline_country'];
215
				if (isset($row['airline_callsign'])) $temp_array['airline_callsign'] = $row['airline_callsign'];
216
				else $temp_array['airline_callsign'] = 'N/A';
217
				$temp_array['airline_type'] = $row['airline_type'];
218
			}
219
			if (isset($temp_array['airline_iata']) && $temp_array['airline_iata'] != '') {
220
				$acars_array = $ACARS->getLiveAcarsData($temp_array['airline_iata'].substr($temp_array['ident'],3));
221
				//$acars_array = ACARS->getLiveAcarsData('BA40YL');
222
				if (count($acars_array) > 0) {
223
					$temp_array['acars'] = $acars_array;
224
					//print_r($acars_array);
225
				}
226
			}
227
			if (isset($row['owner_name']) && $row['owner_name'] != '' && $row['owner_name'] != NULL) {
228
				$temp_array['aircraft_owner'] = $row['owner_name'];
229
			}
230
			if ($temp_array['registration'] != "" && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !isset($temp_array['aircraft_owner'])) {
231
				$owner_info = $this->getAircraftOwnerByRegistration($temp_array['registration']);
232
				if ($owner_info['owner'] != '') $temp_array['aircraft_owner'] = ucwords(strtolower($owner_info['owner']));
233
				$temp_array['aircraft_base'] = $owner_info['base'];
234
				$temp_array['aircraft_date_first_reg'] = $owner_info['date_first_reg'];
235
			}
236
237
			if($temp_array['registration'] != "" || ($globalIVAO && $temp_array['aircraft_type'] != ''))
238
			{
239
				if ($globalIVAO) {
240
					if (isset($temp_array['airline_icao']))	$image_array = $Image->getSpotterImage('',$temp_array['aircraft_type'],$temp_array['airline_icao']);
241
					else $image_array = $Image->getSpotterImage('',$temp_array['aircraft_type']);
242
				} else $image_array = $Image->getSpotterImage($temp_array['registration']);
243
				if (count($image_array) > 0) {
244
					$temp_array['image'] = $image_array[0]['image'];
245
					$temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail'];
246
					$temp_array['image_source'] = $image_array[0]['image_source'];
247
					$temp_array['image_source_website'] = $image_array[0]['image_source_website'];
248
					if ($temp_array['image_source_website'] == '' && $temp_array['image_source'] == 'planespotters') {
249
						$planespotter_url_array = explode("_", $temp_array['image']);
250
						$planespotter_id = str_replace(".jpg", "", $planespotter_url_array[1]);
251
						$temp_array['image_source_website'] = 'http://www.planespotters.net/Aviation_Photos/photo.show?id='.$planespotter_id;
252
					 }
253
					$temp_array['image_copyright'] = $image_array[0]['image_copyright'];
254
				}
255
			}
256
257
258
			if (isset($row['departure_airport_time']) && $row['departure_airport_time'] != '') {
259
				$temp_array['departure_airport_time'] = $row['departure_airport_time'];
260
			}
261
			if (isset($row['arrival_airport_time']) && $row['arrival_airport_time'] != '') {
262
				$temp_array['arrival_airport_time'] = $row['arrival_airport_time'];
263
			}
264
			if ((!isset($globalIVAO) || ! $globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) {
265
				$schedule_array = $Schedule->getSchedule($temp_array['ident']);
266
				//print_r($schedule_array);
267
				if (count($schedule_array) > 0) {
268
					if ($schedule_array['departure_airport_icao'] != '') {
269
						$row['departure_airport_icao'] = $schedule_array['departure_airport_icao'];
270
						 $temp_array['departure_airport'] = $row['departure_airport_icao'];
271
					}
272
					if ($schedule_array['arrival_airport_icao'] != '') {
273
						$row['arrival_airport_icao'] = $schedule_array['arrival_airport_icao'];
274
						$temp_array['arrival_airport'] = $row['arrival_airport_icao'];
275
					}
276
277
					$temp_array['departure_airport_time'] = $schedule_array['departure_airport_time'];
278
					$temp_array['arrival_airport_time'] = $schedule_array['arrival_airport_time'];
279
				}
280
			} else {
281
				if (isset($row['real_departure_airport_time']) && $row['real_departure_airport_time'] != '') {
282
					$temp_array['departure_airport_time'] = $row['real_departure_airport_time'];
283
				}
284
				if (isset($row['real_arrival_airport_time']) && $row['real_arrival_airport_time'] != '') {
285
					$temp_array['real_arrival_airport_time'] = $row['real_arrival_airport_time'];
286
				}
287
			}
288
			
289
			//if ($row['departure_airport_icao'] != '' && $row['departure_airport_name'] == '') {
290
			if ($row['departure_airport_icao'] != '') {
291
				$departure_airport_array = $this->getAllAirportInfo($row['departure_airport_icao']);
292
				if (!isset($departure_airport_array[0]['name'])) $departure_airport_array = $this->getAllAirportInfo('NA');
293
			/*
294
			} elseif ($row['departure_airport_name'] != '') {
295
				$temp_array['departure_airport_name'] = $row['departure_airport_name'];
296
				$temp_array['departure_airport_city'] = $row['departure_airport_city'];
297
				$temp_array['departure_airport_country'] = $row['departure_airport_country'];
298
				$temp_array['departure_airport_icao'] = $row['departure_airport_icao'];
299
			*/
300
			} else $departure_airport_array = $this->getAllAirportInfo('NA');
301
			if (isset($departure_airport_array[0]['name'])) {
302
				$temp_array['departure_airport_name'] = $departure_airport_array[0]['name'];
303
				$temp_array['departure_airport_city'] = $departure_airport_array[0]['city'];
304
				$temp_array['departure_airport_country'] = $departure_airport_array[0]['country'];
305
				$temp_array['departure_airport_iata'] = $departure_airport_array[0]['iata'];
306
				$temp_array['departure_airport_icao'] = $departure_airport_array[0]['icao'];
307
				$temp_array['departure_airport_latitude'] = $departure_airport_array[0]['latitude'];
308
				$temp_array['departure_airport_longitude'] = $departure_airport_array[0]['longitude'];
309
				$temp_array['departure_airport_altitude'] = $departure_airport_array[0]['altitude'];
310
			}
311
312
			/*
313
			if (isset($row['departure_airport_time'])) {
314
				$temp_array['departure_airport_time'] = $row['departure_airport_time'];
315
			}
316
			*/
317
			
318
			if ($row['arrival_airport_icao'] != '') {
319
				$arrival_airport_array = $this->getAllAirportInfo($row['arrival_airport_icao']);
320
				if (count($arrival_airport_array) == 0) $arrival_airport_array = $this->getAllAirportInfo('NA');
321
			} else $arrival_airport_array = $this->getAllAirportInfo('NA');
322
			if (isset($arrival_airport_array[0]['name'])) {
323
				$temp_array['arrival_airport_name'] = $arrival_airport_array[0]['name'];
324
				$temp_array['arrival_airport_city'] = $arrival_airport_array[0]['city'];
325
				$temp_array['arrival_airport_country'] = $arrival_airport_array[0]['country'];
326
				$temp_array['arrival_airport_iata'] = $arrival_airport_array[0]['iata'];
327
				$temp_array['arrival_airport_icao'] = $arrival_airport_array[0]['icao'];
328
				$temp_array['arrival_airport_latitude'] = $arrival_airport_array[0]['latitude'];
329
				$temp_array['arrival_airport_longitude'] = $arrival_airport_array[0]['longitude'];
330
				$temp_array['arrival_airport_altitude'] = $arrival_airport_array[0]['altitude'];
331
			}
332
			/*
333
			if (isset($row['arrival_airport_time'])) {
334
				$temp_array['arrival_airport_time'] = $row['arrival_airport_time'];
335
			}
336
			*/
337
			if (isset($row['pilot_id']) && $row['pilot_id'] != '') $temp_array['pilot_id'] = $row['pilot_id'];
338
			if (isset($row['pilot_name']) && $row['pilot_name'] != '') $temp_array['pilot_name'] = $row['pilot_name'];
339
			if (isset($row['source_name']) && $row['source_name'] != '') $temp_array['source_name'] = $row['source_name'];
340
			if (isset($row['over_country']) && $row['over_country'] != '') $temp_array['over_country'] = $row['over_country'];
341
			if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance'];
342
			if (isset($row['squawk'])) {
343
				$temp_array['squawk'] = $row['squawk'];
344
				if ($row['squawk'] != '' && isset($temp_array['country_iso2'])) {
345
					$temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$temp_array['country_iso2']);
346
					if ($temp_array['squawk_usage'] == '' && isset($globalSquawkCountry)) $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$globalSquawkCountry);
347
				} elseif ($row['squawk'] != '' && isset($temp_array['over_country'])) {
348
					$temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$temp_array['over_country']);
349
					if ($temp_array['squawk_usage'] == '' && isset($globalSquawkCountry)) $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$globalSquawkCountry);
350
				} elseif ($row['squawk'] != '' && isset($globalSquawkCountry)) $temp_array['squawk_usage'] = $this->getSquawkUsage($row['squawk'],$globalSquawkCountry);
351
			}
352
    			
353
			$temp_array['query_number_rows'] = $num_rows;
354
			
355
			$spotter_array[] = $temp_array;
356
		}
357
		if ($num_rows == 0) return array();
358
		$spotter_array[0]['query_number_rows'] = $num_rows;
359
		return $spotter_array;
360
	}	
361
	
362
	
363
	/**
364
	* Gets all the spotter information
365
	*
366
	* @return Array the spotter information
367
	*
368
	*/
369
	public function searchSpotterData($q = '', $registration = '', $aircraft_icao = '', $aircraft_manufacturer = '', $highlights = '', $airline_icao = '', $airline_country = '', $airline_type = '', $airport = '', $airport_country = '', $callsign = '', $departure_airport_route = '', $arrival_airport_route = '', $owner = '',$pilot_id = '',$pilot_name = '',$altitude = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '',$origLat = '',$origLon = '',$dist = '')
370
	{
371
		global $globalTimezone, $globalDBdriver;
372
		require_once(dirname(__FILE__).'/class.Translation.php');
373
		$Translation = new Translation();
374
375
		date_default_timezone_set('UTC');
376
377
		$query_values = array();
378
		$additional_query = '';
379
		if ($q != "")
380
		{
381
			if (!is_string($q))
382
			{
383
				return false;
384
			} else {
385
				$q_array = explode(" ", $q);
386
				foreach ($q_array as $q_item){
387
					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
388
					$additional_query .= " AND (";
389
					if (is_int($q_item)) $additional_query .= "(spotter_output.spotter_id like '%".$q_item."%') OR ";
390
					$additional_query .= "(spotter_output.aircraft_icao like '%".$q_item."%') OR ";
391
					$additional_query .= "(spotter_output.aircraft_name like '%".$q_item."%') OR ";
392
					$additional_query .= "(spotter_output.aircraft_manufacturer like '%".$q_item."%') OR ";
393
					$additional_query .= "(spotter_output.airline_icao like '%".$q_item."%') OR ";
394
					$additional_query .= "(spotter_output.airline_name like '%".$q_item."%') OR ";
395
					$additional_query .= "(spotter_output.airline_country like '%".$q_item."%') OR ";
396
					$additional_query .= "(spotter_output.departure_airport_icao like '%".$q_item."%') OR ";
397
					$additional_query .= "(spotter_output.departure_airport_name like '%".$q_item."%') OR ";
398
					$additional_query .= "(spotter_output.departure_airport_city like '%".$q_item."%') OR ";
399
					$additional_query .= "(spotter_output.departure_airport_country like '%".$q_item."%') OR ";
400
					$additional_query .= "(spotter_output.arrival_airport_icao like '%".$q_item."%') OR ";
401
					$additional_query .= "(spotter_output.arrival_airport_name like '%".$q_item."%') OR ";
402
					$additional_query .= "(spotter_output.arrival_airport_city like '%".$q_item."%') OR ";
403
					$additional_query .= "(spotter_output.arrival_airport_country like '%".$q_item."%') OR ";
404
					$additional_query .= "(spotter_output.registration like '%".$q_item."%') OR ";
405
					$additional_query .= "(spotter_output.owner_name like '%".$q_item."%') OR ";
406
					$additional_query .= "(spotter_output.pilot_id like '%".$q_item."%') OR ";
407
					$additional_query .= "(spotter_output.pilot_name like '%".$q_item."%') OR ";
408
					$additional_query .= "(spotter_output.ident like '%".$q_item."%') OR ";
409
					$translate = $Translation->ident2icao($q_item);
410
					if ($translate != $q_item) $additional_query .= "(spotter_output.ident like '%".$translate."%') OR ";
411
					$additional_query .= "(spotter_output.highlight like '%".$q_item."%')";
412
					$additional_query .= ")";
413
				}
414
			}
415
		}
416
417
		if ($registration != "")
418
		{
419
			$registration = filter_var($registration,FILTER_SANITIZE_STRING);
420
			if (!is_string($registration))
421
			{
422
				return false;
423
			} else {
424
				$additional_query .= " AND spotter_output.registration = :registration";
425
				$query_values = array_merge($query_values,array(':registration' => $registration));
426
			}
427
		}
428
429
		if ($aircraft_icao != "")
430
		{
431
			$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
432
			if (!is_string($aircraft_icao))
433
			{
434
				return false;
435
			} else {
436
				$additional_query .= " AND spotter_output.aircraft_icao = :aircraft_icao";
437
				$query_values = array_merge($query_values,array(':aircraft_icao' => $aircraft_icao));
438
			}
439
		}
440
441
		if ($aircraft_manufacturer != "")
442
		{
443
			$aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING);
444
			if (!is_string($aircraft_manufacturer))
445
			{
446
				return false;
447
			} else {
448
				$additional_query .= " AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer";
449
				$query_values = array_merge($query_values,array(':aircraft_manufacturer' => $aircraft_manufacturer));
450
			}
451
		}
452
453
		if ($highlights == "true")
454
		{
455
			if (!is_string($highlights))
456
			{
457
				return false;
458
			} else {
459
				$additional_query .= " AND (spotter_output.highlight <> '')";
460
			}
461
		}
462
463
		if ($airline_icao != "")
464
		{
465
			$registration = filter_var($airline_icao,FILTER_SANITIZE_STRING);
0 ignored issues
show
Unused Code introduced by
$registration is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
466
			if (!is_string($airline_icao))
467
			{
468
				return false;
469
			} else {
470
				$additional_query .= " AND spotter_output.airline_icao = :airline_icao";
471
				$query_values = array_merge($query_values,array(':airline_icao' => $airline_icao));
472
			}
473
		}
474
475
		if ($airline_country != "")
476
		{
477
			$airline_country = filter_var($airline_country,FILTER_SANITIZE_STRING);
478
			if (!is_string($airline_country))
479
			{
480
				return false;
481
			} else {
482
				$additional_query .= " AND spotter_output.airline_country = :airline_country";
483
				$query_values = array_merge($query_values,array(':airline_country' => $airline_country));
484
			}
485
		}
486
487
		if ($airline_type != "")
488
		{
489
			if (!is_string($airline_type))
490
			{
491
				return false;
492
			} else {
493
				if ($airline_type == "passenger")
494
				{
495
					$additional_query .= " AND (spotter_output.airline_type = 'passenger')";
496
				}
497
				if ($airline_type == "cargo")
498
				{
499
					$additional_query .= " AND (spotter_output.airline_type = 'cargo')";
500
				}
501
				if ($airline_type == "military")
502
				{
503
					$additional_query .= " AND (spotter_output.airline_type = 'military')";
504
				}
505
			}
506
		}
507
508
		if ($airport != "")
509
		{
510
			$airport = filter_var($airport,FILTER_SANITIZE_STRING);
511
			if (!is_string($airport))
512
			{
513
				return false;
514
			} else {
515
				$additional_query .= " AND (spotter_output.departure_airport_icao = :airport OR spotter_output.arrival_airport_icao = :airport)";
516
				$query_values = array_merge($query_values,array(':airport' => $airport));
517
			}
518
		}
519
520
		if ($airport_country != "")
521
		{
522
			$airport_country = filter_var($airport_country,FILTER_SANITIZE_STRING);
523
			if (!is_string($airport_country))
524
			{
525
				return false;
526
			} else {
527
				$additional_query .= " AND (spotter_output.departure_airport_country = :airport_country OR spotter_output.arrival_airport_country = :airport_country)";
528
				$query_values = array_merge($query_values,array(':airport_country' => $airport_country));
529
			}
530
		}
531
    
532
		if ($callsign != "")
533
		{
534
			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
535
			if (!is_string($callsign))
536
			{
537
				return false;
538
			} else {
539
				$translate = $Translation->ident2icao($callsign);
540
				if ($translate != $callsign) {
541
					$additional_query .= " AND (spotter_output.ident = :callsign OR spotter_output.ident = :translate)";
542
					$query_values = array_merge($query_values,array(':callsign' => $callsign,':translate' => $translate));
543
				} else {
544
					$additional_query .= " AND spotter_output.ident = :callsign";
545
					$query_values = array_merge($query_values,array(':callsign' => $callsign));
546
				}
547
			}
548
		}
549
550
		if ($owner != "")
551
		{
552
			$owner = filter_var($owner,FILTER_SANITIZE_STRING);
553
			if (!is_string($owner))
554
			{
555
				return false;
556
			} else {
557
				$additional_query .= " AND spotter_output.owner_name = :owner";
558
				$query_values = array_merge($query_values,array(':owner' => $owner));
559
			}
560
		}
561
562
		if ($pilot_name != "")
563
		{
564
			$pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING);
565
			if (!is_string($pilot_name))
566
			{
567
				return false;
568
			} else {
569
				$additional_query .= " AND spotter_output.pilot_name = :pilot_name";
570
				$query_values = array_merge($query_values,array(':pilot_name' => $pilot_name));
571
			}
572
		}
573
574
		if ($pilot_id != "")
575
		{
576
			$pilot_id = filter_var($pilot_id,FILTER_SANITIZE_NUMBER_INT);
577
			if (!is_string($pilot_id))
578
			{
579
				return false;
580
			} else {
581
				$additional_query .= " AND spotter_output.pilot_id = :pilot_id";
582
				$query_values = array_merge($query_values,array(':pilot_id' => $pilot_id));
583
			}
584
		}
585
586
		if ($departure_airport_route != "")
587
		{
588
			$departure_airport_route = filter_var($departure_airport_route,FILTER_SANITIZE_STRING);
589
			if (!is_string($departure_airport_route))
590
			{
591
				return false;
592
			} else {
593
				$additional_query .= " AND spotter_output.departure_airport_icao = :departure_airport_route";
594
				$query_values = array_merge($query_values,array(':departure_airport_route' => $departure_airport_route));
595
			}
596
		}
597
598
		if ($arrival_airport_route != "")
599
		{
600
			$arrival_airport_route = filter_var($arrival_airport_route,FILTER_SANITIZE_STRING);
601
			if (!is_string($arrival_airport_route))
602
			{
603
				return false;
604
			} else {
605
				$additional_query .= " AND spotter_output.arrival_airport_icao = :arrival_airport_route";
606
				$query_values = array_merge($query_values,array(':arrival_airport_route' => $arrival_airport_route));
607
			}
608
		}
609
610
		if ($altitude != "")
611
		{
612
			$altitude_array = explode(",", $altitude);
613
			$altitude_array[0] = filter_var($altitude_array[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
614
			$altitude_array[1] = filter_var($altitude_array[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
615
616
			if ($altitude_array[1] != "")
617
			{                
618
				$altitude_array[0] = substr($altitude_array[0], 0, -2);
619
				$altitude_array[1] = substr($altitude_array[1], 0, -2);
620
				$additional_query .= " AND altitude BETWEEN '".$altitude_array[0]."' AND '".$altitude_array[1]."' ";
621
			} else {
622
				$altitude_array[0] = substr($altitude_array[0], 0, -2);
623
				$additional_query .= " AND altitude <= '".$altitude_array[0]."' ";
624
			}
625
		}
626
627
		if ($date_posted != "")
628
		{
629
			$date_array = explode(",", $date_posted);
630
			$date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING);
631
			$date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING);
632
633
			if ($globalTimezone != '') {
634
				date_default_timezone_set($globalTimezone);
635
				$datetime = new DateTime();
636
				$offset = $datetime->format('P');
637
			} else $offset = '+00:00';
638
639
			if ($date_array[1] != "")
640
			{
641
				$date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0]));
642
				$date_array[1] = date("Y-m-d H:i:s", strtotime($date_array[1]));
643
				if ($globalDBdriver == 'mysql') {
644
					$additional_query .= " AND TIMESTAMP(CONVERT_TZ(spotter_output.date,'+00:00', '".$offset."')) >= '".$date_array[0]."' AND TIMESTAMP(CONVERT_TZ(spotter_output.date,'+00:00', '".$offset."')) <= '".$date_array[1]."' ";
645
				} else {
646
					$additional_query .= " AND CAST(spotter_output.date AT TIME ZONE INTERVAL ".$offset." AS TIMESTAMP) >= '".$date_array[0]."' AND CAST(spotter_output.date AT TIME ZONE INTERVAL ".$offset." AS TIMESTAMP) <= '".$date_array[1]."' ";
647
				}
648
			} else {
649
				$date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0]));
650
				if ($globalDBdriver == 'mysql') {
651
					$additional_query .= " AND TIMESTAMP(CONVERT_TZ(spotter_output.date,'+00:00', '".$offset."')) >= '".$date_array[0]."' ";
652
				} else {
653
					$additional_query .= " AND CAST(spotter_output.date AT TIME ZONE INTERVAL ".$offset." AS TIMESTAMP) >= '".$date_array[0]."' ";
654
				}
655
			}
656
		}
657
658
		if ($limit != "")
659
		{
660
			$limit_array = explode(",", $limit);
661
			
662
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
663
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
664
			
665
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
666
			{
667
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
668
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
669
			} else $limit_query = "";
670
		} else $limit_query = "";
671
672
673
		if ($sort != "")
674
		{
675
			$search_orderby_array = $this->getOrderBy();
676
			$orderby_query = $search_orderby_array[$sort]['sql'];
677
		} else {
678
			if ($origLat != "" && $origLon != "" && $dist != "") {
679
				$orderby_query = "  ORDER BY distance ASC";
680
			} else {
681
				$orderby_query = " ORDER BY spotter_output.date DESC";
682
			}
683
		}
684
685
		if ($includegeodata == "true")
686
		{
687
			$additional_query .= " AND spotter_output.waypoints <> ''";
688
		}
689
690
691
		if ($origLat != "" && $origLon != "" && $dist != "") {
692
			$dist = number_format($dist*0.621371,2,'.',''); // convert km to mile
693
694
			if ($globalDBdriver == 'mysql') {
695
				$query="SELECT spotter_output.*, 1.60935*3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - spotter_archive.latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(spotter_archive.latitude*pi()/180)*POWER(SIN(($origLon-spotter_archive.longitude)*pi()/180/2),2))) as distance 
696
						FROM spotter_output, spotter_archive WHERE spotter_output.flightaware_id = spotter_archive.flightaware_id AND spotter_output.ident <> '' ".$additional_query."AND spotter_archive.longitude between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat)*69)) and spotter_archive.latitude between ($origLat-($dist/69)) and ($origLat+($dist/69)) 
697
						AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - spotter_archive.latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(spotter_archive.latitude*pi()/180)*POWER(SIN(($origLon-spotter_archive.longitude)*pi()/180/2),2)))) < $dist".$orderby_query;
698
			} else {
699
				$query="SELECT spotter_output.*, 1.60935 * 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(spotter_archive.latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(spotter_archive.latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(spotter_archive.longitude as double precision))*pi()/180/2),2))) as distance 
700
						FROM spotter_output, spotter_archive WHERE spotter_output.flightaware_id = spotter_archive.flightaware_id AND spotter_output.ident <> '' ".$additional_query."AND CAST(spotter_archive.longitude as double precision) between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat))*69) and CAST(spotter_archive.latitude as double precision) between ($origLat-($dist/69)) and ($origLat+($dist/69)) 
701
						AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(spotter_archive.latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(spotter_archive.latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(spotter_archive.longitude as double precision))*pi()/180/2),2)))) < $dist".$orderby_query;
702
			}
703
		} else {		
704
			$query  = "SELECT spotter_output.* FROM spotter_output 
705
					WHERE spotter_output.ident <> '' 
706
					".$additional_query."
707
					".$orderby_query;
708
		}
709
		$spotter_array = $this->getDataFromDB($query, $query_values,$limit_query);
710
		return $spotter_array;
711
	}
712
	
713
	
714
	/**
715
	* Gets all the spotter information based on the latest data entry
716
	*
717
	* @return Array the spotter information
718
	*
719
	*/
720
	public function getLatestSpotterData($limit = '', $sort = '')
721
	{
722
		global $global_query;
723
		
724
		date_default_timezone_set('UTC');
725
		
726
		if ($limit != "")
727
		{
728
			$limit_array = explode(",", $limit);
729
			
730
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
731
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
732
			
733
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
734
			{
735
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
736
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
737
			} else $limit_query = "";
738
		} else $limit_query = "";
739
		
740
		if ($sort != "")
741
		{
742
			$search_orderby_array = $this->getOrderBy();
743
			$orderby_query = $search_orderby_array[$sort]['sql'];
744
		} else {
745
			$orderby_query = " ORDER BY spotter_output.date DESC";
746
		}
747
748
		$query  = $global_query." ".$orderby_query;
749
750
		$spotter_array = $this->getDataFromDB($query, array(),$limit_query);
751
752
		return $spotter_array;
753
	}
754
    
755
    
756
    /**
757
	* Gets all the spotter information based on a user's latitude and longitude
758
	*
759
	* @return Array the spotter information
760
	*
761
	*/
762
	public function getLatestSpotterForLayar($lat, $lng, $radius, $interval)
763
	{
764
		date_default_timezone_set('UTC');
765
		$limit_query = '';
766
		if ($lat != "")
767
		{
768
			if (!is_numeric($lat))
769
			{
770
				return false;
771
			}
772
		}
773
        
774
		if ($lng != "")
775
		{
776
			if (!is_numeric($lng))
777
			{
778
				return false;
779
			}
780
		}
781
		
782
		if ($radius != "")
783
		{
784
			if (!is_numeric($radius))
785
			{
786
				return false;
787
			}
788
		}
789
    		$additional_query = '';
790
		if ($interval != "")
791
		{
792
			if (!is_string($interval))
793
			{
794
				return false;
795
			} else {
796
				if ($interval == "30m"){
797
					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) <= $this_output.date ';
798
				} else if ($interval == "1h"){
799
					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) <= $this_output.date ';
800
				} else if ($interval == "3h"){
801
					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 3 HOUR) <= $this_output.date ';
802
				} else if ($interval == "6h"){
803
					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 6 HOUR) <= $this_output.date ';
804
				} else if ($interval == "12h"){
805
					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 12 HOUR) <= $this_output.date ';
806
				} else if ($interval == "24h"){
807
					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 24 HOUR) <= $this_output.date ';
808
				} else if ($interval == "7d"){
809
					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY) <= $this_output.date ';
810
				} else if ($interval == "30d"){
811
					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 DAY) <= $this_output.date ';
812
				} 
813
			}
814
		}
815
816
		$query  = "SELECT spotter_output.*, ( 6371 * acos( cos( radians($lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians($lng) ) + sin( radians($lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_output 
817
                   WHERE spotter_output.latitude <> '' 
818
				   AND spotter_output.longitude <> '' 
819
                   ".$additional_query."
820
                   HAVING distance < :radius  
821
				   ORDER BY distance";
822
823
		$spotter_array = $this->getDataFromDB($query, array(':radius' => $radius),$limit_query);
824
825
		return $spotter_array;
826
	}
827
    
828
    
829
    /**
830
	* Gets all the spotter information sorted by the newest aircraft type
831
	*
832
	* @return Array the spotter information
833
	*
834
	*/
835
	public function getNewestSpotterDataSortedByAircraftType($limit = '', $sort = '')
836
	{
837
		global $global_query;
838
		
839
		date_default_timezone_set('UTC');
840
		$limit_query = '';
841
		if ($limit != "")
842
		{
843
			$limit_array = explode(",", $limit);
844
			
845
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
846
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
847
			
848
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
849
			{
850
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
851
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
852
			}
853
		}
854
		
855
		if ($sort != "")
856
		{
857
			$search_orderby_array = $this->getOrderBy();
858
			$orderby_query = $search_orderby_array[$sort]['sql'];
859
		} else {
860
			$orderby_query = " ORDER BY spotter_output.date DESC ";
861
		}
862
863
		$query  = $global_query." WHERE spotter_output.aircraft_name <> '' GROUP BY spotter_output.aircraft_icao,spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time ".$orderby_query;
864
865
		$spotter_array = $this->getDataFromDB($query, array(), $limit_query);
866
867
		return $spotter_array;
868
	}
869
    
870
    
871
    /**
872
	* Gets all the spotter information sorted by the newest aircraft registration
873
	*
874
	* @return Array the spotter information
875
	*
876
	*/
877
	public function getNewestSpotterDataSortedByAircraftRegistration($limit = '', $sort = '')
878
	{
879
		global $global_query;
880
		
881
		date_default_timezone_set('UTC');
882
		$limit_query = '';
883
		
884
		if ($limit != "")
885
		{
886
			$limit_array = explode(",", $limit);
887
			
888
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
889
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
890
			
891
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
892
			{
893
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
894
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
895
			}
896
		}
897
		
898
		if ($sort != "")
899
		{
900
			$search_orderby_array = $this->getOrderBy();
901
			$orderby_query = $search_orderby_array[$sort]['sql'];
902
		} else {
903
			$orderby_query = " ORDER BY spotter_output.date DESC ";
904
		}
905
906
		$query  = $global_query." WHERE spotter_output.registration <> '' GROUP BY spotter_output.registration,spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time ".$orderby_query;
907
908
		$spotter_array = $this->getDataFromDB($query, array(), $limit_query);
909
910
		return $spotter_array;
911
	}
912
    
913
    
914
    /**
915
	* Gets all the spotter information sorted by the newest airline
916
	*
917
	* @return Array the spotter information
918
	*
919
	*/
920
	public function getNewestSpotterDataSortedByAirline($limit = '', $sort = '')
921
	{
922
		global $global_query;
923
		
924
		date_default_timezone_set('UTC');
925
		
926
		if ($limit != "")
927
		{
928
			$limit_array = explode(",", $limit);
929
			
930
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
931
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
932
			
933
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
934
			{
935
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
936
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
937
			}
938
		}
939
		
940
		if ($sort != "")
941
		{
942
			$search_orderby_array = $this->getOrderBy();
943
			$orderby_query = $search_orderby_array[$sort]['sql'];
944
		} else {
945
			$orderby_query = " ORDER BY spotter_output.date DESC ";
946
		}
947
948
		$query  = $global_query." WHERE spotter_output.airline_name <> '' GROUP BY spotter_output.airline_icao,spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time ".$orderby_query;
949
950
		$spotter_array = $this->getDataFromDB($query, array(), $limit_query);
0 ignored issues
show
Bug introduced by
The variable $limit_query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
951
952
		return $spotter_array;
953
	}
954
    
955
    
956
    /**
957
	* Gets all the spotter information sorted by the newest departure airport
958
	*
959
	* @return Array the spotter information
960
	*
961
	*/
962
	public function getNewestSpotterDataSortedByDepartureAirport($limit = '', $sort = '')
963
	{
964
		global $global_query;
965
		
966
		date_default_timezone_set('UTC');
967
		$limit_query = '';
968
		
969
		if ($limit != "")
970
		{
971
			$limit_array = explode(",", $limit);
972
			
973
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
974
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
975
			
976
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
977
			{
978
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
979
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
980
			}
981
		}
982
		
983
		if ($sort != "")
984
		{
985
			$search_orderby_array = $this->getOrderBy();
986
			$orderby_query = $search_orderby_array[$sort]['sql'];
987
		} else {
988
			$orderby_query = " ORDER BY spotter_output.date DESC ";
989
		}
990
991
		$query  = $global_query." WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' GROUP BY spotter_output.departure_airport_icao,spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time ".$orderby_query;
992
993
		$spotter_array = $this->getDataFromDB($query, array(), $limit_query);
994
995
		return $spotter_array;
996
	}
997
    
998
    
999
    /**
1000
	* Gets all the spotter information sorted by the newest arrival airport
1001
	*
1002
	* @return Array the spotter information
1003
	*
1004
	*/
1005
	public function getNewestSpotterDataSortedByArrivalAirport($limit = '', $sort = '')
1006
	{
1007
		global $global_query;
1008
		
1009
		date_default_timezone_set('UTC');
1010
		$limit_query = '';
1011
		
1012
		if ($limit != "")
1013
		{
1014
			$limit_array = explode(",", $limit);
1015
			
1016
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1017
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1018
			
1019
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1020
			{
1021
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
1022
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
1023
			}
1024
		}
1025
		
1026
		if ($sort != "")
1027
		{
1028
			$search_orderby_array = $this->getOrderBy();
1029
			$orderby_query = $search_orderby_array[$sort]['sql'];
1030
		} else {
1031
			$orderby_query = " ORDER BY spotter_output.date DESC ";
1032
		}
1033
1034
		$query  = $global_query." WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' GROUP BY spotter_output.arrival_airport_icao,spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time ".$orderby_query;
1035
1036
		$spotter_array = $this->getDataFromDB($query, array(), $limit_query);
1037
1038
		return $spotter_array;
1039
	}
1040
	
1041
1042
	/**
1043
	* Gets all the spotter information based on the spotter id
1044
	*
1045
	* @return Array the spotter information
1046
	*
1047
	*/
1048
	public function getSpotterDataByID($id = '')
1049
	{
1050
		global $global_query;
1051
		
1052
		date_default_timezone_set('UTC');
1053
		$query_values = array();
1054
		$additional_query = '';
1055
		if ($id != "")
1056
		{
1057
			if (!is_string($id))
1058
			{
1059
				return false;
1060
			} else {
1061
				$additional_query = " AND (spotter_output.spotter_id = :id)";
1062
				$query_values = array(':id' => $id);
1063
			}
1064
		}
1065
1066
		$query  = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ";
1067
1068
		$spotter_array = $this->getDataFromDB($query,$query_values);
1069
1070
		return $spotter_array;
1071
	}
1072
1073
	
1074
	
1075
	
1076
	/**
1077
	* Gets all the spotter information based on the callsign
1078
	*
1079
	* @return Array the spotter information
1080
	*
1081
	*/
1082
	public function getSpotterDataByIdent($ident = '', $limit = '', $sort = '')
1083
	{
1084
		global $global_query;
1085
		
1086
		date_default_timezone_set('UTC');
1087
		
1088
		$query_values = array();
1089
		$limit_query = '';
1090
		$additional_query = '';
1091
		if ($ident != "")
1092
		{
1093
			if (!is_string($ident))
1094
			{
1095
				return false;
1096
			} else {
1097
				$additional_query = " AND (spotter_output.ident = :ident)";
1098
				$query_values = array(':ident' => $ident);
1099
			}
1100
		}
1101
		
1102
		if ($limit != "")
1103
		{
1104
			$limit_array = explode(",", $limit);
1105
			
1106
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1107
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1108
			
1109
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1110
			{
1111
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
1112
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
1113
			}
1114
		}
1115
1116
		if ($sort != "")
1117
		{
1118
			$search_orderby_array = $this->getOrderBy();
1119
			$orderby_query = $search_orderby_array[$sort]['sql'];
1120
		} else {
1121
			$orderby_query = " ORDER BY spotter_output.date DESC";
1122
		}
1123
1124
		$query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query;
1125
1126
		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query);
1127
1128
		return $spotter_array;
1129
	}
1130
	
1131
	
1132
	
1133
	/**
1134
	* Gets all the spotter information based on the aircraft type
1135
	*
1136
	* @return Array the spotter information
1137
	*
1138
	*/
1139
	public function getSpotterDataByAircraft($aircraft_type = '', $limit = '', $sort = '')
1140
	{
1141
		global $global_query;
1142
		
1143
		date_default_timezone_set('UTC');
1144
		
1145
		$query_values = array();
1146
		$limit_query = '';
1147
		$additional_query = '';
1148
		
1149
		if ($aircraft_type != "")
1150
		{
1151
			if (!is_string($aircraft_type))
1152
			{
1153
				return false;
1154
			} else {
1155
				$additional_query = " AND (spotter_output.aircraft_icao = :aircraft_type)";
1156
				$query_values = array(':aircraft_type' => $aircraft_type);
1157
			}
1158
		}
1159
		
1160
		if ($limit != "")
1161
		{
1162
			$limit_array = explode(",", $limit);
1163
			
1164
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1165
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1166
			
1167
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1168
			{
1169
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
1170
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
1171
			}
1172
		}
1173
1174
		if ($sort != "")
1175
		{
1176
			$search_orderby_array = $this->getOrderBy();
1177
			$orderby_query = $search_orderby_array[$sort]['sql'];
1178
		} else {
1179
			$orderby_query = " ORDER BY spotter_output.date DESC";
1180
		}
1181
1182
		$query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query;
1183
1184
		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query);
1185
1186
		return $spotter_array;
1187
	}
1188
	
1189
	
1190
	/**
1191
	* Gets all the spotter information based on the aircraft registration
1192
	*
1193
	* @return Array the spotter information
1194
	*
1195
	*/
1196
	public function getSpotterDataByRegistration($registration = '', $limit = '', $sort = '')
1197
	{
1198
		global $global_query;
1199
		
1200
		date_default_timezone_set('UTC');
1201
		
1202
		$query_values = array();
1203
		$limit_query = '';
1204
		$additional_query = '';
1205
		
1206
		if ($registration != "")
1207
		{
1208
			if (!is_string($registration))
1209
			{
1210
				return false;
1211
			} else {
1212
				$additional_query = " AND (spotter_output.registration = :registration)";
1213
				$query_values = array(':registration' => $registration);
1214
			}
1215
		}
1216
		
1217
		if ($limit != "")
1218
		{
1219
			$limit_array = explode(",", $limit);
1220
			
1221
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1222
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1223
			
1224
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1225
			{
1226
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
1227
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
1228
			}
1229
		}
1230
1231
		if ($sort != "")
1232
		{
1233
			$search_orderby_array = $this->getOrderBy();
1234
			$orderby_query = $search_orderby_array[$sort]['sql'];
1235
		} else {
1236
			$orderby_query = " ORDER BY spotter_output.date DESC";
1237
		}
1238
1239
		$query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query;
1240
1241
		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query);
1242
1243
		return $spotter_array;
1244
	}
1245
1246
	
1247
	
1248
	
1249
	/**
1250
	* Gets all the spotter information based on the airline
1251
	*
1252
	* @return Array the spotter information
1253
	*
1254
	*/
1255
	public function getSpotterDataByAirline($airline = '', $limit = '', $sort = '')
1256
	{
1257
		global $global_query;
1258
		
1259
		date_default_timezone_set('UTC');
1260
1261
		$query_values = array();
1262
		$limit_query = '';
1263
		$additional_query = '';
1264
		
1265
		if ($airline != "")
1266
		{
1267
			if (!is_string($airline))
1268
			{
1269
				return false;
1270
			} else {
1271
				$additional_query = " AND (spotter_output.airline_icao = :airline)";
1272
				$query_values = array(':airline' => $airline);
1273
			}
1274
		}
1275
		
1276
		if ($limit != "")
1277
		{
1278
			$limit_array = explode(",", $limit);
1279
			
1280
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1281
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1282
			
1283
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1284
			{
1285
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
1286
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
1287
			}
1288
		}
1289
		
1290
		if ($sort != "")
1291
		{
1292
			$search_orderby_array = $this->getOrderBy();
1293
			$orderby_query = $search_orderby_array[$sort]['sql'];
1294
		} else {
1295
			$orderby_query = " ORDER BY spotter_output.date DESC";
1296
		}
1297
1298
		$query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query;
1299
		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query);
1300
1301
		return $spotter_array;
1302
	}
1303
	
1304
	
1305
	/**
1306
	* Gets all the spotter information based on the airport
1307
	*
1308
	* @return Array the spotter information
1309
	*
1310
	*/
1311
	public function getSpotterDataByAirport($airport = '', $limit = '', $sort = '')
1312
	{
1313
		global $global_query;
1314
		
1315
		date_default_timezone_set('UTC');
1316
		$query_values = array();
1317
		$limit_query = '';
1318
		$additional_query = '';
1319
		
1320
		if ($airport != "")
1321
		{
1322
			if (!is_string($airport))
1323
			{
1324
				return false;
1325
			} else {
1326
				$additional_query .= " AND ((spotter_output.departure_airport_icao = :airport) OR (spotter_output.arrival_airport_icao = :airport))";
1327
				$query_values = array(':airport' => $airport);
1328
			}
1329
		}
1330
		
1331
		if ($limit != "")
1332
		{
1333
			$limit_array = explode(",", $limit);
1334
			
1335
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1336
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1337
			
1338
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1339
			{
1340
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
1341
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
1342
			}
1343
		}
1344
		
1345
		if ($sort != "")
1346
		{
1347
			$search_orderby_array = $this->getOrderBy();
1348
			$orderby_query = $search_orderby_array[$sort]['sql'];
1349
		} else {
1350
			$orderby_query = " ORDER BY spotter_output.date DESC";
1351
		}
1352
1353
		$query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." AND ((spotter_output.departure_airport_icao <> 'NA') AND (spotter_output.arrival_airport_icao <> 'NA')) ".$orderby_query;
1354
1355
		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query);
1356
1357
		return $spotter_array;
1358
	}
1359
1360
1361
1362
	/**
1363
	* Gets all the spotter information based on the date
1364
	*
1365
	* @return Array the spotter information
1366
	*
1367
	*/
1368
	public function getSpotterDataByDate($date = '', $limit = '', $sort = '')
1369
	{
1370
		global $global_query, $globalTimezone, $globalDBdriver;
1371
		
1372
		$query_values = array();
1373
		$limit_query = '';
1374
		$additional_query = '';
1375
		
1376
		if ($date != "")
1377
		{
1378
			if ($globalTimezone != '') {
1379
				date_default_timezone_set($globalTimezone);
1380
				$datetime = new DateTime($date);
1381
				$offset = $datetime->format('P');
1382
			} else {
1383
				date_default_timezone_set('UTC');
1384
				$datetime = new DateTime($date);
1385
				$offset = '+00:00';
1386
			}
1387
			if ($globalDBdriver == 'mysql') {
1388
				$additional_query = " AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date ";
1389
				$query_values = array(':date' => $datetime->format('Y-m-d'), ':offset' => $offset);
1390
			} elseif ($globalDBdriver == 'pgsql') {
1391
				$additional_query = " AND spotter_output.date AT TIME ZONE :timezone = :date ";
1392
				$query_values = array(':date' => $datetime->format('Y-m-d'), ':timezone' => $globalTimezone);
1393
			}
1394
		}
1395
		
1396
		if ($limit != "")
1397
		{
1398
			$limit_array = explode(",", $limit);
1399
			
1400
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1401
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1402
			
1403
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1404
			{
1405
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
1406
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
1407
			}
1408
		}
1409
1410
		if ($sort != "")
1411
		{
1412
			$search_orderby_array = $this->getOrderBy();
1413
			$orderby_query = $search_orderby_array[$sort]['sql'];
1414
		} else {
1415
			$orderby_query = " ORDER BY spotter_output.date DESC";
1416
		}
1417
1418
		$query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query;
1419
		
1420
		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query);
1421
1422
		return $spotter_array;
1423
	}
1424
1425
1426
1427
	/**
1428
	* Gets all the spotter information based on the country name
1429
	*
1430
	* @return Array the spotter information
1431
	*
1432
	*/
1433
	public function getSpotterDataByCountry($country = '', $limit = '', $sort = '')
1434
	{
1435
		global $global_query;
1436
		
1437
		date_default_timezone_set('UTC');
1438
		
1439
		$query_values = array();
1440
		$limit_query = '';
1441
		$additional_query = '';
1442
		if ($country != "")
1443
		{
1444
			if (!is_string($country))
1445
			{
1446
				return false;
1447
			} else {
1448
				$additional_query .= " AND ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country))";
1449
				$additional_query .= " OR spotter_output.airline_country = :country";
1450
				$query_values = array(':country' => $country);
1451
			}
1452
		}
1453
		
1454
		if ($limit != "")
1455
		{
1456
			$limit_array = explode(",", $limit);
1457
			
1458
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1459
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1460
			
1461
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1462
			{
1463
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
1464
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
1465
			}
1466
		}
1467
					
1468
		if ($sort != "")
1469
		{
1470
			$search_orderby_array = $this->getOrderBy();
1471
			$orderby_query = $search_orderby_array[$sort]['sql'];
1472
		} else {
1473
			$orderby_query = " ORDER BY spotter_output.date DESC";
1474
		}
1475
1476
		$query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query;
1477
1478
		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query);
1479
1480
		return $spotter_array;
1481
	}	
1482
	
1483
	
1484
	/**
1485
	* Gets all the spotter information based on the manufacturer name
1486
	*
1487
	* @return Array the spotter information
1488
	*
1489
	*/
1490
	public function getSpotterDataByManufacturer($aircraft_manufacturer = '', $limit = '', $sort = '')
1491
	{
1492
		global $global_query;
1493
		
1494
		date_default_timezone_set('UTC');
1495
		
1496
		$query_values = array();
1497
		$additional_query = '';
1498
		$limit_query = '';
1499
		
1500
		if ($aircraft_manufacturer != "")
1501
		{
1502
			if (!is_string($aircraft_manufacturer))
1503
			{
1504
				return false;
1505
			} else {
1506
				$additional_query .= " AND (spotter_output.aircraft_manufacturer = :aircraft_manufacturer)";
1507
				$query_values = array(':aircraft_manufacturer' => $aircraft_manufacturer);
1508
			}
1509
		}
1510
		
1511
		if ($limit != "")
1512
		{
1513
			$limit_array = explode(",", $limit);
1514
			
1515
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1516
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1517
			
1518
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1519
			{
1520
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
1521
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
1522
			}
1523
		}
1524
1525
		if ($sort != "")
1526
		{
1527
			$search_orderby_array = $this->getOrderBy();
1528
			$orderby_query = $search_orderby_array[$sort]['sql'];
1529
		} else {
1530
			$orderby_query = " ORDER BY spotter_output.date DESC";
1531
		}
1532
1533
		$query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query;
1534
1535
		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query);
1536
1537
		return $spotter_array;
1538
	}
1539
1540
1541
  
1542
  
1543
    /**
1544
	* Gets a list of all aircraft with a special highlight text
1545
	*
1546
	* @param String $aircraft_registration the aircraft registration
0 ignored issues
show
Bug introduced by
There is no parameter named $aircraft_registration. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1547
	* @param String $airport_departure the departure airport
0 ignored issues
show
Bug introduced by
There is no parameter named $airport_departure. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1548
	* @return Array the spotter information
1549
	*
1550
	*/
1551
	public function getSpotterDataByRoute($departure_airport_icao = '', $arrival_airport_icao = '', $limit = '', $sort = '')
1552
	{
1553
		global $global_query;
1554
		
1555
		$query_values = array();
1556
		$additional_query = '';
1557
		$limit_query = '';
1558
		if ($departure_airport_icao != "")
1559
		{
1560
			if (!is_string($departure_airport_icao))
1561
			{
1562
				return false;
1563
			} else {
1564
				$departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING);
1565
				$additional_query .= " AND (spotter_output.departure_airport_icao = :departure_airport_icao)";
1566
				$query_values = array(':departure_airport_icao' => $departure_airport_icao);
1567
			}
1568
		}
1569
		
1570
		if ($arrival_airport_icao != "")
1571
		{
1572
			if (!is_string($arrival_airport_icao))
1573
			{
1574
				return false;
1575
			} else {
1576
				$arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING);
1577
				$additional_query .= " AND (spotter_output.arrival_airport_icao = :arrival_airport_icao)";
1578
				$query_values = array_merge($query_values,array(':arrival_airport_icao' => $arrival_airport_icao));
1579
			}
1580
		}
1581
		
1582
		if ($limit != "")
1583
		{
1584
			$limit_array = explode(",", $limit);
1585
			
1586
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1587
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1588
			
1589
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1590
			{
1591
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
1592
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
1593
			}
1594
		}
1595
	
1596
		if ($sort != "")
1597
		{
1598
			$search_orderby_array = $this->getOrderBy();
1599
			$orderby_query = $search_orderby_array[$sort]['sql'];
1600
		} else {
1601
			$orderby_query = " ORDER BY spotter_output.date DESC";
1602
		}
1603
1604
		$query = $global_query." WHERE spotter_output.ident <> '' ".$additional_query." ".$orderby_query;
1605
          
1606
		//$result = mysqli_query($GLOBALS["___mysqli_ston"], $query);
1607
1608
		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query);
1609
1610
		return $spotter_array;
1611
	}
1612
	
1613
	
1614
	
1615
	/**
1616
	* Gets all the spotter information based on the special column in the table
1617
	*
1618
	* @return Array the spotter information
1619
	*
1620
	*/
1621
	public function getSpotterDataByHighlight($limit = '', $sort = '')
1622
	{
1623
		global $global_query;
1624
		
1625
		date_default_timezone_set('UTC');
1626
		$limit_query = '';
1627
		
1628
		if ($limit != "")
1629
		{
1630
			$limit_array = explode(",", $limit);
1631
			
1632
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1633
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1634
			
1635
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1636
			{
1637
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
1638
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
1639
			}
1640
		}
1641
		
1642
		if ($sort != "")
1643
		{
1644
			$search_orderby_array = $this->getOrderBy();
1645
			$orderby_query = $search_orderby_array[$sort]['sql'];
1646
		} else {
1647
			$orderby_query = " ORDER BY spotter_output.date DESC";
1648
		}
1649
1650
		$query  = $global_query." WHERE spotter_output.highlight <> '' ".$orderby_query;
1651
1652
		$spotter_array = $this->getDataFromDB($query, array(), $limit_query);
1653
1654
		return $spotter_array;
1655
	}
1656
    
1657
    
1658
    
1659
    /**
1660
	* Gets all the highlight based on a aircraft registration
1661
	*
1662
	* @return String the highlight text
1663
	*
1664
	*/
1665
	public function getHighlightByRegistration($registration)
1666
	{
1667
		global $global_query;
1668
		
1669
		date_default_timezone_set('UTC');
1670
		
1671
		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
1672
1673
		
1674
		$query  = $global_query." WHERE spotter_output.highlight <> '' AND spotter_output.registration = :registration";
1675
		$sth = $this->db->prepare($query);
1676
		$sth->execute(array(':registration' => $registration));
1677
1678
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1679
		{
1680
			$highlight = $row['highlight'];
1681
		}
1682
		if (isset($highlight)) return $highlight;
1683
	}
1684
1685
	
1686
	/**
1687
	* Gets the squawk usage from squawk code
1688
	*
1689
	* @param String $squawk squawk code
1690
	* @param String $country country
1691
	* @return String usage
1692
	*
1693
	*/
1694
	public function getSquawkUsage($squawk = '',$country = 'FR')
1695
	{
1696
		
1697
		$squawk = filter_var($squawk,FILTER_SANITIZE_STRING);
1698
		$country = filter_var($country,FILTER_SANITIZE_STRING);
1699
1700
		$query_values = array();
0 ignored issues
show
Unused Code introduced by
$query_values is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1701
1702
		$query  = "SELECT squawk.* FROM squawk WHERE squawk.code = :squawk AND squawk.country = :country LIMIT 1";
1703
		$query_values = array(':squawk' => ltrim($squawk,'0'), ':country' => $country);
1704
		
1705
		$sth = $this->db->prepare($query);
1706
		$sth->execute($query_values);
1707
    
1708
		$temp_array = array();
0 ignored issues
show
Unused Code introduced by
$temp_array is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1709
		
1710
		$row = $sth->fetch(PDO::FETCH_ASSOC);
1711
		if (count($row) > 0) {
1712
			return $row['usage'];
1713
		} else return '';
1714
	}
1715
1716
	/**
1717
	* Gets the airport icao from the iata
1718
	*
1719
	* @param String $airport_iata the iata code of the airport
1720
	* @return String airport iata
1721
	*
1722
	*/
1723
	public function getAirportIcao($airport_iata = '')
1724
	{
1725
		
1726
		$airport_iata = filter_var($airport_iata,FILTER_SANITIZE_STRING);
1727
1728
		$query_values = array();
0 ignored issues
show
Unused Code introduced by
$query_values is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1729
1730
		$query  = "SELECT airport.* FROM airport WHERE airport.iata = :airport LIMIT 1";
1731
		$query_values = array(':airport' => $airport_iata);
1732
		
1733
		
1734
		$sth = $this->db->prepare($query);
1735
		$sth->execute($query_values);
1736
		
1737
		$row = $sth->fetch(PDO::FETCH_ASSOC);
1738
		if (count($row) > 0) {
1739
			return $row['icao'];
1740
		} else return '';
1741
	}
1742
1743
	/**
1744
	* Gets the airport distance
1745
	*
1746
	* @param String $airport_icao the icao code of the airport
1747
	* @param Float $latitude the latitude
1748
	* @param Float $longitude the longitude
1749
	* @return Float distance to the airport
1750
	*
1751
	*/
1752
	public function getAirportDistance($airport_icao,$latitude,$longitude)
1753
	{
1754
		
1755
		$airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING);
1756
1757
		$query_values = array();
0 ignored issues
show
Unused Code introduced by
$query_values is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1758
1759
		$query  = "SELECT airport.latitude, airport.longitude FROM airport WHERE airport.icao = :airport LIMIT 1";
1760
		$query_values = array(':airport' => $airport_icao);
1761
		$sth = $this->db->prepare($query);
1762
		$sth->execute($query_values);
1763
		$row = $sth->fetch(PDO::FETCH_ASSOC);
1764
		if (count($row) > 0) {
1765
			$airport_latitude = $row['latitude'];
1766
			$airport_longitude = $row['longitude'];
1767
			$Common = new Common();
1768
			return $Common->distance($latitude,$longitude,$airport_latitude,$airport_longitude);
1769
		} else return '';
1770
	}
1771
	
1772
	/**
1773
	* Gets the airport info based on the icao
1774
	*
1775
	* @param String $airport_iata the icao code of the airport
0 ignored issues
show
Documentation introduced by
There is no parameter named $airport_iata. Did you maybe mean $airport?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
1776
	* @return Array airport information
1777
	*
1778
	*/
1779
	public function getAllAirportInfo($airport = '')
1780
	{
1781
		
1782
		$airport = filter_var($airport,FILTER_SANITIZE_STRING);
1783
1784
		$query_values = array();
1785
		if ($airport == 'NA') {
1786
			return array(array('name' => 'Not available','city' => 'N/A', 'country' => 'N/A','iata' => 'NA','icao' => 'NA','altitude' => NULL,'latitude' => 0,'longitude' => 0,'type' => 'NA','home_link' => '','wikipedia_link' => '','image_thumb' => '', 'image' => ''));
1787
		} elseif ($airport == '') {
1788
			$query  = "SELECT airport.name, airport.city, airport.country, airport.iata, airport.icao, airport.latitude, airport.longitude, airport.altitude, airport.type, airport.home_link, airport.wikipedia_link, airport.image_thumb, airport.image FROM airport";
1789
		} else {
1790
			$query  = "SELECT airport.name, airport.city, airport.country, airport.iata, airport.icao, airport.latitude, airport.longitude, airport.altitude, airport.type, airport.home_link, airport.wikipedia_link, airport.image_thumb, airport.image FROM airport WHERE airport.icao = :airport LIMIT 1";
1791
			$query_values = array(':airport' => $airport);
1792
		}
1793
		
1794
		$sth = $this->db->prepare($query);
1795
		$sth->execute($query_values);
1796
		/*
1797
		$airport_array = array();
1798
		$temp_array = array();
1799
		
1800
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1801
		{
1802
			$temp_array['name'] = $row['name'];
1803
			$temp_array['city'] = $row['city'];
1804
			$temp_array['country'] = $row['country'];
1805
			$temp_array['iata'] = $row['iata'];
1806
			$temp_array['icao'] = $row['icao'];
1807
			$temp_array['latitude'] = $row['latitude'];
1808
			$temp_array['longitude'] = $row['longitude'];
1809
			$temp_array['altitude'] = $row['altitude'];
1810
			$temp_array['home_link'] = $row['home_link'];
1811
			$temp_array['wikipedia_link'] = $row['wikipedia_link'];
1812
			$temp_array['image'] = $row['image'];
1813
			$temp_array['image_thumb'] = $row['image_thumb'];
1814
1815
			$airport_array[] = $temp_array;
1816
		}
1817
1818
		return $airport_array;
1819
		*/
1820
		return $sth->fetchAll(PDO::FETCH_ASSOC);
1821
	}
1822
	
1823
	/**
1824
	* Gets the airport info based on the country
1825
	*
1826
	* @param Array $countries Airports countries
1827
	* @return Array airport information
1828
	*
1829
	*/
1830
	public function getAllAirportInfobyCountry($countries)
1831
	{
1832
		$lst_countries = '';
1833
		foreach ($countries as $country) {
1834
			$country = filter_var($country,FILTER_SANITIZE_STRING);
1835
			if ($lst_countries == '') {
1836
				$lst_countries = "'".$country."'";
1837
			} else {
1838
				$lst_countries .= ",'".$country."'";
1839
			}
1840
		}
1841
		$query  = "SELECT airport.* FROM airport WHERE airport.country IN (".$lst_countries.")";
1842
		
1843
		$sth = $this->db->prepare($query);
1844
		$sth->execute();
1845
    
1846
		$airport_array = array();
1847
		$temp_array = array();
1848
		
1849
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1850
		{
1851
			$temp_array['name'] = $row['name'];
1852
			$temp_array['city'] = $row['city'];
1853
			$temp_array['country'] = $row['country'];
1854
			$temp_array['iata'] = $row['iata'];
1855
			$temp_array['icao'] = $row['icao'];
1856
			$temp_array['latitude'] = $row['latitude'];
1857
			$temp_array['longitude'] = $row['longitude'];
1858
			$temp_array['altitude'] = $row['altitude'];
1859
1860
			$airport_array[] = $temp_array;
1861
		}
1862
1863
		return $airport_array;
1864
	}
1865
	
1866
	/**
1867
	* Gets airports info based on the coord
1868
	*
1869
	* @param Array $coord Airports longitude min,latitude min, longitude max, latitude max
1870
	* @return Array airport information
1871
	*
1872
	*/
1873
	public function getAllAirportInfobyCoord($coord)
1874
	{
1875
		global $globalDBdriver;
1876
		$lst_countries = '';
0 ignored issues
show
Unused Code introduced by
$lst_countries is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1877
		if (is_array($coord)) {
1878
			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1879
			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1880
			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1881
			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1882
		}
1883
		if ($globalDBdriver == 'mysql') {
1884
			$query  = "SELECT airport.* FROM airport WHERE airport.latitude BETWEEN ".$minlat." AND ".$maxlat." AND airport.longitude BETWEEN ".$minlong." AND ".$maxlong." AND airport.type != 'closed'";
0 ignored issues
show
Bug introduced by
The variable $minlat does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $maxlat does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $minlong does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $maxlong does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1885
		} else {
1886
			$query  = "SELECT airport.* FROM airport WHERE CAST(airport.latitude AS FLOAT) BETWEEN ".$minlat." AND ".$maxlat." AND CAST(airport.longitude AS FLOAT) BETWEEN ".$minlong." AND ".$maxlong." AND airport.type != 'closed'";
1887
		}
1888
		$sth = $this->db->prepare($query);
1889
		$sth->execute();
1890
    
1891
		$airport_array = array();
1892
		$temp_array = array();
0 ignored issues
show
Unused Code introduced by
$temp_array is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1893
		
1894
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1895
		{
1896
			$temp_array = $row;
1897
1898
			$airport_array[] = $temp_array;
1899
		}
1900
1901
		return $airport_array;
1902
	}
1903
1904
	/**
1905
	* Gets waypoints info based on the coord
1906
	*
1907
	* @param Array $coord waypoints coord
1908
	* @return Array airport information
1909
	*
1910
	*/
1911
	public function getAllWaypointsInfobyCoord($coord)
1912
	{
1913
		$lst_countries = '';
0 ignored issues
show
Unused Code introduced by
$lst_countries is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1914
		if (is_array($coord)) {
1915
			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1916
			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1917
			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1918
			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1919
		}
1920
		//$query  = "SELECT waypoints.* FROM waypoints WHERE waypoints.latitude_begin BETWEEN ".$minlat." AND ".$maxlat." AND waypoints.longitude_begin BETWEEN ".$minlong." AND ".$maxlong;
1921
		$query  = "SELECT waypoints.* FROM waypoints WHERE (waypoints.latitude_begin BETWEEN ".$minlat." AND ".$maxlat." AND waypoints.longitude_begin BETWEEN ".$minlong." AND ".$maxlong.") OR (waypoints.latitude_end BETWEEN ".$minlat." AND ".$maxlat." AND waypoints.longitude_end BETWEEN ".$minlong." AND ".$maxlong.")";
0 ignored issues
show
Bug introduced by
The variable $minlat does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $maxlat does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $minlong does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $maxlong does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1922
		//$query  = "SELECT waypoints.* FROM waypoints";
1923
		//$query  = "SELECT waypoints.* FROM waypoints INNER JOIN (SELECT waypoints.* FROM waypoints WHERE waypoints.latitude_begin BETWEEN ".$minlat." AND ".$maxlat." AND waypoints.longitude_begin BETWEEN ".$minlong." AND ".$maxlong.") w ON w.name_end = waypoints.name_begin OR w.name_begin = waypoints.name_begin OR w.name_begin = waypoints.name_end OR w.name_end = waypoints.name_end";
1924
		//$query = "SELECT * FROM waypoints LEFT JOIN waypoints w ON waypoints.name_end = w.name_begin WHERE waypoints.latitude_begin BETWEEN ".$minlat." AND ".$maxlat." AND waypoints.longitude_begin BETWEEN ".$minlong." AND ".$maxlong;
1925
		//$query = "SELECT z.name_begin as name_begin, z.name_end as name_end, z.latitude_begin as latitude_begin, z.longitude_begin as longitude_begin, z.latitude_end as latitude_end, z.longitude_end as longitude_end, z.segment_name as segment_name, w.name_end as name_end_seg2, w.latitude_end as latitude_end_seg2, w.longitude_end as longitude_end_seg2, w.segment_name as segment_name_seg2 FROM waypoints z INNER JOIN waypoints w ON z.name_end = w.name_begin WHERE z.latitude_begin BETWEEN ".$minlat." AND ".$maxlat." AND z.longitude_begin BETWEEN ".$minlong." AND ".$maxlong;
1926
		//echo $query;
1927
		
1928
		$sth = $this->db->prepare($query);
1929
		$sth->execute();
1930
    
1931
		$waypoints_array = array();
1932
		$temp_array = array();
0 ignored issues
show
Unused Code introduced by
$temp_array is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1933
		
1934
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1935
		{
1936
			$temp_array = $row;
1937
1938
			$waypoints_array[] = $temp_array;
1939
		}
1940
1941
		return $waypoints_array;
1942
	}
1943
	
1944
	
1945
	/**
1946
	* Gets the airline info based on the icao code or iata code
1947
	*
1948
	* @param String $airline_icao the iata code of the airport
1949
	* @return Array airport information
1950
	*
1951
	*/
1952
	public function getAllAirlineInfo($airline_icao)
1953
	{
1954
		$airline_icao = strtoupper(filter_var($airline_icao,FILTER_SANITIZE_STRING));
1955
		if ($airline_icao == 'NA') {
1956
			$airline_array[] = array('name' => 'Not Available','iata' => 'NA', 'icao' => 'NA', 'callsign' => '', 'country' => 'NA', 'type' =>'');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$airline_array was never initialized. Although not strictly required by PHP, it is generally a good practice to add $airline_array = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1957
			return $airline_array;
1958
		} else {
1959
			if (strlen($airline_icao) == 2) {
1960
				$query  = "SELECT airlines.name, airlines.iata, airlines.icao, airlines.callsign, airlines.country, airlines.type FROM airlines WHERE airlines.iata = :airline_icao AND airlines.active = 'Y' LIMIT 1";
1961
			} else {
1962
				$query  = "SELECT airlines.name, airlines.iata, airlines.icao, airlines.callsign, airlines.country, airlines.type FROM airlines WHERE airlines.icao = :airline_icao AND airlines.active = 'Y' LIMIT 1";
1963
			}
1964
			
1965
			$sth = $this->db->prepare($query);
1966
			$sth->execute(array(':airline_icao' => $airline_icao));
1967
                        /*
1968
			$airline_array = array();
1969
			$temp_array = array();
1970
		
1971
			while($row = $sth->fetch(PDO::FETCH_ASSOC))
1972
			{
1973
				$temp_array['name'] = $row['name'];
1974
				$temp_array['iata'] = $row['iata'];
1975
				$temp_array['icao'] = $row['icao'];
1976
				$temp_array['callsign'] = $row['callsign'];
1977
				$temp_array['country'] = $row['country'];
1978
				$temp_array['type'] = $row['type'];
1979
				$airline_array[] = $temp_array;
1980
			}
1981
			return $airline_array;
1982
			*/
1983
			return $sth->fetchAll(PDO::FETCH_ASSOC);
1984
		}
1985
	}
1986
	
1987
	
1988
	
1989
	/**
1990
	* Gets the aircraft info based on the aircraft type
1991
	*
1992
	* @param String $aircraft_type the aircraft type
1993
	* @return Array aircraft information
1994
	*
1995
	*/
1996
	public function getAllAircraftInfo($aircraft_type)
1997
	{
1998
		$aircraft_type = filter_var($aircraft_type,FILTER_SANITIZE_STRING);
1999
2000
		if ($aircraft_type == 'NA') {
2001
			return array(array('icao' => 'NA','type' => 'Not Available', 'manufacturer' => 'Not Available', 'aircraft_shadow' => NULL));
2002
		}
2003
		$query  = "SELECT aircraft.icao, aircraft.type,aircraft.manufacturer,aircraft.aircraft_shadow FROM aircraft WHERE aircraft.icao = :aircraft_type";
2004
		
2005
		$sth = $this->db->prepare($query);
2006
		$sth->execute(array(':aircraft_type' => $aircraft_type));
2007
		/*
2008
		$aircraft_array = array();
2009
		$temp_array = array();
2010
		
2011
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2012
		{
2013
			$temp_array = array();
2014
			$temp_array['icao'] = $row['icao'];
2015
			$temp_array['type'] = $row['type'];
2016
			$temp_array['manufacturer'] = $row['manufacturer'];
2017
			$temp_array['aircraft_shadow'] = $row['aircraft_shadow'];
2018
2019
			$aircraft_array[] = $temp_array;
2020
		}
2021
		return $aircraft_array;
2022
		*/
2023
		return $sth->fetchAll(PDO::FETCH_ASSOC);
2024
	}
2025
2026
	/**
2027
	* Gets the aircraft icao based on the aircraft name/type
2028
	*
2029
	* @param String $aircraft_type the aircraft type
2030
	* @return Array aircraft information
2031
	*
2032
	*/
2033
	public function getAircraftIcao($aircraft_type)
2034
	{
2035
		$aircraft_type = filter_var($aircraft_type,FILTER_SANITIZE_STRING);
2036
		$all_aircraft = array('737-300' => 'B733',
2037
				'777-200' => 'B772',
2038
				'777-200ER' => 'B772',
2039
				'777-300ER' => 'B77W',
2040
				'c172p' => 'C172',
2041
				'aerostar' => 'AEST',
2042
				'A320-211' => 'A320',
2043
				'747-8i' => 'B748',
2044
				'A380' => 'A388');
2045
		if (isset($all_aircraft[$aircraft_type])) return $all_aircraft[$aircraft_type];
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $all_aircraft[$aircraft_type]; (string) is incompatible with the return type documented by Spotter::getAircraftIcao of type array.

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:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
2046
2047
		$query  = "SELECT aircraft.icao FROM aircraft WHERE aircraft.type LIKE :saircraft_type OR aircraft.type = :aircraft_type OR aircraft.icao = :aircraft_type LIMIT 1";
2048
		$aircraft_type = strtoupper($aircraft_type);
2049
		$sth = $this->db->prepare($query);
2050
		$sth->execute(array(':saircraft_type' => '%'.$aircraft_type.'%',':aircraft_type' => $aircraft_type,));
2051
		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
2052
		if (isset($result[0]['icao'])) return $result[0]['icao'];
2053
		else return '';
0 ignored issues
show
Bug Best Practice introduced by
The return type of return ''; (string) is incompatible with the return type documented by Spotter::getAircraftIcao of type array.

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:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
2054
	}
2055
	
2056
	/**
2057
	* Gets the aircraft info based on the aircraft ident
2058
	*
2059
	* @param String $aircraft_ident the aircraft ident (hex)
0 ignored issues
show
Bug introduced by
There is no parameter named $aircraft_ident. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2060
	* @return String aircraft type
2061
	*
2062
	*/
2063
	public function getAllAircraftType($aircraft_modes)
2064
	{
2065
		$aircraft_modes = filter_var($aircraft_modes,FILTER_SANITIZE_STRING);
2066
2067
		$query  = "SELECT aircraft_modes.ICAOTypeCode FROM aircraft_modes WHERE aircraft_modes.ModeS = :aircraft_modes LIMIT 1";
2068
		
2069
		$sth = $this->db->prepare($query);
2070
		$sth->execute(array(':aircraft_modes' => $aircraft_modes));
2071
2072
		$row = $sth->fetch(PDO::FETCH_ASSOC);
2073
		if (isset($row['icaotypecode'])) {
2074
			return $row['icaotypecode'];
2075
		} else return '';
2076
	}
2077
2078
	/**
2079
	* Gets correct aircraft operator corde
2080
	*
2081
	* @param String $operator the aircraft operator code (callsign)
2082
	* @return String aircraft operator code
2083
	*
2084
	*/
2085
	public function getOperator($operator)
2086
	{
2087
		$operator = filter_var($operator,FILTER_SANITIZE_STRING);
2088
		$query  = "SELECT translation.operator_correct FROM translation WHERE translation.operator = :operator LIMIT 1";
2089
		
2090
		$sth = $this->db->prepare($query);
2091
		$sth->execute(array(':operator' => $operator));
2092
2093
		$row = $sth->fetch(PDO::FETCH_ASSOC);
2094
		if (isset($row['operator_correct'])) {
2095
			return $row['operator_correct'];
2096
		} else return $operator;
2097
	}
2098
2099
	/**
2100
	* Gets the aircraft route based on the aircraft callsign
2101
	*
2102
	* @param String $callsign the aircraft callsign
2103
	* @return Array aircraft type
2104
	*
2105
	*/
2106
	public function getRouteInfo($callsign)
2107
	{
2108
		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
2109
                if ($callsign == '') return array();
2110
		$query  = "SELECT routes.Operator_ICAO, routes.FromAirport_ICAO, routes.ToAirport_ICAO, routes.RouteStop, routes.FromAirport_Time, routes.ToAirport_Time FROM routes WHERE CallSign = :callsign LIMIT 1";
2111
		
2112
		$sth = $this->db->prepare($query);
2113
		$sth->execute(array(':callsign' => $callsign));
2114
2115
		$row = $sth->fetch(PDO::FETCH_ASSOC);
2116
		if (count($row) > 0) {
2117
			return $row;
2118
		} else return array();
2119
	}
2120
	
2121
	/**
2122
	* Gets the aircraft info based on the aircraft registration
2123
	*
2124
	* @param String $aircraft_registration the aircraft registration
0 ignored issues
show
Documentation introduced by
There is no parameter named $aircraft_registration. Did you maybe mean $registration?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
2125
	* @return Array aircraft information
2126
	*
2127
	*/
2128
	public function getAircraftInfoByRegistration($registration)
2129
	{
2130
		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
2131
2132
		$query  = "SELECT spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.aircraft_manufacturer, spotter_output.airline_icao FROM spotter_output WHERE spotter_output.registration = :registration";
2133
		
2134
		$sth = $this->db->prepare($query);
2135
		$sth->execute(array(':registration' => $registration));
2136
2137
		$aircraft_array = array();
2138
		$temp_array = array();
2139
		
2140
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2141
		{
2142
			$temp_array['airline_icao'] = $row['airline_icao'];
2143
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
2144
			$temp_array['aircraft_name'] = $row['aircraft_name'];
2145
			$temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer'];
2146
2147
			$aircraft_array[] = $temp_array;
2148
		}
2149
2150
		return $aircraft_array;
2151
	}
2152
	
2153
	/**
2154
	* Gets the aircraft owner & base based on the aircraft registration
2155
	*
2156
	* @param String $aircraft_registration the aircraft registration
0 ignored issues
show
Documentation introduced by
There is no parameter named $aircraft_registration. Did you maybe mean $registration?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
2157
	* @return Array aircraft information
2158
	*
2159
	*/
2160
	public function getAircraftOwnerByRegistration($registration)
2161
	{
2162
		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
2163
		$Connection = new Connection($this->db);
2164
		if ($Connection->tableExists('aircraft_owner')) {
2165
			$query  = "SELECT aircraft_owner.base, aircraft_owner.owner, aircraft_owner.date_first_reg FROM aircraft_owner WHERE registration = :registration LIMIT 1";
2166
			$sth = $this->db->prepare($query);
2167
			$sth->execute(array(':registration' => $registration));
2168
2169
			return $sth->fetch(PDO::FETCH_ASSOC);
2170
		} else return array();
2171
	}
2172
	
2173
  
2174
  /**
2175
	* Gets all flights (but with only little info)
2176
	*
2177
	* @return Array basic flight information
2178
	*
2179
	*/
2180
	public function getAllFlightsforSitemap()
2181
	{
2182
		//$query  = "SELECT spotter_output.spotter_id, spotter_output.ident, spotter_output.airline_name, spotter_output.aircraft_name, spotter_output.aircraft_icao FROM spotter_output ORDER BY LIMIT ";
2183
		$query  = "SELECT spotter_output.spotter_id FROM spotter_output ORDER BY spotter_id DESC LIMIT 200 OFFSET 0";
2184
		
2185
		$sth = $this->db->prepare($query);
2186
		$sth->execute();
2187
                  /*
2188
		$flight_array = array();
2189
		$temp_array = array();
2190
		
2191
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2192
		{
2193
			$temp_array['spotter_id'] = $row['spotter_id'];
2194
//			$temp_array['ident'] = $row['ident'];
2195
//			$temp_array['airline_name'] = $row['airline_name'];
2196
//			$temp_array['aircraft_type'] = $row['aircraft_icao'];
2197
//			$temp_array['aircraft_name'] = $row['aircraft_name'];
2198
			//$temp_array['image'] = $row['image'];
2199
2200
			$flight_array[] = $temp_array;
2201
		}
2202
2203
		return $flight_array;
2204
		*/
2205
		return $sth->fetchAll(PDO::FETCH_ASSOC);
2206
	}
2207
  
2208
	/**
2209
	* Gets a list of all aircraft manufacturers
2210
	*
2211
	* @return Array list of aircraft types
2212
	*
2213
	*/
2214
	public function getAllManufacturers()
2215
	{
2216
		/*
2217
		$query  = "SELECT DISTINCT spotter_output.aircraft_manufacturer AS aircraft_manufacturer
2218
								FROM spotter_output
2219
								WHERE spotter_output.aircraft_manufacturer <> '' 
2220
								ORDER BY spotter_output.aircraft_manufacturer ASC";
2221
		  */
2222
		
2223
		$query = "SELECT DISTINCT manufacturer AS aircraft_manufacturer FROM aircraft WHERE manufacturer <> '' ORDER BY manufacturer ASC";
2224
		$sth = $this->db->prepare($query);
2225
		$sth->execute();
2226
2227
		$manufacturer_array = array();
2228
		$temp_array = array();
2229
		
2230
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2231
		{
2232
			$temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer'];
2233
2234
			$manufacturer_array[] = $temp_array;
2235
		}
2236
2237
		return $manufacturer_array;
2238
	}
2239
  
2240
  
2241
  /**
2242
	* Gets a list of all aircraft types
2243
	*
2244
	* @return Array list of aircraft types
2245
	*
2246
	*/
2247
	public function getAllAircraftTypes()
2248
	{
2249
		/*
2250
		$query  = "SELECT DISTINCT spotter_output.aircraft_icao AS aircraft_icao, spotter_output.aircraft_name AS aircraft_name
2251
								FROM spotter_output  
2252
								WHERE spotter_output.aircraft_icao <> '' 
2253
								ORDER BY spotter_output.aircraft_name ASC";
2254
								
2255
		*/
2256
		$query = "SELECT DISTINCT icao AS aircraft_icao, type AS aircraft_name, manufacturer AS aircraft_manufacturer FROM aircraft WHERE icao <> '' ORDER BY aircraft_name ASC";
2257
		
2258
		$sth = $this->db->prepare($query);
2259
		$sth->execute();
2260
2261
		$aircraft_array = array();
2262
		$temp_array = array();
2263
		
2264
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2265
		{
2266
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
2267
			$temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer'];
2268
			$temp_array['aircraft_name'] = $row['aircraft_name'];
2269
2270
			$aircraft_array[] = $temp_array;
2271
		}
2272
2273
		return $aircraft_array;
2274
	}
2275
	
2276
	
2277
	/**
2278
	* Gets a list of all aircraft registrations
2279
	*
2280
	* @return Array list of aircraft registrations
2281
	*
2282
	*/
2283
	public function getAllAircraftRegistrations()
2284
	{
2285
		$query  = "SELECT DISTINCT spotter_output.registration 
2286
				FROM spotter_output  
2287
				WHERE spotter_output.registration <> '' 
2288
				ORDER BY spotter_output.registration ASC";
2289
2290
		$sth = $this->db->prepare($query);
2291
		$sth->execute();
2292
2293
		$aircraft_array = array();
2294
		$temp_array = array();
2295
		
2296
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2297
		{
2298
			$temp_array['registration'] = $row['registration'];
2299
2300
			$aircraft_array[] = $temp_array;
2301
		}
2302
2303
		return $aircraft_array;
2304
	}
2305
2306
	/**
2307
	* Gets all source name
2308
	*
2309
	* @param String type format of source
2310
	* @return Array list of source name
2311
	*
2312
	*/
2313
	public function getAllSourceName($type = '')
2314
	{
2315
		$query_values = array();
2316
		$query  = "SELECT DISTINCT spotter_output.source_name 
2317
				FROM spotter_output  
2318
				WHERE spotter_output.source_name <> ''";
2319
		if ($type != '') {
2320
			$query_values = array(':type' => $type);
2321
			$query .= " AND format_source = :type";
2322
		}
2323
		$query .= " ORDER BY spotter_output.source_name ASC";
2324
2325
		$sth = $this->db->prepare($query);
2326
		if (!empty($query_values)) $sth->execute($query_values);
2327
		else $sth->execute();
2328
2329
		$source_array = array();
2330
		$temp_array = array();
2331
		
2332
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2333
		{
2334
			$temp_array['source_name'] = $row['source_name'];
2335
			$source_array[] = $temp_array;
2336
		}
2337
		return $source_array;
2338
	}
2339
2340
2341
2342
	/**
2343
	* Gets a list of all airline names
2344
	*
2345
	* @return Array list of airline names
2346
	*
2347
	*/
2348
	public function getAllAirlineNames($airline_type = '')
2349
	{
2350
		$airline_type = filter_var($airline_type,FILTER_SANITIZE_STRING);
2351
		if ($airline_type == '' || $airline_type == 'all') {
2352
			/*
2353
			$query  = "SELECT DISTINCT spotter_output.airline_icao AS airline_icao, spotter_output.airline_name AS airline_name, spotter_output.airline_type AS airline_type
2354
								FROM spotter_output
2355
								WHERE spotter_output.airline_icao <> '' 
2356
								ORDER BY spotter_output.airline_name ASC";
2357
			*/
2358
			$query = "SELECT DISTINCT icao AS airline_icao, name AS airline_name, type AS airline_type FROM airlines ORDER BY name ASC";
2359
		} else {
2360
			$query  = "SELECT DISTINCT spotter_output.airline_icao AS airline_icao, spotter_output.airline_name AS airline_name, spotter_output.airline_type AS airline_type
2361
					FROM spotter_output
2362
					WHERE spotter_output.airline_icao <> '' 
2363
					AND spotter_output.airline_type = :airline_type 
2364
					ORDER BY spotter_output.airline_icao ASC";
2365
		}
2366
		
2367
		$sth = $this->db->prepare($query);
2368
		if ($airline_type != '' || $airline_type == 'all') {
2369
			$sth->execute(array(':airline_type' => $airline_type));
2370
		} else {
2371
			$sth->execute();
2372
		}
2373
    
2374
		$airline_array = array();
2375
		$temp_array = array();
2376
		
2377
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2378
		{
2379
			$temp_array['airline_icao'] = $row['airline_icao'];
2380
			$temp_array['airline_name'] = $row['airline_name'];
2381
			$temp_array['airline_type'] = $row['airline_type'];
2382
2383
			$airline_array[] = $temp_array;
2384
		}
2385
		return $airline_array;
2386
	}
2387
	
2388
	
2389
	/**
2390
	* Gets a list of all airline countries
2391
	*
2392
	* @return Array list of airline countries
2393
	*
2394
	*/
2395
	public function getAllAirlineCountries()
2396
	{
2397
		
2398
		$query  = "SELECT DISTINCT spotter_output.airline_country AS airline_country
2399
				FROM spotter_output  
2400
				WHERE spotter_output.airline_country <> '' 
2401
				ORDER BY spotter_output.airline_country ASC";
2402
		
2403
		//$query = "SELECT DISTINCT country AS airline_country FROM airlines WHERE country <> '' AND active = 'Y' ORDER BY country ASC";
2404
		$sth = $this->db->prepare($query);
2405
		$sth->execute();
2406
2407
		$airline_array = array();
2408
		$temp_array = array();
2409
		
2410
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2411
		{
2412
			$temp_array['airline_country'] = $row['airline_country'];
2413
2414
			$airline_array[] = $temp_array;
2415
		}
2416
2417
		return $airline_array;
2418
	}
2419
2420
	
2421
	
2422
	/**
2423
	* Gets a list of all departure & arrival names
2424
	*
2425
	* @return Array list of airport names
2426
	*
2427
	*/
2428
	public function getAllAirportNames()
2429
	{
2430
		$airport_array = array();
2431
2432
		$query  = "SELECT DISTINCT spotter_output.departure_airport_icao AS airport_icao, spotter_output.departure_airport_name AS airport_name, spotter_output.departure_airport_city AS airport_city, spotter_output.departure_airport_country AS airport_country
2433
				FROM spotter_output 
2434
				WHERE spotter_output.departure_airport_icao <> '' AND spotter_output.departure_airport_icao <> 'NA' 
2435
				ORDER BY spotter_output.departure_airport_city ASC";
2436
		
2437
		//$query = "SELECT DISTINCT icao AS airport_icao, name AS airport_name, city AS airport_city, country AS airport_country FROM airport ORDER BY city ASC";
2438
		$sth = $this->db->prepare($query);
2439
		$sth->execute();
2440
2441
		$temp_array = array();
2442
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2443
		{
2444
			$temp_array['airport_icao'] = $row['airport_icao'];
2445
			$temp_array['airport_name'] = $row['airport_name'];
2446
			$temp_array['airport_city'] = $row['airport_city'];
2447
			$temp_array['airport_country'] = $row['airport_country'];
2448
2449
			$airport_array[$row['airport_city'].",".$row['airport_name']] = $temp_array;
2450
		}
2451
2452
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_icao AS airport_icao, spotter_output.arrival_airport_name AS airport_name, spotter_output.arrival_airport_city AS airport_city, spotter_output.arrival_airport_country AS airport_country
2453
								FROM spotter_output 
2454
								WHERE spotter_output.arrival_airport_icao <> '' AND spotter_output.arrival_airport_icao <> 'NA' 
2455
								ORDER BY spotter_output.arrival_airport_city ASC";
2456
					
2457
		$sth = $this->db->prepare($query);
2458
		$sth->execute();
2459
2460
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2461
			{
2462
		//	if ($airport_array[$row['airport_city'].",".$row['airport_name']]['airport_icao'] != $row['airport_icao'])
2463
		//	{
2464
				$temp_array['airport_icao'] = $row['airport_icao'];
2465
				$temp_array['airport_name'] = $row['airport_name'];
2466
				$temp_array['airport_city'] = $row['airport_city'];
2467
				$temp_array['airport_country'] = $row['airport_country'];
2468
				
2469
				$airport_array[$row['airport_city'].",".$row['airport_name']] = $temp_array;
2470
		//	}
2471
		}
2472
2473
		return $airport_array;
2474
	} 
2475
	
2476
	
2477
	/**
2478
	* Gets a list of all departure & arrival airport countries
2479
	*
2480
	* @return Array list of airport countries
2481
	*
2482
	*/
2483
	public function getAllAirportCountries()
2484
	{
2485
		$airport_array = array();
2486
					
2487
		  /*
2488
		$query  = "SELECT DISTINCT spotter_output.departure_airport_country AS airport_country
2489
								FROM spotter_output
2490
								WHERE spotter_output.departure_airport_country <> '' 
2491
								ORDER BY spotter_output.departure_airport_country ASC";
2492
		*/
2493
		$query = "SELECT DISTINCT country AS airport_country FROM airport ORDER BY country ASC";
2494
		
2495
		$sth = $this->db->prepare($query);
2496
		$sth->execute();
2497
   
2498
		$temp_array = array();
2499
		
2500
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2501
		{
2502
			$temp_array['airport_country'] = $row['airport_country'];
2503
2504
			$airport_array[$row['airport_country']] = $temp_array;
2505
		}
2506
								
2507
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_country AS airport_country
2508
								FROM spotter_output
2509
								WHERE spotter_output.arrival_airport_country <> '' 
2510
								ORDER BY spotter_output.arrival_airport_country ASC";
2511
					
2512
		$sth = $this->db->prepare($query);
2513
		$sth->execute();
2514
		
2515
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2516
		{
2517
			if (isset($airport_array[$row['airport_country']]['airport_country']) && $airport_array[$row['airport_country']]['airport_country'] != $row['airport_country'])
2518
			{
2519
				$temp_array['airport_country'] = $row['airport_country'];
2520
				
2521
				$airport_array[$row['airport_country']] = $temp_array;
2522
			}
2523
		}
2524
2525
		return $airport_array;
2526
	} 
2527
	
2528
	
2529
	
2530
	
2531
	/**
2532
	* Gets a list of all countries (airline, departure airport & arrival airport)
2533
	*
2534
	* @return Array list of countries
2535
	*
2536
	*/
2537
	public function getAllCountries()
2538
	{
2539
		$Connection= new Connection($this->db);
2540
		if ($Connection->tableExists('countries')) {
2541
		
2542
		$country_array = array();
2543
					
2544
		$query  = "SELECT countries.name AS airport_country
2545
				FROM countries
2546
				ORDER BY countries.name ASC";
2547
		$sth = $this->db->prepare($query);
2548
		$sth->execute();
2549
   
2550
		$temp_array = array();
2551
		
2552
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2553
		{
2554
			$temp_array['country'] = $row['airport_country'];
2555
2556
			$country_array[$row['airport_country']] = $temp_array;
2557
		}
2558
		} else {
2559
2560
		$query  = "SELECT DISTINCT spotter_output.departure_airport_country AS airport_country
2561
								FROM spotter_output
2562
								WHERE spotter_output.departure_airport_country <> '' 
2563
								ORDER BY spotter_output.departure_airport_country ASC";
2564
		
2565
		$sth = $this->db->prepare($query);
2566
		$sth->execute();
2567
   
2568
		$temp_array = array();
2569
		
2570
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2571
		{
2572
			$temp_array['country'] = $row['airport_country'];
2573
2574
			$country_array[$row['airport_country']] = $temp_array;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$country_array was never initialized. Although not strictly required by PHP, it is generally a good practice to add $country_array = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2575
		}
2576
								
2577
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_country AS airport_country
2578
								FROM spotter_output
2579
								WHERE spotter_output.arrival_airport_country <> '' 
2580
								ORDER BY spotter_output.arrival_airport_country ASC";
2581
					
2582
		$sth = $this->db->prepare($query);
2583
		$sth->execute();
2584
		
2585
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2586
		{
2587
			if ($country_array[$row['airport_country']]['country'] != $row['airport_country'])
2588
			{
2589
				$temp_array['country'] = $row['airport_country'];
2590
				
2591
				$country_array[$row['country']] = $temp_array;
0 ignored issues
show
Bug introduced by
The variable $country_array does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2592
			}
2593
		}
2594
		
2595
		$query  = "SELECT DISTINCT spotter_output.airline_country AS airline_country
2596
								FROM spotter_output  
2597
								WHERE spotter_output.airline_country <> '' 
2598
								ORDER BY spotter_output.airline_country ASC";
2599
					
2600
		$sth = $this->db->prepare($query);
2601
		$sth->execute();
2602
		
2603
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2604
		{
2605
			if (isset($country_array[$row['airline_country']]['country']) && $country_array[$row['airline_country']]['country'] != $row['airline_country'])
2606
			{
2607
				$temp_array['country'] = $row['airline_country'];
2608
				
2609
				$country_array[$row['country']] = $temp_array;
2610
			}
2611
		}
2612
		}  
2613
		return $country_array;
2614
	} 
2615
	
2616
	
2617
	
2618
	
2619
	/**
2620
	* Gets a list of all idents/callsigns
2621
	*
2622
	* @return Array list of ident/callsign names
2623
	*
2624
	*/
2625
	public function getAllIdents()
2626
	{
2627
		$query  = "SELECT DISTINCT spotter_output.ident
2628
								FROM spotter_output
2629
								WHERE spotter_output.ident <> '' 
2630
								ORDER BY spotter_output.date ASC LIMIT 700 OFFSET 0";
2631
2632
		$sth = $this->db->prepare($query);
2633
		$sth->execute();
2634
    
2635
		$ident_array = array();
2636
		$temp_array = array();
2637
		
2638
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2639
		{
2640
			$temp_array['ident'] = $row['ident'];
2641
			$ident_array[] = $temp_array;
2642
		}
2643
2644
		return $ident_array;
2645
	}
2646
2647
	/**
2648
	* Get a list of flights from airport since 7 days
2649
	* @return Array number, icao, name and city of airports
2650
	*/
2651
2652
	public function getLast7DaysAirportsDeparture($airport_icao = '') {
2653
		global $globalTimezone, $globalDBdriver;
2654
		if ($globalTimezone != '') {
2655
			date_default_timezone_set($globalTimezone);
2656
			$datetime = new DateTime();
2657
			$offset = $datetime->format('P');
2658
		} else $offset = '+00:00';
2659
		if ($airport_icao == '') {
2660
			if ($globalDBdriver == 'mysql') {
2661
				$query = "SELECT COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output` WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND departure_airport_icao <> 'NA' GROUP BY departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC";
2662
			} else {
2663
				$query = "SELECT COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND departure_airport_icao <> 'NA' GROUP BY departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC";
2664
			}
2665
			$sth = $this->db->prepare($query);
2666
			$sth->execute(array(':offset' => $offset));
2667
		} else {
2668
			if ($globalDBdriver == 'mysql') {
2669
				$query = "SELECT COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output` WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND departure_airport_icao = :airport_icao GROUP BY departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC";
2670
			} else {
2671
				$query = "SELECT COUNT(departure_airport_icao) AS departure_airport_count, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND departure_airport_icao = :airport_icao GROUP BY departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), departure_airport_name, departure_airport_city, departure_airport_country ORDER BY departure_airport_count DESC";
2672
			}
2673
			$sth = $this->db->prepare($query);
2674
			$sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao));
2675
		}
2676
		return $sth->fetchAll(PDO::FETCH_ASSOC);
2677
	}
2678
2679
	/**
2680
	* Get a list of flights from detected airport since 7 days
2681
	* @return Array number, icao, name and city of airports
2682
	*/
2683
2684
	public function getLast7DaysDetectedAirportsDeparture($airport_icao = '') {
2685
		global $globalTimezone, $globalDBdriver;
2686
		if ($globalTimezone != '') {
2687
			date_default_timezone_set($globalTimezone);
2688
			$datetime = new DateTime();
2689
			$offset = $datetime->format('P');
2690
		} else $offset = '+00:00';
2691
		if ($airport_icao == '') {
2692
			if ($globalDBdriver == 'mysql') {
2693
				$query = "SELECT COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date 
2694
				FROM `spotter_output`, airport 
2695
				WHERE airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND real_departure_airport_icao <> 'NA' 
2696
				GROUP BY real_departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC";
2697
			} else {
2698
				$query = "SELECT COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date 
2699
				FROM spotter_output, airport 
2700
				WHERE airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND real_departure_airport_icao <> 'NA' 
2701
				GROUP BY real_departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC";
2702
			}
2703
			$sth = $this->db->prepare($query);
2704
			$sth->execute(array(':offset' => $offset));
2705
		} else {
2706
			if ($globalDBdriver == 'mysql') {
2707
				$query = "SELECT COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date 
2708
				FROM `spotter_output`, airport 
2709
				WHERE airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND real_departure_airport_icao = :airport_icao 
2710
				GROUP BY departure_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC";
2711
			} else {
2712
				$query = "SELECT COUNT(real_departure_airport_icao) AS departure_airport_count, real_departure_airport_icao AS departure_airport_icao, airport.name AS departure_airport_name, airport.city AS departure_airport_city, airport.country AS departure_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date 
2713
				FROM spotter_output, airport 
2714
				WHERE airport.icao = spotter_output.real_departure_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND real_departure_airport_icao = :airport_icao GROUP BY departure_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY departure_airport_count DESC";
2715
			}
2716
			$sth = $this->db->prepare($query);
2717
			$sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao));
2718
		}
2719
		return $sth->fetchAll(PDO::FETCH_ASSOC);
2720
	}
2721
2722
	/**
2723
	* Get a list of flights to airport since 7 days
2724
	* @return Array number, icao, name and city of airports
2725
	*/
2726
2727
	public function getLast7DaysAirportsArrival($airport_icao = '') {
2728
		global $globalTimezone, $globalDBdriver;
2729
		if ($globalTimezone != '') {
2730
			date_default_timezone_set($globalTimezone);
2731
			$datetime = new DateTime();
2732
			$offset = $datetime->format('P');
2733
		} else $offset = '+00:00';
2734
		if ($airport_icao == '') {
2735
			if ($globalDBdriver == 'mysql') {
2736
				$query = "SELECT COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output` WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao <> 'NA' GROUP BY arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC";
2737
			} else {
2738
				$query = "SELECT COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao <> 'NA' GROUP BY arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC";
2739
			}
2740
			$sth = $this->db->prepare($query);
2741
			$sth->execute(array(':offset' => $offset));
2742
		} else {
2743
			if ($globalDBdriver == 'mysql') {
2744
				$query = "SELECT COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date FROM `spotter_output` WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao = :airport_icao GROUP BY arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'),arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC";
2745
			} else {
2746
				$query = "SELECT COUNT(arrival_airport_icao) AS arrival_airport_count, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date FROM spotter_output WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao = :airport_icao GROUP BY arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), arrival_airport_name, arrival_airport_city, arrival_airport_country ORDER BY arrival_airport_count DESC";
2747
			}
2748
			$sth = $this->db->prepare($query);
2749
			$sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao));
2750
		}
2751
		
2752
		return $sth->fetchAll(PDO::FETCH_ASSOC);
2753
	}
2754
2755
2756
	/**
2757
	* Get a list of flights detected to airport since 7 days
2758
	* @return Array number, icao, name and city of airports
2759
	*/
2760
2761
	public function getLast7DaysDetectedAirportsArrival($airport_icao = '') {
2762
		global $globalTimezone, $globalDBdriver;
2763
		if ($globalTimezone != '') {
2764
			date_default_timezone_set($globalTimezone);
2765
			$datetime = new DateTime();
2766
			$offset = $datetime->format('P');
2767
		} else $offset = '+00:00';
2768
		if ($airport_icao == '') {
2769
			if ($globalDBdriver == 'mysql') {
2770
				$query = "SELECT COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date 
2771
				FROM `spotter_output`, airport 
2772
				WHERE airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao <> 'NA' 
2773
				GROUP BY real_arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'), airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC";
2774
			} else {
2775
				$query = "SELECT COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date 
2776
				FROM spotter_output, airport 
2777
				WHERE airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao <> 'NA' 
2778
				GROUP BY real_arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC";
2779
			}
2780
			$sth = $this->db->prepare($query);
2781
			$sth->execute(array(':offset' => $offset));
2782
		} else {
2783
			if ($globalDBdriver == 'mysql') {
2784
				$query = "SELECT COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d') as date 
2785
				FROM `spotter_output`, airport 
2786
				WHERE airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 7 DAY) AND arrival_airport_icao = :airport_icao 
2787
				GROUP BY real_arrival_airport_icao, DATE_FORMAT(DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)),'%Y-%m-%d'),airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC";
2788
			} else {
2789
				$query = "SELECT COUNT(real_arrival_airport_icao) AS arrival_airport_count, real_arrival_airport_icao AS arrival_airport_icao, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date 
2790
				FROM spotter_output, airport 
2791
				WHERE airport.icao = spotter_output.real_arrival_airport_icao AND spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND arrival_airport_icao = :airport_icao 
2792
				GROUP BY real_arrival_airport_icao, to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd'), airport.name, airport.city, airport.country ORDER BY arrival_airport_count DESC";
2793
			}
2794
			$sth = $this->db->prepare($query);
2795
			$sth->execute(array(':offset' => $offset, ':airport_icao' => $airport_icao));
2796
		}
2797
		
2798
		return $sth->fetchAll(PDO::FETCH_ASSOC);
2799
	}
2800
2801
2802
	/**
2803
	* Gets a list of all dates
2804
	*
2805
	* @return Array list of date names
2806
	*
2807
	*/
2808
	public function getAllDates()
2809
	{
2810
		global $globalTimezone, $globalDBdriver;
2811
		if ($globalTimezone != '') {
2812
			date_default_timezone_set($globalTimezone);
2813
			$datetime = new DateTime();
2814
			$offset = $datetime->format('P');
2815
		} else $offset = '+00:00';
2816
2817
		if ($globalDBdriver == 'mysql') {
2818
			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) as date
2819
								FROM spotter_output
2820
								WHERE spotter_output.date <> '' 
2821
								ORDER BY spotter_output.date ASC LIMIT 0,200";
2822
		} else {
2823
			$query  = "SELECT DISTINCT to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
2824
								FROM spotter_output
2825
								WHERE spotter_output.date <> '' 
2826
								ORDER BY spotter_output.date ASC LIMIT 0,200";
2827
		}
2828
		
2829
		$sth = $this->db->prepare($query);
2830
		$sth->execute(array(':offset' => $offset));
2831
    
2832
		$date_array = array();
2833
		$temp_array = array();
2834
		
2835
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2836
		{
2837
			$temp_array['date'] = $row['date'];
2838
2839
			$date_array[] = $temp_array;
2840
		}
2841
2842
		return $date_array;
2843
	}
2844
	
2845
	
2846
	
2847
	/**
2848
	* Gets all route combinations
2849
	*
2850
	* @return Array the route list
2851
	*
2852
	*/
2853
	public function getAllRoutes()
2854
	{
2855
		$query  = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ',  spotter_output.arrival_airport_icao) AS route,  spotter_output.departure_airport_icao, spotter_output.arrival_airport_icao 
2856
				FROM spotter_output
2857
				WHERE spotter_output.ident <> '' 
2858
				GROUP BY route
2859
				ORDER BY route ASC";
2860
2861
		$sth = $this->db->prepare($query);
2862
		$sth->execute();
2863
2864
		$routes_array = array();
2865
		$temp_array = array();
2866
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2867
		{
2868
			$temp_array['route'] = $row['route'];
2869
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
2870
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
2871
2872
			$routes_array[] = $temp_array;
2873
		}
2874
		return $routes_array;
2875
	}
2876
2877
	/**
2878
	* Update ident spotter data
2879
	*
2880
	* @param String $flightaware_id the ID from flightaware
2881
	* @param String $ident the flight ident
2882
	* @return String success or false
2883
	*
2884
	*/	
2885
	public function updateIdentSpotterData($flightaware_id = '', $ident = '')
2886
	{
2887
		if (!is_numeric(substr($ident, 0, 3)))
2888
		{
2889
			if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) {
2890
				$airline_array = $this->getAllAirlineInfo(substr($ident, 0, 2));
2891
			} elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) {
2892
				$airline_array = $this->getAllAirlineInfo(substr($ident, 0, 3));
2893
			} else {
2894
				$airline_array = $this->getAllAirlineInfo("NA");
2895
			}
2896
			if (count($airline_array) == 0) {
2897
				$airline_array = $this->getAllAirlineInfo("NA");
2898
			}
2899
			if (!isset($airline_array[0]['icao']) || $airline_array[0]['icao'] == ""){
2900
				$airline_array = $this->getAllAirlineInfo("NA");
2901
			}
2902
		} else {
2903
			$airline_array = $this->getAllAirlineInfo("NA");
2904
		}
2905
                $airline_name = $airline_array[0]['name'];
2906
                $airline_icao = $airline_array[0]['icao'];
2907
                $airline_country = $airline_array[0]['country'];
2908
                $airline_type = $airline_array[0]['type'];
2909
2910
2911
		$query = 'UPDATE spotter_output SET ident = :ident, airline_name = :airline_name, airline_icao = :airline_icao, airline_country = :airline_country, airline_type = :airline_type WHERE flightaware_id = :flightaware_id';
2912
                $query_values = array(':flightaware_id' => $flightaware_id,':ident' => $ident,':airline_name' => $airline_name,':airline_icao' => $airline_icao,':airline_country' => $airline_country,':airline_type' => $airline_type);
2913
2914
		try {
2915
			$sth = $this->db->prepare($query);
2916
			$sth->execute($query_values);
2917
		} catch (PDOException $e) {
2918
			return "error : ".$e->getMessage();
2919
		}
2920
		
2921
		return "success";
2922
2923
	}
2924
	/**
2925
	* Update latest spotter data
2926
	*
2927
	* @param String $flightaware_id the ID from flightaware
2928
	* @param String $ident the flight ident
2929
	* @param String $aircraft_icao the aircraft type
0 ignored issues
show
Bug introduced by
There is no parameter named $aircraft_icao. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2930
	* @param String $departure_airport_icao the departure airport
0 ignored issues
show
Bug introduced by
There is no parameter named $departure_airport_icao. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2931
	* @param String $arrival_airport_icao the arrival airport
2932
	* @return String success or false
2933
	*
2934
	*/	
2935
	public function updateLatestSpotterData($flightaware_id = '', $ident = '', $latitude = '', $longitude = '', $altitude = '', $ground = false, $groundspeed = NULL, $date = '', $arrival_airport_icao = '',$arrival_airport_time = '')
2936
	{
2937
		if ($groundspeed == '') $groundspeed = NULL;
2938
		$query = 'UPDATE spotter_output SET ident = :ident, last_latitude = :last_latitude, last_longitude = :last_longitude, last_altitude = :last_altitude, last_ground = :last_ground, last_seen = :last_seen, real_arrival_airport_icao = :real_arrival_airport_icao, real_arrival_airport_time = :real_arrival_airport_time, last_ground_speed = :last_ground_speed WHERE flightaware_id = :flightaware_id';
2939
                $query_values = array(':flightaware_id' => $flightaware_id,':real_arrival_airport_icao' => $arrival_airport_icao,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_altitude' => $altitude,':last_ground_speed' => $groundspeed,':last_seen' => $date,':real_arrival_airport_time' => $arrival_airport_time, ':last_ground' => $ground, ':ident' => $ident);
2940
2941
		try {
2942
			$sth = $this->db->prepare($query);
2943
			$sth->execute($query_values);
2944
		} catch (PDOException $e) {
2945
			return "error : ".$e->getMessage();
2946
		}
2947
		
2948
		return "success";
2949
2950
	}
2951
2952
	/**
2953
	* Adds a new spotter data
2954
	*
2955
	* @param String $flightaware_id the ID from flightaware
2956
	* @param String $ident the flight ident
2957
	* @param String $aircraft_icao the aircraft type
2958
	* @param String $departure_airport_icao the departure airport
2959
	* @param String $arrival_airport_icao the arrival airport
2960
	* @return String success or false
2961
	*
2962
	*/
2963
	public function addSpotterData($flightaware_id = '', $ident = '', $aircraft_icao = '', $departure_airport_icao = '', $arrival_airport_icao = '', $latitude = '', $longitude = '', $waypoints = '', $altitude = '', $heading = '', $groundspeed = '', $date = '', $departure_airport_time = '', $arrival_airport_time = '',$squawk = '', $route_stop = '', $highlight = '', $ModeS = '', $registration = '',$pilot_id = '', $pilot_name = '', $verticalrate = '', $ground = false,$format_source = '', $source_name = '')
2964
	{
2965
		global $globalURL, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalDebugTimeElapsed;
2966
		
2967
		//if (isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
2968
		$Image = new Image($this->db);
2969
		$Common = new Common();
2970
		
2971
		if (!isset($globalIVAO)) $globalIVAO = FALSE;
2972
		if (!isset($globalVATSIM)) $globalVATSIM = FALSE;
2973
		if (!isset($globalphpVMS)) $globalphpVMS = FALSE;
2974
		date_default_timezone_set('UTC');
2975
		
2976
		//getting the registration
2977
		if ($flightaware_id != "" && $registration == '')
2978
		{
2979
			if (!is_string($flightaware_id))
2980
			{
2981
				return false;
2982
			} else {
2983
				if ($ModeS != '') {
2984
					$timeelapsed = microtime(true);
2985
					$registration = $this->getAircraftRegistrationBymodeS($ModeS);
2986
					if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftRegistrationBymodes : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
2987
				} else {
2988
					$myhex = explode('-',$flightaware_id);
2989
					if (count($myhex) > 0) {
2990
						$timeelapsed = microtime(true);
2991
						$registration = $this->getAircraftRegistrationBymodeS($myhex[0]);
2992
						if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftRegistrationBymodes : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
2993
					}
2994
				}
2995
			}
2996
		}
2997
2998
		//getting the airline information
2999
		if ($ident != "")
3000
		{
3001
			if (!is_string($ident))
3002
			{
3003
				return false;
3004
			} else {
3005
				if (!is_numeric(substr($ident, 0, 3)))
3006
				{
3007
					$timeelapsed = microtime(true);
3008
					if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) {
3009
						$airline_array = $this->getAllAirlineInfo(substr($ident, 0, 2));
3010
					} elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) {
3011
						$airline_array = $this->getAllAirlineInfo(substr($ident, 0, 3));
3012
					} else {
3013
						$airline_array = $this->getAllAirlineInfo("NA");
3014
					}
3015
					if (count($airline_array) == 0) {
3016
						$airline_array = $this->getAllAirlineInfo("NA");
3017
					}
3018
					if (!isset($airline_array[0]['icao']) || $airline_array[0]['icao'] == ""){
3019
						$airline_array = $this->getAllAirlineInfo("NA");
3020
					}
3021
					if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAirlineInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
3022
3023
				} else {
3024
					$timeelapsed = microtime(true);
3025
					$airline_array = $this->getAllAirlineInfo("NA");
3026
					if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAirlineInfo(NA) : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
3027
				}
3028
			}
3029
		} else $airline_array = array();
3030
		
3031
		//getting the aircraft information
3032
		if ($aircraft_icao != "")
3033
		{
3034
			if (!is_string($aircraft_icao))
3035
			{
3036
				return false;
3037
			} else {
3038
				if ($aircraft_icao == "" || $aircraft_icao == "XXXX")
3039
				{
3040
					$timeelapsed = microtime(true);
3041
					$aircraft_array = $this->getAllAircraftInfo("NA");
3042
					if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo(NA) : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
3043
				} else {
3044
					$timeelapsed = microtime(true);
3045
					$aircraft_array = $this->getAllAircraftInfo($aircraft_icao);
3046
					if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
3047
				}
3048
			}
3049
		} else {
3050
			if ($ModeS != '') {
3051
				$timeelapsed = microtime(true);
3052
				$aircraft_icao = $this->getAllAircraftType($ModeS);
3053
				if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAllAircraftType : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
3054
				if ($aircraft_icao == "" || $aircraft_icao == "XXXX")
3055
				{
3056
					$timeelapsed = microtime(true);
3057
					$aircraft_array = $this->getAllAircraftInfo("NA");
3058
					if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo(NA) : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
3059
				} else {
3060
					$timeelapsed = microtime(true);
3061
					$aircraft_array = $this->getAllAircraftInfo($aircraft_icao);
3062
					if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
3063
				}
3064
			}
3065
		}
3066
		
3067
		//getting the departure airport information
3068
		if ($departure_airport_icao != "")
3069
		{
3070
			if (!is_string($departure_airport_icao))
3071
			{
3072
				return false;
3073
			} else {
3074
				$timeelapsed = microtime(true);
3075
				$departure_airport_array = $this->getAllAirportInfo($departure_airport_icao);
3076
				if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAllAirportInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
3077
			}
3078
		}
3079
		
3080
		//getting the arrival airport information
3081
		if ($arrival_airport_icao != "")
3082
		{
3083
			if (!is_string($arrival_airport_icao))
3084
			{
3085
				return false;
3086
			} else {
3087
				$timeelapsed = microtime(true);
3088
				$arrival_airport_array = $this->getAllAirportInfo($arrival_airport_icao);
3089
				if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAllAirportInfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
3090
			}
3091
		}
3092
3093
						
3094
		if ($latitude != "")
3095
		{
3096
			if (!is_numeric($latitude))
3097
			{
3098
				return false;
3099
			}
3100
		}
3101
		
3102
		if ($longitude != "")
3103
		{
3104
			if (!is_numeric($longitude))
3105
			{
3106
				return false;
3107
			}
3108
		}
3109
		
3110
		if ($waypoints != "")
3111
		{
3112
			if (!is_string($waypoints))
3113
			{
3114
				return false;
3115
			}
3116
		}
3117
		
3118
		if ($altitude != "")
3119
		{
3120
			if (!is_numeric($altitude))
3121
			{
3122
				return false;
3123
			}
3124
		} else $altitude = 0;
3125
		
3126
		if ($heading != "")
3127
		{
3128
			if (!is_numeric($heading))
3129
			{
3130
				return false;
3131
			}
3132
		}
3133
		
3134
		if ($groundspeed != "")
3135
		{
3136
			if (!is_numeric($groundspeed))
3137
			{
3138
				return false;
3139
			}
3140
		}
3141
3142
    
3143
		if ($date == "")
3144
		{
3145
			$date = date("Y-m-d H:i:s", time());
3146
		}
3147
3148
		//getting the aircraft image
3149
		if (($registration != "" || $registration != 'NA') && !$globalIVAO && !$globalVATSIM && !$globalphpVMS)
3150
		{
3151
			$timeelapsed = microtime(true);
3152
			$image_array = $Image->getSpotterImage($registration);
3153
			if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getSpotterImage : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
3154
			if (!isset($image_array[0]['registration']))
3155
			{
3156
				//echo "Add image !!!! \n";
3157
				$Image->addSpotterImage($registration);
3158
			}
3159
			$timeelapsed = microtime(true);
3160
			$owner_info = $this->getAircraftOwnerByRegistration($registration);
3161
			if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftOwnerByRegistration : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
3162
			if ($owner_info['owner'] != '') $aircraft_owner = ucwords(strtolower($owner_info['owner']));
3163
		}
3164
    
3165
		if ($globalIVAO && $aircraft_icao != '')
3166
		{
3167
            		if (isset($airline_array[0]['icao'])) $airline_icao = $airline_array[0]['icao'];
3168
            		else $airline_icao = '';
3169
			$image_array = $Image->getSpotterImage('',$aircraft_icao,$airline_icao);
3170
			if (!isset($image_array[0]['registration']))
3171
			{
3172
				//echo "Add image !!!! \n";
3173
				$Image->addSpotterImage('',$aircraft_icao,$airline_icao);
3174
			}
3175
		}
3176
    
3177
		$flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING);
3178
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
3179
		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
3180
		$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
3181
		$departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING);
3182
		$arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING);
3183
		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
3184
		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
3185
		$waypoints = filter_var($waypoints,FILTER_SANITIZE_STRING);
3186
		$altitude = filter_var($altitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
3187
		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
3188
		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
3189
		$squawk = filter_var($squawk,FILTER_SANITIZE_NUMBER_INT);
3190
		$route_stop = filter_var($route_stop,FILTER_SANITIZE_STRING);
3191
		$ModeS = filter_var($ModeS,FILTER_SANITIZE_STRING);
3192
		$pilot_id = filter_var($pilot_id,FILTER_SANITIZE_STRING);
3193
		$pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING);
3194
		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
3195
		$verticalrate = filter_var($verticalrate,FILTER_SANITIZE_NUMBER_INT);
3196
	
3197
		if (count($airline_array) == 0) 
3198
		{
3199
                        $airline_array = $this->getAllAirlineInfo('NA');
3200
                }
3201
                if (count($aircraft_array) == 0) 
0 ignored issues
show
Bug introduced by
The variable $aircraft_array does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
3202
                {
3203
                        $aircraft_array = $this->getAllAircraftInfo('NA');
3204
                }
3205
                if (count($departure_airport_array) == 0) 
0 ignored issues
show
Bug introduced by
The variable $departure_airport_array does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
3206
                {
3207
                        $departure_airport_array = $this->getAllAirportInfo('NA');
3208
                }
3209
                if (count($arrival_airport_array) == 0) 
0 ignored issues
show
Bug introduced by
The variable $arrival_airport_array does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
3210
                {
3211
                        $arrival_airport_array = $this->getAllAirportInfo('NA');
3212
                }
3213
                if ($registration == '') $registration = 'NA';
3214
                if ($squawk == '' || $Common->isInteger($squawk) == false) $squawk = NULL;
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
3215
                if ($verticalrate == '' || $Common->isInteger($verticalrate) == false) $verticalrate = NULL;
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
3216
                if ($heading == '' || $Common->isInteger($heading) == false) $heading = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
3217
                if ($groundspeed == '' || $Common->isInteger($groundspeed) == false) $groundspeed = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
3218
                if (!isset($aircraft_owner)) $aircraft_owner = NULL;
3219
                $query  = "INSERT INTO spotter_output (flightaware_id, ident, registration, airline_name, airline_icao, airline_country, airline_type, aircraft_icao, aircraft_name, aircraft_manufacturer, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, latitude, longitude, waypoints, altitude, heading, ground_speed, date, departure_airport_time, arrival_airport_time, squawk, route_stop,highlight,ModeS, pilot_id, pilot_name, verticalrate, owner_name, ground, format_source, source_name) 
3220
                VALUES (:flightaware_id,:ident,:registration,:airline_name,:airline_icao,:airline_country,:airline_type,:aircraft_icao,:aircraft_type,:aircraft_manufacturer,:departure_airport_icao,:departure_airport_name,:departure_airport_city,:departure_airport_country, :arrival_airport_icao, :arrival_airport_name, :arrival_airport_city, :arrival_airport_country, :latitude,:longitude,:waypoints,:altitude,:heading,:groundspeed,:date, :departure_airport_time, :arrival_airport_time, :squawk, :route_stop, :highlight, :ModeS, :pilot_id, :pilot_name, :verticalrate, :owner_name,:ground, :format_source, :source_name)";
3221
3222
                $airline_name = $airline_array[0]['name'];
3223
                $airline_icao = $airline_array[0]['icao'];
3224
                $airline_country = $airline_array[0]['country'];
3225
                $airline_type = $airline_array[0]['type'];
3226
		if ($airline_type == '') {
3227
			$timeelapsed = microtime(true);
3228
			$airline_type = $this->getAircraftTypeBymodeS($ModeS);
3229
			if ($globalDebugTimeElapsed) echo 'ADD SPOTTER DATA : Time elapsed for getAircraftTypeBymodes : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
3230
		}
3231
		if ($airline_type == null) $airline_type = '';
3232
                $aircraft_type = $aircraft_array[0]['type'];
3233
                $aircraft_manufacturer = $aircraft_array[0]['manufacturer'];
3234
                $departure_airport_name = $departure_airport_array[0]['name'];
3235
                $departure_airport_city = $departure_airport_array[0]['city'];
3236
                $departure_airport_country = $departure_airport_array[0]['country'];
3237
                $arrival_airport_icao = $arrival_airport_icao;
0 ignored issues
show
Bug introduced by
Why assign $arrival_airport_icao to itself?

This checks looks for cases where a variable has been assigned to itself.

This assignement can be removed without consequences.

Loading history...
3238
                $arrival_airport_name = $arrival_airport_array[0]['name'];
3239
                $arrival_airport_city = $arrival_airport_array[0]['city'];
3240
                $arrival_airport_country = $arrival_airport_array[0]['country'];
3241
                $query_values = array(':flightaware_id' => $flightaware_id,':ident' => $ident, ':registration' => $registration,':airline_name' => $airline_name,':airline_icao' => $airline_icao,':airline_country' => $airline_country,':airline_type' => $airline_type,':aircraft_icao' => $aircraft_icao,':aircraft_type' => $aircraft_type,':aircraft_manufacturer' => $aircraft_manufacturer,':departure_airport_icao' => $departure_airport_icao,':departure_airport_name' => $departure_airport_name,':departure_airport_city' => $departure_airport_city,':departure_airport_country' => $departure_airport_country,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_name' => $arrival_airport_name,':arrival_airport_city' => $arrival_airport_city,':arrival_airport_country' => $arrival_airport_country,':latitude' => $latitude,':longitude' => $longitude, ':waypoints' => $waypoints,':altitude' => $altitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date,':departure_airport_time' => $departure_airport_time,':arrival_airport_time' => $arrival_airport_time, ':squawk' => $squawk, ':route_stop' => $route_stop, ':highlight' => $highlight, ':ModeS' => $ModeS, ':pilot_id' => $pilot_id, ':pilot_name' => $pilot_name, ':verticalrate' => $verticalrate, ':owner_name' => $aircraft_owner, ':format_source' => $format_source, ':ground' => $ground, ':source_name' => $source_name);
3242
3243
		try {
3244
		        
3245
			$sth = $this->db->prepare($query);
3246
			$sth->execute($query_values);
3247
			$this->db = null;
3248
		} catch (PDOException $e) {
3249
		    return "error : ".$e->getMessage();
3250
		}
3251
		
3252
		return "success";
3253
3254
	}
3255
	
3256
  
3257
  /**
3258
	* Gets the aircraft ident within the last hour
3259
	*
3260
	* @return String the ident
3261
	*
3262
	*/
3263
	public function getIdentFromLastHour($ident)
3264
	{
3265
		global $globalDBdriver, $globalTimezone;
3266
		if ($globalDBdriver == 'mysql') {
3267
			$query  = "SELECT spotter_output.ident FROM spotter_output 
3268
								WHERE spotter_output.ident = :ident 
3269
								AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
3270
								AND spotter_output.date < UTC_TIMESTAMP()";
3271
			$query_data = array(':ident' => $ident);
3272
		} elseif ($globalDBdriver == 'pgsql') {
3273
			$query  = "SELECT spotter_output.ident FROM spotter_output 
3274
								WHERE spotter_output.ident = :ident 
3275
								AND spotter_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
3276
								AND spotter_output.date < now() AT TIME ZONE 'UTC'";
3277
			$query_data = array(':ident' => $ident);
3278
    		}
3279
		
3280
		$sth = $this->db->prepare($query);
0 ignored issues
show
Bug introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
3281
		$sth->execute($query_data);
0 ignored issues
show
Bug introduced by
The variable $query_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
3282
    		$ident_result='';
3283
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3284
		{
3285
			$ident_result = $row['ident'];
3286
		}
3287
3288
		return $ident_result;
3289
	}
3290
	
3291
	
3292
	/**
3293
	* Gets the aircraft data from the last 20 seconds
3294
	*
3295
	* @return Array the spotter data
3296
	*
3297
	*/
3298
	public function getRealTimeData($q = '')
3299
	{
3300
		global $globalDBdriver;
3301
		$additional_query = '';
3302
		if ($q != "")
3303
		{
3304
			if (!is_string($q))
3305
			{
3306
				return false;
3307
			} else {
3308
				$q_array = explode(" ", $q);
3309
				foreach ($q_array as $q_item){
3310
					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
3311
					$additional_query .= " AND (";
3312
					$additional_query .= "(spotter_output.aircraft_icao like '%".$q_item."%') OR ";
3313
					$additional_query .= "(spotter_output.aircraft_name like '%".$q_item."%') OR ";
3314
					$additional_query .= "(spotter_output.aircraft_manufacturer like '%".$q_item."%') OR ";
3315
					$additional_query .= "(spotter_output.airline_icao like '%".$q_item."%') OR ";
3316
					$additional_query .= "(spotter_output.departure_airport_icao like '%".$q_item."%') OR ";
3317
					$additional_query .= "(spotter_output.arrival_airport_icao like '%".$q_item."%') OR ";
3318
					$additional_query .= "(spotter_output.registration like '%".$q_item."%') OR ";
3319
					$additional_query .= "(spotter_output.ident like '%".$q_item."%')";
3320
					$additional_query .= ")";
3321
				}
3322
			}
3323
		}
3324
		if ($globalDBdriver == 'mysql') {
3325
			$query  = "SELECT spotter_output.* FROM spotter_output 
3326
				WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query." 
3327
				AND spotter_output.date < UTC_TIMESTAMP()";
3328
		} else {
3329
			$query  = "SELECT spotter_output.* FROM spotter_output 
3330
				WHERE spotter_output.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query." 
3331
				AND spotter_output.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
3332
		}
3333
		$spotter_array = $this->getDataFromDB($query, array());
3334
3335
		return $spotter_array;
3336
	}
3337
	
3338
	
3339
	
3340
	 /**
3341
	* Gets all airlines that have flown over
3342
	*
3343
	* @return Array the airline list
3344
	*
3345
	*/
3346
	public function countAllAirlines($limit = true, $olderthanmonths = 0, $sincedate = '')
3347
	{
3348
		global $globalDBdriver;
3349
		$query  = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count
3350
		 			FROM spotter_output
3351
					WHERE spotter_output.airline_name <> '' AND spotter_output.airline_icao <> 'NA' ";
3352
		if ($olderthanmonths > 0) {
3353
			if ($globalDBdriver == 'mysql') {
3354
				$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) ';
3355
			} else {
3356
				$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' ";
3357
			}
3358
		}
3359
                if ($sincedate != '') {
3360
			if ($globalDBdriver == 'mysql') {
3361
				$query .= "AND date > '".$sincedate."' ";
3362
			} else {
3363
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
3364
			}
3365
		}
3366
		$query .= "GROUP BY spotter_output.airline_name,spotter_output.airline_icao, spotter_output.airline_country ORDER BY airline_count DESC";
3367
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
3368
		
3369
		$sth = $this->db->prepare($query);
3370
		$sth->execute();
3371
 
3372
		$airline_array = array();
3373
		$temp_array = array();
3374
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3375
		{
3376
			$temp_array['airline_name'] = $row['airline_name'];
3377
			$temp_array['airline_icao'] = $row['airline_icao'];
3378
			$temp_array['airline_count'] = $row['airline_count'];
3379
			$temp_array['airline_country'] = $row['airline_country'];
3380
			$airline_array[] = $temp_array;
3381
		}
3382
		return $airline_array;
3383
	}
3384
3385
	 /**
3386
	* Gets all pilots that have flown over
3387
	*
3388
	* @return Array the pilots list
3389
	*
3390
	*/
3391
	public function countAllPilots($limit = true, $olderthanmonths = 0, $sincedate = '')
3392
	{
3393
		global $globalDBdriver;
3394
		$query  = "SELECT DISTINCT spotter_output.pilot_id, spotter_output.pilot_name, COUNT(spotter_output.pilot_id) AS pilot_count
3395
		 			FROM spotter_output
3396
					WHERE spotter_output.pilot_id <> '' ";
3397
                if ($olderthanmonths > 0) {
3398
            		if ($globalDBdriver == 'mysql') {
3399
				$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) ';
3400
			} else {
3401
				$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' ";
3402
			}
3403
		}
3404
                if ($sincedate != '') {
3405
            		if ($globalDBdriver == 'mysql') {
3406
				$query .= "AND date > '".$sincedate."' ";
3407
			} else {
3408
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
3409
			}
3410
		}
3411
		$query .= "GROUP BY spotter_output.pilot_id,spotter_output.pilot_name ORDER BY pilot_count DESC";
3412
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
3413
      
3414
		
3415
		$sth = $this->db->prepare($query);
3416
		$sth->execute();
3417
      
3418
		$airline_array = array();
3419
		$temp_array = array();
3420
        
3421
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3422
		{
3423
			$temp_array['pilot_name'] = $row['pilot_name'];
3424
			$temp_array['pilot_id'] = $row['pilot_id'];
3425
			$temp_array['pilot_count'] = $row['pilot_count'];
3426
			$airline_array[] = $temp_array;
3427
		}
3428
		return $airline_array;
3429
	}
3430
	
3431
	 /**
3432
	* Gets all owner that have flown over
3433
	*
3434
	* @return Array the pilots list
3435
	*
3436
	*/
3437
	public function countAllOwners($limit = true, $olderthanmonths = 0, $sincedate = '')
0 ignored issues
show
Unused Code introduced by
The parameter $olderthanmonths is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $sincedate is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
3438
	{
3439
		global $globalDBdriver;
3440
		$query  = "SELECT DISTINCT spotter_output.owner_name, COUNT(spotter_output.owner_name) AS owner_count
3441
		 			FROM spotter_output
3442
					WHERE spotter_output.owner_name <> '' AND spotter_output.owner_name IS NOT NULL ";
3443
		$query .= "GROUP BY spotter_output.owner_name ORDER BY owner_count DESC";
3444
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
3445
      
3446
		
3447
		$sth = $this->db->prepare($query);
3448
		$sth->execute();
3449
      
3450
		$airline_array = array();
3451
		$temp_array = array();
3452
        
3453
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3454
		{
3455
			$temp_array['owner_name'] = $row['owner_name'];
3456
			$temp_array['owner_count'] = $row['owner_count'];
3457
			$airline_array[] = $temp_array;
3458
		}
3459
		return $airline_array;
3460
	}
3461
	
3462
	
3463
	/**
3464
	* Gets all airlines that have flown over by aircraft
3465
	*
3466
	* @return Array the airline list
3467
	*
3468
	*/
3469
	public function countAllAirlinesByAircraft($aircraft_icao)
3470
	{
3471
		$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
3472
3473
		$query  = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count
3474
		 			FROM spotter_output
3475
					WHERE spotter_output.airline_name <> '' AND spotter_output.aircraft_icao = :aircraft_icao 
3476
                    GROUP BY spotter_output.airline_name
3477
					ORDER BY airline_count DESC";
3478
      
3479
		
3480
		$sth = $this->db->prepare($query);
3481
		$sth->execute(array(':aircraft_icao' => $aircraft_icao));
3482
      
3483
		$airline_array = array();
3484
		$temp_array = array();
3485
        
3486
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3487
		{
3488
			$temp_array['airline_name'] = $row['airline_name'];
3489
			$temp_array['airline_icao'] = $row['airline_icao'];
3490
			$temp_array['airline_count'] = $row['airline_count'];
3491
			$temp_array['airline_country'] = $row['airline_country'];
3492
3493
			$airline_array[] = $temp_array;
3494
		}
3495
3496
		return $airline_array;
3497
	}
3498
3499
3500
	/**
3501
	* Gets all airline countries that have flown over by aircraft
3502
	*
3503
	* @return Array the airline country list
3504
	*
3505
	*/
3506
	public function countAllAirlineCountriesByAircraft($aircraft_icao)
3507
	{
3508
		$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
3509
      
3510
		$query  = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count
3511
		 			FROM spotter_output
3512
					WHERE spotter_output.airline_country <> '' AND spotter_output.aircraft_icao = :aircraft_icao
3513
                    GROUP BY spotter_output.airline_country
3514
					ORDER BY airline_country_count DESC
3515
					LIMIT 10 OFFSET 0";
3516
      
3517
		
3518
		$sth = $this->db->prepare($query);
3519
		$sth->execute(array(':aircraft_icao' => $aircraft_icao));
3520
      
3521
		$airline_country_array = array();
3522
		$temp_array = array();
3523
        
3524
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3525
		{
3526
			$temp_array['airline_country_count'] = $row['airline_country_count'];
3527
			$temp_array['airline_country'] = $row['airline_country'];
3528
 
3529
			$airline_country_array[] = $temp_array;
3530
		}
3531
		return $airline_country_array;
3532
	}
3533
3534
3535
	
3536
	
3537
	/**
3538
	* Gets all airlines that have flown over by airport
3539
	*
3540
	* @return Array the airline list
3541
	*
3542
	*/
3543
	public function countAllAirlinesByAirport($airport_icao)
3544
	{
3545
		$airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING);
3546
3547
		$query  = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count
3548
		 			FROM spotter_output
3549
					WHERE spotter_output.airline_name <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao ) 
3550
                    GROUP BY spotter_output.airline_name
3551
					ORDER BY airline_count DESC";
3552
      
3553
		
3554
		$sth = $this->db->prepare($query);
3555
		$sth->execute(array(':airport_icao' => $airport_icao));
3556
      
3557
		$airline_array = array();
3558
		$temp_array = array();
3559
        
3560
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3561
		{
3562
			$temp_array['airline_name'] = $row['airline_name'];
3563
			$temp_array['airline_icao'] = $row['airline_icao'];
3564
			$temp_array['airline_count'] = $row['airline_count'];
3565
			$temp_array['airline_country'] = $row['airline_country'];
3566
3567
			$airline_array[] = $temp_array;
3568
		}
3569
		return $airline_array;
3570
	}
3571
3572
3573
	/**
3574
	* Gets all airline countries that have flown over by airport icao
3575
	*
3576
	* @return Array the airline country list
3577
	*
3578
	*/
3579
	public function countAllAirlineCountriesByAirport($airport_icao)
3580
	{
3581
		$airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING);
3582
      
3583
		$query  = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count
3584
		 			FROM spotter_output
3585
					WHERE spotter_output.airline_country <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao )
3586
					GROUP BY spotter_output.airline_country
3587
					ORDER BY airline_country_count DESC
3588
					LIMIT 10 OFFSET 0";
3589
3590
		
3591
		$sth = $this->db->prepare($query);
3592
		$sth->execute(array(':airport_icao' => $airport_icao));
3593
3594
		$airline_country_array = array();
3595
		$temp_array = array();
3596
        
3597
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3598
		{
3599
			$temp_array['airline_country_count'] = $row['airline_country_count'];
3600
			$temp_array['airline_country'] = $row['airline_country'];
3601
 
3602
			$airline_country_array[] = $temp_array;
3603
		}
3604
		return $airline_country_array;
3605
	}
3606
3607
3608
	/**
3609
	* Gets all airlines that have flown over by aircraft manufacturer
3610
	*
3611
	* @return Array the airline list
3612
	*
3613
	*/
3614
	public function countAllAirlinesByManufacturer($aircraft_manufacturer)
3615
	{
3616
		$aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING);
3617
3618
		$query  = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count
3619
		 			FROM spotter_output
3620
					WHERE spotter_output.aircraft_manufacturer = :aircraft_manufacturer 
3621
					GROUP BY spotter_output.airline_name
3622
					ORDER BY airline_count DESC";
3623
 
3624
		$sth = $this->db->prepare($query);
3625
		$sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer));
3626
 
3627
		$airline_array = array();
3628
		$temp_array = array();
3629
        
3630
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3631
		{
3632
			$temp_array['airline_name'] = $row['airline_name'];
3633
			$temp_array['airline_icao'] = $row['airline_icao'];
3634
			$temp_array['airline_count'] = $row['airline_count'];
3635
			$temp_array['airline_country'] = $row['airline_country'];
3636
3637
			$airline_array[] = $temp_array;
3638
		}
3639
		return $airline_array;
3640
	}
3641
3642
3643
3644
	/**
3645
	* Gets all airline countries that have flown over by aircraft manufacturer
3646
	*
3647
	* @return Array the airline country list
3648
	*
3649
	*/
3650
	public function countAllAirlineCountriesByManufacturer($aircraft_manufacturer)
3651
	{
3652
		$aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING);
3653
      
3654
		$query  = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count
3655
		 			FROM spotter_output
3656
					WHERE spotter_output.airline_country <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer 
3657
					GROUP BY spotter_output.airline_country
3658
					ORDER BY airline_country_count DESC
3659
					LIMIT 10 OFFSET 0";
3660
      
3661
		
3662
		$sth = $this->db->prepare($query);
3663
		$sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer));
3664
3665
		$airline_country_array = array();
3666
		$temp_array = array();
3667
        
3668
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3669
		{
3670
			$temp_array['airline_country_count'] = $row['airline_country_count'];
3671
			$temp_array['airline_country'] = $row['airline_country'];
3672
			$airline_country_array[] = $temp_array;
3673
		}
3674
		return $airline_country_array;
3675
	}
3676
3677
3678
	/**
3679
	* Gets all airlines that have flown over by date
3680
	*
3681
	* @return Array the airline list
3682
	*
3683
	*/
3684
	public function countAllAirlinesByDate($date)
3685
	{
3686
		global $globalTimezone, $globalDBdriver;
3687
		$date = filter_var($date,FILTER_SANITIZE_STRING);
3688
3689
		if ($globalTimezone != '') {
3690
			date_default_timezone_set($globalTimezone);
3691
			$datetime = new DateTime($date);
3692
			$offset = $datetime->format('P');
3693
		} else $offset = '+00:00';
3694
3695
		if ($globalDBdriver == 'mysql') {
3696
			$query  = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count
3697
		 			FROM spotter_output
3698
					WHERE DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date 
3699
					GROUP BY spotter_output.airline_name
3700
					ORDER BY airline_count DESC";
3701
		} else {
3702
			$query  = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count
3703
		 			FROM spotter_output
3704
					WHERE to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date 
3705
					GROUP BY spotter_output.airline_name
3706
					ORDER BY airline_count DESC";
3707
		}
3708
		
3709
		$sth = $this->db->prepare($query);
3710
		$sth->execute(array(':date' => $date, ':offset' => $offset));
3711
3712
		$airline_array = array();
3713
		$temp_array = array();
3714
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3715
		{
3716
			$temp_array['airline_name'] = $row['airline_name'];
3717
			$temp_array['airline_icao'] = $row['airline_icao'];
3718
			$temp_array['airline_count'] = $row['airline_count'];
3719
			$temp_array['airline_country'] = $row['airline_country'];
3720
 
3721
			$airline_array[] = $temp_array;
3722
		}
3723
3724
		return $airline_array;
3725
	}	
3726
	
3727
	
3728
	/**
3729
	* Gets all airline countries that have flown over by date
3730
	*
3731
	* @return Array the airline country list
3732
	*
3733
	*/
3734
	public function countAllAirlineCountriesByDate($date)
3735
	{
3736
		global $globalTimezone, $globalDBdriver;
3737
		$date = filter_var($date,FILTER_SANITIZE_STRING);
3738
		if ($globalTimezone != '') {
3739
			date_default_timezone_set($globalTimezone);
3740
			$datetime = new DateTime($date);
3741
			$offset = $datetime->format('P');
3742
		} else $offset = '+00:00';
3743
		
3744
		if ($globalDBdriver == 'mysql') {
3745
			$query  = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count
3746
		 			FROM spotter_output
3747
					WHERE spotter_output.airline_country <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date 
3748
					GROUP BY spotter_output.airline_country
3749
					ORDER BY airline_country_count DESC
3750
					LIMIT 10 OFFSET 0";
3751
		} else {
3752
			$query  = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count
3753
		 			FROM spotter_output
3754
					WHERE spotter_output.airline_country <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date 
3755
					GROUP BY spotter_output.airline_country
3756
					ORDER BY airline_country_count DESC
3757
					LIMIT 10 OFFSET 0";
3758
		}
3759
3760
		$sth = $this->db->prepare($query);
3761
		$sth->execute(array(':date' => $date, ':offset' => $offset));
3762
 
3763
		$airline_country_array = array();
3764
		$temp_array = array();
3765
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3766
		{
3767
			$temp_array['airline_country_count'] = $row['airline_country_count'];
3768
			$temp_array['airline_country'] = $row['airline_country'];
3769
3770
			$airline_country_array[] = $temp_array;
3771
		}
3772
		return $airline_country_array;
3773
	}
3774
3775
3776
	/**
3777
	* Gets all airlines that have flown over by ident/callsign
3778
	*
3779
	* @return Array the airline list
3780
	*
3781
	*/
3782
	public function countAllAirlinesByIdent($ident)
3783
	{
3784
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
3785
3786
		$query  = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count
3787
		 		FROM spotter_output
3788
				WHERE spotter_output.ident = :ident  
3789
				GROUP BY spotter_output.airline_name
3790
				ORDER BY airline_count DESC";
3791
      
3792
		
3793
		$sth = $this->db->prepare($query);
3794
		$sth->execute(array(':ident' => $ident));
3795
      
3796
		$airline_array = array();
3797
		$temp_array = array();
3798
        
3799
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3800
		{
3801
			$temp_array['airline_name'] = $row['airline_name'];
3802
			$temp_array['airline_icao'] = $row['airline_icao'];
3803
			$temp_array['airline_count'] = $row['airline_count'];
3804
			$temp_array['airline_country'] = $row['airline_country'];
3805
3806
			$airline_array[] = $temp_array;
3807
		}
3808
		return $airline_array;
3809
	}
3810
3811
	/**
3812
	* Gets all airlines that have flown over by route
3813
	*
3814
	* @return Array the airline list
3815
	*
3816
	*/
3817
	public function countAllAirlinesByRoute($departure_airport_icao, $arrival_airport_icao)
3818
	{
3819
		$departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING);
3820
		$arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING);
3821
3822
		$query  = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count
3823
		 			FROM spotter_output
3824
					WHERE (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) 
3825
					GROUP BY spotter_output.airline_name
3826
					ORDER BY airline_count DESC";
3827
      
3828
		
3829
		$sth = $this->db->prepare($query);
3830
		$sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao));
3831
      
3832
		$airline_array = array();
3833
		$temp_array = array();
3834
        
3835
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3836
		{
3837
			$temp_array['airline_name'] = $row['airline_name'];
3838
			$temp_array['airline_icao'] = $row['airline_icao'];
3839
			$temp_array['airline_count'] = $row['airline_count'];
3840
			$temp_array['airline_country'] = $row['airline_country'];
3841
3842
			$airline_array[] = $temp_array;
3843
		}
3844
		return $airline_array;
3845
	}
3846
3847
	/**
3848
	* Gets all airline countries that have flown over by route
3849
	*
3850
	* @return Array the airline country list
3851
	*
3852
	*/
3853
	public function countAllAirlineCountriesByRoute($departure_airport_icao, $arrival_airport_icao)
3854
	{
3855
		$departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING);
3856
		$arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING);
3857
      
3858
		$query  = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count
3859
		 		FROM spotter_output
3860
				WHERE spotter_output.airline_country <> '' AND (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) 
3861
				GROUP BY spotter_output.airline_country
3862
				ORDER BY airline_country_count DESC
3863
				LIMIT 10 OFFSET 0";
3864
      
3865
		
3866
		$sth = $this->db->prepare($query);
3867
		$sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao));
3868
      
3869
		$airline_country_array = array();
3870
		$temp_array = array();
3871
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3872
		{
3873
			$temp_array['airline_country_count'] = $row['airline_country_count'];
3874
			$temp_array['airline_country'] = $row['airline_country'];
3875
3876
			$airline_country_array[] = $temp_array;
3877
		}
3878
3879
		return $airline_country_array;
3880
	}
3881
3882
3883
	/**
3884
	* Gets all airlines that have flown over by country
3885
	*
3886
	* @return Array the airline list
3887
	*
3888
	*/
3889
	public function countAllAirlinesByCountry($country)
3890
	{
3891
		$country = filter_var($country,FILTER_SANITIZE_STRING);
3892
3893
		$query  = "SELECT DISTINCT spotter_output.airline_name, spotter_output.airline_icao, spotter_output.airline_country, COUNT(spotter_output.airline_name) AS airline_count
3894
		 		FROM spotter_output
3895
				WHERE ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country  
3896
				GROUP BY spotter_output.airline_name
3897
				ORDER BY airline_count DESC";
3898
      
3899
		
3900
		$sth = $this->db->prepare($query);
3901
		$sth->execute(array(':country' => $country));
3902
3903
		$airline_array = array();
3904
		$temp_array = array();
3905
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3906
		{
3907
			$temp_array['airline_name'] = $row['airline_name'];
3908
			$temp_array['airline_icao'] = $row['airline_icao'];
3909
			$temp_array['airline_count'] = $row['airline_count'];
3910
			$temp_array['airline_country'] = $row['airline_country'];
3911
 
3912
			$airline_array[] = $temp_array;
3913
		}
3914
		return $airline_array;
3915
	}
3916
3917
3918
	/**
3919
	* Gets all airline countries that have flown over by country
3920
	*
3921
	* @return Array the airline country list
3922
	*
3923
	*/
3924
	public function countAllAirlineCountriesByCountry($country)
3925
	{
3926
		$country = filter_var($country,FILTER_SANITIZE_STRING);
3927
      
3928
		$query  = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count
3929
		 		FROM spotter_output
3930
				WHERE spotter_output.airline_country <> '' AND ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country 
3931
				GROUP BY spotter_output.airline_country
3932
				ORDER BY airline_country_count DESC
3933
				LIMIT 10 OFFSET 0";
3934
      
3935
		
3936
		$sth = $this->db->prepare($query);
3937
		$sth->execute(array(':country' => $country));
3938
3939
		$airline_country_array = array();
3940
		$temp_array = array();
3941
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3942
		{
3943
			$temp_array['airline_country_count'] = $row['airline_country_count'];
3944
			$temp_array['airline_country'] = $row['airline_country'];
3945
3946
			$airline_country_array[] = $temp_array;
3947
		}
3948
		return $airline_country_array;
3949
	}
3950
3951
3952
	/**
3953
	* Gets all airlines countries
3954
	*
3955
	* @return Array the airline country list
3956
	*
3957
	*/
3958
	public function countAllAirlineCountries($limit = true)
3959
	{
3960
		$query  = "SELECT DISTINCT spotter_output.airline_country, COUNT(spotter_output.airline_country) AS airline_country_count
3961
		 			FROM spotter_output
3962
					WHERE spotter_output.airline_country <> '' AND spotter_output.airline_country <> 'NA' 
3963
					GROUP BY spotter_output.airline_country
3964
					ORDER BY airline_country_count DESC";
3965
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
3966
      
3967
		$sth = $this->db->prepare($query);
3968
		$sth->execute();
3969
3970
		$airline_array = array();
3971
		$temp_array = array();
3972
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
3973
		{
3974
			$temp_array['airline_country_count'] = $row['airline_country_count'];
3975
			$temp_array['airline_country'] = $row['airline_country'];
3976
3977
			$airline_array[] = $temp_array;
3978
		}
3979
		return $airline_array;
3980
	}
3981
3982
	/**
3983
	* Gets all number of flight over countries
3984
	*
3985
	* @return Array the airline country list
3986
	*
3987
	*/
3988
	public function countAllFlightOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '')
3989
	{
3990
		global $globalDBdriver;
3991
		/*
3992
		$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb 
3993
					FROM countries c, spotter_output s
3994
					WHERE Within(GeomFromText(CONCAT('POINT(',s.longitude,' ',s.latitude,')')), ogc_geom) ";
3995
		*/
3996
		$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb 
3997
					FROM countries c, spotter_live s
3998
					WHERE c.iso2 = s.over_country ";
3999
                if ($olderthanmonths > 0) {
4000
			if ($globalDBdriver == 'mysql') {
4001
				$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
4002
			} else {
4003
				$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
4004
			}
4005
		}
4006
                if ($sincedate != '') $query .= "AND date > '".$sincedate."' ";
4007
		$query .= "GROUP BY c.name ORDER BY nb DESC";
4008
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
4009
      
4010
		
4011
		$sth = $this->db->prepare($query);
4012
		$sth->execute();
4013
 
4014
		$flight_array = array();
4015
		$temp_array = array();
4016
        
4017
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4018
		{
4019
			$temp_array['flight_count'] = $row['nb'];
4020
			$temp_array['flight_country'] = $row['name'];
4021
			$temp_array['flight_country_iso3'] = $row['iso3'];
4022
			$temp_array['flight_country_iso2'] = $row['iso2'];
4023
			$flight_array[] = $temp_array;
4024
		}
4025
		return $flight_array;
4026
	}
4027
	
4028
	
4029
	/**
4030
	* Gets all aircraft types that have flown over
4031
	*
4032
	* @return Array the aircraft list
4033
	*
4034
	*/
4035
	public function countAllAircraftTypes($limit = true,$olderthanmonths = 0,$sincedate = '')
4036
	{
4037
		global $globalDBdriver;
4038
		$query  = "SELECT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name  
4039
                    FROM spotter_output
4040
                    WHERE spotter_output.aircraft_name  <> '' AND spotter_output.aircraft_icao  <> '' ";
4041
                if ($olderthanmonths > 0) {
4042
            		if ($globalDBdriver == 'mysql') {
4043
				$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) ';
4044
			} else {
4045
				$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' ";
4046
			}
4047
                }
4048
                if ($sincedate != '') {
4049
            		if ($globalDBdriver == 'mysql') {
4050
				$query .= "AND date > '".$sincedate."' ";
4051
			} else {
4052
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
4053
			}
4054
		}
4055
4056
                //if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
4057
                //if ($sincedate != '') $query .= "AND date > '".$sincedate."' ";
4058
                $query .= "GROUP BY spotter_output.aircraft_icao, spotter_output.aircraft_name ORDER BY aircraft_icao_count DESC";
4059
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
4060
      
4061
		
4062
		$sth = $this->db->prepare($query);
4063
		$sth->execute();
4064
4065
		$aircraft_array = array();
4066
		$temp_array = array();
4067
        
4068
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4069
		{
4070
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4071
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4072
			$temp_array['aircraft_icao_count'] = $row['aircraft_icao_count'];
4073
4074
			$aircraft_array[] = $temp_array;
4075
		}
4076
		return $aircraft_array;
4077
	}
4078
4079
4080
	/**
4081
	* Gets all aircraft registration that have flown over by aircaft icao
4082
	*
4083
	* @return Array the aircraft list
4084
	*
4085
	*/
4086
	public function countAllAircraftRegistrationByAircraft($aircraft_icao)
4087
	{
4088
		$Image = new Image($this->db);
4089
		$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
4090
4091
		$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name  
4092
				FROM spotter_output
4093
				WHERE spotter_output.registration <> '' AND spotter_output.aircraft_icao = :aircraft_icao  
4094
				GROUP BY spotter_output.registration 
4095
				ORDER BY registration_count DESC";
4096
4097
		$sth = $this->db->prepare($query);
4098
		$sth->execute(array(':aircraft_icao' => $aircraft_icao));
4099
4100
		$aircraft_array = array();
4101
		$temp_array = array();
4102
        
4103
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4104
		{
4105
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4106
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4107
			$temp_array['registration'] = $row['registration'];
4108
			$temp_array['airline_name'] = $row['airline_name'];
4109
			$temp_array['image_thumbnail'] = "";
4110
			if($row['registration'] != "")
4111
			{
4112
				$image_array = $Image->getSpotterImage($row['registration']);
4113
				if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail'];
4114
			}
4115
			$emp_array['registration_count'] = $row['registration_count'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$emp_array was never initialized. Although not strictly required by PHP, it is generally a good practice to add $emp_array = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
4116
4117
			$aircraft_array[] = $temp_array;
4118
		}
4119
		return $aircraft_array;
4120
	}
4121
4122
4123
	/**
4124
	* Gets all aircraft types that have flown over by airline icao
4125
	*
4126
	* @return Array the aircraft list
4127
	*
4128
	*/
4129
	public function countAllAircraftTypesByAirline($airline_icao)
4130
	{
4131
		$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING);
4132
4133
		$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name  
4134
				FROM spotter_output
4135
				WHERE spotter_output.aircraft_icao <> '' AND spotter_output.airline_icao = :airline_icao 
4136
				GROUP BY spotter_output.aircraft_name 
4137
				ORDER BY aircraft_icao_count DESC";
4138
4139
		$sth = $this->db->prepare($query);
4140
		$sth->execute(array(':airline_icao' => $airline_icao));
4141
4142
		$ircraft_array = array();
0 ignored issues
show
Unused Code introduced by
$ircraft_array is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
4143
		$temp_array = array();
4144
4145
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4146
		{
4147
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4148
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4149
			$temp_array['aircraft_icao_count'] = $row['aircraft_icao_count'];
4150
4151
			$aircraft_array[] = $temp_array;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$aircraft_array was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aircraft_array = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
4152
		}
4153
		return $aircraft_array;
0 ignored issues
show
Bug introduced by
The variable $aircraft_array does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
4154
	}
4155
4156
4157
	/**
4158
	* Gets all aircraft registration that have flown over by airline icao
4159
	*
4160
	* @return Array the aircraft list
4161
	*
4162
	*/
4163
	public function countAllAircraftRegistrationByAirline($airline_icao)
4164
	{
4165
		$Image = new Image($this->db);
4166
		$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING);
4167
4168
		$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name   
4169
				FROM spotter_output
4170
				WHERE spotter_output.registration <> '' AND spotter_output.airline_icao = :airline_icao 
4171
				GROUP BY spotter_output.registration 
4172
				ORDER BY registration_count DESC";
4173
4174
		$sth = $this->db->prepare($query);
4175
		$sth->execute(array(':airline_icao' => $airline_icao));
4176
4177
		$aircraft_array = array();
4178
		$temp_array = array();
4179
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4180
		{
4181
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4182
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4183
			$temp_array['registration'] = $row['registration'];
4184
			$temp_array['airline_name'] = $row['airline_name'];
4185
			$temp_array['image_thumbnail'] = "";
4186
			if($row['registration'] != "")
4187
			{
4188
				$image_array = $Image->getSpotterImage($row['registration']);
4189
				if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail'];
4190
			}
4191
			$temp_array['registration_count'] = $row['registration_count'];
4192
4193
			$aircraft_array[] = $temp_array;
4194
		}
4195
		return $aircraft_array;
4196
	}
4197
4198
4199
	/**
4200
	* Gets all aircraft manufacturer that have flown over by airline icao
4201
	*
4202
	* @return Array the aircraft list
4203
	*
4204
	*/
4205
	public function countAllAircraftManufacturerByAirline($airline_icao)
4206
	{
4207
		$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING);
4208
4209
		$query  = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count  
4210
				FROM spotter_output
4211
				WHERE spotter_output.aircraft_manufacturer <> '' AND spotter_output.airline_icao = :airline_icao 
4212
				GROUP BY spotter_output.aircraft_manufacturer 
4213
				ORDER BY aircraft_manufacturer_count DESC";
4214
4215
		$sth = $this->db->prepare($query);
4216
		$sth->execute(array(':airline_icao' => $airline_icao));
4217
4218
		$aircraft_array = array();
4219
		$temp_array = array();
4220
4221
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4222
		{
4223
			$temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer'];
4224
			$temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count'];
4225
4226
			$aircraft_array[] = $temp_array;
4227
		}
4228
		return $aircraft_array;
4229
	}
4230
4231
4232
	/**
4233
	* Gets all aircraft types that have flown over by airline icao
4234
	*
4235
	* @return Array the aircraft list
4236
	*
4237
	*/
4238
	public function countAllAircraftTypesByAirport($airport_icao)
4239
	{
4240
		$airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING);
4241
4242
		$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name  
4243
				FROM spotter_output
4244
				WHERE spotter_output.aircraft_icao <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao) 
4245
				GROUP BY spotter_output.aircraft_name 
4246
				ORDER BY aircraft_icao_count DESC";
4247
 
4248
		$sth = $this->db->prepare($query);
4249
		$sth->execute(array(':airport_icao' => $airport_icao));
4250
4251
		$aircraft_array = array();
4252
		$temp_array = array();
4253
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4254
		{
4255
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4256
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4257
			$temp_array['aircraft_icao_count'] = $row['aircraft_icao_count'];
4258
4259
			$aircraft_array[] = $temp_array;
4260
		}
4261
		return $aircraft_array;
4262
	}
4263
4264
4265
	/**
4266
	* Gets all aircraft registration that have flown over by airport icao
4267
	*
4268
	* @return Array the aircraft list
4269
	*
4270
	*/
4271
	public function countAllAircraftRegistrationByAirport($airport_icao)
4272
	{
4273
		$Image = new Image($this->db);
4274
		$airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING);
4275
4276
		$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name  
4277
                    FROM spotter_output
4278
                    WHERE spotter_output.registration <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao)   
4279
                    GROUP BY spotter_output.registration 
4280
					ORDER BY registration_count DESC";
4281
4282
		
4283
		$sth = $this->db->prepare($query);
4284
		$sth->execute(array(':airport_icao' => $airport_icao));
4285
4286
		$aircraft_array = array();
4287
		$temp_array = array();
4288
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4289
		{
4290
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4291
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4292
			$temp_array['registration'] = $row['registration'];
4293
			$temp_array['airline_name'] = $row['airline_name'];
4294
			$temp_array['image_thumbnail'] = "";
4295
			if($row['registration'] != "")
4296
			{
4297
				$image_array = $Image->getSpotterImage($row['registration']);
4298
				$temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail'];
4299
			}
4300
			$temp_array['registration_count'] = $row['registration_count'];
4301
			$aircraft_array[] = $temp_array;
4302
		}
4303
		return $aircraft_array;
4304
	}
4305
	
4306
	
4307
	/**
4308
	* Gets all aircraft manufacturer that have flown over by airport icao
4309
	*
4310
	* @return Array the aircraft list
4311
	*
4312
	*/
4313
	public function countAllAircraftManufacturerByAirport($airport_icao)
4314
	{
4315
		$airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING);
4316
4317
		$query  = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count  
4318
                    FROM spotter_output
4319
                    WHERE spotter_output.aircraft_manufacturer <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao)  
4320
                    GROUP BY spotter_output.aircraft_manufacturer 
4321
					ORDER BY aircraft_manufacturer_count DESC";
4322
4323
		
4324
		$sth = $this->db->prepare($query);
4325
		$sth->execute(array(':airport_icao' => $airport_icao));
4326
4327
		$aircraft_array = array();
4328
		$temp_array = array();
4329
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4330
		{
4331
			$temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer'];
4332
			$temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count'];
4333
			$aircraft_array[] = $temp_array;
4334
		}
4335
		return $aircraft_array;
4336
	}
4337
4338
	/**
4339
	* Gets all aircraft types that have flown over by aircraft manufacturer
4340
	*
4341
	* @return Array the aircraft list
4342
	*
4343
	*/
4344
	public function countAllAircraftTypesByManufacturer($aircraft_manufacturer)
4345
	{
4346
		$aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING);
4347
4348
		$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name  
4349
                    FROM spotter_output
4350
                    WHERE spotter_output.aircraft_manufacturer = :aircraft_manufacturer
4351
                    GROUP BY spotter_output.aircraft_name 
4352
					ORDER BY aircraft_icao_count DESC";
4353
4354
		$sth = $this->db->prepare($query);
4355
		$sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer));
4356
		$aircraft_array = array();
4357
		$temp_array = array();
4358
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4359
		{
4360
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4361
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4362
			$temp_array['aircraft_icao_count'] = $row['aircraft_icao_count'];
4363
			$aircraft_array[] = $temp_array;
4364
		}
4365
		return $aircraft_array;
4366
	}
4367
4368
4369
	/**
4370
	* Gets all aircraft registration that have flown over by aircaft manufacturer
4371
	*
4372
	* @return Array the aircraft list
4373
	*
4374
	*/
4375
	public function countAllAircraftRegistrationByManufacturer($aircraft_manufacturer)
4376
	{
4377
		$Image = new Image($this->db);
4378
		$aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING);
4379
4380
		$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name   
4381
                    FROM spotter_output
4382
                    WHERE spotter_output.registration <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer   
4383
                    GROUP BY spotter_output.registration 
4384
					ORDER BY registration_count DESC";
4385
4386
		
4387
		$sth = $this->db->prepare($query);
4388
		$sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer));
4389
		$aircraft_array = array();
4390
		$temp_array = array();
4391
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4392
		{
4393
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4394
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4395
			$temp_array['registration'] = $row['registration'];
4396
			$temp_array['airline_name'] = $row['airline_name'];
4397
			$temp_array['image_thumbnail'] = "";
4398
			if($row['registration'] != "")
4399
			{
4400
				$image_array = $Image->getSpotterImage($row['registration']);
4401
				$temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail'];
4402
			}
4403
			$temp_array['registration_count'] = $row['registration_count'];
4404
			$aircraft_array[] = $temp_array;
4405
		}
4406
		return $aircraft_array;
4407
	}
4408
4409
	/**
4410
	* Gets all aircraft types that have flown over by date
4411
	*
4412
	* @return Array the aircraft list
4413
	*
4414
	*/
4415
	public function countAllAircraftTypesByDate($date)
4416
	{
4417
		global $globalTimezone, $globalDBdriver;
4418
		$date = filter_var($date,FILTER_SANITIZE_STRING);
4419
		if ($globalTimezone != '') {
4420
			date_default_timezone_set($globalTimezone);
4421
			$datetime = new DateTime($date);
4422
			$offset = $datetime->format('P');
4423
		} else $offset = '+00:00';
4424
4425
		if ($globalDBdriver == 'mysql') {
4426
			$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name  
4427
					FROM spotter_output
4428
					WHERE DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date
4429
					GROUP BY spotter_output.aircraft_name 
4430
					ORDER BY aircraft_icao_count DESC";
4431
		} else {
4432
			$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name  
4433
					FROM spotter_output
4434
					WHERE to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date
4435
					GROUP BY spotter_output.aircraft_name 
4436
					ORDER BY aircraft_icao_count DESC";
4437
		}
4438
		
4439
		$sth = $this->db->prepare($query);
4440
		$sth->execute(array(':date' => $date, ':offset' => $offset));
4441
4442
		$aircraft_array = array();
4443
		$temp_array = array();
4444
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4445
		{
4446
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4447
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4448
			$temp_array['aircraft_icao_count'] = $row['aircraft_icao_count'];
4449
4450
			$aircraft_array[] = $temp_array;
4451
		}
4452
		return $aircraft_array;
4453
	}
4454
4455
4456
	/**
4457
	* Gets all aircraft registration that have flown over by date
4458
	*
4459
	* @return Array the aircraft list
4460
	*
4461
	*/
4462
	public function countAllAircraftRegistrationByDate($date)
4463
	{
4464
		global $globalTimezone, $globalDBdriver;
4465
		$Image = new Image($this->db);
4466
		$date = filter_var($date,FILTER_SANITIZE_STRING);
4467
		if ($globalTimezone != '') {
4468
			date_default_timezone_set($globalTimezone);
4469
			$datetime = new DateTime($date);
4470
			$offset = $datetime->format('P');
4471
		} else $offset = '+00:00';
4472
4473
		if ($globalDBdriver == 'mysql') {
4474
			$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name    
4475
					FROM spotter_output
4476
					WHERE spotter_output.registration <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date 
4477
					GROUP BY spotter_output.registration 
4478
					ORDER BY registration_count DESC";
4479
		} else {
4480
			$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name    
4481
					FROM spotter_output
4482
					WHERE spotter_output.registration <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date 
4483
					GROUP BY spotter_output.registration 
4484
					ORDER BY registration_count DESC";
4485
		}
4486
		
4487
		$sth = $this->db->prepare($query);
4488
		$sth->execute(array(':date' => $date, ':offset' => $offset));
4489
4490
		$aircraft_array = array();
4491
		$temp_array = array();
4492
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4493
		{
4494
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4495
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4496
			$temp_array['registration'] = $row['registration'];
4497
			$temp_array['airline_name'] = $row['airline_name'];
4498
			$temp_array['image_thumbnail'] = "";
4499
			if($row['registration'] != "")
4500
			{
4501
				$image_array = $Image->getSpotterImage($row['registration']);
4502
				$temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail'];
4503
			}
4504
			$temp_array['registration_count'] = $row['registration_count'];
4505
 
4506
			$aircraft_array[] = $temp_array;
4507
		}
4508
		return $aircraft_array;
4509
	}
4510
4511
4512
	/**
4513
	* Gets all aircraft manufacturer that have flown over by date
4514
	*
4515
	* @return Array the aircraft manufacturer list
4516
	*
4517
	*/
4518
	public function countAllAircraftManufacturerByDate($date)
4519
	{
4520
		global $globalTimezone, $globalDBdriver;
4521
		$date = filter_var($date,FILTER_SANITIZE_STRING);
4522
		if ($globalTimezone != '') {
4523
			date_default_timezone_set($globalTimezone);
4524
			$datetime = new DateTime($date);
4525
			$offset = $datetime->format('P');
4526
		} else $offset = '+00:00';
4527
4528
		if ($globalDBdriver == 'mysql') {
4529
			$query  = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count  
4530
				FROM spotter_output
4531
				WHERE spotter_output.aircraft_manufacturer <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date 
4532
				GROUP BY spotter_output.aircraft_manufacturer 
4533
				ORDER BY aircraft_manufacturer_count DESC";
4534
		} else {
4535
			$query  = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count  
4536
				FROM spotter_output
4537
				WHERE spotter_output.aircraft_manufacturer <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date 
4538
				GROUP BY spotter_output.aircraft_manufacturer 
4539
				ORDER BY aircraft_manufacturer_count DESC";
4540
		}
4541
		
4542
		$sth = $this->db->prepare($query);
4543
		$sth->execute(array(':date' => $date, ':offset' => $offset));
4544
4545
		$aircraft_array = array();
4546
		$temp_array = array();
4547
4548
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4549
		{
4550
			$temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer'];
4551
			$temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count'];
4552
4553
			$aircraft_array[] = $temp_array;
4554
		}
4555
		return $aircraft_array;
4556
	}
4557
4558
4559
	/**
4560
	* Gets all aircraft types that have flown over by ident/callsign
4561
	*
4562
	* @return Array the aircraft list
4563
	*
4564
	*/
4565
	public function countAllAircraftTypesByIdent($ident)
4566
	{
4567
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
4568
4569
		$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name  
4570
				FROM spotter_output
4571
				WHERE spotter_output.ident = :ident 
4572
				GROUP BY spotter_output.aircraft_name, spotter_output.aircraft_icao
4573
				ORDER BY aircraft_icao_count DESC";
4574
4575
		$sth = $this->db->prepare($query);
4576
		$sth->execute(array(':ident' => $ident));
4577
      
4578
		$aircraft_array = array();
4579
		$temp_array = array();
4580
4581
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4582
		{
4583
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4584
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4585
			$temp_array['aircraft_icao_count'] = $row['aircraft_icao_count'];
4586
4587
			$aircraft_array[] = $temp_array;
4588
		}
4589
		return $aircraft_array;
4590
	}
4591
4592
4593
	/**
4594
	* Gets all aircraft registration that have flown over by ident/callsign
4595
	*
4596
	* @return Array the aircraft list
4597
	*
4598
	*/
4599
	public function countAllAircraftRegistrationByIdent($ident)
4600
	{
4601
		$Image = new Image($this->db);
4602
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
4603
4604
		$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name  
4605
                    FROM spotter_output
4606
                    WHERE spotter_output.registration <> '' AND spotter_output.ident = :ident   
4607
                    GROUP BY spotter_output.registration,spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.airline_name
4608
		    ORDER BY registration_count DESC";
4609
4610
		
4611
		$sth = $this->db->prepare($query);
4612
		$sth->execute(array(':ident' => $ident));
4613
      
4614
		$aircraft_array = array();
4615
		$temp_array = array();
4616
        
4617
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4618
		{
4619
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4620
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4621
			$temp_array['registration'] = $row['registration'];
4622
			$temp_array['airline_name'] = $row['airline_name'];
4623
			$temp_array['image_thumbnail'] = "";
4624
			if($row['registration'] != "")
4625
			{
4626
				$image_array = $Image->getSpotterImage($row['registration']);
4627
				if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail'];
4628
				else $temp_array['image_thumbnail'] = '';
4629
			}
4630
			$temp_array['registration_count'] = $row['registration_count'];
4631
			$aircraft_array[] = $temp_array;
4632
		}
4633
		return $aircraft_array;
4634
	}
4635
4636
4637
	/**
4638
	* Gets all aircraft manufacturer that have flown over by ident/callsign
4639
	*
4640
	* @return Array the aircraft manufacturer list
4641
	*
4642
	*/
4643
	public function countAllAircraftManufacturerByIdent($ident)
4644
	{
4645
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
4646
4647
		$query  = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count  
4648
                    FROM spotter_output
4649
                    WHERE spotter_output.aircraft_manufacturer <> '' AND spotter_output.ident = :ident  
4650
                    GROUP BY spotter_output.aircraft_manufacturer 
4651
					ORDER BY aircraft_manufacturer_count DESC";
4652
4653
		
4654
		$sth = $this->db->prepare($query);
4655
		$sth->execute(array(':ident' => $ident));
4656
		$aircraft_array = array();
4657
		$temp_array = array();
4658
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4659
		{
4660
			$temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer'];
4661
			$temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count'];
4662
			$aircraft_array[] = $temp_array;
4663
		}
4664
		return $aircraft_array;
4665
	}
4666
4667
4668
	/**
4669
	* Gets all aircraft types that have flown over by route
4670
	*
4671
	* @return Array the aircraft list
4672
	*
4673
	*/
4674
	public function countAllAircraftTypesByRoute($departure_airport_icao, $arrival_airport_icao)
4675
	{
4676
		$departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING);
4677
		$arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING);
4678
		
4679
4680
		$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name  
4681
                    FROM spotter_output
4682
                    WHERE (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao)
4683
                    GROUP BY spotter_output.aircraft_name 
4684
					ORDER BY aircraft_icao_count DESC";
4685
 
4686
		
4687
		$sth = $this->db->prepare($query);
4688
		$sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao));
4689
		$aircraft_array = array();
4690
		$temp_array = array();
4691
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4692
		{
4693
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4694
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4695
			$temp_array['aircraft_icao_count'] = $row['aircraft_icao_count'];
4696
			$aircraft_array[] = $temp_array;
4697
		}
4698
		return $aircraft_array;
4699
	}
4700
4701
	/**
4702
	* Gets all aircraft registration that have flown over by route
4703
	*
4704
	* @return Array the aircraft list
4705
	*
4706
	*/
4707
	public function countAllAircraftRegistrationByRoute($departure_airport_icao, $arrival_airport_icao)
4708
	{
4709
		$Image = new Image($this->db);
4710
		$departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING);
4711
		$arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING);
4712
4713
		$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name   
4714
                    FROM spotter_output
4715
                    WHERE spotter_output.registration <> '' AND (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao)   
4716
                    GROUP BY spotter_output.registration 
4717
					ORDER BY registration_count DESC";
4718
4719
		
4720
		$sth = $this->db->prepare($query);
4721
		$sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao));
4722
      
4723
		$aircraft_array = array();
4724
		$temp_array = array();
4725
        
4726
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4727
		{
4728
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4729
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4730
			$temp_array['registration'] = $row['registration'];
4731
			$temp_array['airline_name'] = $row['airline_name'];
4732
			$temp_array['image_thumbnail'] = "";
4733
			if($row['registration'] != "")
4734
			{
4735
				$image_array = $Image->getSpotterImage($row['registration']);
4736
				if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail'];
4737
			}
4738
			$temp_array['registration_count'] = $row['registration_count'];
4739
          
4740
			$aircraft_array[] = $temp_array;
4741
		}
4742
4743
		return $aircraft_array;
4744
	}
4745
	
4746
	
4747
	/**
4748
	* Gets all aircraft manufacturer that have flown over by route
4749
	*
4750
	* @return Array the aircraft manufacturer list
4751
	*
4752
	*/
4753
	public function countAllAircraftManufacturerByRoute($departure_airport_icao, $arrival_airport_icao)
4754
	{
4755
		$departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING);
4756
		$arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING);
4757
4758
		$query  = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count  
4759
                    FROM spotter_output
4760
                    WHERE spotter_output.aircraft_manufacturer <> '' AND (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao) 
4761
                    GROUP BY spotter_output.aircraft_manufacturer 
4762
					ORDER BY aircraft_manufacturer_count DESC";
4763
4764
		
4765
		$sth = $this->db->prepare($query);
4766
		$sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao));
4767
      
4768
		$aircraft_array = array();
4769
		$temp_array = array();
4770
        
4771
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4772
		{
4773
			$temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer'];
4774
			$temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count'];
4775
          
4776
			$aircraft_array[] = $temp_array;
4777
		}
4778
4779
		return $aircraft_array;
4780
	}	
4781
4782
	
4783
	
4784
	
4785
	/**
4786
	* Gets all aircraft types that have flown over by country
4787
	*
4788
	* @return Array the aircraft list
4789
	*
4790
	*/
4791
	public function countAllAircraftTypesByCountry($country)
4792
	{
4793
		$country = filter_var($country,FILTER_SANITIZE_STRING);
4794
4795
		$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.aircraft_icao) AS aircraft_icao_count, spotter_output.aircraft_name  
4796
                    FROM spotter_output
4797
                    WHERE ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country 
4798
                    GROUP BY spotter_output.aircraft_name 
4799
					ORDER BY aircraft_icao_count DESC";
4800
 
4801
		
4802
		$sth = $this->db->prepare($query);
4803
		$sth->execute(array(':country' => $country));
4804
      
4805
		$aircraft_array = array();
4806
		$temp_array = array();
4807
        
4808
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4809
		{
4810
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4811
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4812
			$temp_array['aircraft_icao_count'] = $row['aircraft_icao_count'];
4813
          
4814
			$aircraft_array[] = $temp_array;
4815
		}
4816
4817
		return $aircraft_array;
4818
	}
4819
4820
4821
	/**
4822
	* Gets all aircraft registration that have flown over by country
4823
	*
4824
	* @return Array the aircraft list
4825
	*
4826
	*/
4827
	public function countAllAircraftRegistrationByCountry($country)
4828
	{
4829
		$Image = new Image($this->db);
4830
		$country = filter_var($country,FILTER_SANITIZE_STRING);
4831
4832
		$query  = "SELECT DISTINCT spotter_output.aircraft_icao, COUNT(spotter_output.registration) AS registration_count, spotter_output.aircraft_name, spotter_output.registration, spotter_output.airline_name 
4833
                    FROM spotter_output
4834
                    WHERE spotter_output.registration <> '' AND (((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country)    
4835
                    GROUP BY spotter_output.registration 
4836
					ORDER BY registration_count DESC";
4837
4838
		
4839
		$sth = $this->db->prepare($query);
4840
		$sth->execute(array(':country' => $country));
4841
      
4842
		$aircraft_array = array();
4843
		$temp_array = array();
4844
        
4845
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4846
		{
4847
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4848
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4849
			$temp_array['registration'] = $row['registration'];
4850
			$temp_array['airline_name'] = $row['airline_name'];
4851
			$temp_array['image_thumbnail'] = "";
4852
			if($row['registration'] != "")
4853
			{
4854
				$image_array = $Image->getSpotterImage($row['registration']);
4855
				if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail'];
4856
			}
4857
			$temp_array['registration_count'] = $row['registration_count'];
4858
          
4859
			$aircraft_array[] = $temp_array;
4860
		}
4861
4862
		return $aircraft_array;
4863
	}
4864
	
4865
	
4866
	/**
4867
	* Gets all aircraft manufacturer that have flown over by country
4868
	*
4869
	* @return Array the aircraft manufacturer list
4870
	*
4871
	*/
4872
	public function countAllAircraftManufacturerByCountry($country)
4873
	{
4874
		$country = filter_var($country,FILTER_SANITIZE_STRING);
4875
4876
		$query  = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count  
4877
                    FROM spotter_output
4878
                    WHERE spotter_output.aircraft_manufacturer <> '' AND (((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country) 
4879
                    GROUP BY spotter_output.aircraft_manufacturer 
4880
					ORDER BY aircraft_manufacturer_count DESC";
4881
4882
		
4883
		$sth = $this->db->prepare($query);
4884
		$sth->execute(array(':country' => $country));
4885
      
4886
		$aircraft_array = array();
4887
		$temp_array = array();
4888
        
4889
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4890
		{
4891
			$temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer'];
4892
			$temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count'];
4893
          
4894
			$aircraft_array[] = $temp_array;
4895
		}
4896
4897
		return $aircraft_array;
4898
	}	
4899
	
4900
	
4901
	
4902
	/**
4903
	* Gets all aircraft manufacturers that have flown over
4904
	*
4905
	* @return Array the aircraft list
4906
	*
4907
	*/
4908
	public function countAllAircraftManufacturers()
4909
	{
4910
		$query  = "SELECT DISTINCT spotter_output.aircraft_manufacturer, COUNT(spotter_output.aircraft_manufacturer) AS aircraft_manufacturer_count  
4911
                    FROM spotter_output 
4912
                    WHERE spotter_output.aircraft_manufacturer <> '' AND spotter_output.aircraft_manufacturer <> 'Not Available' 
4913
                    GROUP BY spotter_output.aircraft_manufacturer
4914
					ORDER BY aircraft_manufacturer_count DESC
4915
					LIMIT 10";
4916
      
4917
		
4918
		$sth = $this->db->prepare($query);
4919
		$sth->execute();
4920
      
4921
		$manufacturer_array = array();
4922
		$temp_array = array();
4923
        
4924
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4925
		{
4926
			$temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer'];
4927
			$temp_array['aircraft_manufacturer_count'] = $row['aircraft_manufacturer_count'];
4928
          
4929
			$manufacturer_array[] = $temp_array;
4930
		}
4931
4932
		return $manufacturer_array;
4933
	}
4934
	
4935
	
4936
	
4937
	/**
4938
	* Gets all aircraft registrations that have flown over
4939
	*
4940
	* @return Array the aircraft list
4941
	*
4942
	*/
4943
	public function countAllAircraftRegistrations($limit = true,$olderthanmonths = 0,$sincedate = '')
4944
	{
4945
		global $globalDBdriver;
4946
		$Image = new Image($this->db);
4947
		$query  = "SELECT DISTINCT spotter_output.registration, COUNT(spotter_output.registration) AS aircraft_registration_count, spotter_output.aircraft_icao,  spotter_output.aircraft_name, spotter_output.airline_name    
4948
                    FROM spotter_output 
4949
                    WHERE spotter_output.registration <> '' AND spotter_output.registration <> 'NA' ";
4950
                if ($olderthanmonths > 0) {
4951
            		if ($globalDBdriver == 'mysql') {
4952
				$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) ';
4953
			} else {
4954
				$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' ";
4955
			}
4956
		}
4957
                if ($sincedate != '') {
4958
            		if ($globalDBdriver == 'mysql') {
4959
				$query .= "AND date > '".$sincedate."' ";
4960
			} else {
4961
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
4962
			}
4963
		}
4964
4965
		// if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
4966
		//if ($sincedate != '') $query .= "AND date > '".$sincedate."' ";
4967
                $query .= "GROUP BY spotter_output.registration, spotter_output.aircraft_icao, spotter_output.aircraft_name, spotter_output.airline_name ORDER BY aircraft_registration_count DESC";
4968
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
4969
		
4970
		$sth = $this->db->prepare($query);
4971
		$sth->execute();
4972
      
4973
		$aircraft_array = array();
4974
		$temp_array = array();
4975
        
4976
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
4977
		{
4978
			$temp_array['registration'] = $row['registration'];
4979
			$temp_array['aircraft_registration_count'] = $row['aircraft_registration_count'];
4980
			$temp_array['aircraft_icao'] = $row['aircraft_icao'];
4981
			$temp_array['aircraft_name'] = $row['aircraft_name'];
4982
			$temp_array['airline_name'] = $row['airline_name'];
4983
			$temp_array['image_thumbnail'] = "";
4984
			if($row['registration'] != "")
4985
			{
4986
				$image_array = $Image->getSpotterImage($row['registration']);
4987
				if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail'];
4988
			}
4989
          
4990
			$aircraft_array[] = $temp_array;
4991
		}
4992
4993
		return $aircraft_array;
4994
	}
4995
4996
4997
	
4998
	
4999
	/**
5000
	* Gets all departure airports of the airplanes that have flown over
5001
	*
5002
	* @return Array the airport list
5003
	*
5004
	*/
5005
	public function countAllDepartureAirports($limit = true, $olderthanmonths = 0, $sincedate = '')
5006
	{
5007
		global $globalDBdriver;
5008
		$query  = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country 
5009
								FROM spotter_output
5010
                    WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' ";
5011
                if ($olderthanmonths > 0) {
5012
            		if ($globalDBdriver == 'mysql') {
5013
				$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) ';
5014
			} else {
5015
				$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' ";
5016
			}
5017
                }
5018
                if ($sincedate != '') {
5019
            		if ($globalDBdriver == 'mysql') {
5020
				$query .= "AND date > '".$sincedate."' ";
5021
			} else {
5022
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
5023
			}
5024
		}
5025
5026
            	//if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
5027
                //if ($sincedate != '') $query .= "AND date > '".$sincedate."' ";
5028
                $query .= "GROUP BY spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country
5029
				ORDER BY airport_departure_icao_count DESC";
5030
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
5031
      
5032
		$sth = $this->db->prepare($query);
5033
		$sth->execute();
5034
      
5035
		$airport_array = array();
5036
		$temp_array = array();
5037
        
5038
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5039
		{
5040
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
5041
			$temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count'];
5042
			$temp_array['airport_departure_name'] = $row['departure_airport_name'];
5043
			$temp_array['airport_departure_city'] = $row['departure_airport_city'];
5044
			$temp_array['airport_departure_country'] = $row['departure_airport_country'];
5045
          
5046
			$airport_array[] = $temp_array;
5047
		}
5048
		return $airport_array;
5049
	}
5050
	
5051
	/**
5052
	* Gets all detected departure airports of the airplanes that have flown over
5053
	*
5054
	* @return Array the airport list
5055
	*
5056
	*/
5057
	public function countAllDetectedDepartureAirports($limit = true, $olderthanmonths = 0, $sincedate = '')
5058
	{
5059
		global $globalDBdriver;
5060
		$query  = "SELECT DISTINCT spotter_output.real_departure_airport_icao AS departure_airport_icao, COUNT(spotter_output.real_departure_airport_icao) AS airport_departure_icao_count, airport.name as departure_airport_name, airport.city as departure_airport_city, airport.country as departure_airport_country
5061
				FROM spotter_output, airport
5062
                    WHERE spotter_output.real_departure_airport_icao <> '' AND spotter_output.real_departure_airport_icao <> 'NA' AND airport.icao = spotter_output.real_departure_airport_icao ";
5063
                if ($olderthanmonths > 0) {
5064
            		if ($globalDBdriver == 'mysql') {
5065
				$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) ';
5066
			} else {
5067
				$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' ";
5068
			}
5069
                }
5070
                if ($sincedate != '') {
5071
            		if ($globalDBdriver == 'mysql') {
5072
				$query .= "AND date > '".$sincedate."' ";
5073
			} else {
5074
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
5075
			}
5076
		}
5077
5078
            	//if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
5079
                //if ($sincedate != '') $query .= "AND date > '".$sincedate."' ";
5080
                $query .= "GROUP BY spotter_output.real_departure_airport_icao, airport.name, airport.city, airport.country
5081
				ORDER BY airport_departure_icao_count DESC";
5082
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
5083
      
5084
		$sth = $this->db->prepare($query);
5085
		$sth->execute();
5086
      
5087
		$airport_array = array();
5088
		$temp_array = array();
5089
        
5090
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5091
		{
5092
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
5093
			$temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count'];
5094
			$temp_array['airport_departure_name'] = $row['departure_airport_name'];
5095
			$temp_array['airport_departure_city'] = $row['departure_airport_city'];
5096
			$temp_array['airport_departure_country'] = $row['departure_airport_country'];
5097
          
5098
			$airport_array[] = $temp_array;
5099
		}
5100
		return $airport_array;
5101
	}
5102
	
5103
	
5104
	
5105
	/**
5106
	* Gets all departure airports of the airplanes that have flown over based on an airline icao
5107
	*
5108
	* @return Array the airport list
5109
	*
5110
	*/
5111
	public function countAllDepartureAirportsByAirline($airline_icao)
5112
	{
5113
		$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING);
5114
5115
		$query  = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country 
5116
								FROM spotter_output
5117
                    WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.airline_icao = :airline_icao 
5118
                    GROUP BY spotter_output.departure_airport_icao
5119
					ORDER BY airport_departure_icao_count DESC";
5120
      
5121
		
5122
		$sth = $this->db->prepare($query);
5123
		$sth->execute(array(':airline_icao' => $airline_icao));
5124
      
5125
		$airport_array = array();
5126
		$temp_array = array();
5127
        
5128
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5129
		{
5130
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
5131
			$temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count'];
5132
			$temp_array['airport_departure_name'] = $row['departure_airport_name'];
5133
			$temp_array['airport_departure_city'] = $row['departure_airport_city'];
5134
			$temp_array['airport_departure_country'] = $row['departure_airport_country'];
5135
          
5136
			$airport_array[] = $temp_array;
5137
		}
5138
5139
		return $airport_array;
5140
	}
5141
	
5142
	
5143
	
5144
	/**
5145
	* Gets all departure airports by country of the airplanes that have flown over based on an airline icao
5146
	*
5147
	* @return Array the airport list
5148
	*
5149
	*/
5150
	public function countAllDepartureAirportCountriesByAirline($airline_icao)
5151
	{
5152
		$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING);
5153
					
5154
		$query  = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count 
5155
								FROM spotter_output 
5156
                    WHERE spotter_output.departure_airport_country <> '' AND spotter_output.airline_icao = :airline_icao 
5157
                    GROUP BY spotter_output.departure_airport_country
5158
					ORDER BY airport_departure_country_count DESC";
5159
      
5160
		
5161
		$sth = $this->db->prepare($query);
5162
		$sth->execute(array(':airline_icao' => $airline_icao));
5163
      
5164
		$airport_array = array();
5165
		$temp_array = array();
5166
        
5167
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5168
		{
5169
			$temp_array['departure_airport_country'] = $row['departure_airport_country'];
5170
			$temp_array['airport_departure_country_count'] = $row['airport_departure_country_count'];
5171
          
5172
			$airport_array[] = $temp_array;
5173
		}
5174
5175
		return $airport_array;
5176
	}
5177
	
5178
	
5179
	
5180
	/**
5181
	* Gets all departure airports of the airplanes that have flown over based on an aircraft icao
5182
	*
5183
	* @return Array the airport list
5184
	*
5185
	*/
5186
	public function countAllDepartureAirportsByAircraft($aircraft_icao)
5187
	{
5188
		$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
5189
5190
		$query  = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country 
5191
								FROM spotter_output
5192
                    WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.aircraft_icao = :aircraft_icao 
5193
                    GROUP BY spotter_output.departure_airport_icao
5194
					ORDER BY airport_departure_icao_count DESC";
5195
      
5196
		
5197
		$sth = $this->db->prepare($query);
5198
		$sth->execute(array(':aircraft_icao' => $aircraft_icao));
5199
      
5200
		$airport_array = array();
5201
		$temp_array = array();
5202
        
5203
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5204
		{
5205
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
5206
			$temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count'];
5207
			$temp_array['airport_departure_name'] = $row['departure_airport_name'];
5208
			$temp_array['airport_departure_city'] = $row['departure_airport_city'];
5209
			$temp_array['airport_departure_country'] = $row['departure_airport_country'];
5210
          
5211
			$airport_array[] = $temp_array;
5212
		}
5213
5214
		return $airport_array;
5215
	}
5216
	
5217
	
5218
	/**
5219
	* Gets all departure airports by country of the airplanes that have flown over based on an aircraft icao
5220
	*
5221
	* @return Array the airport list
5222
	*
5223
	*/
5224
	public function countAllDepartureAirportCountriesByAircraft($aircraft_icao)
5225
	{
5226
		$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
5227
					
5228
		$query  = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count 
5229
								FROM spotter_output 
5230
                    WHERE spotter_output.departure_airport_country <> '' AND spotter_output.aircraft_icao = :aircraft_icao
5231
                    GROUP BY spotter_output.departure_airport_country
5232
					ORDER BY airport_departure_country_count DESC";
5233
      
5234
		
5235
		$sth = $this->db->prepare($query);
5236
		$sth->execute(array(':aircraft_icao' => $aircraft_icao));
5237
      
5238
		$airport_array = array();
5239
		$temp_array = array();
5240
        
5241
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5242
		{
5243
			$temp_array['departure_airport_country'] = $row['departure_airport_country'];
5244
			$temp_array['airport_departure_country_count'] = $row['airport_departure_country_count'];
5245
          
5246
			$airport_array[] = $temp_array;
5247
		}
5248
5249
		return $airport_array;
5250
	}
5251
	
5252
	
5253
	/**
5254
	* Gets all departure airports of the airplanes that have flown over based on an aircraft registration
5255
	*
5256
	* @return Array the airport list
5257
	*
5258
	*/
5259
	public function countAllDepartureAirportsByRegistration($registration)
5260
	{
5261
		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
5262
5263
		$query  = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country 
5264
								FROM spotter_output
5265
                    WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.registration = :registration 
5266
                    GROUP BY spotter_output.departure_airport_icao
5267
					ORDER BY airport_departure_icao_count DESC";
5268
      
5269
		
5270
		$sth = $this->db->prepare($query);
5271
		$sth->execute(array(':registration' => $registration));
5272
      
5273
		$airport_array = array();
5274
		$temp_array = array();
5275
        
5276
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5277
		{
5278
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
5279
			$temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count'];
5280
			$temp_array['airport_departure_name'] = $row['departure_airport_name'];
5281
			$temp_array['airport_departure_city'] = $row['departure_airport_city'];
5282
			$temp_array['airport_departure_country'] = $row['departure_airport_country'];
5283
          
5284
			$airport_array[] = $temp_array;
5285
		}
5286
5287
		return $airport_array;
5288
	}
5289
	
5290
	
5291
	/**
5292
	* Gets all departure airports by country of the airplanes that have flown over based on an aircraft registration
5293
	*
5294
	* @return Array the airport list
5295
	*
5296
	*/
5297
	public function countAllDepartureAirportCountriesByRegistration($registration)
5298
	{
5299
		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
5300
					
5301
		$query  = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count 
5302
								FROM spotter_output 
5303
                    WHERE spotter_output.departure_airport_country <> '' AND spotter_output.registration = :registration 
5304
                    GROUP BY spotter_output.departure_airport_country
5305
					ORDER BY airport_departure_country_count DESC";
5306
      
5307
		
5308
		$sth = $this->db->prepare($query);
5309
		$sth->execute(array(':registration' => $registration));
5310
      
5311
		$airport_array = array();
5312
		$temp_array = array();
5313
        
5314
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5315
		{
5316
			$temp_array['departure_airport_country'] = $row['departure_airport_country'];
5317
			$temp_array['airport_departure_country_count'] = $row['airport_departure_country_count'];
5318
          
5319
			$airport_array[] = $temp_array;
5320
		}
5321
5322
		return $airport_array;
5323
	}
5324
	
5325
	
5326
	/**
5327
	* Gets all departure airports of the airplanes that have flown over based on an arrivl airport icao
5328
	*
5329
	* @return Array the airport list
5330
	*
5331
	*/
5332
	public function countAllDepartureAirportsByAirport($airport_icao)
5333
	{
5334
		$airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING);
5335
5336
		$query  = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country 
5337
								FROM spotter_output
5338
                    WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao = :airport_icao 
5339
                    GROUP BY spotter_output.departure_airport_icao
5340
					ORDER BY airport_departure_icao_count DESC";
5341
      
5342
		
5343
		$sth = $this->db->prepare($query);
5344
		$sth->execute(array(':airport_icao' => $airport_icao));
5345
      
5346
		$airport_array = array();
5347
		$temp_array = array();
5348
        
5349
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5350
		{
5351
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
5352
			$temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count'];
5353
			$temp_array['airport_departure_name'] = $row['departure_airport_name'];
5354
			$temp_array['airport_departure_city'] = $row['departure_airport_city'];
5355
			$temp_array['airport_departure_country'] = $row['departure_airport_country'];
5356
          
5357
			$airport_array[] = $temp_array;
5358
		}
5359
5360
		return $airport_array;
5361
	}
5362
	
5363
	
5364
	/**
5365
	* Gets all departure airports by country of the airplanes that have flown over based on an airport icao
5366
	*
5367
	* @return Array the airport list
5368
	*
5369
	*/
5370
	public function countAllDepartureAirportCountriesByAirport($airport_icao)
5371
	{
5372
		$airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING);
5373
					
5374
		$query  = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count 
5375
								FROM spotter_output 
5376
                    WHERE spotter_output.departure_airport_country <> '' AND spotter_output.arrival_airport_icao = :airport_icao 
5377
                    GROUP BY spotter_output.departure_airport_country
5378
					ORDER BY airport_departure_country_count DESC";
5379
      
5380
		
5381
		$sth = $this->db->prepare($query);
5382
		$sth->execute(array(':airport_icao' => $airport_icao));
5383
      
5384
		$airport_array = array();
5385
		$temp_array = array();
5386
        
5387
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5388
		{
5389
			$temp_array['departure_airport_country'] = $row['departure_airport_country'];
5390
			$temp_array['airport_departure_country_count'] = $row['airport_departure_country_count'];
5391
          
5392
			$airport_array[] = $temp_array;
5393
		}
5394
5395
		return $airport_array;
5396
	}
5397
	
5398
	
5399
	
5400
	/**
5401
	* Gets all departure airports of the airplanes that have flown over based on an aircraft manufacturer
5402
	*
5403
	* @return Array the airport list
5404
	*
5405
	*/
5406
	public function countAllDepartureAirportsByManufacturer($aircraft_manufacturer)
5407
	{
5408
		$aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING);
5409
5410
		$query  = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country 
5411
								FROM spotter_output
5412
                    WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer 
5413
                    GROUP BY spotter_output.departure_airport_icao
5414
					ORDER BY airport_departure_icao_count DESC";
5415
      
5416
		
5417
		$sth = $this->db->prepare($query);
5418
		$sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer));
5419
      
5420
		$airport_array = array();
5421
		$temp_array = array();
5422
        
5423
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5424
		{
5425
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
5426
			$temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count'];
5427
			$temp_array['airport_departure_name'] = $row['departure_airport_name'];
5428
			$temp_array['airport_departure_city'] = $row['departure_airport_city'];
5429
			$temp_array['airport_departure_country'] = $row['departure_airport_country'];
5430
          
5431
			$airport_array[] = $temp_array;
5432
		}
5433
5434
		return $airport_array;
5435
	}
5436
	
5437
	
5438
	/**
5439
	* Gets all departure airports by country of the airplanes that have flown over based on an aircraft manufacturer
5440
	*
5441
	* @return Array the airport list
5442
	*
5443
	*/
5444
	public function countAllDepartureAirportCountriesByManufacturer($aircraft_manufacturer)
5445
	{
5446
		$aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING);
5447
					
5448
		$query  = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count 
5449
								FROM spotter_output 
5450
                    WHERE spotter_output.departure_airport_country <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer 
5451
                    GROUP BY spotter_output.departure_airport_country
5452
					ORDER BY airport_departure_country_count DESC";
5453
      
5454
		
5455
		$sth = $this->db->prepare($query);
5456
		$sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer));
5457
      
5458
		$airport_array = array();
5459
		$temp_array = array();
5460
        
5461
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5462
		{
5463
			$temp_array['departure_airport_country'] = $row['departure_airport_country'];
5464
			$temp_array['airport_departure_country_count'] = $row['airport_departure_country_count'];
5465
          
5466
			$airport_array[] = $temp_array;
5467
		}
5468
5469
		return $airport_array;
5470
	}
5471
	
5472
	
5473
	/**
5474
	* Gets all departure airports of the airplanes that have flown over based on a date
5475
	*
5476
	* @return Array the airport list
5477
	*
5478
	*/
5479
	public function countAllDepartureAirportsByDate($date)
5480
	{
5481
		global $globalTimezone, $globalDBdriver;
5482
		$date = filter_var($date,FILTER_SANITIZE_STRING);
5483
5484
		if ($globalTimezone != '') {
5485
			date_default_timezone_set($globalTimezone);
5486
			$datetime = new DateTime($date);
5487
			$offset = $datetime->format('P');
5488
		} else $offset = '+00:00';
5489
5490
		if ($globalDBdriver == 'mysql') {
5491
			$query  = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country 
5492
					FROM spotter_output
5493
					WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date
5494
					GROUP BY spotter_output.departure_airport_icao
5495
					ORDER BY airport_departure_icao_count DESC";
5496
		} else {
5497
			$query  = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country 
5498
					FROM spotter_output
5499
					WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date
5500
					GROUP BY spotter_output.departure_airport_icao
5501
					ORDER BY airport_departure_icao_count DESC";
5502
		}
5503
5504
		$sth = $this->db->prepare($query);
5505
		$sth->execute(array(':date' => $date, ':offset' => $offset));
5506
      
5507
		$airport_array = array();
5508
		$temp_array = array();
5509
        
5510
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5511
		{
5512
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
5513
			$temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count'];
5514
			$temp_array['airport_departure_name'] = $row['departure_airport_name'];
5515
			$temp_array['airport_departure_city'] = $row['departure_airport_city'];
5516
			$temp_array['airport_departure_country'] = $row['departure_airport_country'];
5517
          
5518
			$airport_array[] = $temp_array;
5519
		}
5520
		return $airport_array;
5521
	}
5522
	
5523
	
5524
	
5525
	/**
5526
	* Gets all departure airports by country of the airplanes that have flown over based on a date
5527
	*
5528
	* @return Array the airport list
5529
	*
5530
	*/
5531
	public function countAllDepartureAirportCountriesByDate($date)
5532
	{
5533
		global $globalTimezone, $globalDBdriver;
5534
		$date = filter_var($date,FILTER_SANITIZE_STRING);
5535
		if ($globalTimezone != '') {
5536
			date_default_timezone_set($globalTimezone);
5537
			$datetime = new DateTime($date);
5538
			$offset = $datetime->format('P');
5539
		} else $offset = '+00:00';
5540
5541
		if ($globalDBdriver == 'mysql') {
5542
			$query  = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count 
5543
					FROM spotter_output 
5544
					WHERE spotter_output.departure_airport_country <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date 
5545
					GROUP BY spotter_output.departure_airport_country
5546
					ORDER BY airport_departure_country_count DESC";
5547
		} else {
5548
			$query  = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count 
5549
					FROM spotter_output 
5550
					WHERE spotter_output.departure_airport_country <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date 
5551
					GROUP BY spotter_output.departure_airport_country
5552
					ORDER BY airport_departure_country_count DESC";
5553
		}
5554
		
5555
		$sth = $this->db->prepare($query);
5556
		$sth->execute(array(':date' => $date, ':offset' => $offset));
5557
      
5558
		$airport_array = array();
5559
		$temp_array = array();
5560
        
5561
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5562
		{
5563
			$temp_array['departure_airport_country'] = $row['departure_airport_country'];
5564
			$temp_array['airport_departure_country_count'] = $row['airport_departure_country_count'];
5565
          
5566
			$airport_array[] = $temp_array;
5567
		}
5568
		return $airport_array;
5569
	}
5570
	
5571
	
5572
	
5573
	/**
5574
	* Gets all departure airports of the airplanes that have flown over based on a ident/callsign
5575
	*
5576
	* @return Array the airport list
5577
	*
5578
	*/
5579
	public function countAllDepartureAirportsByIdent($ident)
5580
	{
5581
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
5582
5583
		$query  = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country 
5584
		    FROM spotter_output
5585
                    WHERE spotter_output.departure_airport_name <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.ident = :ident 
5586
                    GROUP BY spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country
5587
		    ORDER BY airport_departure_icao_count DESC";
5588
      
5589
		
5590
		$sth = $this->db->prepare($query);
5591
		$sth->execute(array(':ident' => $ident));
5592
      
5593
		$airport_array = array();
5594
		$temp_array = array();
5595
        
5596
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5597
		{
5598
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
5599
			$temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count'];
5600
			$temp_array['airport_departure_name'] = $row['departure_airport_name'];
5601
			$temp_array['airport_departure_city'] = $row['departure_airport_city'];
5602
			$temp_array['airport_departure_country'] = $row['departure_airport_country'];
5603
          
5604
			$airport_array[] = $temp_array;
5605
		}
5606
5607
		return $airport_array;
5608
	}
5609
	
5610
	
5611
	
5612
	/**
5613
	* Gets all departure airports by country of the airplanes that have flown over based on a callsign/ident
5614
	*
5615
	* @return Array the airport list
5616
	*
5617
	*/
5618
	public function countAllDepartureAirportCountriesByIdent($ident)
5619
	{
5620
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
5621
					
5622
		$query  = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count 
5623
								FROM spotter_output 
5624
                    WHERE spotter_output.departure_airport_country <> '' AND spotter_output.ident = :ident 
5625
                    GROUP BY spotter_output.departure_airport_country
5626
					ORDER BY airport_departure_country_count DESC";
5627
      
5628
		
5629
		$sth = $this->db->prepare($query);
5630
		$sth->execute(array(':ident' => $ident));
5631
      
5632
		$airport_array = array();
5633
		$temp_array = array();
5634
        
5635
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5636
		{
5637
			$temp_array['departure_airport_country'] = $row['departure_airport_country'];
5638
			$temp_array['airport_departure_country_count'] = $row['airport_departure_country_count'];
5639
          
5640
			$airport_array[] = $temp_array;
5641
		}
5642
5643
		return $airport_array;
5644
	}
5645
	
5646
	
5647
	
5648
	/**
5649
	* Gets all departure airports of the airplanes that have flown over based on a country
5650
	*
5651
	* @return Array the airport list
5652
	*
5653
	*/
5654
	public function countAllDepartureAirportsByCountry($country)
5655
	{
5656
		$date = filter_var($date,FILTER_SANITIZE_STRING);
0 ignored issues
show
Bug introduced by
The variable $date seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
Unused Code introduced by
$date is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
5657
5658
		$query  = "SELECT DISTINCT spotter_output.departure_airport_icao, COUNT(spotter_output.departure_airport_icao) AS airport_departure_icao_count, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country 
5659
								FROM spotter_output
5660
                    WHERE ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country
5661
                    GROUP BY spotter_output.departure_airport_icao
5662
					ORDER BY airport_departure_icao_count DESC";
5663
      
5664
		
5665
		$sth = $this->db->prepare($query);
5666
		$sth->execute(array(':country' => $country));
5667
      
5668
		$airport_array = array();
5669
		$temp_array = array();
5670
        
5671
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5672
		{
5673
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
5674
			$temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count'];
5675
			$temp_array['airport_departure_name'] = $row['departure_airport_name'];
5676
			$temp_array['airport_departure_city'] = $row['departure_airport_city'];
5677
			$temp_array['airport_departure_country'] = $row['departure_airport_country'];
5678
          
5679
			$airport_array[] = $temp_array;
5680
		}
5681
5682
		return $airport_array;
5683
	}
5684
5685
5686
	/**
5687
	* Gets all departure airports by country of the airplanes that have flown over based on an aircraft icao
5688
	*
5689
	* @return Array the airport list
5690
	*
5691
	*/
5692
	public function countAllDepartureAirportCountriesByCountry($country)
5693
	{
5694
		$country = filter_var($country,FILTER_SANITIZE_STRING);
5695
					
5696
		$query  = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count 
5697
								FROM spotter_output 
5698
                    WHERE spotter_output.departure_airport_country <> '' AND ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country 
5699
                    GROUP BY spotter_output.departure_airport_country
5700
					ORDER BY airport_departure_country_count DESC";
5701
      
5702
		
5703
		$sth = $this->db->prepare($query);
5704
		$sth->execute(array(':country' => $country));
5705
      
5706
		$airport_array = array();
5707
		$temp_array = array();
5708
        
5709
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5710
		{
5711
			$temp_array['departure_airport_country'] = $row['departure_airport_country'];
5712
			$temp_array['airport_departure_country_count'] = $row['airport_departure_country_count'];
5713
          
5714
			$airport_array[] = $temp_array;
5715
		}
5716
5717
		return $airport_array;
5718
	}
5719
	
5720
5721
	/**
5722
	* Gets all arrival airports of the airplanes that have flown over
5723
	*
5724
	* @return Array the airport list
5725
	*
5726
	*/
5727
	public function countAllArrivalAirports($limit = true, $olderthanmonths = 0, $sincedate = '', $icaoaskey = false)
5728
	{
5729
		global $globalDBdriver;
5730
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country 
5731
								FROM spotter_output 
5732
                    WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' ";
5733
                if ($olderthanmonths > 0) {
5734
            		if ($globalDBdriver == 'mysql') {
5735
				$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) ';
5736
			} else {
5737
				$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' ";
5738
			}
5739
                if ($sincedate != '') {
5740
            		if ($globalDBdriver == 'mysql') {
5741
				$query .= "AND date > '".$sincedate."' ";
5742
			} else {
5743
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
5744
			}
5745
		}
5746
            		if ($globalDBdriver == 'mysql') {
5747
				$query .= "AND date > '".$sincedate."' ";
5748
			} else {
5749
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
5750
			}
5751
		}
5752
5753
            	//if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
5754
                //if ($sincedate != '') $query .= "AND date > '".$sincedate."' ";
5755
                $query .= "GROUP BY spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country
5756
					ORDER BY airport_arrival_icao_count DESC";
5757
		if ($limit) $query .= " LIMIT 10";
5758
      
5759
		
5760
		$sth = $this->db->prepare($query);
5761
		$sth->execute();
5762
      
5763
		$airport_array = array();
5764
		$temp_array = array();
5765
        
5766
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5767
		{
5768
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
5769
			$temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count'];
5770
			$temp_array['airport_arrival_name'] = $row['arrival_airport_name'];
5771
			$temp_array['airport_arrival_city'] = $row['arrival_airport_city'];
5772
			$temp_array['airport_arrival_country'] = $row['arrival_airport_country'];
5773
          
5774
			if ($icaoaskey) {
5775
				$icao = $row['arrival_airport_icao'];
5776
				$airport_array[$icao] = $temp_array;
5777
			} else $airport_array[] = $temp_array;
5778
		}
5779
5780
		return $airport_array;
5781
	}
5782
	
5783
	/**
5784
	* Gets all detected arrival airports of the airplanes that have flown over
5785
	*
5786
	* @return Array the airport list
5787
	*
5788
	*/
5789
	public function countAllDetectedArrivalAirports($limit = true, $olderthanmonths = 0, $sincedate = '',$icaoaskey = false)
5790
	{
5791
		global $globalDBdriver;
5792
		$query  = "SELECT DISTINCT spotter_output.real_arrival_airport_icao as arrival_airport_icao, COUNT(spotter_output.real_arrival_airport_icao) AS airport_arrival_icao_count, airport.name AS arrival_airport_name, airport.city AS arrival_airport_city, airport.country AS arrival_airport_country 
5793
			FROM spotter_output, airport 
5794
                    WHERE spotter_output.real_arrival_airport_icao <> '' AND spotter_output.real_arrival_airport_icao <> 'NA' AND airport.icao = spotter_output.real_arrival_airport_icao ";
5795
                if ($olderthanmonths > 0) {
5796
            		if ($globalDBdriver == 'mysql') {
5797
				$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH) ';
5798
			} else {
5799
				$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' ";
5800
			}
5801
                if ($sincedate != '') {
5802
            		if ($globalDBdriver == 'mysql') {
5803
				$query .= "AND date > '".$sincedate."' ";
5804
			} else {
5805
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
5806
			}
5807
		}
5808
            		if ($globalDBdriver == 'mysql') {
5809
				$query .= "AND date > '".$sincedate."' ";
5810
			} else {
5811
				$query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP)";
5812
			}
5813
		}
5814
5815
            	//if ($olderthanmonths > 0) $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
5816
                //if ($sincedate != '') $query .= "AND date > '".$sincedate."' ";
5817
                $query .= "GROUP BY spotter_output.real_arrival_airport_icao, airport.name, airport.city, airport.country
5818
					ORDER BY airport_arrival_icao_count DESC";
5819
		if ($limit) $query .= " LIMIT 10";
5820
      
5821
		
5822
		$sth = $this->db->prepare($query);
5823
		$sth->execute();
5824
      
5825
		$airport_array = array();
5826
		$temp_array = array();
5827
        
5828
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5829
		{
5830
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
5831
			$temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count'];
5832
			$temp_array['airport_arrival_name'] = $row['arrival_airport_name'];
5833
			$temp_array['airport_arrival_city'] = $row['arrival_airport_city'];
5834
			$temp_array['airport_arrival_country'] = $row['arrival_airport_country'];
5835
          
5836
			if ($icaoaskey) {
5837
				$icao = $row['arrival_airport_icao'];
5838
				$airport_array[$icao] = $temp_array;
5839
			} else $airport_array[] = $temp_array;
5840
		}
5841
5842
		return $airport_array;
5843
	}
5844
	
5845
	
5846
	
5847
	/**
5848
	* Gets all arrival airports of the airplanes that have flown over based on an airline icao
5849
	*
5850
	* @return Array the airport list
5851
	*
5852
	*/
5853
	public function countAllArrivalAirportsByAirline($airline_icao)
5854
	{
5855
		$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING);
5856
5857
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country 
5858
								FROM spotter_output 
5859
                    WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.airline_icao = :airline_icao 
5860
                    GROUP BY spotter_output.arrival_airport_icao
5861
					ORDER BY airport_arrival_icao_count DESC";
5862
      
5863
		
5864
		$sth = $this->db->prepare($query);
5865
		$sth->execute(array(':airline_icao' => $airline_icao));
5866
      
5867
		$airport_array = array();
5868
		$temp_array = array();
5869
        
5870
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5871
		{
5872
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
5873
			$temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count'];
5874
			$temp_array['airport_arrival_name'] = $row['arrival_airport_name'];
5875
			$temp_array['airport_arrival_city'] = $row['arrival_airport_city'];
5876
			$temp_array['airport_arrival_country'] = $row['arrival_airport_country'];
5877
          
5878
			$airport_array[] = $temp_array;
5879
		}
5880
5881
		return $airport_array;
5882
	}
5883
	
5884
	
5885
	/**
5886
	* Gets all arrival airports by country of the airplanes that have flown over based on an airline icao
5887
	*
5888
	* @return Array the airport list
5889
	*
5890
	*/
5891
	public function countAllArrivalAirportCountriesByAirline($airline_icao)
5892
	{
5893
		$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING);
5894
					
5895
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count 
5896
								FROM spotter_output 
5897
                    WHERE spotter_output.arrival_airport_country <> '' AND spotter_output.airline_icao = :airline_icao 
5898
                    GROUP BY spotter_output.arrival_airport_country
5899
					ORDER BY airport_arrival_country_count DESC";
5900
      
5901
		
5902
		$sth = $this->db->prepare($query);
5903
		$sth->execute(array(':airline_icao' => $airline_icao));
5904
      
5905
		$airport_array = array();
5906
		$temp_array = array();
5907
        
5908
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5909
		{
5910
			$temp_array['arrival_airport_country'] = $row['arrival_airport_country'];
5911
			$temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count'];
5912
          
5913
			$airport_array[] = $temp_array;
5914
		}
5915
5916
		return $airport_array;
5917
	}
5918
	
5919
	
5920
	/**
5921
	* Gets all arrival airports of the airplanes that have flown over based on an aircraft icao
5922
	*
5923
	* @return Array the airport list
5924
	*
5925
	*/
5926
	public function countAllArrivalAirportsByAircraft($aircraft_icao)
5927
	{
5928
		$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
5929
5930
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country 
5931
								FROM spotter_output 
5932
                    WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.aircraft_icao = :aircraft_icao 
5933
                    GROUP BY spotter_output.arrival_airport_icao
5934
					ORDER BY airport_arrival_icao_count DESC";
5935
      
5936
		
5937
		$sth = $this->db->prepare($query);
5938
		$sth->execute(array(':aircraft_icao' => $aircraft_icao));
5939
      
5940
		$airport_array = array();
5941
		$temp_array = array();
5942
        
5943
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5944
		{
5945
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
5946
			$temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count'];
5947
			$temp_array['airport_arrival_name'] = $row['arrival_airport_name'];
5948
			$temp_array['airport_arrival_city'] = $row['arrival_airport_city'];
5949
			$temp_array['airport_arrival_country'] = $row['arrival_airport_country'];
5950
          
5951
			$airport_array[] = $temp_array;
5952
		}
5953
5954
		return $airport_array;
5955
	}
5956
	
5957
	
5958
	
5959
	/**
5960
	* Gets all arrival airports by country of the airplanes that have flown over based on an aircraft icao
5961
	*
5962
	* @return Array the airport list
5963
	*
5964
	*/
5965
	public function countAllArrivalAirportCountriesByAircraft($aircraft_icao)
5966
	{
5967
		$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
5968
					
5969
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count 
5970
								FROM spotter_output 
5971
                    WHERE spotter_output.arrival_airport_country <> '' AND spotter_output.aircraft_icao = :aircraft_icao
5972
                    GROUP BY spotter_output.arrival_airport_country
5973
					ORDER BY airport_arrival_country_count DESC";
5974
      
5975
		
5976
		$sth = $this->db->prepare($query);
5977
		$sth->execute(array(':aircraft_icao' => $aircraft_icao));
5978
      
5979
		$airport_array = array();
5980
		$temp_array = array();
5981
        
5982
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
5983
		{
5984
			$temp_array['arrival_airport_country'] = $row['arrival_airport_country'];
5985
			$temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count'];
5986
          
5987
			$airport_array[] = $temp_array;
5988
		}
5989
5990
		return $airport_array;
5991
	}
5992
	
5993
	
5994
	/**
5995
	* Gets all arrival airports of the airplanes that have flown over based on an aircraft registration
5996
	*
5997
	* @return Array the airport list
5998
	*
5999
	*/
6000
	public function countAllArrivalAirportsByRegistration($registration)
6001
	{
6002
		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
6003
6004
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country 
6005
								FROM spotter_output 
6006
                    WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.registration = :registration 
6007
                    GROUP BY spotter_output.arrival_airport_icao
6008
					ORDER BY airport_arrival_icao_count DESC";
6009
      
6010
		
6011
		$sth = $this->db->prepare($query);
6012
		$sth->execute(array(':registration' => $registration));
6013
      
6014
		$airport_array = array();
6015
		$temp_array = array();
6016
        
6017
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6018
		{
6019
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6020
			$temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count'];
6021
			$temp_array['airport_arrival_name'] = $row['arrival_airport_name'];
6022
			$temp_array['airport_arrival_city'] = $row['arrival_airport_city'];
6023
			$temp_array['airport_arrival_country'] = $row['arrival_airport_country'];
6024
          
6025
			$airport_array[] = $temp_array;
6026
		}
6027
6028
		return $airport_array;
6029
	}
6030
	
6031
	
6032
	/**
6033
	* Gets all arrival airports by country of the airplanes that have flown over based on an aircraft registration
6034
	*
6035
	* @return Array the airport list
6036
	*
6037
	*/
6038
	public function countAllArrivalAirportCountriesByRegistration($registration)
6039
	{
6040
		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
6041
					
6042
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count 
6043
								FROM spotter_output 
6044
                    WHERE spotter_output.arrival_airport_country <> '' AND spotter_output.registration = :registration 
6045
                    GROUP BY spotter_output.arrival_airport_country
6046
					ORDER BY airport_arrival_country_count DESC";
6047
      
6048
		
6049
		$sth = $this->db->prepare($query);
6050
		$sth->execute(array(':registration' => $registration));
6051
      
6052
		$airport_array = array();
6053
		$temp_array = array();
6054
        
6055
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6056
		{
6057
			$temp_array['arrival_airport_country'] = $row['arrival_airport_country'];
6058
			$temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count'];
6059
          
6060
			$airport_array[] = $temp_array;
6061
		}
6062
6063
		return $airport_array;
6064
	}
6065
	
6066
	
6067
	
6068
	/**
6069
	* Gets all arrival airports of the airplanes that have flown over based on an departure airport
6070
	*
6071
	* @return Array the airport list
6072
	*
6073
	*/
6074
	public function countAllArrivalAirportsByAirport($airport_icao)
6075
	{
6076
		$airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING);
6077
6078
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country 
6079
								FROM spotter_output 
6080
                    WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.departure_airport_icao = :airport_icao 
6081
                    GROUP BY spotter_output.arrival_airport_icao
6082
					ORDER BY airport_arrival_icao_count DESC";
6083
      
6084
		
6085
		$sth = $this->db->prepare($query);
6086
		$sth->execute(array(':airport_icao' => $airport_icao));
6087
      
6088
		$airport_array = array();
6089
		$temp_array = array();
6090
        
6091
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6092
		{
6093
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6094
			$temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count'];
6095
			$temp_array['airport_arrival_name'] = $row['arrival_airport_name'];
6096
			$temp_array['airport_arrival_city'] = $row['arrival_airport_city'];
6097
			$temp_array['airport_arrival_country'] = $row['arrival_airport_country'];
6098
          
6099
			$airport_array[] = $temp_array;
6100
		}
6101
6102
		return $airport_array;
6103
	}
6104
	
6105
	
6106
	/**
6107
	* Gets all arrival airports by country of the airplanes that have flown over based on an airport icao
6108
	*
6109
	* @return Array the airport list
6110
	*
6111
	*/
6112
	public function countAllArrivalAirportCountriesByAirport($airport_icao)
6113
	{
6114
		$airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING);
6115
					
6116
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count 
6117
								FROM spotter_output 
6118
                    WHERE spotter_output.arrival_airport_country <> '' AND spotter_output.departure_airport_icao = :airport_icao 
6119
                    GROUP BY spotter_output.arrival_airport_country
6120
					ORDER BY airport_arrival_country_count DESC";
6121
      
6122
		
6123
		$sth = $this->db->prepare($query);
6124
		$sth->execute(array(':airport_icao' => $airport_icao));
6125
      
6126
		$airport_array = array();
6127
		$temp_array = array();
6128
        
6129
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6130
		{
6131
			$temp_array['arrival_airport_country'] = $row['arrival_airport_country'];
6132
			$temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count'];
6133
          
6134
			$airport_array[] = $temp_array;
6135
		}
6136
6137
		return $airport_array;
6138
	}
6139
	
6140
	
6141
	/**
6142
	* Gets all arrival airports of the airplanes that have flown over based on a aircraft manufacturer
6143
	*
6144
	* @return Array the airport list
6145
	*
6146
	*/
6147
	public function countAllArrivalAirportsByManufacturer($aircraft_manufacturer)
6148
	{
6149
		$aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING);
6150
6151
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country 
6152
								FROM spotter_output 
6153
                    WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer 
6154
                    GROUP BY spotter_output.arrival_airport_icao
6155
					ORDER BY airport_arrival_icao_count DESC";
6156
      
6157
		
6158
		$sth = $this->db->prepare($query);
6159
		$sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer));
6160
      
6161
		$airport_array = array();
6162
		$temp_array = array();
6163
        
6164
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6165
		{
6166
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6167
			$temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count'];
6168
			$temp_array['airport_arrival_name'] = $row['arrival_airport_name'];
6169
			$temp_array['airport_arrival_city'] = $row['arrival_airport_city'];
6170
			$temp_array['airport_arrival_country'] = $row['arrival_airport_country'];
6171
          
6172
			$airport_array[] = $temp_array;
6173
		}
6174
6175
		return $airport_array;
6176
	}
6177
	
6178
	
6179
	
6180
	/**
6181
	* Gets all arrival airports by country of the airplanes that have flown over based on a aircraft manufacturer
6182
	*
6183
	* @return Array the airport list
6184
	*
6185
	*/
6186
	public function countAllArrivalAirportCountriesByManufacturer($aircraft_manufacturer)
6187
	{
6188
		$aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING);
6189
					
6190
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count 
6191
								FROM spotter_output 
6192
                    WHERE spotter_output.arrival_airport_country <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer 
6193
                    GROUP BY spotter_output.arrival_airport_country
6194
					ORDER BY airport_arrival_country_count DESC";
6195
      
6196
		
6197
		$sth = $this->db->prepare($query);
6198
		$sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer));
6199
      
6200
		$airport_array = array();
6201
		$temp_array = array();
6202
        
6203
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6204
		{
6205
			$temp_array['arrival_airport_country'] = $row['arrival_airport_country'];
6206
			$temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count'];
6207
          
6208
			$airport_array[] = $temp_array;
6209
		}
6210
6211
		return $airport_array;
6212
	}
6213
	
6214
	
6215
	
6216
	/**
6217
	* Gets all arrival airports of the airplanes that have flown over based on a date
6218
	*
6219
	* @return Array the airport list
6220
	*
6221
	*/
6222
	public function countAllArrivalAirportsByDate($date)
6223
	{
6224
		global $globalTimezone, $globalDBdriver;
6225
		$date = filter_var($date,FILTER_SANITIZE_STRING);
6226
		if ($globalTimezone != '') {
6227
			date_default_timezone_set($globalTimezone);
6228
			$datetime = new DateTime($date);
6229
			$offset = $datetime->format('P');
6230
		} else $offset = '+00:00';
6231
6232
		if ($globalDBdriver == 'mysql') {
6233
			$query  = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country 
6234
					FROM spotter_output 
6235
					WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date  
6236
					GROUP BY spotter_output.arrival_airport_icao
6237
					ORDER BY airport_arrival_icao_count DESC";
6238
		} else {
6239
			$query  = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country 
6240
					FROM spotter_output 
6241
					WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date  
6242
					GROUP BY spotter_output.arrival_airport_icao
6243
					ORDER BY airport_arrival_icao_count DESC";
6244
		}
6245
		
6246
		$sth = $this->db->prepare($query);
6247
		$sth->execute(array(':date' => $date, ':offset' => $offset));
6248
      
6249
		$airport_array = array();
6250
		$temp_array = array();
6251
        
6252
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6253
		{
6254
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6255
			$temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count'];
6256
			$temp_array['airport_arrival_name'] = $row['arrival_airport_name'];
6257
			$temp_array['airport_arrival_city'] = $row['arrival_airport_city'];
6258
			$temp_array['airport_arrival_country'] = $row['arrival_airport_country'];
6259
          
6260
			$airport_array[] = $temp_array;
6261
		}
6262
		return $airport_array;
6263
	}
6264
	
6265
	
6266
	
6267
	/**
6268
	* Gets all arrival airports by country of the airplanes that have flown over based on a date
6269
	*
6270
	* @return Array the airport list
6271
	*
6272
	*/
6273
	public function countAllArrivalAirportCountriesByDate($date)
6274
	{
6275
		global $globalTimezone, $globalDBdriver;
6276
		$date = filter_var($date,FILTER_SANITIZE_STRING);
6277
		if ($globalTimezone != '') {
6278
			date_default_timezone_set($globalTimezone);
6279
			$datetime = new DateTime($date);
6280
			$offset = $datetime->format('P');
6281
		} else $offset = '+00:00';
6282
6283
		if ($globalDBdriver == 'mysql') {
6284
			$query  = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count 
6285
					FROM spotter_output 
6286
					WHERE spotter_output.arrival_airport_country <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date 
6287
					GROUP BY spotter_output.arrival_airport_country
6288
					ORDER BY airport_arrival_country_count DESC";
6289
		} else {
6290
			$query  = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count 
6291
					FROM spotter_output 
6292
					WHERE spotter_output.arrival_airport_country <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date 
6293
					GROUP BY spotter_output.arrival_airport_country
6294
					ORDER BY airport_arrival_country_count DESC";
6295
		}
6296
		
6297
		$sth = $this->db->prepare($query);
6298
		$sth->execute(array(':date' => $date, ':offset' => $offset));
6299
      
6300
		$airport_array = array();
6301
		$temp_array = array();
6302
        
6303
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6304
		{
6305
			$temp_array['arrival_airport_country'] = $row['arrival_airport_country'];
6306
			$temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count'];
6307
          
6308
			$airport_array[] = $temp_array;
6309
		}
6310
		return $airport_array;
6311
	}
6312
	
6313
	
6314
	
6315
	/**
6316
	* Gets all arrival airports of the airplanes that have flown over based on a ident/callsign
6317
	*
6318
	* @return Array the airport list
6319
	*
6320
	*/
6321
	public function countAllArrivalAirportsByIdent($ident)
6322
	{
6323
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
6324
6325
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country 
6326
		    FROM spotter_output 
6327
                    WHERE spotter_output.arrival_airport_name <> '' AND spotter_output.arrival_airport_icao <> 'NA' AND spotter_output.ident = :ident  
6328
                    GROUP BY spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country
6329
		    ORDER BY airport_arrival_icao_count DESC";
6330
      
6331
		
6332
		$sth = $this->db->prepare($query);
6333
		$sth->execute(array(':ident' => $ident));
6334
      
6335
		$airport_array = array();
6336
		$temp_array = array();
6337
        
6338
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6339
		{
6340
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6341
			$temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count'];
6342
			$temp_array['airport_arrival_name'] = $row['arrival_airport_name'];
6343
			$temp_array['airport_arrival_city'] = $row['arrival_airport_city'];
6344
			$temp_array['airport_arrival_country'] = $row['arrival_airport_country'];
6345
          
6346
			$airport_array[] = $temp_array;
6347
		}
6348
6349
		return $airport_array;
6350
	}
6351
	
6352
	
6353
	/**
6354
	* Gets all arrival airports by country of the airplanes that have flown over based on a callsign/ident
6355
	*
6356
	* @return Array the airport list
6357
	*
6358
	*/
6359
	public function countAllArrivalAirportCountriesByIdent($ident)
6360
	{
6361
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
6362
					
6363
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count 
6364
								FROM spotter_output 
6365
                    WHERE spotter_output.arrival_airport_country <> '' AND spotter_output.ident = :ident 
6366
                    GROUP BY spotter_output.arrival_airport_country
6367
					ORDER BY airport_arrival_country_count DESC";
6368
      
6369
		
6370
		$sth = $this->db->prepare($query);
6371
		$sth->execute(array(':ident' => $ident));
6372
      
6373
		$airport_array = array();
6374
		$temp_array = array();
6375
        
6376
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6377
		{
6378
			$temp_array['arrival_airport_country'] = $row['arrival_airport_country'];
6379
			$temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count'];
6380
          
6381
			$airport_array[] = $temp_array;
6382
		}
6383
6384
		return $airport_array;
6385
	}
6386
	
6387
	
6388
	
6389
	/**
6390
	* Gets all arrival airports of the airplanes that have flown over based on a country
6391
	*
6392
	* @return Array the airport list
6393
	*
6394
	*/
6395
	public function countAllArrivalAirportsByCountry($country)
6396
	{
6397
		$country = filter_var($country,FILTER_SANITIZE_STRING);
6398
6399
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_icao, COUNT(spotter_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country 
6400
								FROM spotter_output 
6401
                    WHERE ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country  
6402
                    GROUP BY spotter_output.arrival_airport_icao
6403
					ORDER BY airport_arrival_icao_count DESC";
6404
      
6405
		
6406
		$sth = $this->db->prepare($query);
6407
		$sth->execute(array(':country' => $country));
6408
      
6409
		$airport_array = array();
6410
		$temp_array = array();
6411
        
6412
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6413
		{
6414
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6415
			$temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count'];
6416
			$temp_array['airport_arrival_name'] = $row['arrival_airport_name'];
6417
			$temp_array['airport_arrival_city'] = $row['arrival_airport_city'];
6418
			$temp_array['airport_arrival_country'] = $row['arrival_airport_country'];
6419
          
6420
			$airport_array[] = $temp_array;
6421
		}
6422
6423
		return $airport_array;
6424
	}
6425
	
6426
	
6427
	/**
6428
	* Gets all arrival airports by country of the airplanes that have flown over based on a country
6429
	*
6430
	* @return Array the airport list
6431
	*
6432
	*/
6433
	public function countAllArrivalAirportCountriesByCountry($country)
6434
	{
6435
		$country = filter_var($country,FILTER_SANITIZE_STRING);
6436
					
6437
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count 
6438
								FROM spotter_output 
6439
                    WHERE spotter_output.arrival_airport_country <> '' AND ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country 
6440
                    GROUP BY spotter_output.arrival_airport_country
6441
					ORDER BY airport_arrival_country_count DESC";
6442
      
6443
		
6444
		$sth = $this->db->prepare($query);
6445
		$sth->execute(array(':country' => $country));
6446
      
6447
		$airport_array = array();
6448
		$temp_array = array();
6449
        
6450
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6451
		{
6452
			$temp_array['arrival_airport_country'] = $row['arrival_airport_country'];
6453
			$temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count'];
6454
          
6455
			$airport_array[] = $temp_array;
6456
		}
6457
6458
		return $airport_array;
6459
	}
6460
6461
6462
6463
	/**
6464
	* Counts all airport departure countries
6465
	*
6466
	* @return Array the airport departure list
6467
	*
6468
	*/
6469
	public function countAllDepartureCountries()
6470
	{
6471
		$query  = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count 
6472
								FROM spotter_output 
6473
                    WHERE spotter_output.departure_airport_country <> '' AND spotter_output.departure_airport_icao <> 'NA' 
6474
                    GROUP BY spotter_output.departure_airport_country
6475
					ORDER BY airport_departure_country_count DESC
6476
					LIMIT 10 OFFSET 0";
6477
      
6478
		
6479
		$sth = $this->db->prepare($query);
6480
		$sth->execute();
6481
      
6482
		$airport_array = array();
6483
		$temp_array = array();
6484
        
6485
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6486
		{
6487
			$temp_array['airport_departure_country_count'] = $row['airport_departure_country_count'];
6488
			$temp_array['airport_departure_country'] = $row['departure_airport_country'];
6489
          
6490
			$airport_array[] = $temp_array;
6491
		}
6492
6493
		return $airport_array;
6494
	}
6495
	
6496
	
6497
	/**
6498
	* Counts all airport arrival countries
6499
	*
6500
	* @return Array the airport arrival list
6501
	*
6502
	*/
6503
	public function countAllArrivalCountries($limit = true)
6504
	{
6505
		$query  = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count 
6506
								FROM spotter_output 
6507
                    WHERE spotter_output.arrival_airport_country <> '' AND spotter_output.arrival_airport_icao <> 'NA' 
6508
                    GROUP BY spotter_output.arrival_airport_country
6509
					ORDER BY airport_arrival_country_count DESC";
6510
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
6511
      
6512
		
6513
		$sth = $this->db->prepare($query);
6514
		$sth->execute();
6515
      
6516
		$airport_array = array();
6517
		$temp_array = array();
6518
        
6519
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6520
		{
6521
			$temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count'];
6522
			$temp_array['airport_arrival_country'] = $row['arrival_airport_country'];
6523
          
6524
			$airport_array[] = $temp_array;
6525
		}
6526
6527
		return $airport_array;
6528
	}
6529
6530
6531
6532
6533
6534
	/**
6535
	* Gets all route combinations
6536
	*
6537
	* @return Array the route list
6538
	*
6539
	*/
6540
	public function countAllRoutes()
6541
	{
6542
		
6543
		$query  = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ',  spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country
6544
		    FROM spotter_output
6545
                    WHERE spotter_output.ident <> '' AND spotter_output.departure_airport_icao <> 'NA' AND spotter_output.arrival_airport_icao <> 'NA'
6546
                    GROUP BY route,spotter_output.departure_airport_icao, spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country
6547
                    ORDER BY route_count DESC
6548
		    LIMIT 10 OFFSET 0";
6549
      
6550
		
6551
		$sth = $this->db->prepare($query);
6552
		$sth->execute();
6553
      
6554
		$routes_array = array();
6555
		$temp_array = array();
6556
        
6557
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6558
		{
6559
			$temp_array['route_count'] = $row['route_count'];
6560
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
6561
			$temp_array['airport_departure_name'] = $row['airport_departure_name'];
6562
			$temp_array['airport_departure_city'] = $row['airport_departure_city'];
6563
			$temp_array['airport_departure_country'] = $row['airport_departure_country'];
6564
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6565
			$temp_array['airport_arrival_name'] = $row['airport_arrival_name'];
6566
			$temp_array['airport_arrival_city'] = $row['airport_arrival_city'];
6567
			$temp_array['airport_arrival_country'] = $row['airport_arrival_country'];
6568
          
6569
			$routes_array[] = $temp_array;
6570
		}
6571
6572
		return $routes_array;
6573
	}
6574
	
6575
	
6576
	
6577
	
6578
	/**
6579
	* Gets all route combinations based on an aircraft
6580
	*
6581
	* @return Array the route list
6582
	*
6583
	*/
6584
	public function countAllRoutesByAircraft($aircraft_icao)
6585
	{
6586
		$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
6587
		
6588
		$query  = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ',  spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country
6589
								FROM spotter_output
6590
                    WHERE spotter_output.ident <> '' AND spotter_output.aircraft_icao = :aircraft_icao 
6591
                    GROUP BY route
6592
                    ORDER BY route_count DESC";
6593
      
6594
		
6595
		$sth = $this->db->prepare($query);
6596
		$sth->execute(array(':aircraft_icao' => $aircraft_icao));
6597
      
6598
		$routes_array = array();
6599
		$temp_array = array();
6600
        
6601
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6602
		{
6603
			$temp_array['route_count'] = $row['route_count'];
6604
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
6605
			$temp_array['airport_departure_name'] = $row['airport_departure_name'];
6606
			$temp_array['airport_departure_city'] = $row['airport_departure_city'];
6607
			$temp_array['airport_departure_country'] = $row['airport_departure_country'];
6608
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6609
			$temp_array['airport_arrival_name'] = $row['airport_arrival_name'];
6610
			$temp_array['airport_arrival_city'] = $row['airport_arrival_city'];
6611
			$temp_array['airport_arrival_country'] = $row['airport_arrival_country'];
6612
          
6613
			$routes_array[] = $temp_array;
6614
		}
6615
6616
		return $routes_array;
6617
	}
6618
	
6619
	
6620
	/**
6621
	* Gets all route combinations based on an aircraft registration
6622
	*
6623
	* @return Array the route list
6624
	*
6625
	*/
6626
	public function countAllRoutesByRegistration($registration)
6627
	{
6628
		$registration = filter_var($registration, FILTER_SANITIZE_STRING);
6629
		
6630
		$query  = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ',  spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country
6631
								FROM spotter_output
6632
                    WHERE spotter_output.ident <> '' AND spotter_output.registration = :registration 
6633
                    GROUP BY route
6634
                    ORDER BY route_count DESC";
6635
      
6636
		
6637
		$sth = $this->db->prepare($query);
6638
		$sth->execute(array(':registration' => $registration));
6639
      
6640
		$routes_array = array();
6641
		$temp_array = array();
6642
        
6643
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6644
		{
6645
			$temp_array['route_count'] = $row['route_count'];
6646
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
6647
			$temp_array['airport_departure_name'] = $row['airport_departure_name'];
6648
			$temp_array['airport_departure_city'] = $row['airport_departure_city'];
6649
			$temp_array['airport_departure_country'] = $row['airport_departure_country'];
6650
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6651
			$temp_array['airport_arrival_name'] = $row['airport_arrival_name'];
6652
			$temp_array['airport_arrival_city'] = $row['airport_arrival_city'];
6653
			$temp_array['airport_arrival_country'] = $row['airport_arrival_country'];
6654
          
6655
			$routes_array[] = $temp_array;
6656
		}
6657
6658
		return $routes_array;
6659
	}
6660
	
6661
	
6662
	
6663
	/**
6664
	* Gets all route combinations based on an airline
6665
	*
6666
	* @return Array the route list
6667
	*
6668
	*/
6669
	public function countAllRoutesByAirline($airline_icao)
6670
	{
6671
		$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING);
6672
		
6673
		$query  = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ',  spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country
6674
								FROM spotter_output
6675
                    WHERE spotter_output.ident <> '' AND spotter_output.airline_icao = :airline_icao 
6676
                    GROUP BY route
6677
                    ORDER BY route_count DESC";
6678
      
6679
		
6680
		$sth = $this->db->prepare($query);
6681
		$sth->execute(array(':airline_icao' => $airline_icao));
6682
      
6683
		$routes_array = array();
6684
		$temp_array = array();
6685
        
6686
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6687
		{
6688
			$temp_array['route_count'] = $row['route_count'];
6689
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
6690
			$temp_array['airport_departure_name'] = $row['airport_departure_name'];
6691
			$temp_array['airport_departure_city'] = $row['airport_departure_city'];
6692
			$temp_array['airport_departure_country'] = $row['airport_departure_country'];
6693
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6694
			$temp_array['airport_arrival_name'] = $row['airport_arrival_name'];
6695
			$temp_array['airport_arrival_city'] = $row['airport_arrival_city'];
6696
			$temp_array['airport_arrival_country'] = $row['airport_arrival_country'];
6697
          
6698
			$routes_array[] = $temp_array;
6699
		}
6700
6701
		return $routes_array;
6702
	}
6703
	
6704
	
6705
	
6706
	/**
6707
	* Gets all route combinations based on an airport
6708
	*
6709
	* @return Array the route list
6710
	*
6711
	*/
6712
	public function countAllRoutesByAirport($airport_icao)
6713
	{
6714
		$airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING);
6715
		
6716
		$query  = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ',  spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country
6717
								FROM spotter_output
6718
                    WHERE spotter_output.ident <> '' AND (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao)
6719
                    GROUP BY route
6720
                    ORDER BY route_count DESC";
6721
      
6722
		
6723
		$sth = $this->db->prepare($query);
6724
		$sth->execute(array(':airport_icao' => $airport_icao));
6725
      
6726
		$routes_array = array();
6727
		$temp_array = array();
6728
        
6729
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6730
		{
6731
			$temp_array['route_count'] = $row['route_count'];
6732
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
6733
			$temp_array['airport_departure_name'] = $row['airport_departure_name'];
6734
			$temp_array['airport_departure_city'] = $row['airport_departure_city'];
6735
			$temp_array['airport_departure_country'] = $row['airport_departure_country'];
6736
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6737
			$temp_array['airport_arrival_name'] = $row['airport_arrival_name'];
6738
			$temp_array['airport_arrival_city'] = $row['airport_arrival_city'];
6739
			$temp_array['airport_arrival_country'] = $row['airport_arrival_country'];
6740
          
6741
			$routes_array[] = $temp_array;
6742
		}
6743
6744
		return $routes_array;
6745
	}
6746
	
6747
	
6748
	
6749
	/**
6750
	* Gets all route combinations based on an country
6751
	*
6752
	* @return Array the route list
6753
	*
6754
	*/
6755
	public function countAllRoutesByCountry($country)
6756
	{
6757
		$country = filter_var($country,FILTER_SANITIZE_STRING);
6758
		
6759
		$query  = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ',  spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country
6760
								FROM spotter_output
6761
                    WHERE spotter_output.ident <> '' AND ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country 
6762
                    GROUP BY route
6763
                    ORDER BY route_count DESC";
6764
      
6765
		
6766
		$sth = $this->db->prepare($query);
6767
		$sth->execute(array(':country' => $country));
6768
      
6769
		$routes_array = array();
6770
		$temp_array = array();
6771
        
6772
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6773
		{
6774
			$temp_array['route_count'] = $row['route_count'];
6775
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
6776
			$temp_array['airport_departure_name'] = $row['airport_departure_name'];
6777
			$temp_array['airport_departure_city'] = $row['airport_departure_city'];
6778
			$temp_array['airport_departure_country'] = $row['airport_departure_country'];
6779
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6780
			$temp_array['airport_arrival_name'] = $row['airport_arrival_name'];
6781
			$temp_array['airport_arrival_city'] = $row['airport_arrival_city'];
6782
			$temp_array['airport_arrival_country'] = $row['airport_arrival_country'];
6783
          
6784
			$routes_array[] = $temp_array;
6785
		}
6786
6787
		return $routes_array;
6788
	}
6789
6790
6791
	/**
6792
	* Gets all route combinations based on an date
6793
	*
6794
	* @return Array the route list
6795
	*
6796
	*/
6797
	public function countAllRoutesByDate($date)
6798
	{
6799
		global $globalTimezone, $globalDBdriver;
6800
		$date = filter_var($date,FILTER_SANITIZE_STRING);
6801
		if ($globalTimezone != '') {
6802
			date_default_timezone_set($globalTimezone);
6803
			$datetime = new DateTime($date);
6804
			$offset = $datetime->format('P');
6805
		} else $offset = '+00:00';
6806
		
6807
		if ($globalDBdriver == 'mysql') {
6808
			$query  = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ',  spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country
6809
					FROM spotter_output
6810
					WHERE spotter_output.ident <> '' AND DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date  
6811
					GROUP BY route
6812
					ORDER BY route_count DESC";
6813
		} else {
6814
			$query  = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ',  spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country
6815
					FROM spotter_output
6816
					WHERE spotter_output.ident <> '' AND to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = :date  
6817
					GROUP BY route
6818
					ORDER BY route_count DESC";
6819
		}
6820
		
6821
		$sth = $this->db->prepare($query);
6822
		$sth->execute(array(':date' => $date, ':offset' => $offset));
6823
      
6824
		$routes_array = array();
6825
		$temp_array = array();
6826
        
6827
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6828
		{
6829
			$temp_array['route_count'] = $row['route_count'];
6830
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
6831
			$temp_array['airport_departure_name'] = $row['airport_departure_name'];
6832
			$temp_array['airport_departure_city'] = $row['airport_departure_city'];
6833
			$temp_array['airport_departure_country'] = $row['airport_departure_country'];
6834
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6835
			$temp_array['airport_arrival_name'] = $row['airport_arrival_name'];
6836
			$temp_array['airport_arrival_city'] = $row['airport_arrival_city'];
6837
			$temp_array['airport_arrival_country'] = $row['airport_arrival_country'];
6838
          
6839
			$routes_array[] = $temp_array;
6840
		}
6841
6842
		return $routes_array;
6843
	}
6844
	
6845
	
6846
	/**
6847
	* Gets all route combinations based on an ident/callsign
6848
	*
6849
	* @return Array the route list
6850
	*
6851
	*/
6852
	public function countAllRoutesByIdent($ident)
6853
	{
6854
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
6855
		
6856
		$query  = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ',  spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country
6857
		    FROM spotter_output
6858
                    WHERE spotter_output.ident <> '' AND spotter_output.ident = :ident   
6859
                    GROUP BY route, spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country
6860
                    ORDER BY route_count DESC";
6861
      
6862
		
6863
		$sth = $this->db->prepare($query);
6864
		$sth->execute(array(':ident' => $ident));
6865
      
6866
		$routes_array = array();
6867
		$temp_array = array();
6868
        
6869
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6870
		{
6871
			$temp_array['route_count'] = $row['route_count'];
6872
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
6873
			$temp_array['airport_departure_name'] = $row['airport_departure_name'];
6874
			$temp_array['airport_departure_city'] = $row['airport_departure_city'];
6875
			$temp_array['airport_departure_country'] = $row['airport_departure_country'];
6876
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6877
			$temp_array['airport_arrival_name'] = $row['airport_arrival_name'];
6878
			$temp_array['airport_arrival_city'] = $row['airport_arrival_city'];
6879
			$temp_array['airport_arrival_country'] = $row['airport_arrival_country'];
6880
          
6881
			$routes_array[] = $temp_array;
6882
		}
6883
6884
		return $routes_array;
6885
	}
6886
	
6887
	
6888
	/**
6889
	* Gets all route combinations based on an manufacturer
6890
	*
6891
	* @return Array the route list
6892
	*
6893
	*/
6894
	public function countAllRoutesByManufacturer($aircraft_manufacturer)
0 ignored issues
show
Unused Code introduced by
The parameter $aircraft_manufacturer is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
6895
	{
6896
		$aircraft_manufacturer = filter_var($aircraft_manufactuer,FILTER_SANITIZE_STRING);
0 ignored issues
show
Bug introduced by
The variable $aircraft_manufactuer does not exist. Did you mean $aircraft_manufacturer?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
6897
		
6898
		$query  = "SELECT DISTINCT concat(spotter_output.departure_airport_icao, ' - ',  spotter_output.arrival_airport_icao) AS route, count(concat(spotter_output.departure_airport_icao, ' - ', spotter_output.arrival_airport_icao)) AS route_count, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country
6899
								FROM spotter_output
6900
                    WHERE spotter_output.ident <> '' AND spotter_output.aircraft_manufacturer = :aircraft_manufacturer   
6901
                    GROUP BY route
6902
                    ORDER BY route_count DESC";
6903
      
6904
		
6905
		$sth = $this->db->prepare($query);
6906
		$sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer));
6907
      
6908
		$routes_array = array();
6909
		$temp_array = array();
6910
        
6911
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6912
		{
6913
			$temp_array['route_count'] = $row['route_count'];
6914
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
6915
			$temp_array['airport_departure_name'] = $row['airport_departure_name'];
6916
			$temp_array['airport_departure_city'] = $row['airport_departure_city'];
6917
			$temp_array['airport_departure_country'] = $row['airport_departure_country'];
6918
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6919
			$temp_array['airport_arrival_name'] = $row['airport_arrival_name'];
6920
			$temp_array['airport_arrival_city'] = $row['airport_arrival_city'];
6921
			$temp_array['airport_arrival_country'] = $row['airport_arrival_country'];
6922
          
6923
			$routes_array[] = $temp_array;
6924
		}
6925
6926
		return $routes_array;
6927
	}
6928
6929
	
6930
	
6931
	/**
6932
	* Gets all route combinations with waypoints
6933
	*
6934
	* @return Array the route list
6935
	*
6936
	*/
6937
	public function countAllRoutesWithWaypoints()
6938
	{
6939
		$query  = "SELECT DISTINCT spotter_output.waypoints AS route, count(spotter_output.waypoints) AS route_count, spotter_output.spotter_id, spotter_output.departure_airport_icao, spotter_output.departure_airport_name AS airport_departure_name, spotter_output.departure_airport_city AS airport_departure_city, spotter_output.departure_airport_country AS airport_departure_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name AS airport_arrival_name, spotter_output.arrival_airport_city AS airport_arrival_city, spotter_output.arrival_airport_country AS airport_arrival_country
6940
		    FROM spotter_output
6941
                    WHERE spotter_output.ident <> '' AND spotter_output.waypoints <> '' 
6942
                    GROUP BY route, spotter_output.spotter_id, spotter_output.departure_airport_icao, spotter_output.departure_airport_name, spotter_output.departure_airport_city, spotter_output.departure_airport_country, spotter_output.arrival_airport_icao, spotter_output.arrival_airport_name, spotter_output.arrival_airport_city, spotter_output.arrival_airport_country
6943
                    ORDER BY route_count DESC
6944
		    LIMIT 10 OFFSET 0";
6945
      
6946
		
6947
		$sth = $this->db->prepare($query);
6948
		$sth->execute();
6949
      
6950
		$routes_array = array();
6951
		$temp_array = array();
6952
        
6953
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
6954
		{
6955
			$temp_array['spotter_id'] = $row['spotter_id'];
6956
			$temp_array['route_count'] = $row['route_count'];
6957
			$temp_array['airport_departure_icao'] = $row['departure_airport_icao'];
6958
			$temp_array['airport_departure_name'] = $row['airport_departure_name'];
6959
			$temp_array['airport_departure_city'] = $row['airport_departure_city'];
6960
			$temp_array['airport_departure_country'] = $row['airport_departure_country'];
6961
			$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao'];
6962
			$temp_array['airport_arrival_name'] = $row['airport_arrival_name'];
6963
			$temp_array['airport_arrival_city'] = $row['airport_arrival_city'];
6964
			$temp_array['airport_arrival_country'] = $row['airport_arrival_country'];
6965
          
6966
			$routes_array[] = $temp_array;
6967
		}
6968
6969
		return $routes_array;
6970
	}
6971
	
6972
	
6973
	
6974
	
6975
	/**
6976
	* Gets all callsigns that have flown over
6977
	*
6978
	* @return Array the callsign list
6979
	*
6980
	*/
6981
	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '')
6982
	{
6983
		global $globalDBdriver;
6984
		$query  = "SELECT DISTINCT spotter_output.ident, COUNT(spotter_output.ident) AS callsign_icao_count, spotter_output.airline_name, spotter_output.airline_icao  
6985
                    FROM spotter_output
6986
                    WHERE spotter_output.ident <> ''  ";
6987
		 if ($olderthanmonths > 0) {
6988
			if ($globalDBdriver == 'mysql') $query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
6989
			else $query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS' ";
6990
		}
6991
		if ($sincedate != '') {
6992
			if ($globalDBdriver == 'mysql') $query .= "AND date > '".$sincedate."' ";
6993
			else $query .= "AND date > CAST('".$sincedate."' AS TIMESTAMP) ";
6994
		}
6995
		$query .= "GROUP BY spotter_output.ident, spotter_output.airline_name, spotter_output.airline_icao ORDER BY callsign_icao_count DESC";
6996
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
6997
      		
6998
		$sth = $this->db->prepare($query);
6999
		$sth->execute();
7000
      
7001
		$callsign_array = array();
7002
		$temp_array = array();
7003
        
7004
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7005
		{
7006
			$temp_array['callsign_icao'] = $row['ident'];
7007
			$temp_array['airline_name'] = $row['airline_name'];
7008
			$temp_array['airline_icao'] = $row['airline_icao'];
7009
			$temp_array['callsign_icao_count'] = $row['callsign_icao_count'];
7010
          
7011
			$callsign_array[] = $temp_array;
7012
		}
7013
7014
		return $callsign_array;
7015
	}
7016
7017
7018
7019
7020
	/**
7021
	* Counts all dates
7022
	*
7023
	* @return Array the date list
7024
	*
7025
	*/
7026
	public function countAllDates()
7027
	{
7028
		global $globalTimezone, $globalDBdriver;
7029
		if ($globalTimezone != '') {
7030
			date_default_timezone_set($globalTimezone);
7031
			$datetime = new DateTime();
7032
			$offset = $datetime->format('P');
7033
		} else $offset = '+00:00';
7034
7035
		if ($globalDBdriver == 'mysql') {
7036
			$query  = "SELECT DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
7037
								FROM spotter_output 
7038
								GROUP BY date_name 
7039
								ORDER BY date_count DESC
7040
								LIMIT 10 OFFSET 0";
7041
		} else {
7042
			$query  = "SELECT to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count
7043
								FROM spotter_output 
7044
								GROUP BY date_name 
7045
								ORDER BY date_count DESC
7046
								LIMIT 10 OFFSET 0";
7047
		}
7048
      
7049
		
7050
		$sth = $this->db->prepare($query);
7051
		$sth->execute(array(':offset' => $offset));
7052
      
7053
		$date_array = array();
7054
		$temp_array = array();
7055
        
7056
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7057
		{
7058
			$temp_array['date_name'] = $row['date_name'];
7059
			$temp_array['date_count'] = $row['date_count'];
7060
7061
			$date_array[] = $temp_array;
7062
		}
7063
7064
		return $date_array;
7065
	}
7066
	
7067
	
7068
	
7069
	/**
7070
	* Counts all dates during the last 7 days
7071
	*
7072
	* @return Array the date list
7073
	*
7074
	*/
7075
	public function countAllDatesLast7Days()
7076
	{
7077
		global $globalTimezone, $globalDBdriver;
7078
		if ($globalTimezone != '') {
7079
			date_default_timezone_set($globalTimezone);
7080
			$datetime = new DateTime();
7081
			$offset = $datetime->format('P');
7082
		} else $offset = '+00:00';
7083
		
7084
		if ($globalDBdriver == 'mysql') {
7085
			$query  = "SELECT DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
7086
								FROM spotter_output 
7087
								WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY)
7088
								GROUP BY date_name 
7089
								ORDER BY spotter_output.date ASC";
7090
			$query_data = array(':offset' => $offset);
7091
		} elseif ($globalDBdriver == 'pgsql') {
7092
			$query  = "SELECT to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count
7093
								FROM spotter_output 
7094
								WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '7 DAYS'
7095
								GROUP BY date_name 
7096
								ORDER BY date_name ASC";
7097
			$query_data = array(':offset' => $offset);
7098
    		}
7099
		
7100
		$sth = $this->db->prepare($query);
0 ignored issues
show
Bug introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
7101
		$sth->execute($query_data);
0 ignored issues
show
Bug introduced by
The variable $query_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
7102
      
7103
		$date_array = array();
7104
		$temp_array = array();
7105
        
7106
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7107
		{
7108
			$temp_array['date_name'] = $row['date_name'];
7109
			$temp_array['date_count'] = $row['date_count'];
7110
          
7111
			$date_array[] = $temp_array;
7112
		}
7113
7114
		return $date_array;
7115
	}
7116
7117
	/**
7118
	* Counts all dates during the last month
7119
	*
7120
	* @return Array the date list
7121
	*
7122
	*/
7123
	public function countAllDatesLastMonth()
7124
	{
7125
		global $globalTimezone, $globalDBdriver;
7126
		if ($globalTimezone != '') {
7127
			date_default_timezone_set($globalTimezone);
7128
			$datetime = new DateTime();
7129
			$offset = $datetime->format('P');
7130
		} else $offset = '+00:00';
7131
		
7132
		if ($globalDBdriver == 'mysql') {
7133
			$query  = "SELECT DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
7134
								FROM spotter_output 
7135
								WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MONTH)
7136
								GROUP BY date_name 
7137
								ORDER BY spotter_output.date ASC";
7138
			$query_data = array(':offset' => $offset);
7139
		} elseif ($globalDBdriver == 'pgsql') {
7140
			$query  = "SELECT to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count
7141
								FROM spotter_output 
7142
								WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '1 MONTHS'
7143
								GROUP BY date_name 
7144
								ORDER BY date_name ASC";
7145
			$query_data = array(':offset' => $offset);
7146
    		}
7147
		
7148
		$sth = $this->db->prepare($query);
0 ignored issues
show
Bug introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
7149
		$sth->execute($query_data);
0 ignored issues
show
Bug introduced by
The variable $query_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
7150
      
7151
		$date_array = array();
7152
		$temp_array = array();
7153
        
7154
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7155
		{
7156
			$temp_array['date_name'] = $row['date_name'];
7157
			$temp_array['date_count'] = $row['date_count'];
7158
          
7159
			$date_array[] = $temp_array;
7160
		}
7161
7162
		return $date_array;
7163
	}
7164
	
7165
	/**
7166
	* Counts all month
7167
	*
7168
	* @return Array the month list
7169
	*
7170
	*/
7171
	public function countAllMonths()
7172
	{
7173
		global $globalTimezone, $globalDBdriver;
7174
		if ($globalTimezone != '') {
7175
			date_default_timezone_set($globalTimezone);
7176
			$datetime = new DateTime();
7177
			$offset = $datetime->format('P');
7178
		} else $offset = '+00:00';
7179
7180
		if ($globalDBdriver == 'mysql') {
7181
			$query  = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count
7182
								FROM spotter_output 
7183
								GROUP BY year_name, month_name 
7184
								ORDER BY date_count DESC";
7185
		} else {
7186
			$query  = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(*) as date_count
7187
								FROM spotter_output 
7188
								GROUP BY year_name, month_name 
7189
								ORDER BY date_count DESC";
7190
		}
7191
      
7192
		
7193
		$sth = $this->db->prepare($query);
7194
		$sth->execute(array(':offset' => $offset));
7195
      
7196
		$date_array = array();
7197
		$temp_array = array();
7198
        
7199
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7200
		{
7201
			$temp_array['month_name'] = $row['month_name'];
7202
			$temp_array['year_name'] = $row['year_name'];
7203
			$temp_array['date_count'] = $row['date_count'];
7204
7205
			$date_array[] = $temp_array;
7206
		}
7207
7208
		return $date_array;
7209
	}
7210
7211
	/**
7212
	* Counts all military month
7213
	*
7214
	* @return Array the month list
7215
	*
7216
	*/
7217
	public function countAllMilitaryMonths()
7218
	{
7219
		global $globalTimezone, $globalDBdriver;
7220
		if ($globalTimezone != '') {
7221
			date_default_timezone_set($globalTimezone);
7222
			$datetime = new DateTime();
7223
			$offset = $datetime->format('P');
7224
		} else $offset = '+00:00';
7225
7226
		if ($globalDBdriver == 'mysql') {
7227
			$query  = "SELECT YEAR(CONVERT_TZ(s.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(s.date,'+00:00', :offset)) AS month_name, count(*) as date_count
7228
								FROM spotter_output s
7229
								WHERE s.airline_type = 'military'
7230
								GROUP BY year_name, month_name 
7231
								ORDER BY date_count DESC";
7232
		} else {
7233
			$query  = "SELECT EXTRACT(YEAR FROM s.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM s.date AT TIME ZONE INTERVAL :offset) AS month_name, count(*) as date_count
7234
								FROM spotter_output s
7235
								WHERE s.airline_type = 'military'
7236
								GROUP BY year_name, month_name 
7237
								ORDER BY date_count DESC";
7238
		}
7239
		
7240
		$sth = $this->db->prepare($query);
7241
		$sth->execute(array(':offset' => $offset));
7242
      
7243
		$date_array = array();
7244
		$temp_array = array();
7245
        
7246
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7247
		{
7248
			$temp_array['month_name'] = $row['month_name'];
7249
			$temp_array['year_name'] = $row['year_name'];
7250
			$temp_array['date_count'] = $row['date_count'];
7251
7252
			$date_array[] = $temp_array;
7253
		}
7254
7255
		return $date_array;
7256
	}
7257
	
7258
	/**
7259
	* Counts all month owners
7260
	*
7261
	* @return Array the month list
7262
	*
7263
	*/
7264
	public function countAllMonthsOwners()
7265
	{
7266
		global $globalTimezone, $globalDBdriver;
7267
		if ($globalTimezone != '') {
7268
			date_default_timezone_set($globalTimezone);
7269
			$datetime = new DateTime();
7270
			$offset = $datetime->format('P');
7271
		} else $offset = '+00:00';
7272
7273
		if ($globalDBdriver == 'mysql') {
7274
			$query  = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(distinct owner_name) as date_count
7275
								FROM spotter_output 
7276
								WHERE owner_name <> ''
7277
								GROUP BY year_name, month_name
7278
								ORDER BY date_count DESC";
7279
		} else {
7280
			$query  = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(distinct owner_name) as date_count
7281
								FROM spotter_output 
7282
								WHERE owner_name <> ''
7283
								GROUP BY year_name, month_name
7284
								ORDER BY date_count DESC";
7285
		}
7286
		
7287
		$sth = $this->db->prepare($query);
7288
		$sth->execute(array(':offset' => $offset));
7289
      
7290
		$date_array = array();
7291
		$temp_array = array();
7292
        
7293
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7294
		{
7295
			$temp_array['month_name'] = $row['month_name'];
7296
			$temp_array['year_name'] = $row['year_name'];
7297
			$temp_array['date_count'] = $row['date_count'];
7298
7299
			$date_array[] = $temp_array;
7300
		}
7301
7302
		return $date_array;
7303
	}
7304
7305
	/**
7306
	* Counts all month pilot
7307
	*
7308
	* @return Array the month list
7309
	*
7310
	*/
7311
	public function countAllMonthsPilots()
7312
	{
7313
		global $globalTimezone, $globalDBdriver;
7314
		if ($globalTimezone != '') {
7315
			date_default_timezone_set($globalTimezone);
7316
			$datetime = new DateTime();
7317
			$offset = $datetime->format('P');
7318
		} else $offset = '+00:00';
7319
7320
		if ($globalDBdriver == 'mysql') {
7321
			$query  = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(distinct pilot_id) as date_count
7322
								FROM spotter_output 
7323
								WHERE pilot_id <> '' AND pilot_id IS NOT NULL
7324
								GROUP BY year_name, month_name
7325
								ORDER BY date_count DESC";
7326
		} else {
7327
			$query  = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(distinct pilot_id) as date_count
7328
								FROM spotter_output 
7329
								WHERE pilot_id <> '' AND pilot_id IS NOT NULL
7330
								GROUP BY year_name, month_name
7331
								ORDER BY date_count DESC";
7332
		}
7333
		
7334
		$sth = $this->db->prepare($query);
7335
		$sth->execute(array(':offset' => $offset));
7336
      
7337
		$date_array = array();
7338
		$temp_array = array();
7339
        
7340
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7341
		{
7342
			$temp_array['month_name'] = $row['month_name'];
7343
			$temp_array['year_name'] = $row['year_name'];
7344
			$temp_array['date_count'] = $row['date_count'];
7345
7346
			$date_array[] = $temp_array;
7347
		}
7348
7349
		return $date_array;
7350
	}
7351
	
7352
7353
	/**
7354
	* Counts all month airline
7355
	*
7356
	* @return Array the month list
7357
	*
7358
	*/
7359
	public function countAllMonthsAirlines()
7360
	{
7361
		global $globalTimezone, $globalDBdriver;
7362
		if ($globalTimezone != '') {
7363
			date_default_timezone_set($globalTimezone);
7364
			$datetime = new DateTime();
7365
			$offset = $datetime->format('P');
7366
		} else $offset = '+00:00';
7367
7368
		if ($globalDBdriver == 'mysql') {
7369
			$query  = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(distinct airline_icao) as date_count
7370
								FROM spotter_output 
7371
								WHERE airline_icao <> '' 
7372
								GROUP BY year_name, month_name
7373
								ORDER BY date_count DESC";
7374
		} else {
7375
			$query  = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(distinct airline_icao) as date_count
7376
								FROM spotter_output 
7377
								WHERE airline_icao <> '' 
7378
								GROUP BY year_name, month_name
7379
								ORDER BY date_count DESC";
7380
		}
7381
		
7382
		$sth = $this->db->prepare($query);
7383
		$sth->execute(array(':offset' => $offset));
7384
      
7385
		$date_array = array();
7386
		$temp_array = array();
7387
        
7388
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7389
		{
7390
			$temp_array['month_name'] = $row['month_name'];
7391
			$temp_array['year_name'] = $row['year_name'];
7392
			$temp_array['date_count'] = $row['date_count'];
7393
7394
			$date_array[] = $temp_array;
7395
		}
7396
7397
		return $date_array;
7398
	}
7399
	
7400
	/**
7401
	* Counts all month aircraft
7402
	*
7403
	* @return Array the month list
7404
	*
7405
	*/
7406
	public function countAllMonthsAircrafts()
7407
	{
7408
		global $globalTimezone, $globalDBdriver;
7409
		if ($globalTimezone != '') {
7410
			date_default_timezone_set($globalTimezone);
7411
			$datetime = new DateTime();
7412
			$offset = $datetime->format('P');
7413
		} else $offset = '+00:00';
7414
7415
		if ($globalDBdriver == 'mysql') {
7416
			$query  = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(distinct aircraft_icao) as date_count
7417
								FROM spotter_output 
7418
								WHERE aircraft_icao <> '' 
7419
								GROUP BY year_name, month_name
7420
								ORDER BY date_count DESC";
7421
		} else {
7422
			$query  = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(distinct aircraft_icao) as date_count
7423
								FROM spotter_output 
7424
								WHERE aircraft_icao <> '' 
7425
								GROUP BY year_name, month_name
7426
								ORDER BY date_count DESC";
7427
		}
7428
		
7429
		$sth = $this->db->prepare($query);
7430
		$sth->execute(array(':offset' => $offset));
7431
      
7432
		$date_array = array();
7433
		$temp_array = array();
7434
        
7435
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7436
		{
7437
			$temp_array['month_name'] = $row['month_name'];
7438
			$temp_array['year_name'] = $row['year_name'];
7439
			$temp_array['date_count'] = $row['date_count'];
7440
7441
			$date_array[] = $temp_array;
7442
		}
7443
7444
		return $date_array;
7445
	}
7446
	
7447
7448
	/**
7449
	* Counts all month real arrival
7450
	*
7451
	* @return Array the month list
7452
	*
7453
	*/
7454
	public function countAllMonthsRealArrivals()
7455
	{
7456
		global $globalTimezone, $globalDBdriver;
7457
		if ($globalTimezone != '') {
7458
			date_default_timezone_set($globalTimezone);
7459
			$datetime = new DateTime();
7460
			$offset = $datetime->format('P');
7461
		} else $offset = '+00:00';
7462
7463
		if ($globalDBdriver == 'mysql') {
7464
			$query  = "SELECT YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, count(real_arrival_airport_icao) as date_count
7465
								FROM spotter_output 
7466
								WHERE real_arrival_airport_icao <> '' 
7467
								GROUP BY year_name, month_name
7468
								ORDER BY date_count DESC";
7469
		} else {
7470
			$query  = "SELECT EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(real_arrival_airport_icao) as date_count
7471
								FROM spotter_output 
7472
								WHERE real_arrival_airport_icao <> '' 
7473
								GROUP BY year_name, month_name
7474
								ORDER BY date_count DESC";
7475
		}
7476
		
7477
		$sth = $this->db->prepare($query);
7478
		$sth->execute(array(':offset' => $offset));
7479
      
7480
		$date_array = array();
7481
		$temp_array = array();
7482
        
7483
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7484
		{
7485
			$temp_array['month_name'] = $row['month_name'];
7486
			$temp_array['year_name'] = $row['year_name'];
7487
			$temp_array['date_count'] = $row['date_count'];
7488
7489
			$date_array[] = $temp_array;
7490
		}
7491
7492
		return $date_array;
7493
	}
7494
	
7495
7496
7497
	/**
7498
	* Counts all dates during the last year
7499
	*
7500
	* @return Array the date list
7501
	*
7502
	*/
7503
	public function countAllMonthsLastYear()
7504
	{
7505
		global $globalTimezone, $globalDBdriver;
7506
		if ($globalTimezone != '') {
7507
			date_default_timezone_set($globalTimezone);
7508
			$datetime = new DateTime();
7509
			$offset = $datetime->format('P');
7510
		} else $offset = '+00:00';
7511
		
7512
		if ($globalDBdriver == 'mysql') {
7513
			$query  = "SELECT MONTH(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count
7514
								FROM spotter_output 
7515
								WHERE spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 YEAR)
7516
								GROUP BY year_name, month_name
7517
								ORDER BY year_name, month_name ASC";
7518
			$query_data = array(':offset' => $offset);
7519
		} elseif ($globalDBdriver == 'pgsql') {
7520
			$query  = "SELECT EXTRACT(MONTH FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS month_name, EXTRACT(YEAR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS year_name, count(*) as date_count
7521
								FROM spotter_output 
7522
								WHERE spotter_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '1 YEARS'
7523
								GROUP BY year_name, month_name
7524
								ORDER BY year_name, month_name ASC";
7525
			$query_data = array(':offset' => $offset);
7526
    		}
7527
		
7528
		$sth = $this->db->prepare($query);
0 ignored issues
show
Bug introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
7529
		$sth->execute($query_data);
0 ignored issues
show
Bug introduced by
The variable $query_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
7530
      
7531
		$date_array = array();
7532
		$temp_array = array();
7533
        
7534
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7535
		{
7536
			$temp_array['year_name'] = $row['year_name'];
7537
			$temp_array['month_name'] = $row['month_name'];
7538
			$temp_array['date_count'] = $row['date_count'];
7539
          
7540
			$date_array[] = $temp_array;
7541
		}
7542
7543
		return $date_array;
7544
	}
7545
	
7546
	
7547
	
7548
	/**
7549
	* Counts all hours
7550
	*
7551
	* @return Array the hour list
7552
	*
7553
	*/
7554
	public function countAllHours($orderby)
7555
	{
7556
		global $globalTimezone, $globalDBdriver;
7557
		if ($globalTimezone != '') {
7558
			date_default_timezone_set($globalTimezone);
7559
			$datetime = new DateTime();
7560
			$offset = $datetime->format('P');
7561
		} else $offset = '+00:00';
7562
7563
		if ($orderby == "hour")
7564
		{
7565
			$orderby_sql = "ORDER BY hour_name ASC";
7566
		}
7567
		if ($orderby == "count")
7568
		{
7569
			$orderby_sql = "ORDER BY hour_count DESC";
7570
		}
7571
		
7572
		if ($globalDBdriver == 'mysql') {
7573
			$query  = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
7574
								FROM spotter_output 
7575
								GROUP BY hour_name 
7576
								".$orderby_sql;
0 ignored issues
show
Bug introduced by
The variable $orderby_sql does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
7577
7578
/*		$query  = "SELECT HOUR(spotter_output.date) AS hour_name, count(*) as hour_count
7579
								FROM spotter_output 
7580
								GROUP BY hour_name 
7581
								".$orderby_sql."
7582
								LIMIT 10 OFFSET 00";
7583
  */    
7584
		$query_data = array(':offset' => $offset);
7585
		} elseif ($globalDBdriver == 'pgsql') {
7586
			$query  = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
7587
								FROM spotter_output 
7588
								GROUP BY hour_name 
7589
								".$orderby_sql;
7590
		$query_data = array(':offset' => $offset);
7591
		}
7592
		
7593
		$sth = $this->db->prepare($query);
0 ignored issues
show
Bug introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
7594
		$sth->execute($query_data);
0 ignored issues
show
Bug introduced by
The variable $query_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
7595
      
7596
		$hour_array = array();
7597
		$temp_array = array();
7598
        
7599
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7600
		{
7601
			$temp_array['hour_name'] = $row['hour_name'];
7602
			$temp_array['hour_count'] = $row['hour_count'];
7603
          
7604
			$hour_array[] = $temp_array;
7605
		}
7606
7607
		return $hour_array;
7608
	}
7609
	
7610
	
7611
	/**
7612
	* Counts all hours by airline
7613
	*
7614
	* @return Array the hour list
7615
	*
7616
	*/
7617
	public function countAllHoursByAirline($airline_icao)
7618
	{
7619
		global $globalTimezone, $globalDBdriver;
7620
		if ($globalTimezone != '') {
7621
			date_default_timezone_set($globalTimezone);
7622
			$datetime = new DateTime();
7623
			$offset = $datetime->format('P');
7624
		} else $offset = '+00:00';
7625
7626
		$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING);
7627
7628
		if ($globalDBdriver == 'mysql') {
7629
			$query  = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
7630
								FROM spotter_output 
7631
								WHERE spotter_output.airline_icao = :airline_icao
7632
								GROUP BY hour_name 
7633
								ORDER BY hour_name ASC";
7634
		} else {
7635
			$query  = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
7636
								FROM spotter_output 
7637
								WHERE spotter_output.airline_icao = :airline_icao
7638
								GROUP BY hour_name 
7639
								ORDER BY hour_name ASC";
7640
		}
7641
		
7642
		$sth = $this->db->prepare($query);
7643
		$sth->execute(array(':airline_icao' => $airline_icao,':offset' => $offset));
7644
      
7645
		$hour_array = array();
7646
		$temp_array = array();
7647
        
7648
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7649
		{
7650
			$temp_array['hour_name'] = $row['hour_name'];
7651
			$temp_array['hour_count'] = $row['hour_count'];
7652
          
7653
			$hour_array[] = $temp_array;
7654
		}
7655
7656
		return $hour_array;
7657
	}
7658
	
7659
	
7660
	
7661
	
7662
	/**
7663
	* Counts all hours by aircraft
7664
	*
7665
	* @return Array the hour list
7666
	*
7667
	*/
7668
	public function countAllHoursByAircraft($aircraft_icao)
7669
	{
7670
		global $globalTimezone, $globalDBdriver;
7671
		$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
7672
		if ($globalTimezone != '') {
7673
			date_default_timezone_set($globalTimezone);
7674
			$datetime = new DateTime();
7675
			$offset = $datetime->format('P');
7676
		} else $offset = '+00:00';
7677
7678
		if ($globalDBdriver == 'mysql') {
7679
			$query  = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
7680
								FROM spotter_output 
7681
								WHERE spotter_output.aircraft_icao = :aircraft_icao
7682
								GROUP BY hour_name 
7683
								ORDER BY hour_name ASC";
7684
		} else {
7685
			$query  = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
7686
								FROM spotter_output 
7687
								WHERE spotter_output.aircraft_icao = :aircraft_icao
7688
								GROUP BY hour_name 
7689
								ORDER BY hour_name ASC";
7690
		}
7691
		
7692
		$sth = $this->db->prepare($query);
7693
		$sth->execute(array(':aircraft_icao' => $aircraft_icao,':offset' => $offset));
7694
      
7695
		$hour_array = array();
7696
		$temp_array = array();
7697
        
7698
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7699
		{
7700
			$temp_array['hour_name'] = $row['hour_name'];
7701
			$temp_array['hour_count'] = $row['hour_count'];
7702
          
7703
			$hour_array[] = $temp_array;
7704
		}
7705
7706
		return $hour_array;
7707
	}
7708
	
7709
	
7710
	/**
7711
	* Counts all hours by aircraft registration
7712
	*
7713
	* @return Array the hour list
7714
	*
7715
	*/
7716
	public function countAllHoursByRegistration($registration)
7717
	{
7718
		global $globalTimezone, $globalDBdriver;
7719
		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
7720
		if ($globalTimezone != '') {
7721
			date_default_timezone_set($globalTimezone);
7722
			$datetime = new DateTime();
7723
			$offset = $datetime->format('P');
7724
		} else $offset = '+00:00';
7725
7726
		if ($globalDBdriver == 'mysql') {
7727
			$query  = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
7728
								FROM spotter_output 
7729
								WHERE spotter_output.registration = :registration
7730
								GROUP BY hour_name 
7731
								ORDER BY hour_name ASC";
7732
		} else {
7733
			$query  = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
7734
								FROM spotter_output 
7735
								WHERE spotter_output.registration = :registration
7736
								GROUP BY hour_name 
7737
								ORDER BY hour_name ASC";
7738
		}
7739
		
7740
		$sth = $this->db->prepare($query);
7741
		$sth->execute(array(':registration' => $registration,':offset' => $offset));
7742
      
7743
		$hour_array = array();
7744
		$temp_array = array();
7745
        
7746
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7747
		{
7748
			$temp_array['hour_name'] = $row['hour_name'];
7749
			$temp_array['hour_count'] = $row['hour_count'];
7750
          
7751
			$hour_array[] = $temp_array;
7752
		}
7753
7754
		return $hour_array;
7755
	}
7756
	
7757
	
7758
	/**
7759
	* Counts all hours by airport
7760
	*
7761
	* @return Array the hour list
7762
	*
7763
	*/
7764
	public function countAllHoursByAirport($airport_icao)
7765
	{
7766
		global $globalTimezone, $globalDBdriver;
7767
		$airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING);
7768
		if ($globalTimezone != '') {
7769
			date_default_timezone_set($globalTimezone);
7770
			$datetime = new DateTime();
7771
			$offset = $datetime->format('P');
7772
		} else $offset = '+00:00';
7773
7774
		if ($globalDBdriver == 'mysql') {
7775
			$query  = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
7776
								FROM spotter_output 
7777
								WHERE (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao)
7778
								GROUP BY hour_name 
7779
								ORDER BY hour_name ASC";
7780
		} else {
7781
			$query  = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
7782
								FROM spotter_output 
7783
								WHERE (spotter_output.departure_airport_icao = :airport_icao OR spotter_output.arrival_airport_icao = :airport_icao)
7784
								GROUP BY hour_name 
7785
								ORDER BY hour_name ASC";
7786
		}
7787
		
7788
		$sth = $this->db->prepare($query);
7789
		$sth->execute(array(':airport_icao' => $airport_icao,':offset' => $offset));
7790
      
7791
		$hour_array = array();
7792
		$temp_array = array();
7793
        
7794
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7795
		{
7796
			$temp_array['hour_name'] = $row['hour_name'];
7797
			$temp_array['hour_count'] = $row['hour_count'];
7798
          
7799
			$hour_array[] = $temp_array;
7800
		}
7801
7802
		return $hour_array;
7803
	}
7804
	
7805
	
7806
	
7807
	/**
7808
	* Counts all hours by manufacturer
7809
	*
7810
	* @return Array the hour list
7811
	*
7812
	*/
7813
	public function countAllHoursByManufacturer($aircraft_manufacturer)
7814
	{
7815
		global $globalTimezone, $globalDBdriver;
7816
		$aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING);
7817
		if ($globalTimezone != '') {
7818
			date_default_timezone_set($globalTimezone);
7819
			$datetime = new DateTime();
7820
			$offset = $datetime->format('P');
7821
		} else $offset = '+00:00';
7822
7823
		if ($globalDBdriver == 'mysql') {
7824
			$query  = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
7825
								FROM spotter_output 
7826
								WHERE spotter_output.aircraft_manufacturer = :aircraft_manufacturer
7827
								GROUP BY hour_name 
7828
								ORDER BY hour_name ASC";
7829
		} else {
7830
			$query  = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
7831
								FROM spotter_output 
7832
								WHERE spotter_output.aircraft_manufacturer = :aircraft_manufacturer
7833
								GROUP BY hour_name 
7834
								ORDER BY hour_name ASC";
7835
		}
7836
		
7837
		$sth = $this->db->prepare($query);
7838
		$sth->execute(array(':aircraft_manufacturer' => $aircraft_manufacturer,':offset' => $offset));
7839
      
7840
		$hour_array = array();
7841
		$temp_array = array();
7842
        
7843
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7844
		{
7845
			$temp_array['hour_name'] = $row['hour_name'];
7846
			$temp_array['hour_count'] = $row['hour_count'];
7847
          
7848
			$hour_array[] = $temp_array;
7849
		}
7850
7851
		return $hour_array;
7852
	}
7853
	
7854
	
7855
	
7856
	/**
7857
	* Counts all hours by date
7858
	*
7859
	* @return Array the hour list
7860
	*
7861
	*/
7862
	public function countAllHoursByDate($date)
7863
	{
7864
		global $globalTimezone, $globalDBdriver;
7865
		$date = filter_var($date,FILTER_SANITIZE_STRING);
7866
		if ($globalTimezone != '') {
7867
			date_default_timezone_set($globalTimezone);
7868
			$datetime = new DateTime($date);
7869
			$offset = $datetime->format('P');
7870
		} else $offset = '+00:00';
7871
7872
		if ($globalDBdriver == 'mysql') {
7873
			$query  = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
7874
								FROM spotter_output 
7875
								WHERE DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = :date
7876
								GROUP BY hour_name 
7877
								ORDER BY hour_name ASC";
7878
		} else {
7879
			$query  = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
7880
								FROM spotter_output 
7881
								WHERE to_char(spotter_output.date AT TIME ZONE INTERVAL :offset, 'YYYY-mm-dd') = :date
7882
								GROUP BY hour_name 
7883
								ORDER BY hour_name ASC";
7884
		}
7885
		
7886
		$sth = $this->db->prepare($query);
7887
		$sth->execute(array(':date' => $date, ':offset' => $offset));
7888
      
7889
		$hour_array = array();
7890
		$temp_array = array();
7891
        
7892
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7893
		{
7894
			$temp_array['hour_name'] = $row['hour_name'];
7895
			$temp_array['hour_count'] = $row['hour_count'];
7896
          
7897
			$hour_array[] = $temp_array;
7898
		}
7899
7900
		return $hour_array;
7901
	}
7902
	
7903
	
7904
	
7905
	/**
7906
	* Counts all hours by a ident/callsign
7907
	*
7908
	* @return Array the hour list
7909
	*
7910
	*/
7911
	public function countAllHoursByIdent($ident)
7912
	{
7913
		global $globalTimezone, $globalDBdriver;
7914
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
7915
		if ($globalTimezone != '') {
7916
			date_default_timezone_set($globalTimezone);
7917
			$datetime = new DateTime();
7918
			$offset = $datetime->format('P');
7919
		} else $offset = '+00:00';
7920
7921
		if ($globalDBdriver == 'mysql') {
7922
			$query  = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
7923
								FROM spotter_output 
7924
								WHERE spotter_output.ident = :ident 
7925
								GROUP BY hour_name 
7926
								ORDER BY hour_name ASC";
7927
		} else {
7928
			$query  = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
7929
								FROM spotter_output 
7930
								WHERE spotter_output.ident = :ident 
7931
								GROUP BY hour_name 
7932
								ORDER BY hour_name ASC";
7933
		}
7934
      
7935
		
7936
		$sth = $this->db->prepare($query);
7937
		$sth->execute(array(':ident' => $ident,':offset' => $offset));
7938
      
7939
		$hour_array = array();
7940
		$temp_array = array();
7941
        
7942
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7943
		{
7944
			$temp_array['hour_name'] = $row['hour_name'];
7945
			$temp_array['hour_count'] = $row['hour_count'];
7946
          
7947
			$hour_array[] = $temp_array;
7948
		}
7949
7950
		return $hour_array;
7951
	}
7952
	
7953
	
7954
	
7955
	/**
7956
	* Counts all hours by route
7957
	*
7958
	* @return Array the hour list
7959
	*
7960
	*/
7961
	public function countAllHoursByRoute($departure_airport_icao, $arrival_airport_icao)
7962
	{
7963
		global $globalTimezone, $globalDBdriver;
7964
		$departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING);
7965
		$arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING);
7966
		if ($globalTimezone != '') {
7967
			date_default_timezone_set($globalTimezone);
7968
			$datetime = new DateTime();
7969
			$offset = $datetime->format('P');
7970
		} else $offset = '+00:00';
7971
7972
		if ($globalDBdriver == 'mysql') {
7973
			$query  = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
7974
								FROM spotter_output 
7975
								WHERE (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao)
7976
								GROUP BY hour_name 
7977
								ORDER BY hour_name ASC";
7978
		} else {
7979
			$query  = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
7980
								FROM spotter_output 
7981
								WHERE (spotter_output.departure_airport_icao = :departure_airport_icao) AND (spotter_output.arrival_airport_icao = :arrival_airport_icao)
7982
								GROUP BY hour_name 
7983
								ORDER BY hour_name ASC";
7984
		}
7985
		
7986
		$sth = $this->db->prepare($query);
7987
		$sth->execute(array(':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':offset' => $offset));
7988
      
7989
		$hour_array = array();
7990
		$temp_array = array();
7991
        
7992
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
7993
		{
7994
			$temp_array['hour_name'] = $row['hour_name'];
7995
			$temp_array['hour_count'] = $row['hour_count'];
7996
          
7997
			$hour_array[] = $temp_array;
7998
		}
7999
8000
		return $hour_array;
8001
	}
8002
	
8003
	
8004
	/**
8005
	* Counts all hours by country
8006
	*
8007
	* @return Array the hour list
8008
	*
8009
	*/
8010
	public function countAllHoursByCountry($country)
8011
	{
8012
		global $globalTimezone, $globalDBdriver;
8013
		$country = filter_var($country,FILTER_SANITIZE_STRING);
8014
		if ($globalTimezone != '') {
8015
			date_default_timezone_set($globalTimezone);
8016
			$datetime = new DateTime();
8017
			$offset = $datetime->format('P');
8018
		} else $offset = '+00:00';
8019
8020
		if ($globalDBdriver == 'mysql') {
8021
			$query  = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
8022
								FROM spotter_output 
8023
								WHERE ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country
8024
								GROUP BY hour_name 
8025
								ORDER BY hour_name ASC";
8026
		} else {
8027
			$query  = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
8028
								FROM spotter_output 
8029
								WHERE ((spotter_output.departure_airport_country = :country) OR (spotter_output.arrival_airport_country = :country)) OR spotter_output.airline_country = :country
8030
								GROUP BY hour_name 
8031
								ORDER BY hour_name ASC";
8032
		}
8033
		
8034
		$sth = $this->db->prepare($query);
8035
		$sth->execute(array(':country' => $country,':offset' => $offset));
8036
      
8037
		$hour_array = array();
8038
		$temp_array = array();
8039
        
8040
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
8041
		{
8042
			$temp_array['hour_name'] = $row['hour_name'];
8043
			$temp_array['hour_count'] = $row['hour_count'];
8044
          
8045
			$hour_array[] = $temp_array;
8046
		}
8047
8048
		return $hour_array;
8049
	}
8050
8051
8052
8053
8054
	/**
8055
	* Counts all aircraft that have flown over
8056
	*
8057
	* @return Integer the number of aircrafts
8058
	*
8059
	*/
8060
	public function countOverallAircrafts()
8061
	{
8062
		$query  = "SELECT COUNT(DISTINCT spotter_output.aircraft_icao) AS aircraft_count  
8063
                    FROM spotter_output
8064
                    WHERE spotter_output.ident <> ''";
8065
      
8066
		
8067
		$sth = $this->db->prepare($query);
8068
		$sth->execute();
8069
		return $sth->fetchColumn();
8070
	}
8071
8072
	/**
8073
	* Counts all flight that really arrival
8074
	*
8075
	* @return Integer the number of aircrafts
8076
	*
8077
	*/
8078
	public function countOverallArrival()
8079
	{
8080
		$query  = "SELECT COUNT(spotter_output.real_arrival_airport_icao) AS arrival_count  
8081
                    FROM spotter_output
8082
                    WHERE spotter_output.arrival_airport_icao <> ''";
8083
      
8084
		
8085
		$sth = $this->db->prepare($query);
8086
		$sth->execute();
8087
		return $sth->fetchColumn();
8088
	}
8089
8090
	/**
8091
	* Counts all pilots that have flown over
8092
	*
8093
	* @return Integer the number of pilots
8094
	*
8095
	*/
8096
	public function countOverallPilots()
8097
	{
8098
		$query  = "SELECT COUNT(DISTINCT spotter_output.pilot_id) AS pilot_count  
8099
                    FROM spotter_output
8100
                    WHERE spotter_output.pilot_id <> ''";
8101
      
8102
		
8103
		$sth = $this->db->prepare($query);
8104
		$sth->execute();
8105
		return $sth->fetchColumn();
8106
	}
8107
8108
	/**
8109
	* Counts all owners that have flown over
8110
	*
8111
	* @return Integer the number of owners
8112
	*
8113
	*/
8114
	public function countOverallOwners()
8115
	{
8116
		$query  = "SELECT COUNT(DISTINCT spotter_output.owner_name) AS owner_count  
8117
                    FROM spotter_output
8118
                    WHERE spotter_output.owner_name <> ''";
8119
      
8120
		
8121
		$sth = $this->db->prepare($query);
8122
		$sth->execute();
8123
		return $sth->fetchColumn();
8124
	}
8125
	
8126
	
8127
	/**
8128
	* Counts all flights that have flown over
8129
	*
8130
	* @return Integer the number of flights
8131
	*
8132
	*/
8133
	public function countOverallFlights()
8134
	{
8135
		$query  = "SELECT COUNT(spotter_output.spotter_id) AS flight_count  
8136
                    FROM spotter_output";
8137
      
8138
		
8139
		$sth = $this->db->prepare($query);
8140
		$sth->execute();
8141
		return $sth->fetchColumn();
8142
	}
8143
	
8144
	/**
8145
	* Counts all military flights that have flown over
8146
	*
8147
	* @return Integer the number of flights
8148
	*
8149
	*/
8150
	public function countOverallMilitaryFlights()
8151
	{
8152
		$query  = "SELECT COUNT(s.spotter_id) AS flight_count  
8153
                    FROM spotter_output s, airlines a WHERE s.airline_icao = a.icao AND a.type = 'military'";
8154
      
8155
		
8156
		$sth = $this->db->prepare($query);
8157
		$sth->execute();
8158
		return $sth->fetchColumn();
8159
	}
8160
	
8161
	
8162
	
8163
	/**
8164
	* Counts all airlines that have flown over
8165
	*
8166
	* @return Integer the number of airlines
8167
	*
8168
	*/
8169
	public function countOverallAirlines()
8170
	{
8171
		$query  = "SELECT COUNT(DISTINCT spotter_output.airline_name) AS airline_count 
8172
							FROM spotter_output";
8173
      
8174
		
8175
		$sth = $this->db->prepare($query);
8176
		$sth->execute();
8177
		return $sth->fetchColumn();
8178
	}
8179
8180
  
8181
	/**
8182
	* Counts all hours of today
8183
	*
8184
	* @return Array the hour list
8185
	*
8186
	*/
8187
	public function countAllHoursFromToday()
8188
	{
8189
		global $globalTimezone, $globalDBdriver;
8190
		if ($globalTimezone != '') {
8191
			date_default_timezone_set($globalTimezone);
8192
			$datetime = new DateTime();
8193
			$offset = $datetime->format('P');
8194
		} else $offset = '+00:00';
8195
8196
		if ($globalDBdriver == 'mysql') {
8197
			$query  = "SELECT HOUR(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
8198
								FROM spotter_output 
8199
								WHERE DATE(CONVERT_TZ(spotter_output.date,'+00:00', :offset)) = CURDATE()
8200
								GROUP BY hour_name 
8201
								ORDER BY hour_name ASC";
8202
		} else {
8203
			$query  = "SELECT EXTRACT(HOUR FROM spotter_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
8204
								FROM spotter_output 
8205
								WHERE to_char(spotter_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = CAST(NOW() AS date)
8206
								GROUP BY hour_name 
8207
								ORDER BY hour_name ASC";
8208
		}
8209
		
8210
		$sth = $this->db->prepare($query);
8211
		$sth->execute(array(':offset' => $offset));
8212
      
8213
		$hour_array = array();
8214
		$temp_array = array();
8215
        
8216
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
8217
		{
8218
			$temp_array['hour_name'] = $row['hour_name'];
8219
			$temp_array['hour_count'] = $row['hour_count'];
8220
			$hour_array[] = $temp_array;
8221
		}
8222
8223
		return $hour_array;
8224
	}
8225
    
8226
	/**
8227
	* Gets all the spotter information based on calculated upcoming flights
8228
	*
8229
	* @return Array the spotter information
8230
	*
8231
	*/
8232
	public function getUpcomingFlights($limit = '', $sort = '')
8233
	{
8234
		global $global_query, $globalDBdriver, $globalTimezone;
8235
		date_default_timezone_set('UTC');
8236
		if ($limit != "")
8237
		{
8238
			$limit_array = explode(",", $limit);
8239
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
8240
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
8241
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
8242
			{
8243
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
8244
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
8245
			}
8246
		}
8247
		$currentHour = date("G");
8248
		$next3Hours = date("G", strtotime("+3 hour"));
8249
		//if the next 3 hours is already equal to/past midnight, we limit it to stay there, otherwise the query will fail
8250
		if ($currentHour >= 21 && $next3Hours >= 00)
8251
		{
8252
			$next3Hours = 24;
8253
		}
8254
		$currentDayofWeek = date("l");
8255
		if ($globalDBdriver == 'mysql') {
8256
			if ($sort != "")
8257
			{
8258
				$search_orderby_array = $this->getOrderBy();
8259
				$orderby_query = $search_orderby_array[$sort]['sql'];
8260
			} else {
8261
				$orderby_query = " ORDER BY HOUR(spotter_output.date) ASC";
8262
			}
8263
8264
			$query = "SELECT spotter_output.*, count(spotter_output.ident) as ident_count
8265
			    FROM spotter_output
8266
			    WHERE DAYNAME(spotter_output.date) = '$currentDayofWeek' AND HOUR(spotter_output.date) >= '$currentHour' AND HOUR(spotter_output.date) <= '$next3Hours' AND spotter_output.ident <> '' AND format_source <> 'aprs'
8267
			    GROUP BY spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time HAVING count(spotter_output.ident) > 10 $orderby_query";
8268
8269
/*			$query = "SELECT spotter_output.ident, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time, count(spotter_output.ident) as ident_count
8270
			    FROM spotter_output
8271
			    WHERE DAYNAME(spotter_output.date) = '$currentDayofWeek' AND HOUR(spotter_output.date) >= '$currentHour' AND HOUR(spotter_output.date) <= '$next3Hours' AND spotter_output.ident <> '' AND format_source <> 'aprs'
8272
			    GROUP BY spotter_output.ident,spotter_output.spotter_id, spotter_output.flightaware_id, spotter_output.registration,spotter_output.airline_name,spotter_output.airline_icao,spotter_output.airline_country,spotter_output.airline_type,spotter_output.aircraft_icao,spotter_output.aircraft_name,spotter_output.aircraft_manufacturer,spotter_output.departure_airport_icao,spotter_output.departure_airport_name,spotter_output.departure_airport_city,spotter_output.departure_airport_country,spotter_output.departure_airport_time,spotter_output.arrival_airport_icao,spotter_output.arrival_airport_name,spotter_output.arrival_airport_city,spotter_output.arrival_airport_country,spotter_output.arrival_airport_time,spotter_output.route_stop,spotter_output.date,spotter_output.latitude,spotter_output.longitude,spotter_output.waypoints,spotter_output.altitude,spotter_output.heading,spotter_output.ground_speed,spotter_output.highlight,spotter_output.squawk,spotter_output.ModeS,spotter_output.pilot_id,spotter_output.pilot_name,spotter_output.verticalrate,spotter_output.owner_name,spotter_output.format_source,spotter_output.source_name,spotter_output.ground,spotter_output.last_ground,spotter_output.last_seen,spotter_output.last_latitude,spotter_output.last_longitude,spotter_output.last_altitude,spotter_output.last_ground_speed,spotter_output.real_arrival_airport_icao,spotter_output.real_arrival_airport_time HAVING count(spotter_output.ident) > 10 $orderby_query";
8273
*/
8274
			$spotter_array = $this->getDataFromDB($query.$limit_query);
0 ignored issues
show
Bug introduced by
The variable $limit_query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
8275
		} else if ($globalDBdriver == 'pgsql') {
8276
			if ($sort != "")
8277
			{
8278
				$search_orderby_array = $this->getOrderBy();
8279
				$orderby_query = $search_orderby_array[$sort]['sql'];
8280
			} else {
8281
				$orderby_query = " ORDER BY EXTRACT (HOUR FROM spotter_output.date) ASC";
8282
			}
8283
			$query = "SELECT spotter_output.*, count(spotter_output.ident) as ident_count
8284
			    FROM spotter_output
8285
			    WHERE DATE_PART('dow', spotter_output.date) = DATE_PART('dow', date 'now' AT TIME ZONE :timezone) AND EXTRACT (HOUR FROM spotter_output.date AT TIME ZONE :timezone) >= '$currentHour' AND EXTRACT (HOUR FROM spotter_output.date AT TIME ZONE :timezone) <= '$next3Hours' AND ident <> '' 
8286
			    GROUP BY spotter_output.ident, spotter_output.spotter_id HAVING count(spotter_output.ident) > 10 $orderby_query";
8287
		$spotter_array = $this->getDataFromDB($query.$limit_query,array(':timezone' => $globalTimezone));
8288
		}
8289
		return $spotter_array;
0 ignored issues
show
Bug introduced by
The variable $spotter_array does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
8290
	}
8291
    
8292
    
8293
     /**
8294
	* Gets the Barrie Spotter ID based on the FlightAware ID
8295
	*
8296
	* @return Integer the Barrie Spotter ID
8297
	*
8298
	*/
8299
	public function getSpotterIDBasedOnFlightAwareID($flightaware_id)
8300
	{
8301
		$flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING);
8302
8303
		$query  = "SELECT spotter_output.spotter_id
8304
								FROM spotter_output 
8305
								WHERE spotter_output.flightaware_id = '".$flightaware_id."'";
8306
        
8307
		
8308
		$sth = $this->db->prepare($query);
8309
		$sth->execute();
8310
8311
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
8312
		{
8313
			return $row['spotter_id'];
8314
		}
8315
	}
8316
  
8317
 
8318
	/**
8319
	* Parses a date string
8320
	*
8321
	* @param String $dateString the date string
8322
	* @param String $timezone the timezone of a user
8323
	* @return Array the time information
8324
	*
8325
	*/
8326
	public function parseDateString($dateString, $timezone = '')
8327
	{
8328
		$time_array = array();
8329
	
8330
		if ($timezone != "")
8331
		{
8332
			date_default_timezone_set($timezone);
8333
		}
8334
		
8335
		$current_date = date("Y-m-d H:i:s");
8336
		$date = date("Y-m-d H:i:s",strtotime($dateString." UTC"));
8337
		
8338
		$diff = abs(strtotime($current_date) - strtotime($date));
8339
8340
		$time_array['years'] = floor($diff / (365*60*60*24)); 
8341
		$years = $time_array['years'];
8342
		
8343
		$time_array['months'] = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
8344
		$months = $time_array['months'];
8345
		
8346
		$time_array['days'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
8347
		$days = $time_array['days'];
8348
		$time_array['hours'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60));
8349
		$hours = $time_array['hours'];
8350
		$time_array['minutes'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60);
8351
		$minutes = $time_array['minutes'];
8352
		$time_array['seconds'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
8353
		
8354
		return $time_array;	
8355
	}	
8356
	
8357
	
8358
	
8359
	
8360
	/**
8361
	* Parses the direction degrees to working
8362
	*
8363
	* @param Float $direction the direction in degrees
8364
	* @return Array the direction information
8365
	*
8366
	*/
8367
	public function parseDirection($direction = 0)
8368
	{
8369
		if ($direction == '') $direction = 0;
8370
		$direction_array = array();
8371
		$temp_array = array();
8372
8373
		if ($direction == 360 || ($direction >= 0 && $direction < 22.5))
8374
		{
8375
			$temp_array['direction_degree'] = $direction;
8376
			$temp_array['direction_shortname'] = "N";
8377
			$temp_array['direction_fullname'] = "North";
8378
		} elseif ($direction >= 22.5 && $direction < 45){
8379
			$temp_array['direction_degree'] = $direction;
8380
			$temp_array['direction_shortname'] = "NNE";
8381
			$temp_array['direction_fullname'] = "North-Northeast";
8382
		} elseif ($direction >= 45 && $direction < 67.5){
8383
			$temp_array['direction_degree'] = $direction;
8384
			$temp_array['direction_shortname'] = "NE";
8385
			$temp_array['direction_fullname'] = "Northeast";
8386
		} elseif ($direction >= 67.5 && $direction < 90){
8387
			$temp_array['direction_degree'] = $direction;
8388
			$temp_array['direction_shortname'] = "ENE";
8389
			$temp_array['direction_fullname'] = "East-Northeast";
8390
		} elseif ($direction >= 90 && $direction < 112.5){
8391
			$temp_array['direction_degree'] = $direction;
8392
			$temp_array['direction_shortname'] = "E";
8393
			$temp_array['direction_fullname'] = "East";
8394
		} elseif ($direction >= 112.5 && $direction < 135){
8395
			$temp_array['direction_degree'] = $direction;
8396
			$temp_array['direction_shortname'] = "ESE";
8397
			$temp_array['direction_fullname'] = "East-Southeast";
8398
		} elseif ($direction >= 135 && $direction < 157.5){
8399
			$temp_array['direction_degree'] = $direction;
8400
			$temp_array['direction_shortname'] = "SE";
8401
			$temp_array['direction_fullname'] = "Southeast";
8402
		} elseif ($direction >= 157.5 && $direction < 180){
8403
			$temp_array['direction_degree'] = $direction;
8404
			$temp_array['direction_shortname'] = "SSE";
8405
			$temp_array['direction_fullname'] = "South-Southeast";
8406
		} elseif ($direction >= 180 && $direction < 202.5){
8407
			$temp_array['direction_degree'] = $direction;
8408
			$temp_array['direction_shortname'] = "S";
8409
			$temp_array['direction_fullname'] = "South";
8410
		} elseif ($direction >= 202.5 && $direction < 225){
8411
			$temp_array['direction_degree'] = $direction;
8412
			$temp_array['direction_shortname'] = "SSW";
8413
			$temp_array['direction_fullname'] = "South-Southwest";
8414
		} elseif ($direction >= 225 && $direction < 247.5){
8415
			$temp_array['direction_degree'] = $direction;
8416
			$temp_array['direction_shortname'] = "SW";
8417
			$temp_array['direction_fullname'] = "Southwest";
8418
		} elseif ($direction >= 247.5 && $direction < 270){
8419
			$temp_array['direction_degree'] = $direction;
8420
			$temp_array['direction_shortname'] = "WSW";
8421
			$temp_array['direction_fullname'] = "West-Southwest";
8422
		} elseif ($direction >= 270 && $direction < 292.5){
8423
			$temp_array['direction_degree'] = $direction;
8424
			$temp_array['direction_shortname'] = "W";
8425
			$temp_array['direction_fullname'] = "West";
8426
		} elseif ($direction >= 292.5 && $direction < 315){
8427
			$temp_array['direction_degree'] = $direction;
8428
			$temp_array['direction_shortname'] = "WNW";
8429
			$temp_array['direction_fullname'] = "West-Northwest";
8430
		} elseif ($direction >= 315 && $direction < 337.5){
8431
			$temp_array['direction_degree'] = $direction;
8432
			$temp_array['direction_shortname'] = "NW";
8433
			$temp_array['direction_fullname'] = "Northwest";
8434
		} elseif ($direction >= 337.5 && $direction < 360){
8435
			$temp_array['direction_degree'] = $direction;
8436
			$temp_array['direction_shortname'] = "NNW";
8437
			$temp_array['direction_fullname'] = "North-Northwest";
8438
		}
8439
		$direction_array[] = $temp_array;
8440
		return $direction_array;
8441
	}
8442
	
8443
	
8444
	/**
8445
	* Gets the aircraft registration
8446
	*
8447
	* @param String $flightaware_id the flight aware id
8448
	* @return String the aircraft registration
8449
	*
8450
	*/
8451
	
8452
	public function getAircraftRegistration($flightaware_id)
8453
	{
8454
		global $globalFlightAwareUsername, $globalFlightAwarePassword;
8455
        
8456
        $options = array(
8457
			'trace' => true,
8458
			'exceptions' => 0,
8459
			'login' => $globalFlightAwareUsername,
8460
			'password' => $globalFlightAwarePassword,
8461
		);
8462
		$client = new SoapClient('http://flightxml.flightaware.com/soap/FlightXML2/wsdl', $options);
8463
		
8464
		$params = array('faFlightID' => $flightaware_id);
8465
		$result = $client->AirlineFlightInfo($params);
8466
		
8467
		if (isset($result->AirlineFlightInfoResult))
8468
		{
8469
			$registration = $result->AirlineFlightInfoResult->tailnumber;
8470
		}
8471
		
8472
		$registration = $this->convertAircraftRegistration($registration);
0 ignored issues
show
Bug introduced by
The variable $registration does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
8473
		
8474
		return $registration;	
8475
	}
8476
8477
8478
	/**
8479
	* Gets the aircraft registration from ModeS
8480
	*
8481
	* @param String $aircraft_modes the flight ModeS in hex
8482
	* @return String the aircraft registration
8483
	*
8484
	*/
8485
	
8486
	public function getAircraftRegistrationBymodeS($aircraft_modes)
8487
	{
8488
		$aircraft_modes = filter_var($aircraft_modes,FILTER_SANITIZE_STRING);
8489
	
8490
		$query  = "SELECT aircraft_modes.Registration FROM aircraft_modes WHERE aircraft_modes.ModeS = :aircraft_modes LIMIT 1";
8491
		
8492
		$sth = $this->db->prepare($query);
8493
		$sth->execute(array(':aircraft_modes' => $aircraft_modes));
8494
    
8495
		$row = $sth->fetch(PDO::FETCH_ASSOC);
8496
		if (count($row) > 0) {
8497
		    //return $row['Registration'];
8498
		    return $row['registration'];
8499
		} else return '';
8500
	
8501
	}
8502
8503
	/**
8504
	* Gets the aircraft type from ModeS
8505
	*
8506
	* @param String $aircraft_modes the flight ModeS in hex
8507
	* @return String the aircraft type
8508
	*
8509
	*/
8510
	
8511
	public function getAircraftTypeBymodeS($aircraft_modes)
8512
	{
8513
		$aircraft_modes = filter_var($aircraft_modes,FILTER_SANITIZE_STRING);
8514
	
8515
		$query  = "SELECT aircraft_modes.type_flight FROM aircraft_modes WHERE aircraft_modes.ModeS = :aircraft_modes LIMIT 1";
8516
		
8517
		$sth = $this->db->prepare($query);
8518
		$sth->execute(array(':aircraft_modes' => $aircraft_modes));
8519
    
8520
		$row = $sth->fetch(PDO::FETCH_ASSOC);
8521
		if (count($row) > 0) {
8522
		    if ($row['type_flight'] == null) return '';
8523
		    else return $row['type_flight'];
8524
		} else return '';
8525
	
8526
	}
8527
8528
	/**
8529
	* Gets Countrie from latitude/longitude
8530
	*
8531
	* @param String $aircraft_modes the flight ModeS in hex
8532
	* @return String the aircraft registration
0 ignored issues
show
Bug introduced by
There is no parameter named $aircraft_modes. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
8533
	*
8534
	*/
8535
	
8536
	public function getCountryFromLatitudeLongitude($latitude,$longitude)
8537
	{
8538
		global $globalDBdriver;
8539
		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
8540
		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
8541
	
8542
		try {
8543
			/*
8544
			if ($globalDBdriver == 'mysql') {
8545
				//$query  = "SELECT name, iso2, iso3 FROM countries WHERE Within(GeomFromText('POINT(:latitude :longitude)'), ogc_geom) LIMIT 1";
8546
				$query = "SELECT name, iso2, iso3 FROM countries WHERE Within(GeomFromText('POINT(".$longitude.' '.$latitude.")'), ogc_geom) LIMIT 1";
8547
			}
8548
			*/
8549
			// This query seems to work both for MariaDB and PostgreSQL
8550
			$query = "SELECT name,iso2,iso3 FROM countries WHERE ST_Within(ST_GeomFromText('POINT(".$longitude." ".$latitude.")',4326), ogc_geom) LIMIT 1";
8551
		
8552
			$sth = $this->db->prepare($query);
8553
			//$sth->execute(array(':latitude' => $latitude,':longitude' => $longitude));
8554
			$sth->execute();
8555
    
8556
			$row = $sth->fetch(PDO::FETCH_ASSOC);
8557
			if (count($row) > 0) {
8558
				return $row;
8559
			} else return '';
8560
		} catch (PDOException $e) {
8561
			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
0 ignored issues
show
Bug introduced by
The variable $globalDebug seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
8562
			return '';
8563
		}
8564
	
8565
	}
8566
8567
	/**
8568
	* converts the registration code using the country prefix
8569
	*
8570
	* @param String $registration the aircraft registration
8571
	* @return String the aircraft registration
8572
	*
8573
	*/
8574
	public function convertAircraftRegistration($registration)
8575
	{
8576
		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
8577
		$registration_prefix = '';
8578
		$registration_1 = substr($registration, 0, 1);
8579
		$registration_2 = substr($registration, 0, 2);
8580
8581
		//first get the prefix based on two characters
8582
		$query  = "SELECT aircraft_registration.registration_prefix FROM aircraft_registration WHERE registration_prefix = :registration_2";
8583
      
8584
		
8585
		$sth = $this->db->prepare($query);
8586
		$sth->execute(array(':registration_2' => $registration_2));
8587
        
8588
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
8589
		{
8590
			$registration_prefix = $row['registration_prefix'];
8591
		}
8592
8593
		//if we didn't find a two chracter prefix lets just search the one with one character
8594
		if ($registration_prefix == "")
8595
		{
8596
			$query  = "SELECT aircraft_registration.registration_prefix FROM aircraft_registration WHERE registration_prefix = :registration_1";
8597
	      
8598
			$sth = $this->db->prepare($query);
8599
			$sth->execute(array(':registration_1' => $registration_1));
8600
	        
8601
			while($row = $sth->fetch(PDO::FETCH_ASSOC))
8602
			{
8603
				$registration_prefix = $row['registration_prefix'];
8604
			}
8605
		}
8606
8607
		//determine which characters are being used and convert the registration code appropiately
8608
		if (strlen($registration_prefix) == 1)
8609
		{
8610
			if (0 === strpos($registration, 'N')) {
8611
                $registration = preg_replace("/^(.{1})/", "$1", $registration);
8612
            } else {
8613
                $registration = preg_replace("/^(.{1})/", "$1-", $registration);
8614
            }
8615
		} else if(strlen($registration_prefix) == 2){
8616
            if (0 === strpos($registration, 'N')) {
8617
                $registration = preg_replace("/^(.{2})/", "$1", $registration);
8618
            } else {
8619
                $registration = preg_replace("/^(.{2})/", "$1-", $registration);
8620
            }
8621
		}
8622
8623
		return $registration;	
8624
	}
8625
8626
	/**
8627
	* Country from the registration code
8628
	*
8629
	* @param String $registration the aircraft registration
8630
	* @return String the country
8631
	*
8632
	*/
8633
	public function countryFromAircraftRegistration($registration)
8634
	{
8635
		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
8636
		
8637
		$registration_prefix = '';
8638
		
8639
		$registration_test = explode('-',$registration);
8640
		$country = '';
8641
		if ($registration_test[0] != $registration) {
8642
			$query  = "SELECT aircraft_registration.registration_prefix, aircraft_registration.country FROM aircraft_registration WHERE registration_prefix = :registration_1 LIMIT 1";
8643
	      
8644
			$sth = $this->db->prepare($query);
8645
			$sth->execute(array(':registration_1' => $registration_test[0]));
8646
	        
8647
			while($row = $sth->fetch(PDO::FETCH_ASSOC))
8648
			{
8649
				$registration_prefix = $row['registration_prefix'];
0 ignored issues
show
Unused Code introduced by
$registration_prefix is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
8650
				$country = $row['country'];
8651
			}
8652
		} else {
8653
    			$registration_1 = substr($registration, 0, 1);
8654
		        $registration_2 = substr($registration, 0, 2);
8655
8656
			$country = '';
8657
			//first get the prefix based on two characters
8658
			$query  = "SELECT aircraft_registration.registration_prefix, aircraft_registration.country FROM aircraft_registration WHERE registration_prefix = :registration_2 LIMIT 1";
8659
      
8660
			
8661
			$sth = $this->db->prepare($query);
8662
			$sth->execute(array(':registration_2' => $registration_2));
8663
        
8664
			while($row = $sth->fetch(PDO::FETCH_ASSOC))
8665
			{
8666
				$registration_prefix = $row['registration_prefix'];
8667
				$country = $row['country'];
8668
			}
8669
8670
			//if we didn't find a two chracter prefix lets just search the one with one character
8671
			if ($registration_prefix == "")
8672
			{
8673
				$query  = "SELECT aircraft_registration.registration_prefix, aircraft_registration.country FROM aircraft_registration WHERE registration_prefix = :registration_1 LIMIT 1";
8674
	      
8675
				$sth = $this->db->prepare($query);
8676
				$sth->execute(array(':registration_1' => $registration_1));
8677
	        
8678
				while($row = $sth->fetch(PDO::FETCH_ASSOC))
8679
				{
8680
					$registration_prefix = $row['registration_prefix'];
0 ignored issues
show
Unused Code introduced by
$registration_prefix is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
8681
					$country = $row['country'];
8682
				}
8683
			}
8684
		}
8685
    
8686
		return $country;
8687
	}
8688
	
8689
	/**
8690
	* Set a new highlight value for a flight
8691
	*
8692
	* @param String $flightaware_id flightaware_id from spotter_output table
8693
	* @param String $highlight New highlight value
8694
	*/
8695
	public function setHighlightFlight($flightaware_id,$highlight) {
8696
		
8697
		$query  = "UPDATE spotter_output SET highlight = :highlight WHERE flightaware_id = :flightaware_id";
8698
		$sth = $this->db->prepare($query);
8699
		$sth->execute(array(':flightaware_id' => $flightaware_id, ':highlight' => $highlight));
8700
	}
8701
	
8702
	/**
8703
	* Gets the short url from bit.ly
8704
	*
8705
	* @param String $url the full url
8706
	* @return String the bit.ly url
8707
	*
8708
	*/
8709
	public function getBitlyURL($url)
8710
	{
8711
		global $globalBitlyAccessToken;
8712
		
8713
		if ($globalBitlyAccessToken == '') return $url;
8714
        
8715
		$google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url;
8716
		
8717
		$ch = curl_init();
8718
		curl_setopt($ch, CURLOPT_HEADER, 0);
8719
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
8720
		curl_setopt($ch, CURLOPT_URL, $google_url);
8721
		$bitly_data = curl_exec($ch);
8722
		curl_close($ch);
8723
		
8724
		$bitly_data = json_decode($bitly_data);
8725
		
8726
		if ($bitly_data->status_txt = "OK"){
8727
			$bitly_url = $bitly_data->data->url;
8728
		}
8729
8730
		return $bitly_url;
0 ignored issues
show
Bug introduced by
The variable $bitly_url does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
8731
	}
8732
8733
8734
	public function getOrderBy()
8735
	{
8736
		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY spotter_output.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY spotter_output.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY spotter_output.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY spotter_output.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY spotter_output.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY spotter_output.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY spotter_output.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY spotter_output.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY spotter_output.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY spotter_output.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY spotter_output.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY spotter_output.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY spotter_output.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY spotter_output.date DESC"),"distance_asc" => array("key" => "distance_asc","value" => "Distance - ASC","sql" => "ORDER BY distance ASC"),"distance_desc" => array("key" => "distance_desc","value" => "Distance - DESC","sql" => "ORDER BY distance DESC"));
8737
		
8738
		return $orderby;
8739
		
8740
	}
8741
    
8742
/*
8743
	public function importFromFlightAware()
8744
	{
8745
		global $globalFlightAwareUsername, $globalFlightAwarePassword, $globalLatitudeMax, $globalLatitudeMin, $globalLongitudeMax, $globalLongitudeMin, $globalAirportIgnore;
8746
		$Spotter = new Spotter($this->db);
8747
		$SpotterLive = new SpotterLive($this->db);
8748
		$options = array(
8749
		            'trace' => true,
8750
		            'exceptions' => 0,
8751
		            'login' => $globalFlightAwareUsername,
8752
		            'password' => $globalFlightAwarePassword,
8753
		);
8754
		$client = new SoapClient('http://flightxml.flightaware.com/soap/FlightXML2/wsdl', $options);
8755
		$params = array('query' => '{range lat '.$globalLatitudeMin.' '.$globalLatitudeMax.'} {range lon '.$globalLongitudeMax.' '.$globalLongitudeMin.'} {true inAir}', 'howMany' => '15', 'offset' => '0');
8756
		$result = $client->SearchBirdseyeInFlight($params);
8757
		$dataFound = false;
8758
		$ignoreImport = false;
8759
		if (isset($result->SearchBirdseyeInFlightResult))
8760
		{
8761
			if (is_array($result->SearchBirdseyeInFlightResult->aircraft))
8762
			{
8763
				foreach($result->SearchBirdseyeInFlightResult->aircraft as $aircraft)
8764
				{
8765
					if (!strstr($aircraft->origin, 'L ') && !strstr($aircraft->destination, 'L '))
8766
					{
8767
						foreach($globalAirportIgnore as $airportIgnore)
8768
						{
8769
							if ($aircraft->origin == $airportIgnore || $aircraft->destination == $airportIgnore)
8770
							{
8771
								$ignoreImport = true; 
8772
							}
8773
						}
8774
						if ($ignoreImport == false)
8775
						{
8776
							$flightaware_id = $aircraft->faFlightID;
8777
							$ident = $aircraft->ident;
8778
							$aircraft_type = $aircraft->type;
8779
							$departure_airport = $aircraft->origin;
8780
							$arrival_airport = $aircraft->destination;
8781
							$latitude = $aircraft->latitude;
8782
							$longitude = $aircraft->longitude;
8783
							$waypoints = $aircraft->waypoints;
8784
							$altitude = $aircraft->altitude;
8785
							$heading = $aircraft->heading;
8786
							$groundspeed = $aircraft->groundspeed;
8787
							$dataFound = true;
8788
							//gets the callsign from the last hour
8789
							$last_hour_ident = $this->getIdentFromLastHour($ident);
8790
							//change the departure/arrival airport to NA if its not available
8791
							if ($departure_airport == "" || $departure_airport == "---" || $departure_airport == "ZZZ" || $departure_airport == "ZZZZ") { $departure_airport = "NA"; }
8792
							if ($arrival_airport == "" || $arrival_airport == "---" || $arrival_airport == "ZZZ" || $arrival_airport == "ZZZZ") { $arrival_airport = "NA"; }
8793
							//if there was no aircraft with the same callsign within the last hour and go post it into the archive
8794
							if($last_hour_ident == "")
8795
							{
8796
								//adds the spotter data for the archive
8797
								$Spotter->addSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
8798
							}
8799
8800
							//adds the spotter LIVE data
8801
							$SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
8802
						}
8803
					}
8804
					$ignoreImport = false;
8805
				}
8806
			} else {
8807
				if (!strstr($result->SearchBirdseyeInFlightResult->aircraft->origin, 'L ') && !strstr($result->SearchBirdseyeInFlightResult->aircraft->destination, 'L '))
8808
				{
8809
					foreach($globalAirportIgnore as $airportIgnore)
8810
					{
8811
						foreach($globalAirportIgnore as $airportIgnore)
8812
						{
8813
							if ($aircraft->origin == $airportIgnore || $aircraft->destination == $airportIgnore)
8814
							{
8815
								$ignoreImport = true; 
8816
							}
8817
						}
8818
						if ($ignoreImport == false)
8819
						{
8820
							$flightaware_id = $result->SearchBirdseyeInFlightResult->aircraft->faFlightID;
8821
							$ident = $result->SearchBirdseyeInFlightResult->aircraft->ident;
8822
							$aircraft_type = $result->SearchBirdseyeInFlightResult->aircraft->type;
8823
							$departure_airport = $result->SearchBirdseyeInFlightResult->aircraft->origin;
8824
							$arrival_airport = $result->SearchBirdseyeInFlightResult->aircraft->destination;
8825
							$latitude = $result->SearchBirdseyeInFlightResult->aircraft->latitude;
8826
							$longitude = $result->SearchBirdseyeInFlightResult->aircraft->longitude;
8827
							$waypoints = $result->SearchBirdseyeInFlightResult->aircraft->waypoints;
8828
							$altitude = $result->SearchBirdseyeInFlightResult->aircraft->altitude;
8829
							$heading = $result->SearchBirdseyeInFlightResult->aircraft->heading;
8830
							$groundspeed = $result->SearchBirdseyeInFlightResult->aircraft->groundspeed;
8831
							$dataFound = true;
8832
							//gets the callsign from the last hour
8833
							$last_hour_ident = $this->getIdentFromLastHour($ident);
8834
							//change the departure/arrival airport to NA if its not available
8835
							if ($departure_airport == "" || $departure_airport == "---" || $departure_airport == "ZZZ" || $departure_airport == "ZZZZ") { $departure_airport = "NA"; }
8836
							if ($arrival_airport == "" || $arrival_airport == "---" || $arrival_airport == "ZZZ" || $arrival_airport == "ZZZZ") { $arrival_airport = "NA"; }
8837
							//if there was no aircraft with the same callsign within the last hour and go post it into the archive
8838
							if($last_hour_ident == "")
8839
							{
8840
								//adds the spotter data for the archive
8841
								$Spotter->addSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
8842
							}
8843
							//adds the spotter LIVE data
8844
							$SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
8845
						}
8846
						$ignoreImport = false;
8847
					}
8848
				}
8849
			}
8850
		} 
8851
	}
8852
*/
8853
8854
	// Update flights data when new data in DB
8855
	public function updateFieldsFromOtherTables()
8856
	{
8857
		global $globalDebug, $globalDBdriver;
8858
		$Image = new Image($this->db);
8859
		
8860
8861
		// routes
8862
		if ($globalDebug) print "Routes...\n";
8863
		if ($globalDBdriver == 'mysql') {
8864
			$query = "SELECT spotter_output.spotter_id, routes.FromAirport_ICAO, routes.ToAirport_ICAO FROM spotter_output, routes WHERE spotter_output.ident = routes.CallSign AND ( spotter_output.departure_airport_icao != routes.FromAirport_ICAO OR spotter_output.arrival_airport_icao != routes.ToAirport_ICAO) AND routes.FromAirport_ICAO != '' AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 DAY)";
8865
		} elseif ($globalDBdriver == 'pgsql') {
8866
			$query = "SELECT spotter_output.spotter_id, routes.FromAirport_ICAO, routes.ToAirport_ICAO FROM spotter_output, routes WHERE spotter_output.ident = routes.CallSign AND ( spotter_output.departure_airport_icao != routes.FromAirport_ICAO OR spotter_output.arrival_airport_icao != routes.ToAirport_ICAO) AND routes.FromAirport_ICAO != '' AND spotter_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '15 DAYS'";
8867
		}
8868
		$sth = $this->db->prepare($query);
0 ignored issues
show
Bug introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
8869
		$sth->execute();
8870
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
8871
		{
8872
			$departure_airport_array = $this->getAllAirportInfo($row['fromairport_icao']);
8873
			$arrival_airport_array = $this->getAllAirportInfo($row['toairport_icao']);
8874
			if (count($departure_airport_array) > 0 && count($arrival_airport_array) > 0) {
8875
				$update_query="UPDATE spotter_output SET departure_airport_icao = :fromicao, arrival_airport_icao = :toicao, departure_airport_name = :departure_airport_name, departure_airport_city = :departure_airport_city, departure_airport_country = :departure_airport_country, arrival_airport_name = :arrival_airport_name, arrival_airport_city = :arrival_airport_city, arrival_airport_country = :arrival_airport_country WHERE spotter_id = :spotter_id";
8876
				$sthu = $this->db->prepare($update_query);
8877
				$sthu->execute(array(':fromicao' => $row['fromairport_icao'],':toicao' => $row['toairport_icao'],':spotter_id' => $row['spotter_id'],':departure_airport_name' => $departure_airport_array[0]['name'],':departure_airport_city' => $departure_airport_array[0]['city'],':departure_airport_country' => $departure_airport_array[0]['country'],':arrival_airport_name' => $arrival_airport_array[0]['name'],':arrival_airport_city' => $arrival_airport_array[0]['city'],':arrival_airport_country' => $arrival_airport_array[0]['country']));
8878
			}
8879
		}
8880
		
8881
		if ($globalDebug) print "Airlines...\n";
8882
		//airlines
8883
		if ($globalDBdriver == 'mysql') {
8884
			$query  = "SELECT spotter_output.spotter_id, spotter_output.ident FROM spotter_output WHERE (spotter_output.airline_name = '' OR spotter_output.airline_name = 'Not Available') AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 DAY)";
8885
		} elseif ($globalDBdriver == 'pgsql') {
8886
			$query  = "SELECT spotter_output.spotter_id, spotter_output.ident FROM spotter_output WHERE (spotter_output.airline_name = '' OR spotter_output.airline_name = 'Not Available') AND spotter_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '15 DAYS'";
8887
		}
8888
		$sth = $this->db->prepare($query);
8889
		$sth->execute();
8890
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
8891
		{
8892
			if (is_numeric(substr($row['ident'], -1, 1)))
8893
			{
8894
				$airline_array = $this->getAllAirlineInfo(substr($row['ident'], 0, 3));
8895
				if (isset($airline_array[0]['name'])) {
8896
					$update_query  = "UPDATE spotter_output SET spotter_output.airline_name = :airline_name, spotter_output.airline_icao = :airline_icao, spotter_output.airline_country = :airline_country, spotter_output.airline_type = :airline_type WHERE spotter_output.spotter_id = :spotter_id";
8897
					$sthu = $this->db->prepare($update_query);
8898
					$sthu->execute(array(':airline_name' => $airline_array[0]['name'],':airline_icao' => $airline_array[0]['icao'], ':airline_country' => $airline_array[0]['country'], ':airline_type' => $airline_array[0]['type'], ':spotter_id' => $row['spotter_id']));
8899
				}
8900
			}
8901
		}
8902
8903
		if ($globalDebug) print "Remove Duplicate in aircraft_modes...\n";
8904
		//duplicate modes
8905
		$query = "DELETE aircraft_modes FROM aircraft_modes LEFT OUTER JOIN (SELECT max(`AircraftID`) as `AircraftID`,`ModeS` FROM `aircraft_modes` group by ModeS) as KeepRows ON aircraft_modes.AircraftID = KeepRows.AircraftID WHERE KeepRows.AircraftID IS NULL";
8906
		$sth = $this->db->prepare($query);
8907
		$sth->execute();
8908
		
8909
		if ($globalDebug) print "Aircraft...\n";
8910
		//aircraft
8911
		if ($globalDBdriver == 'mysql') {
8912
			$query  = "SELECT spotter_output.spotter_id, spotter_output.aircraft_icao, spotter_output.registration FROM spotter_output WHERE (spotter_output.aircraft_name = '' OR spotter_output.aircraft_name = 'Not Available') AND spotter_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY)";
8913
		} elseif ($globalDBdriver == 'pgsql') {
8914
			$query  = "SELECT spotter_output.spotter_id, spotter_output.aircraft_icao, spotter_output.registration FROM spotter_output WHERE (spotter_output.aircraft_name = '' OR spotter_output.aircraft_name = 'Not Available') AND spotter_output.date >= now() AT TIME ZONE 'UTC' - INERVAL '15 DAYS'";
8915
		}
8916
		$sth = $this->db->prepare($query);
8917
		$sth->execute();
8918
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
8919
		{
8920
			if ($row['aircraft_icao'] != '') {
8921
				$aircraft_name = $this->getAllAircraftInfo($row['aircraft_icao']);
8922
				if ($row['registration'] != ""){
8923
					$image_array = $Image->getSpotterImage($row['registration']);
8924
					if (count($image_array) == 0) {
8925
						$Image->addSpotterImage($row['registration']);
8926
					}
8927
				}
8928
				if (count($aircraft_name) > 0) {
8929
					$update_query  = "UPDATE spotter_output SET spotter_output.aircraft_name = :aircraft_name, spotter_output.aircraft_manufacturer = :aircraft_manufacturer WHERE spotter_output.spotter_id = :spotter_id";
8930
					$sthu = $this->db->prepare($update_query);
8931
					$sthu->execute(array(':aircraft_name' => $aircraft_name[0]['type'], ':aircraft_manufacturer' => $aircraft_name[0]['manufacturer'], ':spotter_id' => $row['spotter_id']));
8932
				}
8933
			}
8934
		}
8935
	}	
8936
8937
	// Update arrival airports for data already in DB
8938
	public function updateArrivalAirports()
8939
	{
8940
		global $globalDebug, $globalDBdriver, $globalClosestMinDist;
8941
		$query = "SELECT spotter_output.spotter_id, spotter_output.last_latitude, spotter_output.last_longitude, spotter_output.last_altitude, spotter_output.arrival_airport_icao, spotter_output.real_arrival_airport_icao FROM spotter_output";
8942
		$sth = $this->db->prepare($query);
8943
		$sth->execute();
8944
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
8945
		{
8946
			if ($row['last_latitude'] != '' && $row['last_longitude'] != '') {
8947
				$closestAirports = $this->closestAirports($row['last_latitude'],$row['last_longitude'],$globalClosestMinDist);
8948
				$airport_icao = '';
8949
				 if (isset($closestAirports[0])) {
8950
					if ($row['arrival_airport_icao'] == $closestAirports[0]['icao']) {
8951
						$airport_icao = $closestAirports[0]['icao'];
8952
						if ($globalDebug) echo "\o/ 1st ---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
8953
					} elseif (count($closestAirports > 1) && $row['arrival_airport_icao'] != '' && $row['arrival_airport_icao'] != 'NA') {
8954
						foreach ($closestAirports as $airport) {
8955
							if ($row['arrival_airport_icao'] == $airport['icao']) {
8956
								$airport_icao = $airport['icao'];
8957
								if ($globalDebug) echo "\o/ try --++ Find arrival airport. airport_icao : ".$airport_icao."\n";
8958
								break;
8959
							}
8960
						}
8961
					} elseif ($row['last_altitude'] == 0 || ($row['last_altitude'] != '' && ($closestAirports[0]['altitude'] <= $row['last_altitude']*100+1000 && $row['last_altitude']*100 < $closestAirports[0]['altitude']+5000))) {
8962
						$airport_icao = $closestAirports[0]['icao'];
8963
						if ($globalDebug) echo "\o/ NP --++ Find arrival airport. Airport ICAO : ".$airport_icao." !  Latitude : ".$row['last_latitude'].' - Longitude : '.$row['last_longitude'].' - MinDist : '.$globalClosestMinDist." - Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.($row['last_altitude']*100)."\n";
8964
					} else {
8965
						if ($globalDebug) echo "----- Can't find arrival airport. Latitude : ".$row['last_latitude'].' - Longitude : '.$row['last_longitude'].' - MinDist : '.$globalClosestMinDist." - Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.($row['last_altitude']*100)."\n";
8966
					}
8967
				} else {
8968
					if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$row['last_latitude'].' - Longitude : '.$row['last_longitude'].' - MinDist : '.$globalClosestMinDist."\n";
8969
				}
8970
				if ($row['real_arrival_airport_icao'] != $airport_icao) {
8971
					if ($globalDebug) echo "Updating airport to ".$airport_icao."...\n";
8972
					$update_query="UPDATE spotter_output SET real_arrival_airport_icao = :airport_icao WHERE spotter_id = :spotter_id";
8973
					$sthu = $this->db->prepare($update_query);
8974
					$sthu->execute(array(':airport_icao' => $airport_icao,':spotter_id' => $row['spotter_id']));
8975
				}
8976
			}
8977
		}
8978
	}
8979
	
8980
	public function closestAirports($origLat,$origLon,$dist = 10) {
8981
		global $globalDBdriver;
8982
		$dist = number_format($dist*0.621371,2,'.',''); // convert km to mile
8983
/*
8984
		$query="SELECT name, icao, latitude, longitude, altitude, 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - abs(latitude))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(abs(latitude)*pi()/180)*POWER(SIN(($origLon-longitude)*pi()/180/2),2))) as distance 
8985
                      FROM airport WHERE longitude between ($origLon-$dist/abs(cos(radians($origLat))*69)) and ($origLon+$dist/abs(cos(radians($origLat))*69)) and latitude between ($origLat-($dist/69)) and ($origLat+($dist/69)) 
8986
                      having distance < $dist ORDER BY distance limit 100;";
8987
*/
8988
		if ($globalDBdriver == 'mysql') {
8989
			$query="SELECT name, icao, latitude, longitude, altitude, 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(latitude*pi()/180)*POWER(SIN(($origLon-longitude)*pi()/180/2),2))) as distance 
8990
	                      FROM airport WHERE longitude between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat)*69)) and latitude between ($origLat-($dist/69)) and ($origLat+($dist/69)) 
8991
	                      AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(latitude*pi()/180)*POWER(SIN(($origLon-longitude)*pi()/180/2),2)))) < $dist ORDER BY distance limit 100;";
8992
                } else {
8993
			$query="SELECT name, icao, latitude, longitude, altitude, 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(longitude as double precision))*pi()/180/2),2))) as distance 
8994
	                      FROM airport WHERE CAST(longitude as double precision) between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat))*69) and CAST(latitude as double precision) between ($origLat-($dist/69)) and ($origLat+($dist/69)) 
8995
	                      AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(longitude as double precision))*pi()/180/2),2)))) < $dist ORDER BY distance limit 100;";
8996
    		}
8997
		$sth = $this->db->prepare($query);
8998
		$sth->execute();
8999
		return $sth->fetchAll(PDO::FETCH_ASSOC);
9000
	}
9001
}
9002
/*
9003
$Spotter = new Spotter();
9004
print_r($Spotter->closestAirports('-19.9813','-47.8286',10));
9005
*/
9006
/*
9007
$Spotter = new Spotter();
9008
$da = $Spotter->countAllDetectedArrivalAirports(true,0,'',true);
9009
$aa = $Spotter->countAllArrivalAirports(true,0,'',true);
9010
print_r($da);
9011
print_r($aa);
9012
print_r(array_merge($da,$aa));
9013
*/
9014
?>
1 ignored issue
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...