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