Completed
Push — master ( 492b3e...b38f26 )
by Yannick
29:43
created

live-geojson.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
require_once('require/class.Connection.php');
3
require_once('require/class.Common.php');
4
5
if (isset($globalProtect) && $globalProtect) {
6
	@session_start();
7
	if (!isset($_SESSION['protect']) || !isset($_SERVER['HTTP_REFERER'])) {
8
		echo 'You must access this page using the right way.';
9
		die();
10
	}
11
}
12
$tracker = false;
13
$marine = false;
14
$usecoord = false;
15
if (isset($_GET['tracker'])) {
16
    $tracker = true;
17
}
18
if (isset($_GET['marine'])) {
19
    $marine = true;
20
}
21
if ($tracker) {
22
    require_once('require/class.Tracker.php');
23
    require_once('require/class.TrackerLive.php');
24
    require_once('require/class.TrackerArchive.php');
25
} elseif ($marine) {
26
    require_once('require/class.Marine.php');
27
    require_once('require/class.MarineLive.php');
28
    require_once('require/class.MarineArchive.php');
29
} else {
30
    require_once('require/class.Spotter.php');
31
    require_once('require/class.SpotterLive.php');
32
    require_once('require/class.SpotterArchive.php');
33
}
34
35
$begintime = microtime(true);
36
if ($tracker) {
37
	$TrackerLive = new TrackerLive();
38
	$Tracker = new Tracker();
39
	$TrackerArchive = new TrackerArchive();
40
} elseif ($marine) {
41
	$MarineLive = new MarineLive();
42
	$Marine = new Marine();
43
	$MarineArchive = new MarineArchive();
44
} else {
45
	$SpotterLive = new SpotterLive();
46
	$Spotter = new Spotter();
47
	$SpotterArchive = new SpotterArchive();
48
}
49
$Common = new Common();
50
51
if (isset($_GET['download'])) {
52
    if ($_GET['download'] == "true")
53
    {
54
	header('Content-disposition: attachment; filename="flightairmap.json"');
55
    }
56
}
57
header('Content-Type: text/javascript');
58
59
if (!isset($globalJsonCompress)) $compress = true;
60
else $compress = $globalJsonCompress;
61
62
$from_archive = false;
63
$min = true;
64
$allhistory = false;
65
$filter['source'] = array();
66
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalVATSIM) && $globalVATSIM && isset($_COOKIE['filter_ShowVATSIM']) && $_COOKIE['filter_ShowVATSIM'] == 'true') $filter['source'] = array_merge($filter['source'],array('vatsimtxt'));
67
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalIVAO) && $globalIVAO && isset($_COOKIE['filter_ShowIVAO']) && $_COOKIE['filter_ShowIVAO'] == 'true') $filter['source'] = array_merge($filter['source'],array('whazzup'));
68
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalphpVMS) && $globalphpVMS && isset($_COOKIE['filter_ShowVMS']) && $_COOKIE['filter_ShowVMS'] == 'true') $filter['source'] = array_merge($filter['source'],array('phpvmacars'));
69
if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalSBS1) && $globalSBS1 && isset($_COOKIE['filter_ShowSBS1']) && $_COOKIE['filter_ShowSBS1'] == 'true') $filter['source'] = array_merge($filter['source'],array('sbs','famaprs'));
70
if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalAPRS) && $globalAPRS && isset($_COOKIE['filter_ShowAPRS']) && $_COOKIE['filter_ShowAPRS'] == 'true') $filter['source'] = array_merge($filter['source'],array('aprs'));
71
if (isset($_COOKIE['filter_ident']) && $_COOKIE['filter_ident'] != '') $filter['ident'] = filter_var($_COOKIE['filter_ident'],FILTER_SANITIZE_STRING);
72
if (isset($_COOKIE['filter_mmsi']) && $_COOKIE['filter_mmsi'] != '') $filter['mmsi'] = filter_var($_COOKIE['filter_mmsi'],FILTER_SANITIZE_STRING);
73
if (isset($_COOKIE['filter_Airlines']) && $_COOKIE['filter_Airlines'] != '') $filter['airlines'] = filter_var_array(explode(',',$_COOKIE['filter_Airlines']),FILTER_SANITIZE_STRING);
74
if (isset($_COOKIE['filter_Sources']) && $_COOKIE['filter_Sources'] != '') $filter['source_aprs'] = filter_var_array(explode(',',$_COOKIE['filter_Sources']),FILTER_SANITIZE_STRING);
75
if (isset($_COOKIE['filter_airlinestype']) && $_COOKIE['filter_airlinestype'] != 'all') $filter['airlinestype'] = filter_var($_COOKIE['filter_airlinestype'],FILTER_SANITIZE_STRING);
76
if (isset($_COOKIE['filter_alliance']) && $_COOKIE['filter_alliance'] != 'all') $filter['alliance'] = filter_var($_COOKIE['filter_alliance'],FILTER_SANITIZE_STRING);
77
78
if (isset($globalMapPopup) && !$globalMapPopup && !(isset($_COOKIE['flightpopup']) && $_COOKIE['flightpopup'] == 'true')) {
79
	$min = true;
80
} else $min = false;
81
82
$spotter_array = array();
83
84
if (isset($_GET['ident'])) {
85
	$ident = urldecode(filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING));
86
	if ($tracker) {
87
		$spotter_array = $TrackerLive->getLastLiveTrackerDataByIdent($ident);
88
	} elseif ($marine) {
89
		$spotter_array = $MarineLive->getLastLiveMarineDataByIdent($ident);
90
	} else {
91
		$spotter_array = $SpotterLive->getLastLiveSpotterDataByIdent($ident);
92
		if (empty($spotter_array)) {
93
			$from_archive = true;
94
			$spotter_array = $SpotterArchive->getLastArchiveSpotterDataByIdent($ident);
95
		}
96
	}
97
	$allhistory = true;
98
} elseif (isset($_GET['flightaware_id'])) {
99
	$flightaware_id = filter_input(INPUT_GET,'flightaware_id',FILTER_SANITIZE_STRING);
100
	$spotter_array = $SpotterLive->getLastLiveSpotterDataById($flightaware_id);
101
	if (empty($spotter_array)) {
102
		$from_archive = true;
103
		$spotter_array = $SpotterArchive->getLastArchiveSpotterDataById($flightaware_id);
104
	}
105
	$allhistory = true;
106
} elseif (isset($_GET['famtrack_id'])) {
107
	$famtrack_id = urldecode(filter_input(INPUT_GET,'famtrack_id',FILTER_SANITIZE_STRING));
108
	$spotter_array = $TrackerLive->getLastLiveTrackerDataById($famtrack_id);
109
	$allhistory = true;
110
} elseif (isset($_GET['fammarine_id'])) {
111
	$fammarine_id = urldecode(filter_input(INPUT_GET,'fammarine_id',FILTER_SANITIZE_STRING));
112
	$spotter_array = $MarineLive->getLastLiveMarineDataById($fammarine_id);
113
	$allhistory = true;
114
/*
115
} elseif (isset($globalMapUseBbox) && $globalMapUseBbox && isset($_GET['coord']) && (!isset($globalMapPopup) || $globalMapPopup || (isset($_COOKIE['flightpopup']) && $_COOKIE['flightpopup'] == 'true'))) {
116
	$usecoord = true;
117
	$coord = explode(',',$_GET['coord']);
118
	if (filter_var($coord[0],FILTER_VALIDATE_FLOAT) && filter_var($coord[1],FILTER_VALIDATE_FLOAT) && filter_var($coord[2],FILTER_VALIDATE_FLOAT) && filter_var($coord[3],FILTER_VALIDATE_FLOAT) 
119
	    && $coord[0] > -180.0 && $coord[0] < 180.0 && $coord[1] > -90.0 && $coord[1] < 90.0 && $coord[2] > -180.0 && $coord[2] < 180.0 && $coord[3] > -90.0 && $coord[3] < 90.0) {
120
		if ($tracker) {
121
			$spotter_array = $TrackerLive->getLiveTrackerDatabyCoord($coord,$filter);
122
		} elseif ($marine) {
123
			$spotter_array = $MarineLive->getLiveMarineDatabyCoord($coord,$filter);
124
		} else {
125
			$spotter_array = $SpotterLive->getLiveSpotterDatabyCoord($coord,$filter);
126
		}
127
	}
128
*/
129
} elseif (isset($globalMapUseBbox) && $globalMapUseBbox && isset($_GET['coord']) && $min) {
130
	$usecoord = true;
131
	$coord = explode(',',$_GET['coord']);
132
	if (filter_var($coord[0],FILTER_VALIDATE_FLOAT) && filter_var($coord[1],FILTER_VALIDATE_FLOAT) && filter_var($coord[2],FILTER_VALIDATE_FLOAT) && filter_var($coord[3],FILTER_VALIDATE_FLOAT) 
133
	    && $coord[0] > -180.0 && $coord[0] < 180.0 && $coord[1] > -90.0 && $coord[1] < 90.0 && $coord[2] > -180.0 && $coord[2] < 180.0 && $coord[3] > -90.0 && $coord[3] < 90.0) {
134
		if ($tracker) {
135
			$spotter_array = $TrackerLive->getMinLiveTrackerDatabyCoord($coord,$filter);
136
		} elseif ($marine) {
137
			$spotter_array = $MarineLive->getMinLiveMarineDatabyCoord($coord,$filter);
138
		} else {
139
			$spotter_array = $SpotterLive->getMinLiveSpotterDatabyCoord($coord,$filter);
140
		}
141
	} else {
142
		if ($tracker) {
143
			$spotter_array = $TrackerLive->getMinLiveTrackerData($filter);
144
		} elseif ($marine) {
145
			$spotter_array = $MarineLive->getMinLiveMarineData($filter);
146
		} else {
147
			$spotter_array = $SpotterLive->getMinLiveSpotterData($filter);
148
		}
149
	}
150
} elseif (isset($_GET['archive']) && isset($_GET['begindate']) && isset($_GET['enddate']) && isset($_GET['speed']) && !isset($_GET['tracker']) && !isset($_GET['marine'])) {
151
	$from_archive = true;
152
//	$begindate = filter_input(INPUT_GET,'begindate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
153
//	$enddate = filter_input(INPUT_GET,'enddate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
154
	$begindate = filter_input(INPUT_GET,'begindate',FILTER_SANITIZE_NUMBER_INT);
155
	$enddate = filter_input(INPUT_GET,'enddate',FILTER_SANITIZE_NUMBER_INT);
156
	$archivespeed = filter_input(INPUT_GET,'speed',FILTER_SANITIZE_NUMBER_INT);
157
	$begindate = date('Y-m-d H:i:s',$begindate);
158
	$enddate = date('Y-m-d H:i:s',$enddate);
159
	$spotter_array = $SpotterArchive->getMinLiveSpotterData($begindate,$enddate,$filter);
160
} elseif ($min) {
161
	if ($tracker) {
162
		$spotter_array = $TrackerLive->getMinLiveTrackerData($filter);
163
	} elseif ($marine) {
164
		$spotter_array = $MarineLive->getMinLiveMarineData($filter);
165
	} else {
166
		$spotter_array = $SpotterLive->getMinLiveSpotterData($filter);
167
	}
168
#	$min = true;
169
} else {
170
	if ($tracker) {
171
		$spotter_array = $TrackerLive->getLiveTrackerData('','',$filter);
172
	} elseif ($marine) {
173
		$spotter_array = $marineLive->getLiveMarineData('','',$filter);
174
	} else {
175
		$spotter_array = $SpotterLive->getLiveSpotterData('','',$filter);
176
	}
177
}
178
179
if ($usecoord) {
180
	if (isset($_GET['archive'])) {
181
		$flightcnt = $SpotterArchive->getLiveSpotterCount($begindate,$enddate,$filter);
182
	} else {
183
		if ($tracker) {
184
			$flightcnt = $TrackerLive->getLiveTrackerCount($filter);
185
		} elseif ($marine) {
186
			$flightcnt = $MarineLive->getLiveMarineCount($filter);
187
		} else {
188
			$flightcnt = $SpotterLive->getLiveSpotterCount($filter);
189
		}
190
	}
191
	if ($flightcnt == '') $flightcnt = 0;
192
} else $flightcnt = 0;
193
194
$sqltime = round(microtime(true)-$begintime,2);
195
196
$currenttime = filter_input(INPUT_GET,'currenttime',FILTER_SANITIZE_NUMBER_INT);
197
if ($currenttime != '') $currenttime = round($currenttime/1000);
198
199
if ((!isset($_COOKIE['flightestimation']) && isset($globalMapEstimation) && $globalMapEstimation == FALSE) || (isset($_COOKIE['flightestimation']) && $_COOKIE['flightestimation'] == 'false')) $usenextlatlon = false;
200
else $usenextlatlon = true;
201
if ($usenextlatlon === false) $currenttime = '';
202
$j = 0;
203
$prev_flightaware_id = '';
204
$aircrafts_shadow = array();
205
$output = '{';
206
	$output .= '"type": "FeatureCollection",';
207
		if ($min) $output .= '"minimal": "true",';
208
		else $output .= '"minimal": "false",';
209
		//$output .= '"fc": "'.$flightcnt.'",';
210
		$output .= '"sqt": "'.$sqltime.'",';
211
212
		if (!empty($spotter_array) && is_array($spotter_array))
213
		{
214
			$output .= '"features": [';
215
			foreach($spotter_array as $spotter_item)
216
			{
217
				$j++;
218
				unset($idistance);
219
				date_default_timezone_set('UTC');
220
221
				if (isset($spotter_item['image_thumbnail']) && $spotter_item['image_thumbnail'] != "")
222
				{
223
					$image = $spotter_item['image_thumbnail'];
224
				} else {
225
					$image = "images/placeholder_thumb.png";
226
				}
227
228
/*
229
				if ($prev_flightaware_id != $spotter_item['flightaware_id']) {
230
				    if ($prev_flightaware_id != '') {
231
						$output .= ']';
232
						$output .= '}';
233
						$output .= '},';
234
				    }
235
				$prev_flightaware_id = $spotter_item['flightaware_id'];
236
*/
237
238
				//location of aircraft
239
//				print_r($spotter_item);
240
				$output .= '{';
241
					$output .= '"type": "Feature",';
242
						//$output .= '"fc": "'.$flightcnt.'",';
243
						//$output .= '"sqt": "'.$sqltime.'",';
244
						if (isset($spotter_item['flightaware_id'])) {
245
							$output .= '"id": "'.$spotter_item['flightaware_id'].'",';
246
						} elseif (isset($spotter_item['famtrackid'])) {
247
							$output .= '"id": "'.$spotter_item['famtrackid'].'",';
248
						} elseif (isset($spotter_item['fammarine_id'])) {
249
							$output .= '"id": "'.$spotter_item['fammarine_id'].'",';
250
						}
251
						$output .= '"properties": {';
252
						if (isset($spotter_item['flightaware_id'])) {
253
							if ($compress) $output .= '"fi": "'.$spotter_item['flightaware_id'].'",';
254
							else $output .= '"flightaware_id": "'.$spotter_item['flightaware_id'].'",';
255
						} elseif (isset($spotter_item['famtrackid'])) {
256
							if ($compress) $output .= '"fti": "'.$spotter_item['famtrackid'].'",';
257
							else $output .= '"famtrackid": "'.$spotter_item['famtrackid'].'",';
258
						} elseif (isset($spotter_item['fammarine_id'])) {
259
							if ($compress) $output .= '"fmi": "'.$spotter_item['fammarine_id'].'",';
260
							else $output .= '"fammarineid": "'.$spotter_item['fammarine_id'].'",';
261
						}
262
							$output .= '"fc": "'.$flightcnt.'",';
263
							$output .= '"sqt": "'.$sqltime.'",';
264
							if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",';
265
266
/*
267
							if ($min) $output .= '"minimal": "true",';
268
							else $output .= '"minimal": "false",';
269
*/
270
							//$output .= '"fc": "'.$spotter_item['nb'].'",';
271
						if (isset($spotter_item['ident']) && $spotter_item['ident'] != '') {
272
							if ($compress) $output .= '"c": "'.str_replace('\\','',$spotter_item['ident']).'",';
273
							else $output .= '"callsign": "'.str_replace('\\','',$spotter_item['ident']).'",';
274
							//"
275
						} else {
276
							if ($compress) $output .= '"c": "NA",';
277
							else $output .= '"callsign": "NA",';
278
						}
279
						if (isset($spotter_item['registration'])) $output .= '"registration": "'.$spotter_item['registration'].'",';
280
						if (isset($spotter_item['aircraft_name']) && isset($spotter_item['aircraft_type'])) {
281
							$output .= '"aircraft_name": "'.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].')",';
282
							$output .= '"aircraft_wiki": "http://'.strtolower($globalLanguage).'.wikipedia.org/wiki/'.urlencode(str_replace(' ','_',$spotter_item['aircraft_name'])).'",';
283
						} elseif (isset($spotter_item['aircraft_type'])) {
284
							$output .= '"aircraft_name": "NA ('.$spotter_item['aircraft_type'].')",';
285
						} elseif (!$min) {
286
							$output .= '"aircraft_name": "NA",';
287
						}
288
						if (!$min && isset($spotter_item['aircraft_icao'])) {
289
							$output .= '"aircraft_icao": "'.$spotter_item['aircraft_icao'].'",';
290
						}
291
						if (!isset($spotter_item['aircraft_shadow']) && !$tracker) {
292
							if (!isset($spotter_item['aircraft_icao']) || $spotter_item['aircraft_icao'] == '') $spotter_item['aircraft_shadow'] = '';
293
							else {
294
								$aircraft_icao = $spotter_item['aircraft_icao'];
295
								if (isset($aircrafts_shadow[$aircraft_icao])) $spotter_item['aircraft_shadow'] = $aircrafts_shadow[$aircraft_icao];
296
								else {
297
									$aircraft_info = $Spotter->getAllAircraftInfo($spotter_item['aircraft_icao']);
298
									if (count($aircraft_info) > 0) $spotter_item['aircraft_shadow'] = $aircraft_info[0]['aircraft_shadow'];
299
									elseif (isset($spotter_item['format_source']) && $spotter_item['format_source'] == 'aprs') $spotter_item['aircraft_shadow'] = 'PA18.png';
300
									elseif ($aircraft_icao == 'PARAGLIDER') $spotter_item['aircraft_shadow'] = 'PARAGLIDER.png';
301
									else $spotter_item['aircraft_shadow'] = '';
302
									$aircrafts_shadow[$aircraft_icao] = $spotter_item['aircraft_shadow'];
303
								}
304
							}
305
						}
306
						if (!isset($spotter_item['aircraft_shadow']) || $spotter_item['aircraft_shadow'] == '') {
307
							if ($tracker) {
308
								if (isset($spotter_item['type']) && $spotter_item['type'] == 'Ambulance') {
309
									if ($compress) $output .= '"as": "ambulance.png",';
310
									else $output .= '"aircraft_shadow": "ambulance.png",';
311
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Police') {
312
									if ($compress) $output .= '"as": "police.png",';
313
									else $output .= '"aircraft_shadow": "police.png",';
314
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Yacht (Sail)') {
315
									if ($compress) $output .= '"as": "ship.png",';
316
									else $output .= '"aircraft_shadow": "ship.png",';
317
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Ship (Power Boat)') {
318
									if ($compress) $output .= '"as": "ship.png",';
319
									else $output .= '"aircraft_shadow": "ship.png",';
320
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Shuttle') {
321
									if ($compress) $output .= '"as": "ship.png",';
322
									else $output .= '"aircraft_shadow": "ship.png",';
323
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Truck') {
324
									if ($compress) $output .= '"as": "truck.png",';
325
									else $output .= '"aircraft_shadow": "truck.png",';
326
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Truck (18 Wheeler)') {
327
									if ($compress) $output .= '"as": "truck.png",';
328
									else $output .= '"aircraft_shadow": "truck.png",';
329
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Aircraft (small)') {
330
									if ($compress) $output .= '"as": "aircraft.png",';
331
									else $output .= '"aircraft_shadow": "aircraft.png",';
332
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Large Aircraft') {
333
									if ($compress) $output .= '"as": "aircraft.png",';
334
									else $output .= '"aircraft_shadow": "aircraft.png",';
335
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Helicopter') {
336
									if ($compress) $output .= '"as": "helico.png",';
337
									else $output .= '"aircraft_shadow": "helico.png",';
338
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Railroad Engine') {
339
									if ($compress) $output .= '"as": "rail.png",';
340
									else $output .= '"aircraft_shadow": "rail.png",';
341
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Firetruck') {
342
									if ($compress) $output .= '"as": "firetruck.png",';
343
									else $output .= '"aircraft_shadow": "firetruck.png",';
344
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Bus') {
345
									if ($compress) $output .= '"as": "bus.png",';
346
									else $output .= '"aircraft_shadow": "bus.png",';
347
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Phone') {
348
									if ($compress) $output .= '"as": "phone.png",';
349
									else $output .= '"aircraft_shadow": "phone.png",';
350
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Jogger') {
351
									if ($compress) $output .= '"as": "jogger.png",';
352
									else $output .= '"aircraft_shadow": "jogger.png",';
353
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Bike') {
354
									if ($compress) $output .= '"as": "bike.png",';
355
									else $output .= '"aircraft_shadow": "bike.png",';
356
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Motorcycle') {
357
									if ($compress) $output .= '"as": "motorcycle.png",';
358
									else $output .= '"aircraft_shadow": "motorcycle.png",';
359
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Balloon') {
360
									if ($compress) $output .= '"as": "balloon.png",';
361
									else $output .= '"aircraft_shadow": "balloon.png",';
362
								} else {
363
									if ($compress) $output .= '"as": "car.png",';
364
									else $output .= '"aircraft_shadow": "car.png",';
365
								}
366
							} elseif ($marine) {
367
								if ($compress) $output .= '"as": "ship.png",';
368
								else $output .= '"aircraft_shadow": "ship.png",';
369
							} else {
370
								if ($compress) $output .= '"as": "default.png",';
371
								else $output .= '"aircraft_shadow": "default.png",';
372
							}
373
						} else {
374
							if ($compress) $output .= '"as": "'.$spotter_item['aircraft_shadow'].'",';
375
							else $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",';
376
						}
377
						if (isset($spotter_item['airline_name'])) {
378
							$output .= '"airline_name": "'.$spotter_item['airline_name'].'",';
379
						} elseif (!$min) {
380
							$output .= '"airline_name": "NA",';
381
						}
382
						if (isset($spotter_item['departure_airport'])) {
383
							if ($compress) $output .= '"dac": "'.$spotter_item['departure_airport'].'",';
384
							else $output .= '"departure_airport_code": "'.$spotter_item['departure_airport'].'",';
385
						}
386
						if (isset($spotter_item['departure_airport_city'])) {
387
							$output .= '"departure_airport": "'.$spotter_item['departure_airport_city'].', '.$spotter_item['departure_airport_country'].'",';
388
						}
389
						if (isset($spotter_item['departure_airport_time'])) {
390
							$output .= '"departure_airport_time": "'.$spotter_item['departure_airport_time'].'",';
391
						}
392
						if (isset($spotter_item['arrival_airport_time'])) {
393
							$output .= '"arrival_airport_time": "'.$spotter_item['arrival_airport_time'].'",';
394
						}
395
						if (isset($spotter_item['arrival_airport'])) {
396
							if ($compress) $output .= '"aac": "'.$spotter_item['arrival_airport'].'",';
397
							else $output .= '"arrival_airport_code": "'.$spotter_item['arrival_airport'].'",';
398
						}
399
						if (isset($spotter_item['arrival_airport_city'])) {
400
							$output .= '"arrival_airport": "'.$spotter_item['arrival_airport_city'].', '.$spotter_item['arrival_airport_country'].'",';
401
						}
402
						
403
						if (isset($spotter_item['date_iso_8601'])) {
404
							$output .= '"date_update": "'.date("M j, Y, g:i a T", strtotime($spotter_item['date_iso_8601'])).'",';
405
						}
406
						if (isset($spotter_item['date'])) {
407
							$output .= '"lu": "'.strtotime($spotter_item['date_iso_8601']).'",';
408
						}
409
						if (!$min) {
410
							$output .= '"latitude": "'.$spotter_item['latitude'].'",';
411
							$output .= '"longitude": "'.$spotter_item['longitude'].'",';
412
							$output .= '"ground_speed": "'.$spotter_item['ground_speed'].'",';
413
						}
414
						
415
						if (isset($spotter_item['altitude'])) {
416
							if ($compress) $output .= '"a": "'.$spotter_item['altitude'].'",';
417
							else $output .= '"altitude": "'.$spotter_item['altitude'].'",';
418
						}
419
						
420
						$heading = $spotter_item['heading'];
421
						
422
						if (isset($archivespeed) || $usenextlatlon) {
423
							if (isset($spotter_item['arrival_airport']) && $spotter_item['arrival_airport'] != 'NA') {
424
								if (isset($spotter_item['arrival_airport_latitude'])) {
425
									$cheading = $Common->getHeading($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['arrival_airport_latitude'],$spotter_item['arrival_airport_longitude']);
426
									$idistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['arrival_airport_latitude'],$spotter_item['arrival_airport_longitude']);
427
									$farr_lat = $spotter_item['arrival_airport_latitude'];
428
									$farr_lon = $spotter_item['arrival_airport_longitude'];
429
								} else {
430
									$aairport = $Spotter->getAllAirportInfo($spotter_item['arrival_airport']);
431
									if (isset($aairport[0]['latitude'])) {
432
										$cheading = $Common->getHeading($spotter_item['latitude'],$spotter_item['longitude'],$aairport[0]['latitude'],$aairport[0]['longitude']);
433
										$idistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$aairport[0]['latitude'],$aairport[0]['longitude']);
434
										$farr_lat = $aairport[0]['latitude'];
435
										$farr_lon = $aairport[0]['longitude'];
436
									}
437
								}
438
							}
439
						}
440
						
441
						if ($compress)$output .= '"h": "'.$heading.'",';
442
						else $output .= '"heading": "'.$heading.'",';
443
						if ($currenttime != '') {
444
							if (strtotime($spotter_item['date']) < $currenttime) {
445
								if (isset($archivespeed)) {
446
									$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading,$archivespeed,($currenttime-strtotime($spotter_item['date'])+$globalMapRefresh));
447
									$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
448
									if (!isset($idistance) || $fdistance < $idistance) $output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
449
									else {
450
										$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$cheading,$archivespeed,($currenttime-strtotime($spotter_item['date'])+$globalMapRefresh));
451
										$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
452
										if (!isset($idistance) || $fdistance < $idistance) $output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
453
										else {
454
											$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading,$archivespeed);
455
											$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
456
										}
457
									}
458
								} elseif ($usenextlatlon) {
459
									$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading,1,($currenttime-strtotime($spotter_item['date'])+$globalMapRefresh));
460
									$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
461
									if (!isset($idistance) || $fdistance < $idistance) $output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
462
									else {
463
										$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$cheading,1,($currenttime-strtotime($spotter_item['date'])+$globalMapRefresh));
464
										$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
465
										if (!isset($idistance) || $fdistance < $idistance) $output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
466
										else {
467
											$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading);
468
											$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
469
										}
470
									}
471
								}
472
							} else {
473
								if (isset($archivespeed)) {
474
									$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading,$archivespeed);
475
									$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
476
								} elseif ($usenextlatlon) {
477
									$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading);
478
									$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
479
								}
480
							}
481
						} else {
482
							if (isset($archivespeed)) {
483
								$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading,$archivespeed);
484
								$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
485
								if (!isset($idistance) || $fdistance < $idistance) {
486
									$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
487
								} else {
488
									$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$cheading,$archivespeed);
489
									//$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
490
									$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
491
								}
492
							} elseif ($usenextlatlon) {
493
								$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading);
494
								$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
495
								if (!isset($idistance) || $fdistance < $idistance) {
496
										$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
497
								} else {
498
									$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$cheading);
499
									//$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
500
									$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
501
								}
502
							}
503
						}
504
505
						if (!$min) $output .= '"image": "'.$image.'",';
506
						if (isset($spotter_item['image_copyright']) && $spotter_item['image_copyright'] != '') {
507
							$output .= '"image_copyright": "'.str_replace('"',"'",trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$spotter_item['image_copyright']))).'",';
508
						}
509
						if (isset($spotter_item['image_source_website'])) {
510
							$output .= '"image_source_website": "'.urlencode($spotter_item['image_source_website']).'",';
511
						}
512
						if (isset($spotter_item['squawk'])) {
513
							if ($compress) $output .= '"sq": "'.$spotter_item['squawk'].'",';
514
							else $output .= '"squawk": "'.$spotter_item['squawk'].'",';
515
						}
516
						if (isset($spotter_item['squawk_usage'])) {
517
							$output .= '"squawk_usage": "'.$spotter_item['squawk_usage'].'",';
518
						}
519
						if (isset($spotter_item['pilot_id'])) {
520
							$output .= '"pilot_id": "'.$spotter_item['pilot_id'].'",';
521
						}
522
						if (isset($spotter_item['pilot_name'])) {
523
							$output .= '"pilot_name": "'.$spotter_item['pilot_name'].'",';
524
						}
525
						if (isset($spotter_item['waypoints']) && $spotter_item['waypoints'] != '') {
526
							$output .= '"waypoints": "'.$spotter_item['waypoints'].'",';
527
						}
528
						if (isset($spotter_item['acars'])) {
529
							$output .= '"acars": "'.trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"), '<br />',$spotter_item['acars']['message'])).'",';
530
						}
531
						// type when not aircraft ?
532
						if (isset($spotter_item['type'])) {
533
							if ($compress) $output .= '"t": "'.$spotter_item['type'].'"';
534
							else $output .= '"type": "'.$spotter_item['type'].'"';
535
						} elseif ($marine) {
536
							if ($compress) $output .= '"t": "ship"';
537
							else $output .= '"type": "ship"';
538
						} else {
539
							if ($compress) $output .= '"t": "aircraft"';
540
							else $output .= '"type": "aircraft"';
541
						}
542
						$output .= '},';
543
						$output .= '"geometry": {';
544
							$output .= '"type": "Point",';
545
								$output .= '"coordinates": [';
546
								if ($currenttime != '') {
547
									if (strtotime($spotter_item['date']) < $currenttime) {
548
										if (!isset($archivespeed)) $archivespeed = 1;
549
										$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading,$archivespeed,($currenttime-strtotime($spotter_item['date'])));
550
										$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
551
										if (!isset($idistance) || $fdistance < $idistance) $output .= $nextcoord['longitude'].','.$nextcoord['latitude'];
552
										else {
553
											$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$cheading,$archivespeed,($currenttime-strtotime($spotter_item['date'])));
554
											$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
555
											if (!isset($idistance) || $fdistance < $idistance) $output .= $nextcoord['longitude'].','.$nextcoord['latitude'];
556
											else {
557
												$output .= $spotter_item['longitude'].', ';
558
												$output .= $spotter_item['latitude'];
559
											}
560
										}
561
										/*
562
										if (!isset($archivespeed)) $archivespeed = 1;
563
										$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$spotter_item['heading'],$archivespeed,$currenttime-strtotime($spotter_item['date']));
564
										$output .= $nextcoord['longitude'].','.$nextcoord['latitude'];
565
										*/
566
									} else {
567
										$output .= $spotter_item['longitude'].', ';
568
										$output .= $spotter_item['latitude'];
569
									}
570
								} else {
571
									$output .= $spotter_item['longitude'].', ';
572
									$output .= $spotter_item['latitude'];
573
								}
574
										/*
575
										.', ';
576
										$output .= $spotter_item['altitude']*30.48;
577
										$output .= ', '.strtotime($spotter_item['date']);
578
										*/
579
								$output .= ']';
580
							$output .= '}';
581
				$output .= '},';
582
					
583
			/*	} else {
584
								$output .= ', ';
585
								$output .= $spotter_item['longitude'].', ';
586
								$output .= $spotter_item['latitude'].', ';
587
								$output .= $spotter_item['altitude']*30.48;
588
								$output .= ', '.strtotime($spotter_item['date']);
589
590
				}
591
*/                
592
593
/*                
594
                //previous location history of aircraft
595
                $output .= '{';
596
					$output .= '"type": "Feature",';
597
                        $output .= '"properties": {';
598
							$output .= '"callsign": "'.$spotter_item['ident'].'",';
599
							$output .= '"type": "history"';
600
						$output .= '},';
601
						$output .= '"geometry": {';
602
							$output .= '"type": "LineString",';
603
								$output .= '"coordinates": [';
604
                                    //$spotter_history_array = SpotterLive::getAllLiveSpotterDataByIdent($spotter_item['ident']);
605
                                    if ($from_archive) {
606
					    $spotter_history_array = SpotterArchive::getAllArchiveSpotterDataById($spotter_item['flightaware_id']);
607
                                    } else {
608
					    $spotter_history_array = SpotterLive::getAllLiveSpotterDataById($spotter_item['flightaware_id']);
609
                                    }
610
										$d = false;
611
										$neg = false;
612
									$history_output = '';
613
									foreach ($spotter_history_array as $key => $spotter_history)
614
									{
615
										if (abs($spotter_history['longitude']-$spotter_item['longitude']) > 200 || $d==true) {
616
											if ($d == false) $d = true;
617
									        } else {
618
											$history_output .= '[';
619
											$history_output .=  $spotter_history['longitude'].', ';
620
											$history_output .=  $spotter_history['latitude'].',';
621
											$history_output .=  $spotter_history['altitude'];
622
											$history_output .= '],';
623
624
										}
625
									}
626
									if ($history_output != '') $output .= substr($history_output, 0, -1);
627
								$output .= ']';
628
							$output .= '}';
629
				$output .= '},';
630
                
631
			}
632
*/
633
				$history = filter_input(INPUT_GET,'history',FILTER_SANITIZE_STRING);
634
				if ($history == '' && isset($_COOKIE['history'])) $history = $_COOKIE['history'];
635
				
636
				if (
637
				    (isset($_COOKIE['flightpath']) && $_COOKIE['flightpath'] == 'true') 
638
				    || ((isset($globalMapHistory) && $globalMapHistory) || $allhistory)
639
				//    || (isset($history) && $history != '' && $history != 'NA' && ($history == $spotter_item['ident'] || $history == $spotter_item['flightaware_id']))
640
				//    || (isset($history) && $history != '' && $history != 'NA' && $history == $spotter_item['ident'])
641
				    || (isset($history) && $history != '' && $history != 'NA' && isset($spotter_item['flightaware_id']) && str_replace('-','',$history) == str_replace('-','',$spotter_item['flightaware_id']))
642
				    || (isset($history) && $history == '' && isset($spotter_item['flightaware_id']) && isset($_GET['flightaware_id']) && $_GET['flightaware_id'] == $spotter_item['flightaware_id'])
643
				    || (isset($history) && $history != '' && $history != 'NA' && isset($spotter_item['fammarine_id']) && str_replace('-','',$history) == str_replace('-','',$spotter_item['fammarine_id']))
644
				    || (isset($history) && $history == '' && isset($spotter_item['flightaware_id']) && isset($_GET['fammarine_id']) && $_GET['fammarine_id'] == $spotter_item['fammarine_id'])
645
				    || (isset($history) && $history != '' && $history != 'NA' && isset($spotter_item['famtrackid']) && str_replace('-','',$history) == str_replace('-','',$spotter_item['famtrackid']))
646
				    || (isset($history) && $history == '' && isset($spotter_item['flightaware_id']) && isset($_GET['famtrackid']) && $_GET['famtrackid'] == $spotter_item['famtrackid'])
647
				    ) {
648
					if ($tracker) {
649
						if ($from_archive || $globalArchive) {
650
							$spotter_history_array = $TrackerArchive->getAllArchiveTrackerDataById($spotter_item['famtrackid'],strtotime($spotter_item['date_iso_8601']));
651
						} else {
652
							$spotter_history_array = $TrackerLive->getAllLiveTrackerDataById($spotter_item['famtrackid']);
653
						}
654
						if (((isset($_COOKIE['mapmatching']) && $_COOKIE['mapmatching'] == 'true') ||
655
						    (!isset($_COOKIE['mapmatching']) && $globalMapMatching === TRUE)) && 
656
						    isset($_GET['zoom']) && $_GET['zoom'] > 12 && 
657
						    isset($spotter_item['type']) && (
658
							$spotter_item['type'] == 'Firetruck' ||
659
							$spotter_item['type'] == 'Ambulance' ||
660
							$spotter_item['type'] == 'Truck (18 Wheeler)' ||
661
							$spotter_item['type'] == 'Truck' ||
662
							$spotter_item['type'] == 'Mobile Satellite Station' ||
663
							$spotter_item['type'] == 'Van' ||
664
							$spotter_item['type'] == 'Police' ||
665
							$spotter_item['type'] == 'Bus' ||
666
							$spotter_item['type'] == 'Jeep' ||
667
							$spotter_item['type'] == 'Motorcycle' ||
668
							$spotter_item['type'] == 'Car'
669
						    )
670
						) {
671
							require(dirname(__FILE__).'/require/class.MapMatching.php');
672
							$MapMatching = new MapMatching();
673
							$spotter_history_array_mm = array_merge($spotter_history_array,array(array('latitude' => $spotter_item['latitude'],'longitude' => $spotter_item['longitude'],'date' => date('c',strtotime($spotter_item['date_iso_8601'])))));
674
							$spotter_history_array = $MapMatching->match($spotter_history_array_mm);
675
						}
676
					} elseif ($marine) {
677
						if ($from_archive || $globalArchive) {
678
							$spotter_history_array = $MarineArchive->getAllArchiveMarineDataById($spotter_item['fammarine_id']);
679
						} else {
680
							$spotter_history_array = $MarineLive->getAllLiveMarineDataById($spotter_item['fammarine_id']);
681
						}
682
					} else {
683
						if ($from_archive || $globalArchive) {
684
							$spotter_history_array = $SpotterArchive->getAllArchiveSpotterDataById($spotter_item['flightaware_id']);
685
						} else {
686
							$spotter_history_array = $SpotterLive->getAllLiveSpotterDataById($spotter_item['flightaware_id']);
687
						}
688
					}
689
					$d = false;
690
					foreach ($spotter_history_array as $key => $spotter_history)
691
					{
692
						if (isset($spotter_history['altitude'])) {
693
							$alt = round($spotter_history['altitude']/10)*10;
694
							if (!isset($prev_alt) || $prev_alt != $alt) {
695
								if (isset($prev_alt)) {
696
									$output_history .= '['.$spotter_history['longitude'].', '.$spotter_history['latitude'].', '.$spotter_history['altitude'].']';
697
									$output_history .= ']}},';
698
									$output .= $output_history;
699
								}
700
								if ($compress) $output_history = '{"type": "Feature","properties": {"c": "'.$spotter_item['ident'].'","t": "history","a": "'.$alt.'"},"geometry": {"type": "LineString","coordinates": [';
701
								else $output_history = '{"type": "Feature","properties": {"callsign": "'.$spotter_item['ident'].'","type": "history","altitude": "'.$alt.'"},"geometry": {"type": "LineString","coordinates": [';
702
							}
703
							$output_history .= '[';
704
							$output_history .=  $spotter_history['longitude'].', ';
705
							$output_history .=  $spotter_history['latitude'].', ';
706
							$output_history .=  $spotter_history['altitude']*30.48;
707
							$output_history .= '],';
708
							/*
709
							if ($from_archive === false) {
710
								$output_history .= '[';
711
								$output_history .=  $spotter_item['longitude'].', ';
712
								$output_history .=  $spotter_item['latitude'].', ';
713
								$output_history .=  $spotter_item['altitude']*30.48;
714
								$output_history .= '],';
715
							}
716
							*/
717
							$prev_alt = $alt;
718
						} else {
719
							if ($d == false) {
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...
720
								if ($compress) {
721
									$output_history = '{"type": "Feature","properties": {"c": "'.$spotter_item['ident'].'",';
722
									if (isset($spotter_history_array[0]['mapmatching_engine']) && $spotter_history_array[0]['mapmatching_engine'] == 'graphhopper') $output_history .= '"atr": "Powered by <a href=\"https://www.graphhopper.com/\">GraphHopper API</a>", Map matching engine use data from © <a href=\"http://www.openstreetmap.org/copyright\">OpenStreetMap</a>",';
723
									elseif (isset($spotter_history_array[0]['mapmatching_engine'])) $output_history .= '"atr": "Map matching engine use data from © <a href=\"http://www.openstreetmap.org/copyright\">OpenStreetMap</a>",';
724
									$output_history .= '"t": "history"},"geometry": {"type": "LineString","coordinates": [';
725
								} else $output_history = '{"type": "Feature","properties": {"callsign": "'.$spotter_item['ident'].'","type": "history"},"geometry": {"type": "LineString","coordinates": [';
726
								$d = true;
727
							}
728
							$output_history .= '[';
729
							$output_history .=  $spotter_history['longitude'].', ';
730
							$output_history .=  $spotter_history['latitude'];
731
							$output_history .= '],';
732
							/*
733
							if ($from_archive === false) {
734
								$output_history .= '[';
735
								$output_history .=  $spotter_item['longitude'].', ';
736
								$output_history .=  $spotter_item['latitude'];
737
								$output_history .= '],';
738
							}
739
							*/
740
						}
741
					}
742
					if (isset($output_history)) {
743
						//echo $output_history;
744
						if ($from_archive === false && !isset($spotter_history_array[0]['mapmatching_engine'])) {
745
							$output_historyd = '[';
746
							$output_historyd .=  $spotter_item['longitude'].', ';
747
							$output_historyd .=  $spotter_item['latitude'];
748
							if (isset($spotter_history['altitude'])) $output_historyd .=  ','.$spotter_item['altitude']*30.48;
749
							$output_historyd .= '],';
750
							//$output_history = $output_historyd.$output_history;
751
							$output_history = $output_history.$output_historyd;
752
						} elseif (isset($spotter_history_array[0]['mapmatching_engine'])) {
753
							$last = array_pop($spotter_history_array);
754
							$latitude = $last['latitude'];
755
							$longitude = $last['longitude'];
756
							$output = str_replace('"coordinates": ['.$spotter_item['longitude'].', '.$spotter_item['latitude'].']}','"coordinates": ['.$longitude.', '.$latitude.']}',$output);
757
						}
758
						
759
						$output_history  = substr($output_history, 0, -1);
760
						$output_history .= ']}},';
761
						$output .= $output_history;
762
						unset($prev_alt);
763
						unset($output_history);
764
					}
765
				}
766
				
767
				if (((isset($history) && $history != '' && $history != 'NA' && isset($spotter_item['flightaware_id']) && str_replace('-','',$history) == str_replace('-','',$spotter_item['flightaware_id']))
768
				    || (isset($history) && $history == '' && isset($spotter_item['flightaware_id']) && isset($_GET['flightaware_id']) && $_GET['flightaware_id'] == $spotter_item['flightaware_id']))
769
				     && (isset($spotter_item['departure_airport']) 
770
				        && $spotter_item['departure_airport'] != 'NA' 
771
				        && isset($spotter_item['arrival_airport']) 
772
				        && $spotter_item['arrival_airport'] != 'NA' 
773
				        && ((isset($_COOKIE['MapRoute']) && $_COOKIE['MapRoute'] == "true") 
774
				    	    || (!isset($_COOKIE['MapRoute']) && isset($globalMapRoute) && $globalMapRoute)))) {
775
				    if ($compress) $output_air = '{"type": "Feature","properties": {"c": "'.$spotter_item['ident'].'","t": "route"},"geometry": {"type": "LineString","coordinates": [';
776
				    else $output_air = '{"type": "Feature","properties": {"callsign": "'.$spotter_item['ident'].'","type": "route"},"geometry": {"type": "LineString","coordinates": [';
777
				    if (isset($spotter_item['departure_airport_latitude'])) {
778
					$output_air .= '['.$spotter_item['departure_airport_longitude'].','.$spotter_item['departure_airport_latitude'].'],';
779
				    } elseif (isset($spotter_item['departure_airport']) && $spotter_item['departure_airport'] != 'NA') {
780
					$dairport = $Spotter->getAllAirportInfo($spotter_item['departure_airport']);
781
					if (isset($dairport[0]['latitude'])) {
782
					    $output_air .= '['.$dairport[0]['longitude'].','.$dairport[0]['latitude'].'],';
783
					}
784
				    }
785
				    if (isset($spotter_item['arrival_airport_latitude'])) {
786
					$output_air .= '['.$spotter_item['arrival_airport_longitude'].','.$spotter_item['arrival_airport_latitude'].'],';
787
				    } elseif (isset($spotter_item['arrival_airport']) && $spotter_item['arrival_airport'] != 'NA') {
788
					$aairport = $Spotter->getAllAirportInfo($spotter_item['arrival_airport']);
789
					if (isset($aairport[0]['latitude'])) {
790
					    $output_air .= '['.$aairport[0]['longitude'].','.$aairport[0]['latitude'].'],';
791
					}
792
				    }
793
				    $output_air  = substr($output_air, 0, -1);
794
				    $output_air .= ']}},';
795
				    $output .= $output_air;
796
				    unset($output_air);
797
				}
798
799
				//if (isset($history) && $history != '' && $history == $spotter_item['ident'] && isset($spotter_item['departure_airport']) && $spotter_item['departure_airport'] != 'NA' && isset($spotter_item['arrival_airport']) && $spotter_item['arrival_airport'] != 'NA' && ((isset($_COOKIE['MapRoute']) && $_COOKIE['MapRoute'] == "true") || (!isset($_COOKIE['MapRoute']) && (!isset($globalMapRoute) || (isset($globalMapRoute) && $globalMapRoute))))) {
800
				//if (isset($history) && $history != '' && $history == $spotter_item['ident'] && isset($spotter_item['arrival_airport']) && $spotter_item['arrival_airport'] != 'NA' && ((isset($_COOKIE['MapRoute']) && $_COOKIE['MapRoute'] == "true") || (!isset($_COOKIE['MapRoute']) && (!isset($globalMapRoute) || (isset($globalMapRoute) && $globalMapRoute))))) {
801
				if (((isset($history) && $history != '' && $history != 'NA' && isset($spotter_item['flightaware_id']) && str_replace('-','',$history) == str_replace('-','',$spotter_item['flightaware_id']))
802
				    || (isset($history) && $history == '' && isset($spotter_item['flightaware_id']) && isset($_GET['flightaware_id']) && $_GET['flightaware_id'] == $spotter_item['flightaware_id']))
803
				     && (isset($spotter_item['arrival_airport']) 
804
				        && $spotter_item['arrival_airport'] != 'NA' 
805
				        && ((isset($_COOKIE['MapRemainingRoute']) && $_COOKIE['MapRemainingRoute'] == "true") 
806
				    	    || (!isset($_COOKIE['MapRemainingRoute']) && (!isset($globalMapRemainingRoute) 
807
				    	    || (isset($globalMapRemainingRoute) && $globalMapRemainingRoute)))))) {
808
				    $havedata = false;
809
				    if ($compress) $output_dest = '{"type": "Feature","properties": {"c": "'.$spotter_item['ident'].'","t": "routedest"},"geometry": {"type": "LineString","coordinates": [';
810
				    else $output_dest = '{"type": "Feature","properties": {"callsign": "'.$spotter_item['ident'].'","type": "routedest"},"geometry": {"type": "LineString","coordinates": [';
811
				    $output_dest .= '['.$spotter_item['longitude'].','.$spotter_item['latitude'].'],';
812
813
				    if (isset($spotter_item['arrival_airport_latitude'])) {
814
					$output_dest .= '['.$spotter_item['arrival_airport_longitude'].','.$spotter_item['arrival_airport_latitude'].']';
815
					$havedata = true;
816
				    } elseif (isset($spotter_item['arrival_airport']) && $spotter_item['arrival_airport'] != 'NA') {
817
					$aairport = $Spotter->getAllAirportInfo($spotter_item['arrival_airport']);
818
					if (isset($aairport[0]['latitude'])) {
819
					    $output_dest .= '['.$aairport[0]['longitude'].','.$aairport[0]['latitude'].']';
820
					    $havedata = true;
821
					}
822
				    }
823
				    //$output_dest  = substr($output_dest, 0, -1);
824
				    $output_dest .= ']}},';
825
				    if ($havedata) $output .= $output_dest;
826
				    unset($output_dest);
827
				}
828
			}
829
			$output  = substr($output, 0, -1);
830
			$output .= ']';
831
			$output .= ',"initial_sqltime": "'.$sqltime.'",';
832
			$output .= '"totaltime": "'.round(microtime(true)-$begintime,2).'",';
833
			if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",';
834
			$output .= '"fc": "'.$j.'"';
835
		} else {
836
			$output .= '"features": ';
837
			$output .= '[{';
838
			$output .= '"type": "Feature",';
839
			$output .= '"properties": {';
840
			$output .= '"fc": "'.$flightcnt.'",';
841
			$output .= '"empty": "true"}';
842
			$output .= ',"geometry": {"type": "Point","coordinates": [0, 0]}';
843
			$output .= '}]';
844
		}
845
		
846
$output .= '}';
847
848
print $output;
849
850
?>
851