Issues (843)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

require/class.SpotterImport.php (1 issue)

Labels
Severity

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
/**
3
 * This class is part of FlightAirmap. It's used to import spotter data
4
 *
5
 * Copyright (c) Ycarus (Yannick Chabanois) <[email protected]>
6
 * Licensed under AGPL license.
7
 * For more information see: https://www.flightairmap.com/
8
*/
9
require_once(dirname(__FILE__).'/class.Connection.php');
10
require_once(dirname(__FILE__).'/class.Spotter.php');
11
require_once(dirname(__FILE__).'/class.SpotterLive.php');
12
require_once(dirname(__FILE__).'/class.SpotterArchive.php');
13
require_once(dirname(__FILE__).'/class.Scheduler.php');
14
require_once(dirname(__FILE__).'/class.Translation.php');
15
require_once(dirname(__FILE__).'/class.Stats.php');
16
require_once(dirname(__FILE__).'/class.Source.php');
17
require_once(dirname(__FILE__).'/class.GeoidHeight.php');
18
if (isset($globalServerAPRS) && $globalServerAPRS) {
19
    require_once(dirname(__FILE__).'/class.APRS.php');
20
}
21
22
class SpotterImport {
23
    private $all_flights = array();
24
    private $last_delete_hourly = 0;
25
    private $last_delete = 0;
26
    private $stats = array();
27
    private $tmd = 0;
28
    private $source_location = array();
29
    public $db = null;
30
    public $nb = 0;
31
32
    public function __construct($dbc = null) {
33
	global $globalBeta, $globalServerAPRS, $APRSSpotter, $globalNoDB, $GeoidClass, $globalDebug, $globalGeoid;
34
	if (!(isset($globalNoDB) && $globalNoDB)) {
35
		$Connection = new Connection($dbc);
36
		$this->db = $Connection->db();
37
		date_default_timezone_set('UTC');
38
39
		// Get previous source stats
40
		$Stats = new Stats($dbc);
41
		$currentdate = date('Y-m-d');
42
		$sourcestat = $Stats->getStatsSource($currentdate);
43
		if (!empty($sourcestat)) {
44
		    foreach($sourcestat as $srcst) {
45
		    	$type = $srcst['stats_type'];
46
			if ($type == 'polar' || $type == 'hist') {
47
			    $source = $srcst['source_name'];
48
			    $data = $srcst['source_data'];
49
			    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
50
	    		}
51
		    }
52
		}
53
	}
54
	if (isset($globalServerAPRS) && $globalServerAPRS) {
55
		$APRSSpotter = new APRSSpotter();
56
		//$APRSSpotter->connect();
57
	}
58
	if (isset($globalGeoid) && $globalGeoid) {
59
		try {
60
			$GeoidClass = new GeoidHeight();
61
		} catch(Exception $e) {
62
			if ($globalDebug) echo "Can't calculate geoid, check that you downloaded it via update_db.php (".$e.")\n";
63
			$GeoidClass = FALSE;
64
		}
65
	}
66
    }
67
68
    public function get_Schedule($id,$ident) {
69
	global $globalDebug, $globalFork, $globalSchedulesFetch;
70
	// Get schedule here, so it's done only one time
71
	
72
	/*
73
	if ($globalFork) {
74
		$Connection = new Connection();
75
		$dbc = $Connection->db;
76
	} else $dbc = $this->db;
77
	*/
78
	$dbc = $this->db;
79
	$this->all_flights[$id]['schedule_check'] = true;
80
	if ($globalSchedulesFetch) {
81
	if ($globalDebug) echo 'Getting schedule info...'."\n";
82
	$Spotter = new Spotter($dbc);
83
	$Schedule = new Schedule($dbc);
84
	$Translation = new Translation($dbc);
85
	$operator = $Spotter->getOperator($ident);
86
	$scheduleexist = false;
87
	if ($Schedule->checkSchedule($operator) == 0) {
88
	    $operator = $Translation->checkTranslation($ident);
89
	    if ($Schedule->checkSchedule($operator) == 0) {
90
		$schedule = $Schedule->fetchSchedule($operator);
91
		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
92
		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
93
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
94
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
95
		    // Should also check if route schedule = route from DB
96
		    if ($schedule['DepartureAirportIATA'] != '') {
97
			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
98
			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
99
			    if (trim($airport_icao) != '') {
100
				$this->all_flights[$id]['departure_airport'] = $airport_icao;
101
				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
102
			    }
103
			}
104
		    }
105
		    if ($schedule['ArrivalAirportIATA'] != '') {
106
			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) {
107
			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
108
			    if (trim($airport_icao) != '') {
109
				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
110
				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
111
			    }
112
			}
113
		    }
114
		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
115
		}
116
	    } else $scheduleexist = true;
117
	} else $scheduleexist = true;
118
	// close connection, at least one way will work ?
119
       if ($scheduleexist) {
120
		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
121
    		$sch = $Schedule->getSchedule($operator);
122
		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
123
		if ($this->all_flights[$id]['addedSpotter'] == 1) $Spotter->updateLatestScheduleSpotterData($this->all_flights[$id]['id'],$sch['departure_airport_icao'],$sch['departure_airport_time'],$sch['arrival_airport_icao'],$sch['arrival_airport_time']);
124
       }
125
	$Spotter->db = null;
126
	$Schedule->db = null;
127
	$Translation->db = null;
128
	unset($Spotter->db);
129
	unset($Schedule->db);
130
	unset($Translation->db);
131
132
	/*
133
	if ($globalFork) {
134
	    $Connection->db = null;
135
	    unset($Connection->db);
136
	}
137
	  */
138
	}
139
    }
140
141
    public function checkAll() {
142
	global $globalDebug, $globalNoImport;
143
	if ($globalDebug) echo "Update last seen flights data...\n";
144
	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
145
	    foreach ($this->all_flights as $key => $flight) {
146
		if (isset($this->all_flights[$key]['id'])) {
147
		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
148
    		    $Spotter = new Spotter($this->db);
149
        	    $real_arrival = $this->arrival($key);
150
        	    if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],'',$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
151
        	}
152
	    }
153
	}
154
    }
155
156
    public function arrival($key) {
157
	global $globalClosestMinDist, $globalDebug;
158
	if ($globalDebug) echo 'Update arrival...'."\n";
159
	$Spotter = new Spotter($this->db);
160
        $airport_icao = '';
161
        $airport_time = '';
162
        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
163
	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
164
	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
165
    	    if (isset($closestAirports[0])) {
166
        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
167
        	    $airport_icao = $closestAirports[0]['icao'];
168
        	    $airport_time = $this->all_flights[$key]['datetime'];
169
        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
170
        	} elseif (count($closestAirports) > 1 && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
171
        	    foreach ($closestAirports as $airport) {
172
        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
173
        		    $airport_icao = $airport['icao'];
174
        		    $airport_time = $this->all_flights[$key]['datetime'];
175
        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
176
        		    break;
177
        		}
178
        	    }
179
        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
180
        		$airport_icao = $closestAirports[0]['icao'];
181
        		$airport_time = $this->all_flights[$key]['datetime'];
182
        	} else {
183
        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
184
        	}
185
    	    } else {
186
    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
187
    	    }
188
189
        } else {
190
        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
191
        }
192
        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
193
    }
194
195
196
197
    public function del() {
198
	global $globalDebug, $globalNoImport, $globalNoDB;
199
	// Delete old infos
200
	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
201
	
202
	foreach ($this->all_flights as $key => $flight) {
203
		if (isset($flight['lastupdate'])) {
204
			if ($flight['lastupdate'] < (time()-1800)) {
205
				$this->delKey($key);
206
			}
207
		}
208
	}
209
    }
210
211
    public function delKey($key) {
212
	global $globalDebug, $globalNoImport, $globalNoDB;
213
	// Delete old infos
214
	if (isset($this->all_flights[$key]['id'])) {
215
		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
216
		if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
217
			$real_arrival = $this->arrival($key);
218
			$Spotter = new Spotter($this->db);
219
			$SpotterLive = new SpotterLive($this->db);
220
			if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
221
				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],'',$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
222
				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
223
				$this->all_flights[$key]['putinarchive'] = true;
224
				$result = $SpotterLive->addLiveSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['aircraft_icao'], $this->all_flights[$key]['departure_airport'], $this->all_flights[$key]['arrival_airport'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['waypoints'], $this->all_flights[$key]['altitude'],$this->all_flights[$key]['altitude_real'], $this->all_flights[$key]['heading'], $this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'], $this->all_flights[$key]['departure_airport_time'], $this->all_flights[$key]['arrival_airport_time'], $this->all_flights[$key]['squawk'],$this->all_flights[$key]['route_stop'],$this->all_flights[$key]['hex'],$this->all_flights[$key]['putinarchive'],$this->all_flights[$key]['registration'],$this->all_flights[$key]['pilot_id'],$this->all_flights[$key]['pilot_name'], $this->all_flights[$key]['verticalrate'], $this->all_flights[$key]['noarchive'], $this->all_flights[$key]['ground'],$this->all_flights[$key]['format_source'],$this->all_flights[$key]['source_name'],$this->all_flights[$key]['over_country']);
225
				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
226
			}
227
			$Spotter->db = null;
228
			$SpotterLive->db = null;
229
		}
230
		if ($globalDebug) echo "\n";
231
	}
232
	unset($this->all_flights[$key]);
233
    }
234
235
    public function add($line) {
236
	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport, $globalNoDB, $globalVA, $globalAircraftMaxUpdate, $globalAircraftMinUpdate, $globalLiveInterval, $GeoidClass, $globalArchive, $globalAPRSdelete;
237
	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
238
	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.01';
239
	if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') $globalAircraftMaxUpdate = 3000;
240
/*
241
	$Spotter = new Spotter();
242
	$dbc = $Spotter->db;
243
	$SpotterLive = new SpotterLive($dbc);
244
	$Common = new Common();
245
	$Schedule = new Schedule($dbc);
246
*/
247
	date_default_timezone_set('UTC');
248
	// signal handler - playing nice with sockets and dump1090
249
	// pcntl_signal_dispatch();
250
251
	// get the time (so we can figure the timeout)
252
	//$time = time();
253
254
	//pcntl_signal_dispatch();
255
	$dataFound = false;
256
	//$putinarchive = false;
257
	$send = false;
258
	
259
	// SBS format is CSV format
260
	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
261
	    //print_r($line);
262
	    if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
263
  	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && substr($line['hex'],0,1) != '~' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
264
265
		// Increment message number
266
		if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) {
267
		    $current_date = date('Y-m-d');
268
		    if (isset($line['source_name'])) $source = $line['source_name'];
269
		    else $source = '';
270
		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
271
		    if (!isset($this->stats[$current_date][$source]['msg'])) {
272
		    	$this->stats[$current_date][$source]['msg']['date'] = time();
273
		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
274
		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
275
		}
276
		
277
		/*
278
		$dbc = $this->db;
279
		$Connection = new Connection($dbc);
280
		$Connection->connectionExists();
281
		$dbc = $Connection->db;
282
		*/
283
		//$Spotter = new Spotter($dbc);
284
		//$SpotterLive = new SpotterLive($dbc);
285
		$Common = new Common();
286
//		echo $this->nb++."\n";
287
		//$this->db = $dbc;
288
289
		//$hex = trim($line['hex']);
290
	        if (!isset($line['id'])) $id = trim($line['hex']);
291
	        else $id = trim($line['id']);
292
		
293
		if (!isset($this->all_flights[$id])) {
294
		    if ($globalDebug) echo 'New flight...'."\n";
295
		    $this->all_flights[$id] = array();
296
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
297
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => '','coordinates' => 0));
298
		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
299
		    if (!isset($line['id'])) {
300
			if (!isset($globalDaemon)) $globalDaemon = TRUE;
301
//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
302
//			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
303
			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
304
		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
305
		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
306
		    if ($globalAllFlights !== FALSE) $dataFound = true;
307
		}
308
		if (isset($line['source_type']) && $line['source_type'] != '') {
309
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
310
		}
311
		
312
		//print_r($this->all_flights);
313
		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
314
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
315
		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
316
			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
317
		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
318
		    if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
319
			$timeelapsed = microtime(true);
320
			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
321
			    $Spotter = new Spotter($this->db);
322
			    if (isset($this->all_flights[$id]['source_type'])) {
323
				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
324
			    } else {
325
				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
326
			    }
327
			    $Spotter->db = null;
328
			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
329
			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
330
			}
331
		    }
332
		    if ($globalAllFlights !== FALSE) $dataFound = true;
333
		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
334
		}
335
	        if (isset($line['id']) && !isset($line['hex'])) {
336
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
337
	        }
338
		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
339
			$icao = $line['aircraft_icao'];
340
			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
341
				$Spotter = new Spotter($this->db);
342
				if (isset($Spotter->aircraft_correct_icaotype[$icao])) $icao = $Spotter->aircraft_correct_icaotype[$icao];
343
				$Spotter->db = null;
344
			}
345
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $icao));
346
		} elseif (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_name'])) {
347
			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
348
				// Get aircraft ICAO from aircraft name
349
				$Spotter = new Spotter($this->db);
350
				$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
351
				$Spotter->db = null;
352
				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
353
			}
354
		}
355
		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
356
			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
357
			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
358
			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
359
			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
360
			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
361
		}
362
		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
363
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
364
		}
365
		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
366
		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) {
367
		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
368
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
369
		    } else {
370
				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
371
				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
372
				/*
373
				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
374
				print_r($this->all_flights[$id]);
375
				print_r($line);
376
				*/
377
				return '';
378
		    }
379
		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
380
			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
381
			return '';
382
		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) {
383
			if ($globalDebug) echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
384
			return '';
385
		} elseif (!isset($line['datetime'])) {
386
			date_default_timezone_set('UTC');
387
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
388
		} else {
389
			if ($globalDebug) echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
390
			return '';
391
		}
392
393
		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG' && $line['registration'] != 'NA') {
394
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
395
		}
396
		if (isset($line['waypoints']) && $line['waypoints'] != '') {
397
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
398
		}
399
		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
400
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
401
		}
402
		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
403
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
404
		}
405
 
406
		if (isset($line['ident']) && trim($line['ident']) != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
407
408
		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
409
			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 800) {
410
				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
411
				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
412
				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
413
				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
414
				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
415
				elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
416
			} else {
417
			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
418
			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
419
				$timeelapsed = microtime(true);
420
            			$Spotter = new Spotter($this->db);
421
            			$fromsource = NULL;
422
            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
423
            			elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
424
				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
425
				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
426
				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
427
            			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource,$this->all_flights[$id]['source_type']);
428
				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
429
				$Spotter->db = null;
430
				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
431
			    }
432
			}
433
		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
434
		    
435
/*
436
		    if (!isset($line['id'])) {
437
			if (!isset($globalDaemon)) $globalDaemon = TRUE;
438
//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
439
			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
440
		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
441
		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
442
  */
443
		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
444
445
		    //$putinarchive = true;
446
		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
447
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
448
		    }
449
		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
450
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
451
		    }
452
		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
453
		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
454
		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
455
			$timeelapsed = microtime(true);
456
			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
457
				$Spotter = new Spotter($this->db);
458
				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
459
				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
460
		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
461
				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
462
                        }
463
		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
464
			$timeelapsed = microtime(true);
465
			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
466
			    $Spotter = new Spotter($this->db);
467
			    $route = $Spotter->getRouteInfo(trim($line['ident']));
468
			    if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) {
469
				$Translation = new Translation($this->db);
470
				$ident = $Translation->checkTranslation(trim($line['ident']));
471
				$route = $Spotter->getRouteInfo($ident);
472
				$Translation->db = null;
473
			    }
474
			    $Spotter->db = null;
475
			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
476
                    	}
477
			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
478
			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
479
			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
480
				//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop']));
481
		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
482
		    	    }
483
			}
484
			if (!isset($globalFork)) $globalFork = TRUE;
485
			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
486
				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
487
			}
488
		    }
489
		}
490
491
		if (isset($line['speed']) && $line['speed'] != '' && $line['speed'] != 0) {
492
		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
493
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
494
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
495
		    //$dataFound = true;
496
		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
497
		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
498
		    if ($distance > 1000 && $distance < 10000) {
499
		    // use datetime
500
			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
501
			$speed = $speed*3.6;
502
			if ($speed < 1000) {
503
				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
504
	  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
505
	  		} else {
506
	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
507
	  		}
508
		    }
509
		}
510
511
512
513
	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
514
	    	    if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
515
	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
516
	    	    	return false;
517
	    	    }
518
	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
519
	    	    else unset($timediff);
520
	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
521
	    	    else unset($timediff_archive);
522
	    	    if ($this->tmd > 5
523
	    	        || (isset($line['format_source']) 
524
	    	    	    && $line['format_source'] == 'airwhere' 
525
	    	    	    && ((!isset($this->all_flights[$id]['latitude']) 
526
	    	    		|| !isset($this->all_flights[$id]['longitude'])) 
527
	    	    		|| (isset($this->all_flights[$id]['latitude']) 
528
	    	    		    && isset($this->all_flights[$id]['longitude']) 
529
	    	    		    && $this->all_flights[$id]['latitude'] != $line['latitude'] 
530
	    	    		    && $this->all_flights[$id]['longitude'] != $line['longitude']
531
	    	    		)
532
	    	    	    )
533
	    	    	)
534
	    		|| (isset($globalVA) && $globalVA) 
535
	    	    	|| (isset($globalIVAO) && $globalIVAO)
536
	    	    	|| (isset($globalVATSIM) && $globalVATSIM)
537
	    	    	|| (isset($globalphpVMS) && $globalphpVMS)
538
	    	    	|| (isset($globalVAM) && $globalVAM)
539
	    	    	|| !isset($timediff)
540
	    	    	|| (isset($timediff) && $timediff > $globalLiveInterval)
541
	    	    	|| $globalArchive
542
	    	    	|| (isset($timediff) && $timediff > 30
543
	    	    	    && isset($this->all_flights[$id]['latitude']) 
544
	    	    	    && isset($this->all_flights[$id]['longitude']) 
545
	    	    	    && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
546
	    	    	    )
547
	    	    	) {
548
549
			if ((isset($timediff) && !isset($timediff_archive)) || (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude']))) {
550
			    if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
0 ignored issues
show
The variable $timediff_archive does not seem to be defined for all execution paths leading up to this point.

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
551
				|| (isset($line['format_source']) && $line['format_source'] == 'airwhere') 
552
				|| (
553
				    (isset($this->all_flights[$id]['archive_latitude']) 
554
				    && isset($this->all_flights[$id]['archive_longitude']) 
555
				    && isset($this->all_flights[$id]['livedb_latitude']) 
556
				    && isset($this->all_flights[$id]['livedb_longitude']))
557
				    && !$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])
558
				)
559
				) {
560
				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
561
				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
562
				$this->all_flights[$id]['putinarchive'] = true;
563
				if ($this->tmd > 5 && $this->all_flights[$id]['putinarchive'] == true) {
564
					if ($globalDebug) echo "\n".' Update Initial data ! '."\n";
565
					$updateinitial = true;
566
				}
567
				$this->tmd = 0;
568
				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
569
				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
570
				    $timeelapsed = microtime(true);
571
				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
572
					$Spotter = new Spotter($this->db);
573
					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
574
					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
575
					else $this->all_flights[$id]['over_country'] = '';
576
					$Spotter->db = null;
577
					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
578
					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
579
				    }
580
				}
581
				$this->all_flights[$id]['time_last_archive_coord'] = time();
582
			    } 
583
			    /*
584
			    else {
585
				if (!isset($timediff)) echo 'NO TIMEDIFF';
586
				else {
587
				echo 'timediff : '.$timediff.' - maxupdate : '.$globalAircraftMaxUpdate."\n";
588
				var_dump($Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude']));
589
				echo 'lat1: '.$this->all_flights[$id]['archive_latitude'].' lon1: '.$this->all_flights[$id]['archive_longitude'].' - lat2: '.$this->all_flights[$id]['livedb_latitude'].' lon2: '.$this->all_flights[$id]['livedb_longitude'].' - lat3: '.$line['latitude'].' lon3: '.$line['longitude']."\n";
590
				}
591
				echo 'NOT OK HERE';
592
			    }
593
			    */
594
			}
595
596
			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
597
			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
598
				if (!isset($this->all_flights[$id]['archive_latitude'])) {
599
					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
600
					$this->all_flights[$id]['time_last_coord'] = time();
601
				}
602
				//if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
603
				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
604
				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
605
				    $dataFound = true;
606
				    $this->all_flights[$id]['time_last_coord'] = time();
607
				}
608
				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
609
				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
610
				/*
611
				if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) {
612
				    $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
613
				    $this->all_flights[$id]['putinarchive'] = true;
614
				    //$putinarchive = true;
615
				}
616
				*/
617
			    /*
618
			    } elseif (isset($this->all_flights[$id]['latitude'])) {
619
				if ($globalDebug) echo '!!! Strange latitude value - diff : '.abs($this->all_flights[$id]['latitude']-$line['latitude']).'- previous lat : '.$this->all_flights[$id]['latitude'].'- new lat : '.$line['latitude']."\n";
620
			    }
621
			    */
622
			}
623
			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
624
			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
625
			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
626
				if (!isset($this->all_flights[$id]['archive_longitude'])) {
627
					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
628
					$this->all_flights[$id]['time_last_coord'] = time();
629
				}
630
				//if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
631
				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
632
				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
633
				    $dataFound = true;
634
				    $this->all_flights[$id]['coordinates'] += 1;
635
				    $this->all_flights[$id]['time_last_coord'] = time();
636
				}
637
				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
638
				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
639
				/*
640
				if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) {
641
				    $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
642
				    $this->all_flights[$id]['putinarchive'] = true;
643
				    //$putinarchive = true;
644
				}
645
				*/
646
			/*
647
			    } elseif (isset($this->all_flights[$id]['longitude'])) {
648
				if ($globalDebug) echo '!!! Strange longitude value - diff : '.abs($this->all_flights[$id]['longitude']-$line['longitude']).'- previous lat : '.$this->all_flights[$id]['longitude'].'- new lat : '.$line['longitude']."\n";
649
			    }
650
			    */
651
			}
652
			if ($globalDaemon === TRUE && isset($updateinitial) && $updateinitial && $this->all_flights[$id]['addedSpotter'] == 1) {
653
			    if ($globalDebug) echo "\n".'>>> Update initial data !'."\n";
654
			    unset($updateinitial);
655
			    $SpotterArchive = new SpotterArchive();
656
			    $SpotterArchive->deleteSpotterArchiveTrackDataByID($this->all_flights[$id]['id']);
657
			    $SpotterArchive->db = null;
658
			    $Spotter = new Spotter();
659
			    $Spotter->updateInitialSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime']);
660
			    $Spotter->db = null;
661
			}
662
		    } else if ($globalDebug && $timediff > 30) {
663
			$this->tmd = $this->tmd + 1;
664
			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
665
			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
666
			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
667
			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
668
		    }
669
		}
670
		if (isset($line['last_update']) && $line['last_update'] != '') {
671
		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
672
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
673
		}
674
		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
675
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
676
		    //$dataFound = true;
677
		}
678
		if (isset($line['format_source']) && $line['format_source'] != '') {
679
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
680
		}
681
		if (isset($line['source_name']) && $line['source_name'] != '') {
682
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
683
		}
684
		if (isset($line['emergency']) && $line['emergency'] != '') {
685
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
686
		    //$dataFound = true;
687
		}
688
		if (isset($line['ground']) && $line['ground'] != '') {
689
		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
690
			// Here we force archive of flight because after ground it's a new one (or should be)
691
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
692
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
693
			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
694
		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
695
			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
696
		    }
697
		    if ($line['ground'] != 1) $line['ground'] = 0;
698
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
699
		    //$dataFound = true;
700
		}
701
		if (isset($line['squawk']) && $line['squawk'] != '') {
702
		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
703
			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
704
			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
705
			    $highlight = '';
706
			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
707
			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
708
			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
709
			    if ($highlight != '') {
710
				$timeelapsed = microtime(true);
711
				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
712
				    $Spotter = new Spotter($this->db);
713
				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
714
				    $Spotter->db = null;
715
				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
716
				}
717
				//$putinarchive = true;
718
				//$highlight = '';
719
			    }
720
			    
721
		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
722
		    //$dataFound = true;
723
		}
724
725
		if (isset($line['altitude']) && $line['altitude'] != '' && is_numeric($line['altitude'])) {
726
			if (isset($line['altitude_relative']) && isset($GeoidClass) && is_object($GeoidClass)) {
727
				if ($line['altitude_relative'] == 'AMSL' || $line['altitude_relative'] == 'MSL') {
728
					$geoid = round($GeoidClass->get($this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'])*3.28084,2);
729
					//if ($globalDebug) echo '=> Set altitude to WGS84 Ellipsoid, add '.$geoid.' to '.$line['altitude']."\n";
730
					$line['altitude'] = $line['altitude'] - $geoid;
731
				}
732
			}
733
		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
734
			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
735
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
736
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
737
			//$dataFound = true;
738
		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
739
		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
740
			if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
741
				if ($globalDebug) echo '--- Reset because of altitude'."\n";
742
				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
743
				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
744
				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
745
				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
746
				elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
747
			}
748
		    }
749
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
750
		}
751
752
		if (isset($line['noarchive']) && $line['noarchive'] === true) {
753
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
754
		}
755
		
756
		if (isset($line['heading']) && $line['heading'] != '') {
757
		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
758
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
759
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
760
		    //$dataFound = true;
761
  		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
762
  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
763
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
764
		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
765
  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
766
  		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
767
  		    // If not enough messages and ACARS set heading to 0
768
  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
769
  		}
770
		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
771
		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
772
		elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalAircraftMinUpdate) $dataFound = false;
773
774
//		print_r($this->all_flights[$id]);
775
		//gets the callsign from the last hour
776
		//if (time()-$this->all_flights[$id]['lastupdate'] > 30 && $dataFound == true && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
777
		//if ($dataFound == true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
778
		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
779
		//if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
780
		if ($dataFound === true && isset($this->all_flights[$id]['id'])) {
781
		    $this->all_flights[$id]['lastupdate'] = time();
782
		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
783
		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
784
			    //print_r($this->all_flights);
785
			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
786
			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
787
			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
788
				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
789
				    if ($globalDebug) echo "Check if aircraft is already in DB...";
790
				    $timeelapsed = microtime(true);
791
				    $SpotterLive = new SpotterLive($this->db);
792
				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
793
					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
794
					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
795
				    } elseif (isset($line['id'])) {
796
					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
797
					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
798
				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
799
					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
800
					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
801
				    } else $recent_ident = '';
802
				    $SpotterLive->db=null;
803
				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
804
				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
805
				} else $recent_ident = '';
806
			    } else {
807
				$recent_ident = '';
808
				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
809
			    }
810
			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
811
			    if($recent_ident == "")
812
			    {
813
				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
814
				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
815
				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
816
				//adds the spotter data for the archive
817
				$ignoreImport = false;
818
				foreach($globalAirportIgnore as $airportIgnore) {
819
				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
820
					$ignoreImport = true;
821
				    }
822
				}
823
				if (count($globalAirportAccept) > 0) {
824
				    $ignoreImport = true;
825
				    foreach($globalAirportIgnore as $airportIgnore) {
826
					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
827
					    $ignoreImport = false;
828
					}
829
				    }
830
				}
831
				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
832
				    foreach($globalAirlineIgnore as $airlineIgnore) {
833
					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
834
					    $ignoreImport = true;
835
					}
836
				    }
837
				}
838
				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
839
				    $ignoreImport = true;
840
				    foreach($globalAirlineAccept as $airlineAccept) {
841
					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
842
					    $ignoreImport = false;
843
					}
844
				    }
845
				}
846
				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
847
				    $ignoreImport = true;
848
				    foreach($globalPilotIdAccept as $pilotIdAccept) {
849
					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
850
					    $ignoreImport = false;
851
					}
852
				    }
853
				}
854
				
855
				if (!$ignoreImport) {
856
				    $highlight = '';
857
				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
858
				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
859
				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
860
				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
861
				    $timeelapsed = microtime(true);
862
				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
863
					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
864
					    $Spotter = new Spotter($this->db);
865
					    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
866
					    $Spotter->db = null;
867
					    if ($globalDebug) {
868
						if (isset($result['error'])) echo 'Error: '.$result['error']."\n";
869
						else echo 'Success';
870
					    }
871
					    if (count($result) > 1) {
872
					    // ':airline_name' => $airline_name,':airline_icao' => $airline_icao,':airline_country' => $airline_country,':airline_type' => $airline_type,
873
						if ($this->all_flights[$id]['aircraft_icao'] == '') $this->all_flights[$id]['aircraft_icao'] = $result[':aircraft_icao'];
874
						if ($this->all_flights[$id]['registration'] == '') $this->all_flights[$id]['registration'] = $result[':registration'];
875
					    }
876
					}
877
				    }
878
				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
879
				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
880
881
				    // Add source stat in DB
882
				    $Stats = new Stats($this->db);
883
				    if (!empty($this->stats)) {
884
					if ($globalDebug) echo 'Add source stats : ';
885
				        foreach($this->stats as $date => $data) {
886
					    foreach($data as $source => $sourced) {
887
					        //print_r($sourced);
888
				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
889
				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
890
				    		if (isset($sourced['msg'])) {
891
				    		    if (time() - $sourced['msg']['date'] > 10) {
892
				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
893
				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
894
			    			        unset($this->stats[$date][$source]['msg']);
895
			    			    }
896
			    			}
897
			    		    }
898
			    		    if ($date != date('Y-m-d')) {
899
			    			unset($this->stats[$date]);
900
			    		    }
901
				    	}
902
				    	if ($globalDebug) echo 'Done'."\n";
903
904
				    }
905
				    $Stats->db = null;
906
				    }
907
				    $this->del();
908
				} elseif ($globalDebug) echo 'Ignore data'."\n";
909
				//$ignoreImport = false;
910
				$this->all_flights[$id]['addedSpotter'] = 1;
911
				//print_r($this->all_flights[$id]);
912
			/*
913
			if (isset($globalArchive) && $globalArchive) {
914
			    $archives_ident = SpotterLive->getAllLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
915
			    foreach ($archives_ident as $archive) {
916
				SpotterArchive->addSpotterArchiveData($archive['flightaware_id'], $archive['ident'], $archive['registration'],$archive['airline_name'],$archive['airline_icao'],$archive['airline_country'],$archive['airline_type'],$archive['aircraft_icao'],$archive['aircraft_shadow'],$archive['aircraft_name'],$archive['aircraft_manufacturer'], $archive['departure_airport_icao'],$archive['departure_airport_name'],$archive['departure_airport_city'],$archive['departure_airport_country'],$archive['departure_airport_time'],
917
				$archive['arrival_airport_icao'],$archive['arrival_airport_name'],$archive['arrival_airport_city'],$archive['arrival_airport_country'],$archive['arrival_airport_time'],
918
				$archive['route_stop'],$archive['date'],$archive['latitude'], $archive['longitude'], $archive['waypoints'], $archive['altitude'], $archive['heading'], $archive['ground_speed'],
919
				$archive['squawk'],$archive['ModeS']);
920
			    }
921
			}
922
			*/
923
			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
924
				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
925
				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
926
				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
927
				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
928
					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
929
					    $SpotterLive = new SpotterLive($this->db);
930
					    $SpotterLive->deleteLiveSpotterData();
931
					    $SpotterLive->db=null;
932
					}
933
				    }
934
				    if ($globalDebug) echo " Done\n";
935
				    $this->last_delete = time();
936
				}
937
			    } else {
938
				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'famaprs' || $line['format_source'] === 'airwhere')) {
939
				    $this->all_flights[$id]['id'] = $recent_ident;
940
				    $this->all_flights[$id]['addedSpotter'] = 1;
941
				}
942
				if (isset($globalDaemon) && !$globalDaemon) {
943
				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
944
					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
945
					    $Spotter = new Spotter($this->db);
946
					    $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
947
					    $Spotter->db = null;
948
					}
949
				    }
950
				}
951
				
952
			    }
953
			}
954
		    }
955
		    //adds the spotter LIVE data
956
		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
957
		    //echo "\nAdd in Live !! \n";
958
		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
959
		    if ($globalDebug) {
960
			if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
961
				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
962
				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
963
			} else {
964
				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
965
				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
966
			}
967
		    }
968
		    $ignoreImport = false;
969
		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
970
		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
971
972
		    foreach($globalAirportIgnore as $airportIgnore) {
973
		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
974
			    $ignoreImport = true;
975
			}
976
		    }
977
		    if (count($globalAirportAccept) > 0) {
978
		        $ignoreImport = true;
979
		        foreach($globalAirportIgnore as $airportIgnore) {
980
			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
981
				$ignoreImport = false;
982
			    }
983
			}
984
		    }
985
		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
986
			foreach($globalAirlineIgnore as $airlineIgnore) {
987
			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
988
				$ignoreImport = true;
989
			    }
990
			}
991
		    }
992
		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
993
			$ignoreImport = true;
994
			foreach($globalAirlineAccept as $airlineAccept) {
995
			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
996
				$ignoreImport = false;
997
			    }
998
			}
999
		    }
1000
		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
1001
			$ignoreImport = true;
1002
			foreach($globalPilotIdAccept as $pilotIdAccept) {
1003
			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
1004
			        $ignoreImport = false;
1005
			    }
1006
			}
1007
		    }
1008
1009
		    if (!$ignoreImport) {
1010
			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
1011
				if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1012
				$timeelapsed = microtime(true);
1013
				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
1014
				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
1015
					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1016
					$SpotterLive = new SpotterLive($this->db);
1017
					//var_dump($this->all_flights[$id]);
1018
					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
1019
					$SpotterLive->db = null;
1020
					if ($globalDebug) echo $result."\n";
1021
				    }
1022
				}
1023
				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
1024
					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
1025
				}
1026
				$this->all_flights[$id]['putinarchive'] = false;
1027
				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1028
1029
				// Put statistics in $this->stats variable
1030
				//if ($line['format_source'] != 'aprs') {
1031
				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
1032
				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
1033
				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
1034
					$source = $this->all_flights[$id]['source_name'];
1035
					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1036
					if (!isset($this->source_location[$source])) {
1037
						$Location = new Source($this->db);
1038
						$coord = $Location->getLocationInfobySourceName($source);
1039
						if (count($coord) > 0) {
1040
							$latitude = $coord[0]['latitude'];
1041
							$longitude = $coord[0]['longitude'];
1042
						} else {
1043
							$latitude = $globalCenterLatitude;
1044
							$longitude = $globalCenterLongitude;
1045
						}
1046
						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
1047
					} else {
1048
						$latitude = $this->source_location[$source]['latitude'];
1049
						$longitude = $this->source_location[$source]['longitude'];
1050
					}
1051
					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
1052
					//$stats_heading = $stats_heading%22.5;
1053
					$stats_heading = round($stats_heading/22.5);
1054
					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
1055
					$current_date = date('Y-m-d');
1056
					if ($stats_heading == 16) $stats_heading = 0;
1057
					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
1058
						for ($i=0;$i<=15;$i++) {
1059
						    $this->stats[$current_date][$source]['polar'][$i] = 0;
1060
						}
1061
						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
1062
					} else {
1063
						if ($this->stats[$current_date][$source]['polar'][$stats_heading] < $stats_distance) {
1064
							$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
1065
						}
1066
					}
1067
					$distance = (round($stats_distance/10)*10);
1068
					//echo '$$$$$$$$$$ DISTANCE : '.$distance.' - '.$source."\n";
1069
					//var_dump($this->stats);
1070
					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
1071
						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1072
						    end($this->stats[$current_date][$source]['hist']);
1073
						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1074
						} else $mini = 0;
1075
						for ($i=$mini;$i<=$distance;$i+=10) {
1076
						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1077
						}
1078
						$this->stats[$current_date][$source]['hist'][$distance] = 1;
1079
					} else {
1080
						$this->stats[$current_date][$source]['hist'][$distance] += 1;
1081
					}
1082
				    }
1083
				}
1084
1085
				$this->all_flights[$id]['lastupdate'] = time();
1086
				if ($this->all_flights[$id]['putinarchive']) $send = true;
1087
				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1088
			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1089
			//$this->del();
1090
			
1091
			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
1092
			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1093
				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1094
				$SpotterLive = new SpotterLive($this->db);
1095
				$SpotterLive->deleteLiveSpotterDataNotUpdated();
1096
				$SpotterLive->db = null;
1097
				//SpotterLive->deleteLiveSpotterData();
1098
				if ($globalDebug) echo " Done\n";
1099
				if (isset($globalAPRSdelete) && $globalAPRSdelete) {
1100
					if ($globalDebug) echo "---- Deleting old APRS data...";
1101
					$Spotter = new Spotter($this->db);
1102
					$Spotter->deleteOldAPRSData();
1103
					$Spotter->db = null;
1104
					if ($globalDebug) echo " Done\n";
1105
				}
1106
				$this->last_delete_hourly = time();
1107
			    } else {
1108
				$this->del();
1109
				$this->last_delete_hourly = time();
1110
			    }
1111
			}
1112
			
1113
		    }
1114
		    //$ignoreImport = false;
1115
		}
1116
		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
1117
		if ($send) return $this->all_flights[$id];
1118
	    }
1119
	}
1120
    }
1121
}
1122
?>
1123