Completed
Push — master ( 30b860...f1043a )
by Yannick
32:05
created

archive-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
13
$tracker = false;
14
$marine = false;
15
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.TrackerArchive.php');
25
}
26
elseif ($marine) {
27
	require_once('require/class.Marine.php');
28
	require_once('require/class.MarineArchive.php');
29
}
30
else {
31
	require_once('require/class.Spotter.php');
32
	require_once('require/class.SpotterArchive.php');
33
}
34
$begintime = microtime(true);
35
if ($tracker) {
36
	$Tracker = new Tracker();
37
	$TrackerArchive = new TrackerArchive();
38
}
39
elseif ($marine) {
40
	$Marine = new Marine();
41
	$MarineArchive = new MarineArchive();
42
}
43
else {
44
	$Spotter = new Spotter();
45
	$SpotterArchive = new SpotterArchive();
46
}
47
$Common = new Common();
48
49
if (isset($_GET['download'])) {
50
	if ($_GET['download'] == "true") {
51
		header('Content-disposition: attachment; filename="flightairmap.json"');
52
	}
53
}
54
header('Content-Type: text/javascript');
55
56
if (!isset($globalJsonCompress)) $compress = true;
57
else $compress = $globalJsonCompress;
58
59
$from_archive = false;
60
$min = false;
61
$allhistory = false;
62
$filter['source'] = array();
63
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalVATSIM) && $globalVATSIM && isset($_COOKIE['filter_ShowVATSIM']) && $_COOKIE['filter_ShowVATSIM'] == 'true') $filter['source'] = array_merge($filter['source'],array('vatsimtxt'));
64
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalIVAO) && $globalIVAO && isset($_COOKIE['filter_ShowIVAO']) && $_COOKIE['filter_ShowIVAO'] == 'true') $filter['source'] = array_merge($filter['source'],array('whazzup'));
65
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalphpVMS) && $globalphpVMS && isset($_COOKIE['filter_ShowVMS']) && $_COOKIE['filter_ShowVMS'] == 'true') $filter['source'] = array_merge($filter['source'],array('phpvmacars'));
66
if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalSBS1) && $globalSBS1 && isset($_COOKIE['filter_ShowSBS1']) && $_COOKIE['filter_ShowSBS1'] == 'true') $filter['source'] = array_merge($filter['source'],array('sbs','famaprs'));
67
if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalAPRS) && $globalAPRS && isset($_COOKIE['filter_ShowAPRS']) && $_COOKIE['filter_ShowAPRS'] == 'true') $filter['source'] = array_merge($filter['source'],array('aprs'));
68
if (isset($_COOKIE['filter_ident']) && $_COOKIE['filter_ident'] != '') $filter['ident'] = filter_var($_COOKIE['filter_ident'],FILTER_SANITIZE_STRING);
69
if (isset($_COOKIE['filter_mmsi']) && $_COOKIE['filter_mmsi'] != '') $filter['mmsi'] = filter_var($_COOKIE['filter_mmsi'],FILTER_SANITIZE_STRING);
70
if (isset($_COOKIE['filter_Airlines']) && $_COOKIE['filter_Airlines'] != '') $filter['airlines'] = filter_var_array(explode(',',$_COOKIE['filter_Airlines']),FILTER_SANITIZE_STRING);
71
if (isset($_COOKIE['filter_Sources']) && $_COOKIE['filter_Sources'] != '') $filter['source_aprs'] = filter_var_array(explode(',',$_COOKIE['filter_Sources']),FILTER_SANITIZE_STRING);
72
if (isset($_COOKIE['filter_airlinestype']) && $_COOKIE['filter_airlinestype'] != 'all') $filter['airlinestype'] = filter_var($_COOKIE['filter_airlinestype'],FILTER_SANITIZE_STRING);
73
if (isset($_COOKIE['filter_alliance']) && $_COOKIE['filter_alliance'] != 'all') $filter['alliance'] = filter_var($_COOKIE['filter_alliance'],FILTER_SANITIZE_STRING);
74
75
if (isset($globalMapPopup) && !$globalMapPopup && !(isset($_COOKIE['flightpopup']) && $_COOKIE['flightpopup'] == 'true')) {
76
	$min = true;
77
} else $min = false;
78
79
if (isset($_GET['ident'])) {
80
	$ident = filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING);
81
	$from_archive = true;
82
	if ($tracker) {
83
		$spotter_array = $TrackerArchive->getLastArchiveTrackerDataByIdent($ident);
84
	}
85
	elseif ($marine) {
86
		$spotter_array = $MarineArchive->getLastArchiveMarineDataByIdent($ident);
87
	}
88
	else {
89
		$spotter_array = $SpotterArchive->getLastArchiveSpotterDataByIdent($ident);
90
	}
91
	$allhistory = true;
92
}
93
elseif (isset($_GET['flightaware_id'])) {
94
	$flightaware_id = filter_input(INPUT_GET,'flightaware_id',FILTER_SANITIZE_STRING);
95
	$from_archive = true;
96
	if ($tracker) {
97
		$spotter_array = $TrackerArchive->getLastArchiveTrackerDataById($flightaware_id);
98
	}
99
	elseif ($marine) {
100
		$spotter_array = $MarineArchive->getLastArchiveMarineDataById($flightaware_id);
101
	}
102
	else {
103
		$spotter_array = $SpotterArchive->getLastArchiveSpotterDataById($flightaware_id);
104
	}
105
	$allhistory = true;
106
}
107
elseif (isset($_GET['archive']) && isset($_GET['begindate']) && isset($_GET['enddate']) && isset($_GET['speed'])) {
108
	$from_archive = true;
109
	$begindate = filter_input(INPUT_GET,'begindate',FILTER_SANITIZE_NUMBER_INT);
110
	if (isset($globalAircraftMaxUpdate)) $begindate = $begindate - $globalAircraftMaxUpdate;
111
	else $begindate = $begindate - 3000;
112
	$enddate = filter_input(INPUT_GET,'enddate',FILTER_SANITIZE_NUMBER_INT);
113
	$archivespeed = filter_input(INPUT_GET,'speed',FILTER_SANITIZE_NUMBER_INT);
114
	if ($begindate != '' && $enddate != '') {
115
		$begindate = date('Y-m-d H:i:s',$begindate);
116
		$enddate = date('Y-m-d H:i:s',$enddate);
117
		//$spotter_array = $SpotterArchive->getMinLiveSpotterDataPlayback($begindate,$enddate,$filter);
118
		if ($tracker) {
119
			$spotter_array = $TrackerArchive->getMinLiveTrackerData($begindate,$enddate,$filter);
120
		}
121
		elseif ($marine) {
122
			$spotter_array = $MarineArchive->getMinLiveMarineData($begindate,$enddate,$filter);
123
		}
124
		else {
125
			$spotter_array = $SpotterArchive->getMinLiveSpotterData($begindate,$enddate,$filter);
126
		}
127
	}
128
}
129
130
if (!empty($spotter_array)) {
131
	//$flightcnt = $SpotterArchive->getLiveSpotterCount($begindate,$enddate,$filter);
132
	$flightcnt = 0;
133
	if ($flightcnt == '') $flightcnt = 0;
134
} else $flightcnt = 0;
135
136
$sqltime = round(microtime(true)-$begintime,2);
137
138
$pfi = '';
139
//var_dump($spotter_array);
140
$j = 0;
141
142
$output = '{';
143
$output .= '"type": "FeatureCollection",';
144
if ($min) $output .= '"minimal": "true",';
145
else $output .= '"minimal": "false",';
146
$output .= '"fc": "'.$flightcnt.'",';
147
$output .= '"sqt": "'.$sqltime.'",';
148
149
if (!empty($spotter_array) && is_array($spotter_array)) {
150
	$output .= '"features": [';
151
	foreach($spotter_array as $spotter_item) {
152
		$j++;
153
		date_default_timezone_set('UTC');
154
		if ($tracker) {
155
			if ($pfi != $spotter_item['famtrackid']) {
156
				$spotter_history_array = $TrackerArchive->getCoordArchiveTrackerDataById($spotter_item['famtrackid']);
157
				$pfi = $spotter_item['famtrackid'];
158
			} else $spotter_history_array = 0;
159
		}
160
		elseif ($marine) {
161
			if ($pfi != $spotter_item['fammarine_d']) {
162
				$spotter_history_array = $MarineArchive->getCoordArchiveMarineDataById($spotter_item['fammarine_id']);
163
				$pfi = $spotter_item['fammarine_id'];
164
			} else $spotter_history_array = 0;
165
		}
166
		else {
167
			if ($pfi != $spotter_item['flightaware_id']) {
168
				$spotter_history_array = $SpotterArchive->getCoordArchiveSpotterDataById($spotter_item['flightaware_id']);
169
				$pfi = $spotter_item['flightaware_id'];
170
			} else $spotter_history_array = 0;
171
		}
172
		if (count($spotter_history_array) > 1) {
173
			//location of aircraft
174
			$output .= '{';
175
			$output .= '"type": "Feature",';
176
			$output .= '"properties": {';
177
			$output .= '"fi": "'.$pfi.'",';
178
			if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",';
179
			if (isset($spotter_item['ident']) && $spotter_item['ident'] != '') {
180
				$output .= '"c": "'.$spotter_item['ident'].'",';
181
			} else {
182
				$output .= '"c": "NA",';
183
			}
184
			if (!isset($spotter_item['aircraft_shadow']) && !$tracker && !$marine) {
185
				if (!isset($spotter_item['aircraft_icao']) || $spotter_item['aircraft_icao'] == '') $spotter_item['aircraft_shadow'] = '';
186
				else {
187
					$aircraft_info = $Spotter->getAllAircraftInfo($spotter_item['aircraft_icao']);
188
					if (count($aircraft_info) > 0) $spotter_item['aircraft_shadow'] = $aircraft_info[0]['aircraft_shadow'];
189
					elseif (isset($spotter_item['format_source']) && $spotter_item['format_source'] == 'aprs') $spotter_item['aircraft_shadow'] = 'PA18.png';
190
					elseif ($aircraft_icao == 'PARAGLIDER') $spotter_item['aircraft_shadow'] = 'PARAGLIDER.png';
191
					else $spotter_item['aircraft_shadow'] = '';
192
					$aircrafts_shadow[$aircraft_icao] = $spotter_item['aircraft_shadow'];
193
				}
194
			}
195
196
			if (!isset($spotter_item['aircraft_shadow']) || $spotter_item['aircraft_shadow'] == '') {
197
				if ($tracker) {
198
					if (isset($spotter_item['type']) && $spotter_item['type'] == 'Ambulance') {
199
						if ($compress) $output .= '"as": "ambulance.png",';
200
						else $output .= '"aircraft_shadow": "ambulance.png",';
201
					}
202
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Police') {
203
						if ($compress) $output .= '"as": "police.png",';
204
						else $output .= '"aircraft_shadow": "police.png",';
205
					}
206
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Yacht (Sail)') {
207
						if ($compress) $output .= '"as": "ship.png",';
208
						else $output .= '"aircraft_shadow": "ship.png",';
209
					}
210
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Ship (Power Boat)') {
211
						if ($compress) $output .= '"as": "ship.png",';
212
						else $output .= '"aircraft_shadow": "ship.png",';
213
					}
214
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Shuttle') {
215
						if ($compress) $output .= '"as": "ship.png",';
216
						else $output .= '"aircraft_shadow": "ship.png",';
217
					}
218
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Truck') {
219
						if ($compress) $output .= '"as": "truck.png",';
220
						else $output .= '"aircraft_shadow": "truck.png",';
221
					}
222
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Truck (18 Wheeler)') {
223
						if ($compress) $output .= '"as": "truck.png",';
224
						else $output .= '"aircraft_shadow": "truck.png",';
225
					}
226
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Aircraft (small)') {
227
						if ($compress) $output .= '"as": "aircraft.png",';
228
						else $output .= '"aircraft_shadow": "aircraft.png",';
229
					}
230
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Large Aircraft') {
231
						if ($compress) $output .= '"as": "aircraft.png",';
232
						else $output .= '"aircraft_shadow": "aircraft.png",';
233
					}
234
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Helicopter') {
235
						if ($compress) $output .= '"as": "helico.png",';
236
						else $output .= '"aircraft_shadow": "helico.png",';
237
					}
238
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Railroad Engine') {
239
						if ($compress) $output .= '"as": "rail.png",';
240
						else $output .= '"aircraft_shadow": "rail.png",';
241
					}
242
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Firetruck') {
243
						if ($compress) $output .= '"as": "firetruck.png",';
244
						else $output .= '"aircraft_shadow": "firetruck.png",';
245
					}
246
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Bus') {
247
						if ($compress) $output .= '"as": "bus.png",';
248
						else $output .= '"aircraft_shadow": "bus.png",';
249
					}
250
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Phone') {
251
						if ($compress) $output .= '"as": "phone.png",';
252
						else $output .= '"aircraft_shadow": "phone.png",';
253
					}
254
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Jogger') {
255
						if ($compress) $output .= '"as": "jogger.png",';
256
						else $output .= '"aircraft_shadow": "jogger.png",';
257
					}
258
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Bike') {
259
						if ($compress) $output .= '"as": "bike.png",';
260
						else $output .= '"aircraft_shadow": "bike.png",';
261
					}
262
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Motorcycle') {
263
						if ($compress) $output .= '"as": "motorcycle.png",';
264
						else $output .= '"aircraft_shadow": "motorcycle.png",';
265
					}
266
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Balloon') {
267
						if ($compress) $output .= '"as": "balloon.png",';
268
						else $output .= '"aircraft_shadow": "balloon.png",';
269
					}
270
					else {
271
						if ($compress) $output .= '"as": "car.png",';
272
						else $output .= '"aircraft_shadow": "car.png",';
273
					}
274
				}
275
				elseif ($marine) {
276
					if ($compress) $output .= '"as": "ship.png",';
277
					else $output .= '"aircraft_shadow": "ship.png",';
278
				}
279
				else {
280
					if ($compress) $output .= '"as": "default.png",';
281
					else $output .= '"aircraft_shadow": "default.png",';
282
				}
283
			} else {
284
				if ($compress) $output .= '"as": "'.$spotter_item['aircraft_shadow'].'",';
285
				else $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",';
286
			}
287
288
			if (isset($spotter_item['date_iso_8601'])) {
289
				$output .= '"date_update": "'.date("M j, Y, g:i a T", strtotime($spotter_item['date_iso_8601'])).'",';
290
			}
291
			if (isset($spotter_item['date'])) {
292
				$output .= '"lu": "'.strtotime($spotter_item['date']).'",';
293
			}
294
			if (isset($spotter_item['squawk'])) {
295
				$output .= '"sq": "'.$spotter_item['squawk'].'",';
296
			}
297
			if (isset($spotter_item['squawk_usage'])) {
298
				$output .= '"squawk_usage": "'.$spotter_item['squawk_usage'].'",';
299
			}
300
			//$spotter_history_array = $SpotterArchive->getCoordArchiveSpotterDataById($spotter_item['flightaware_id']);
301
			//$spotter_history_array = array();
302
			$output_history = '';
303
			$output_time = '';
304
			$output_timediff = '';
305
			$previousts = 0;
306
			$end = false;
307
			$k = 0;
308
			foreach ($spotter_history_array as $key => $spotter_history) {
309
				if ($end == false) {
310
					$k++;
311
					$output_history .= '['.$spotter_history['longitude'].', '.$spotter_history['latitude'].'],';
312
					$output_time .= (strtotime($spotter_history['date'])*1000).',';
313
					if ($previousts != 0) $output_timediff .= (strtotime($spotter_history['date'])-$previousts).',';
314
					$previousts = strtotime($spotter_history['date']);
315
					if ($k > 1 && (strtotime($spotter_history['date'])*1000 > $enddate)) $end = true;
316
				}
317
			}
318
			if (isset($output_time)) {
319
				$output_time  = substr($output_time, 0, -1);
320
				$output .= '"time": ['.$output_time.'],';
321
			}
322
			if (isset($output_timediff)) {
323
				$output_timediff  = substr($output_timediff, 0, -1);
324
				$output .= '"timediff": ['.$output_timediff.'],';
325
			}
326
			// FIXME : type when not aircraft ?
327
			if ($compress) $output .= '"t": "aircraft"';
328
			else $output .= '"type": "aircraft"';
329
			$output .= '},';
330
			$output .= '"geometry": {';
331
			//$output .= '"type": "MultiPoint",';
332
			$output .= '"type": "LineString",';
333
			$output .= '"coordinates": [';
334
335
			if (isset($output_history)) {
336
				$output_history  = substr($output_history, 0, -1);
337
				$output .= $output_history;
338
			}
339
			$output .= ']';
340
			$output .= '}';
341
			$output .= '},';
342
		}
343
	}
344
	$output  = substr($output, 0, -1);
345
	$output .= ']';
346
	$output .= ',"initial_sqltime": "'.$sqltime.'",';
347
	$output .= '"totaltime": "'.round(microtime(true)-$begintime,2).'",';
348
	if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",';
349
	$output .= '"fc": "'.$flightcnt.'"';
350
} else {
351
	$output .= '"features": ';
352
	$output .= '{';
353
	$output .= '"type": "Feature",';
354
	$output .= '"properties": {';
355
	$output .= '"fc": "'.$flightcnt.'"}}';
356
}
357
$output .= '}';
358
print $output;
359
360
?>
361