Completed
Push — master ( 224e85...2b99a8 )
by Yannick
97:50 queued 62:41
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();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
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
								} elseif (isset($spotter_item['type']) && $spotter_item['type']  == 'Nordic Folkboat') {
396
									if ($compress) $output .= '"as": "nordic.png",';
397
									else $output .= '"aircraft_shadow": "nordic.png",';
398
								} else {
399
									if ($compress) $output .= '"as": "ship.png",';
400
									else $output .= '"aircraft_shadow": "ship.png",';
401
								}
402
							} else {
403
								if ($compress) $output .= '"as": "default.png",';
404
								else $output .= '"aircraft_shadow": "default.png",';
405
							}
406
						} else {
407
							if ($compress) $output .= '"as": "'.$spotter_item['aircraft_shadow'].'",';
408
							else $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",';
409
						}
410
						if (isset($spotter_item['airline_name'])) {
411
							$output .= '"airline_name": "'.$spotter_item['airline_name'].'",';
412
						} elseif (!$min) {
413
							$output .= '"airline_name": "NA",';
414
						}
415
						if (isset($spotter_item['departure_airport'])) {
416
							if ($compress) $output .= '"dac": "'.$spotter_item['departure_airport'].'",';
417
							else $output .= '"departure_airport_code": "'.$spotter_item['departure_airport'].'",';
418
						}
419
						if (isset($spotter_item['departure_airport_city'])) {
420
							$output .= '"departure_airport": "'.$spotter_item['departure_airport_city'].', '.$spotter_item['departure_airport_country'].'",';
421
						}
422
						if (isset($spotter_item['departure_airport_time'])) {
423
							$output .= '"departure_airport_time": "'.$spotter_item['departure_airport_time'].'",';
424
						}
425
						if (isset($spotter_item['arrival_airport_time'])) {
426
							$output .= '"arrival_airport_time": "'.$spotter_item['arrival_airport_time'].'",';
427
						}
428
						if (isset($spotter_item['arrival_airport'])) {
429
							if ($compress) $output .= '"aac": "'.$spotter_item['arrival_airport'].'",';
430
							else $output .= '"arrival_airport_code": "'.$spotter_item['arrival_airport'].'",';
431
						}
432
						if (isset($spotter_item['arrival_airport_city'])) {
433
							$output .= '"arrival_airport": "'.$spotter_item['arrival_airport_city'].', '.$spotter_item['arrival_airport_country'].'",';
434
						}
435
						
436
						if (isset($spotter_item['date_iso_8601'])) {
437
							$output .= '"date_update": "'.date("M j, Y, g:i a T", strtotime($spotter_item['date_iso_8601'])).'",';
438
							$output .= '"lu": "'.strtotime($spotter_item['date_iso_8601']).'",';
439
						} elseif (isset($spotter_item['date'])) {
440
							$output .= '"lu": "'.strtotime($spotter_item['date']).'",';
441
						}
442
						if (!$min) {
443
							$output .= '"latitude": "'.$spotter_item['latitude'].'",';
444
							$output .= '"longitude": "'.$spotter_item['longitude'].'",';
445
							$output .= '"ground_speed": "'.$spotter_item['ground_speed'].'",';
446
						}
447
						
448
						if (isset($spotter_item['real_altitude'])) {
449
							if ($compress) $output .= '"a": "'.($spotter_item['real_altitude']/100).'",';
450
							else $output .= '"altitude": "'.($spotter_item['real_altitude']/100).'",';
451
						} elseif (isset($spotter_item['altitude'])) {
452
							if ($compress) $output .= '"a": "'.$spotter_item['altitude'].'",';
453
							else $output .= '"altitude": "'.$spotter_item['altitude'].'",';
454
						}
455
						
456
						$heading = $spotter_item['heading'];
457
						
458
						if (isset($archivespeed) || $usenextlatlon) {
459
							if (isset($spotter_item['arrival_airport']) && $spotter_item['arrival_airport'] != 'NA') {
460
								if (isset($spotter_item['arrival_airport_latitude'])) {
461
									$cheading = $Common->getHeading($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['arrival_airport_latitude'],$spotter_item['arrival_airport_longitude']);
462
									$idistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['arrival_airport_latitude'],$spotter_item['arrival_airport_longitude']);
463
									$farr_lat = $spotter_item['arrival_airport_latitude'];
464
									$farr_lon = $spotter_item['arrival_airport_longitude'];
465
								} else {
466
									$aairport = $Spotter->getAllAirportInfo($spotter_item['arrival_airport']);
467
									if (isset($aairport[0]['latitude'])) {
468
										$cheading = $Common->getHeading($spotter_item['latitude'],$spotter_item['longitude'],$aairport[0]['latitude'],$aairport[0]['longitude']);
469
										$idistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$aairport[0]['latitude'],$aairport[0]['longitude']);
470
										$farr_lat = $aairport[0]['latitude'];
471
										$farr_lon = $aairport[0]['longitude'];
472
									}
473
								}
474
							}
475
						}
476
						
477
						if ($compress)$output .= '"h": "'.$heading.'",';
478
						else $output .= '"heading": "'.$heading.'",';
479
						if ($currenttime != '') {
480
							if (strtotime($spotter_item['date']) < $currenttime) {
481
								if (isset($archivespeed)) {
482
									$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading,$archivespeed,($currenttime-strtotime($spotter_item['date'])+$globalMapRefresh));
483
									$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
484
									if (!isset($idistance) || $fdistance < $idistance) $output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
485
									else {
486
										$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$cheading,$archivespeed,($currenttime-strtotime($spotter_item['date'])+$globalMapRefresh));
487
										$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
488
										if (!isset($idistance) || $fdistance < $idistance) $output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
489
										else {
490
											$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading,$archivespeed);
491
											$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
492
										}
493
									}
494
								} elseif ($usenextlatlon) {
495
									$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading,1,($currenttime-strtotime($spotter_item['date'])+$globalMapRefresh));
496
									$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
497
									if (!isset($idistance) || $fdistance < $idistance) $output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
498
									else {
499
										$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$cheading,1,($currenttime-strtotime($spotter_item['date'])+$globalMapRefresh));
500
										$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
501
										if (!isset($idistance) || $fdistance < $idistance) $output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
502
										else {
503
											$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading);
504
											$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
505
										}
506
									}
507
								}
508
							} else {
509
								if (isset($archivespeed)) {
510
									$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading,$archivespeed);
511
									$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
512
								} elseif ($usenextlatlon) {
513
									$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading);
514
									$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
515
								}
516
							}
517
						} else {
518
							if (isset($archivespeed)) {
519
								$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading,$archivespeed);
520
								$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
521
								if (!isset($idistance) || $fdistance < $idistance) {
522
									$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
523
								} else {
524
									$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$cheading,$archivespeed);
525
									//$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
526
									$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
527
								}
528
							} elseif ($usenextlatlon) {
529
								$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading);
530
								$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
531
								if (!isset($idistance) || $fdistance < $idistance) {
532
										$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
533
								} else {
534
									$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$cheading);
535
									//$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
536
									$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
537
								}
538
							}
539
						}
540
541
						if (!$min) $output .= '"image": "'.$image.'",';
542
						if (isset($spotter_item['image_copyright']) && $spotter_item['image_copyright'] != '') {
543
							$output .= '"image_copyright": "'.str_replace('"',"'",trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$spotter_item['image_copyright']))).'",';
544
						}
545
						if (isset($spotter_item['image_source_website'])) {
546
							$output .= '"image_source_website": "'.urlencode($spotter_item['image_source_website']).'",';
547
						}
548
						if (isset($spotter_item['squawk'])) {
549
							if ($compress) $output .= '"sq": "'.$spotter_item['squawk'].'",';
550
							else $output .= '"squawk": "'.$spotter_item['squawk'].'",';
551
						}
552
						if (isset($spotter_item['squawk_usage'])) {
553
							$output .= '"squawk_usage": "'.$spotter_item['squawk_usage'].'",';
554
						}
555
						if (isset($spotter_item['captain_name'])) {
556
							$output .= '"cap": '.json_encode($spotter_item['captain_name']).',';
557
						}
558
						if (isset($spotter_item['race_id']) && $spotter_item['race_id'] != '') {
559
							$output .= '"rid": '.$spotter_item['race_id'].',';
560
						}
561
						if (isset($spotter_item['race_rank']) && $spotter_item['race_rank'] != '') {
562
							$output .= '"rrk": '.$spotter_item['race_rank'].',';
563
						}
564
						if (isset($spotter_item['race_name']) && $spotter_item['race_name'] != '') {
565
							$output .= '"rname": '.json_encode($spotter_item['race_name']).',';
566
						}
567
						if (isset($spotter_item['pilot_id'])) {
568
							$output .= '"pilot_id": "'.$spotter_item['pilot_id'].'",';
569
						}
570
						if (isset($spotter_item['pilot_name'])) {
571
							$output .= '"pilot_name": "'.$spotter_item['pilot_name'].'",';
572
						}
573
						if (isset($spotter_item['waypoints']) && $spotter_item['waypoints'] != '') {
574
							$output .= '"waypoints": "'.$spotter_item['waypoints'].'",';
575
						}
576
						if (isset($spotter_item['acars'])) {
577
							$output .= '"acars": "'.trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"), '<br />',$spotter_item['acars']['message'])).'",';
578
						}
579
						// type when not aircraft ?
580
						if (isset($spotter_item['type'])) {
581
							if ($compress) $output .= '"t": "'.$spotter_item['type'].'"';
582
							else $output .= '"type": "'.$spotter_item['type'].'"';
583
						} elseif ($marine) {
584
							if ($compress) $output .= '"t": "ship"';
585
							else $output .= '"type": "ship"';
586
						} else {
587
							if ($compress) $output .= '"t": "aircraft"';
588
							else $output .= '"type": "aircraft"';
589
						}
590
						$output .= '},';
591
						$output .= '"geometry": {';
592
							$output .= '"type": "Point",';
593
								$output .= '"coordinates": [';
594
								if ($currenttime != '') {
595
									if (strtotime($spotter_item['date']) < $currenttime) {
596
										if (!isset($archivespeed)) $archivespeed = 1;
597
										$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$heading,$archivespeed,($currenttime-strtotime($spotter_item['date'])));
598
										$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
599
										if (!isset($idistance) || $fdistance < $idistance) $output .= $nextcoord['longitude'].','.$nextcoord['latitude'];
600
										else {
601
											$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$cheading,$archivespeed,($currenttime-strtotime($spotter_item['date'])));
602
											$fdistance = $Common->distance($spotter_item['latitude'],$spotter_item['longitude'],$nextcoord['latitude'],$nextcoord['longitude']);
603
											if (!isset($idistance) || $fdistance < $idistance) $output .= $nextcoord['longitude'].','.$nextcoord['latitude'];
604
											else {
605
												$output .= $spotter_item['longitude'].', ';
606
												$output .= $spotter_item['latitude'];
607
											}
608
										}
609
										/*
610
										if (!isset($archivespeed)) $archivespeed = 1;
611
										$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$spotter_item['heading'],$archivespeed,$currenttime-strtotime($spotter_item['date']));
612
										$output .= $nextcoord['longitude'].','.$nextcoord['latitude'];
613
										*/
614
									} else {
615
										$output .= $spotter_item['longitude'].', ';
616
										$output .= $spotter_item['latitude'];
617
									}
618
								} else {
619
									$output .= $spotter_item['longitude'].', ';
620
									$output .= $spotter_item['latitude'];
621
								}
622
										/*
623
										.', ';
624
										$output .= $spotter_item['altitude']*30.48;
625
										$output .= ', '.strtotime($spotter_item['date']);
626
										*/
627
								$output .= ']';
628
							$output .= '}';
629
				$output .= '},';
630
					
631
			/*	} else {
632
								$output .= ', ';
633
								$output .= $spotter_item['longitude'].', ';
634
								$output .= $spotter_item['latitude'].', ';
635
								$output .= $spotter_item['altitude']*30.48;
636
								$output .= ', '.strtotime($spotter_item['date']);
637
638
				}
639
*/                
640
641
/*                
642
                //previous location history of aircraft
643
                $output .= '{';
644
					$output .= '"type": "Feature",';
645
                        $output .= '"properties": {';
646
							$output .= '"callsign": "'.$spotter_item['ident'].'",';
647
							$output .= '"type": "history"';
648
						$output .= '},';
649
						$output .= '"geometry": {';
650
							$output .= '"type": "LineString",';
651
								$output .= '"coordinates": [';
652
                                    //$spotter_history_array = SpotterLive::getAllLiveSpotterDataByIdent($spotter_item['ident']);
653
                                    if ($from_archive) {
654
					    $spotter_history_array = SpotterArchive::getAllArchiveSpotterDataById($spotter_item['flightaware_id']);
655
                                    } else {
656
					    $spotter_history_array = SpotterLive::getAllLiveSpotterDataById($spotter_item['flightaware_id']);
657
                                    }
658
										$d = false;
659
										$neg = false;
660
									$history_output = '';
661
									foreach ($spotter_history_array as $key => $spotter_history)
662
									{
663
										if (abs($spotter_history['longitude']-$spotter_item['longitude']) > 200 || $d==true) {
664
											if ($d == false) $d = true;
665
									        } else {
666
											$history_output .= '[';
667
											$history_output .=  $spotter_history['longitude'].', ';
668
											$history_output .=  $spotter_history['latitude'].',';
669
											$history_output .=  $spotter_history['altitude'];
670
											$history_output .= '],';
671
672
										}
673
									}
674
									if ($history_output != '') $output .= substr($history_output, 0, -1);
675
								$output .= ']';
676
							$output .= '}';
677
				$output .= '},';
678
                
679
			}
680
*/
681
				$history = filter_input(INPUT_GET,'history',FILTER_SANITIZE_STRING);
682
				if ($history == '' && isset($_COOKIE['history'])) $history = $_COOKIE['history'];
683
				
684
				if (
685
				    (isset($_COOKIE['flightpath']) && $_COOKIE['flightpath'] == 'true') 
686
				    || ((isset($globalMapHistory) && $globalMapHistory) || $allhistory)
687
				//    || (isset($history) && $history != '' && $history != 'NA' && ($history == $spotter_item['ident'] || $history == $spotter_item['flightaware_id']))
688
				//    || (isset($history) && $history != '' && $history != 'NA' && $history == $spotter_item['ident'])
689
				    || (isset($history) && $history != '' && $history != 'NA' && isset($spotter_item['flightaware_id']) && str_replace('-','',$history) == str_replace('-','',$spotter_item['flightaware_id']))
690
				    || (isset($history) && $history == '' && isset($spotter_item['flightaware_id']) && isset($_GET['flightaware_id']) && $_GET['flightaware_id'] == $spotter_item['flightaware_id'])
691
				    || (isset($history) && $history != '' && $history != 'NA' && isset($spotter_item['fammarine_id']) && str_replace('-','',$history) == str_replace('-','',$spotter_item['fammarine_id']))
692
				    || (isset($history) && $history == '' && isset($spotter_item['flightaware_id']) && isset($_GET['fammarine_id']) && $_GET['fammarine_id'] == $spotter_item['fammarine_id'])
693
				    || (isset($history) && $history != '' && $history != 'NA' && isset($spotter_item['famtrackid']) && str_replace('-','',$history) == str_replace('-','',$spotter_item['famtrackid']))
694
				    || (isset($history) && $history == '' && isset($spotter_item['flightaware_id']) && isset($_GET['famtrackid']) && $_GET['famtrackid'] == $spotter_item['famtrackid'])
695
				    ) {
696
					if ($tracker) {
697
						if ($from_archive || $globalArchive) {
698
							$spotter_history_array = $TrackerArchive->getAllArchiveTrackerDataById($spotter_item['famtrackid']);
699
						} else {
700
							$spotter_history_array = $TrackerLive->getAllLiveTrackerDataById($spotter_item['famtrackid']);
701
						}
702
						if (((isset($_COOKIE['mapmatching']) && $_COOKIE['mapmatching'] == 'true') ||
703
						    (!isset($_COOKIE['mapmatching']) && $globalMapMatching === TRUE)) && 
704
						    isset($_GET['zoom']) && $_GET['zoom'] > 12 && 
705
						    isset($spotter_item['type']) && (
706
							$spotter_item['type'] == 'Firetruck' ||
707
							$spotter_item['type'] == 'Ambulance' ||
708
							$spotter_item['type'] == 'Truck (18 Wheeler)' ||
709
							$spotter_item['type'] == 'Truck' ||
710
							$spotter_item['type'] == 'Mobile Satellite Station' ||
711
							$spotter_item['type'] == 'Van' ||
712
							$spotter_item['type'] == 'Police' ||
713
							$spotter_item['type'] == 'Bus' ||
714
							$spotter_item['type'] == 'Jeep' ||
715
							$spotter_item['type'] == 'Motorcycle' ||
716
							$spotter_item['type'] == 'Car'
717
						    )
718
						) {
719
							require(dirname(__FILE__).'/require/class.MapMatching.php');
720
							$MapMatching = new MapMatching();
721
							if (isset($spotter_item['date_iso_8601'])) {
722
								$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'])))));
723
							} else {
724
								$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'])))));
725
							}
726
							$spotter_history_array = $MapMatching->match($spotter_history_array_mm);
727
						}
728
					} elseif ($marine) {
729
						if ($from_archive || $globalArchive) {
730
							$spotter_history_array = $MarineArchive->getAllArchiveMarineDataById($spotter_item['fammarine_id']);
731
						} else {
732
							$spotter_history_array = $MarineLive->getAllLiveMarineDataById($spotter_item['fammarine_id']);
733
						}
734
					} else {
735
						if ($from_archive || $globalArchive) {
736
							$spotter_history_array = $SpotterArchive->getAllArchiveSpotterDataById($spotter_item['flightaware_id']);
737
							//print_r($spotter_history_array);
738
						} else {
739
							$spotter_history_array = $SpotterLive->getAllLiveSpotterDataById($spotter_item['flightaware_id']);
740
						}
741
					}
742
					$d = false;
743
					foreach ($spotter_history_array as $key => $spotter_history)
744
					{
745
						if (isset($spotter_history['altitude'])) {
746
							$alt = round($spotter_history['altitude']/10)*10;
747
							if (!isset($prev_alt) || $prev_alt != $alt) {
748
								if (isset($prev_alt)) {
749
									$output_history .= '['.$spotter_history['longitude'].', '.$spotter_history['latitude'].', '.$spotter_history['altitude'].']';
750
									$output_history .= ']}},';
751
									$output .= $output_history;
752
								}
753
								if ($compress) $output_history = '{"type": "Feature","properties": {"c": "'.$spotter_item['ident'].'","t": "history","a": "'.$alt.'"},"geometry": {"type": "LineString","coordinates": [';
754
								else $output_history = '{"type": "Feature","properties": {"callsign": "'.$spotter_item['ident'].'","type": "history","altitude": "'.$alt.'"},"geometry": {"type": "LineString","coordinates": [';
755
							}
756
							$output_history .= '[';
757
							$output_history .=  $spotter_history['longitude'].', ';
758
							$output_history .=  $spotter_history['latitude'].', ';
759
							$output_history .=  $spotter_history['altitude']*30.48;
760
							$output_history .= '],';
761
							/*
762
							if ($from_archive === false) {
763
								$output_history .= '[';
764
								$output_history .=  $spotter_item['longitude'].', ';
765
								$output_history .=  $spotter_item['latitude'].', ';
766
								$output_history .=  $spotter_item['altitude']*30.48;
767
								$output_history .= '],';
768
							}
769
							*/
770
							$prev_alt = $alt;
771
						} else {
772
							if ($d === false) {
773
								if ($compress) {
774
									$output_history = '{"type": "Feature","properties": {"c": "'.$spotter_item['ident'].'",';
775
									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>",';
776
									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>",';
777
									$output_history .= '"t": "history"},"geometry": {"type": "LineString","coordinates": [';
778
								} else $output_history = '{"type": "Feature","properties": {"callsign": "'.$spotter_item['ident'].'","type": "history"},"geometry": {"type": "LineString","coordinates": [';
779
								$d = true;
780
							}
781
							$output_history .= '[';
782
							$output_history .=  $spotter_history['longitude'].', ';
783
							$output_history .=  $spotter_history['latitude'];
784
							$output_history .= '],';
785
							/*
786
							if ($from_archive === false) {
787
								$output_history .= '[';
788
								$output_history .=  $spotter_item['longitude'].', ';
789
								$output_history .=  $spotter_item['latitude'];
790
								$output_history .= '],';
791
							}
792
							*/
793
						}
794
					}
795
					if (isset($output_history)) {
796
						//echo $output_history;
797
						if ($from_archive === false && !isset($spotter_history_array[0]['mapmatching_engine'])) {
798
							$output_historyd = '[';
799
							$output_historyd .=  $spotter_item['longitude'].', ';
800
							$output_historyd .=  $spotter_item['latitude'];
801
							if (isset($spotter_history['altitude'])) $output_historyd .=  ','.$spotter_item['altitude']*30.48;
802
							$output_historyd .= '],';
803
							//$output_history = $output_historyd.$output_history;
804
							$output_history = $output_history.$output_historyd;
805
						} elseif (isset($spotter_history_array[0]['mapmatching_engine'])) {
806
							$last = array_pop($spotter_history_array);
807
							$latitude = $last['latitude'];
808
							$longitude = $last['longitude'];
809
							$output = str_replace('"coordinates": ['.$spotter_item['longitude'].', '.$spotter_item['latitude'].']}','"coordinates": ['.$longitude.', '.$latitude.']}',$output);
810
						}
811
						
812
						$output_history  = substr($output_history, 0, -1);
813
						$output_history .= ']}},';
814
						$output .= $output_history;
815
						unset($prev_alt);
816
						unset($output_history);
817
					}
818
					
819
				}
820
				
821
				if (((isset($history) && $history != '' && $history != 'NA' && isset($spotter_item['flightaware_id']) && str_replace('-','',$history) == str_replace('-','',$spotter_item['flightaware_id']))
822
				    || (isset($history) && $history == '' && isset($spotter_item['flightaware_id']) && isset($_GET['flightaware_id']) && $_GET['flightaware_id'] == $spotter_item['flightaware_id']))
823
				     && (isset($spotter_item['departure_airport']) 
824
				        && $spotter_item['departure_airport'] != 'NA' 
825
				        && isset($spotter_item['arrival_airport']) 
826
				        && $spotter_item['arrival_airport'] != 'NA' 
827
				        && ((isset($_COOKIE['MapRoute']) && $_COOKIE['MapRoute'] == "true") 
828
				    	    || (!isset($_COOKIE['MapRoute']) && isset($globalMapRoute) && $globalMapRoute)))) {
829
				    if ($compress) $output_air = '{"type": "Feature","properties": {"c": "'.$spotter_item['ident'].'","t": "route"},"geometry": {"type": "LineString","coordinates": [';
830
				    else $output_air = '{"type": "Feature","properties": {"callsign": "'.$spotter_item['ident'].'","type": "route"},"geometry": {"type": "LineString","coordinates": [';
831
				    if (isset($spotter_item['departure_airport_latitude'])) {
832
					$output_air .= '['.$spotter_item['departure_airport_longitude'].','.$spotter_item['departure_airport_latitude'].'],';
833
				    } elseif (isset($spotter_item['departure_airport']) && $spotter_item['departure_airport'] != 'NA') {
834
					$dairport = $Spotter->getAllAirportInfo($spotter_item['departure_airport']);
835
					if (isset($dairport[0]['latitude'])) {
836
					    $output_air .= '['.$dairport[0]['longitude'].','.$dairport[0]['latitude'].'],';
837
					}
838
				    }
839
				    if (isset($spotter_item['arrival_airport_latitude'])) {
840
					$output_air .= '['.$spotter_item['arrival_airport_longitude'].','.$spotter_item['arrival_airport_latitude'].'],';
841
				    } elseif (isset($spotter_item['arrival_airport']) && $spotter_item['arrival_airport'] != 'NA') {
842
					$aairport = $Spotter->getAllAirportInfo($spotter_item['arrival_airport']);
843
					if (isset($aairport[0]['latitude'])) {
844
					    $output_air .= '['.$aairport[0]['longitude'].','.$aairport[0]['latitude'].'],';
845
					}
846
				    }
847
				    $output_air  = substr($output_air, 0, -1);
848
				    $output_air .= ']}},';
849
				    $output .= $output_air;
850
				    unset($output_air);
851
				}
852
853
				//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))))) {
854
				//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))))) {
855
				if (((isset($history) && $history != '' && $history != 'NA' && isset($spotter_item['flightaware_id']) && str_replace('-','',$history) == str_replace('-','',$spotter_item['flightaware_id']))
856
				    || (isset($history) && $history == '' && isset($spotter_item['flightaware_id']) && isset($_GET['flightaware_id']) && $_GET['flightaware_id'] == $spotter_item['flightaware_id']))
857
				     && (isset($spotter_item['arrival_airport']) 
858
				        && $spotter_item['arrival_airport'] != 'NA' 
859
				        && ((isset($_COOKIE['MapRemainingRoute']) && $_COOKIE['MapRemainingRoute'] == "true") 
860
				    	    || (!isset($_COOKIE['MapRemainingRoute']) && (!isset($globalMapRemainingRoute) 
861
				    	    || (isset($globalMapRemainingRoute) && $globalMapRemainingRoute)))))) {
862
				    $havedata = false;
863
				    if ($compress) $output_dest = '{"type": "Feature","properties": {"c": "'.$spotter_item['ident'].'","t": "routedest"},"geometry": {"type": "LineString","coordinates": [';
864
				    else $output_dest = '{"type": "Feature","properties": {"callsign": "'.$spotter_item['ident'].'","type": "routedest"},"geometry": {"type": "LineString","coordinates": [';
865
				    
866
				    //$output_dest .= '['.$spotter_item['longitude'].','.$spotter_item['latitude'].'],';
867
				    if (isset($spotter_item['arrival_airport_latitude'])) {
868
					//$output_dest .= '['.$spotter_item['arrival_airport_longitude'].','.$spotter_item['arrival_airport_latitude'].']';
869
					$end_lon = $spotter_item['arrival_airport_longitude'];
870
					$end_lat = $spotter_item['arrival_airport_latitude'];
871
					$havedata = true;
872
				    } elseif (isset($spotter_item['arrival_airport']) && $spotter_item['arrival_airport'] != 'NA') {
873
					$aairport = $Spotter->getAllAirportInfo($spotter_item['arrival_airport']);
874
					if (isset($aairport[0]['latitude'])) {
875
					    //$output_dest .= '['.$aairport[0]['longitude'].','.$aairport[0]['latitude'].']';
876
					    $end_lon = $aairport[0]['longitude'];
877
					    $end_lat = $aairport[0]['latitude'];
878
					    $havedata = true;
879
					}
880
				    }
881
				    if ($havedata) {
882
					$line = $Common->greatCircle($spotter_item['latitude'],$spotter_item['longitude'],$end_lat,$end_lon);
883
					foreach ($line[0] as $coord) {
884
						$output_dest .= '['.$coord[0].','.$coord[1].'],';
885
					}
886
					$output_dest  = substr($output_dest, 0, -1);
887
				    }
888
				    $output_dest .= ']}},';
889
				    if ($havedata) $output .= $output_dest;
890
				    unset($output_dest);
891
				}
892
			}
893
			$output  = substr($output, 0, -1);
894
			$output .= ']';
895
			$output .= ',"initial_sqltime": "'.$sqltime.'",';
896
			$output .= '"totaltime": "'.round(microtime(true)-$begintime,2).'",';
897
			if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",';
898
			$output .= '"fc": "'.$j.'"';
899
		} else {
900
			$output .= '"features": ';
901
			$output .= '[{';
902
			$output .= '"type": "Feature",';
903
			$output .= '"properties": {';
904
			$output .= '"fc": "'.$flightcnt.'",';
905
			$output .= '"empty": "true"}';
906
			$output .= ',"geometry": {"type": "Point","coordinates": [0, 0]}';
907
			$output .= '}]';
908
		}
909
		
910
$output .= '}';
911
912
print $output;
913
914
?>
915