Completed
Push — master ( c7884b...e258db )
by Yannick
36:25
created
require/class.SpotterImport.php 1 patch
Indentation   +433 added lines, -433 removed lines patch added patch discarded remove patch
@@ -16,20 +16,20 @@  discard block
 block discarded – undo
16 16
 require_once(dirname(__FILE__).'/class.Source.php');
17 17
 require_once(dirname(__FILE__).'/class.GeoidHeight.php');
18 18
 if (isset($globalServerAPRS) && $globalServerAPRS) {
19
-    require_once(dirname(__FILE__).'/class.APRS.php');
19
+	require_once(dirname(__FILE__).'/class.APRS.php');
20 20
 }
21 21
 
22 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;
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 31
 
32
-    public function __construct($dbc = null) {
32
+	public function __construct($dbc = null) {
33 33
 	global $globalBeta, $globalServerAPRS, $APRSSpotter, $globalNoDB, $GeoidClass, $globalDebug, $globalGeoid;
34 34
 	if (!(isset($globalNoDB) && $globalNoDB)) {
35 35
 		$Connection = new Connection($dbc);
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
 		$currentdate = date('Y-m-d');
42 42
 		$sourcestat = $Stats->getStatsSource($currentdate);
43 43
 		if (!empty($sourcestat)) {
44
-		    foreach($sourcestat as $srcst) {
45
-		    	$type = $srcst['stats_type'];
44
+			foreach($sourcestat as $srcst) {
45
+				$type = $srcst['stats_type'];
46 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
-		    }
47
+				$source = $srcst['source_name'];
48
+				$data = $srcst['source_data'];
49
+				$this->stats[$currentdate][$source][$type] = json_decode($data,true);
50
+				}
51
+			}
52 52
 		}
53 53
 	}
54 54
 	if (isset($globalServerAPRS) && $globalServerAPRS) {
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 			$GeoidClass = FALSE;
64 64
 		}
65 65
 	}
66
-    }
66
+	}
67 67
 
68
-    public function get_Schedule($id,$ident) {
68
+	public function get_Schedule($id,$ident) {
69 69
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
70 70
 	// Get schedule here, so it's done only one time
71 71
 	
@@ -85,43 +85,43 @@  discard block
 block discarded – undo
85 85
 	$operator = $Spotter->getOperator($ident);
86 86
 	$scheduleexist = false;
87 87
 	if ($Schedule->checkSchedule($operator) == 0) {
88
-	    $operator = $Translation->checkTranslation($ident);
89
-	    if ($Schedule->checkSchedule($operator) == 0) {
88
+		$operator = $Translation->checkTranslation($ident);
89
+		if ($Schedule->checkSchedule($operator) == 0) {
90 90
 		$schedule = $Schedule->fetchSchedule($operator);
91 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'] != '') {
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 97
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
98
-			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
99
-			    if (trim($airport_icao) != '') {
98
+				$airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
99
+				if (trim($airport_icao) != '') {
100 100
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
101 101
 				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
102
-			    }
102
+				}
103
+			}
103 104
 			}
104
-		    }
105
-		    if ($schedule['ArrivalAirportIATA'] != '') {
105
+			if ($schedule['ArrivalAirportIATA'] != '') {
106 106
 			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) {
107
-			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
108
-			    if (trim($airport_icao) != '') {
107
+				$airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
108
+				if (trim($airport_icao) != '') {
109 109
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
110 110
 				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
111
-			    }
111
+				}
112 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']);
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 115
 		}
116
-	    } else $scheduleexist = true;
116
+		} else $scheduleexist = true;
117 117
 	} else $scheduleexist = true;
118 118
 	// close connection, at least one way will work ?
119
-       if ($scheduleexist) {
119
+	   if ($scheduleexist) {
120 120
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
121
-    		$sch = $Schedule->getSchedule($operator);
121
+			$sch = $Schedule->getSchedule($operator);
122 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 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
-       }
124
+	   }
125 125
 	$Spotter->db = null;
126 126
 	$Schedule->db = null;
127 127
 	$Translation->db = null;
@@ -136,65 +136,65 @@  discard block
 block discarded – undo
136 136
 	}
137 137
 	  */
138 138
 	}
139
-    }
139
+	}
140 140
 
141
-    public function checkAll() {
141
+	public function checkAll() {
142 142
 	global $globalDebug, $globalNoImport;
143 143
 	if ($globalDebug) echo "Update last seen flights data...\n";
144 144
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
145
-	    foreach ($this->all_flights as $key => $flight) {
145
+		foreach ($this->all_flights as $key => $flight) {
146 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
-	    }
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
+	}
153 154
 	}
154
-    }
155 155
 
156
-    public function arrival($key) {
156
+	public function arrival($key) {
157 157
 	global $globalClosestMinDist, $globalDebug;
158 158
 	if ($globalDebug) echo 'Update arrival...'."\n";
159 159
 	$Spotter = new Spotter($this->db);
160
-        $airport_icao = '';
161
-        $airport_time = '';
162
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
160
+		$airport_icao = '';
161
+		$airport_time = '';
162
+		if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
163 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
-    	    }
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 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
-    }
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 194
 
195 195
 
196 196
 
197
-    public function del() {
197
+	public function del() {
198 198
 	global $globalDebug, $globalNoImport, $globalNoDB;
199 199
 	// Delete old infos
200 200
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
 			}
207 207
 		}
208 208
 	}
209
-    }
209
+	}
210 210
 
211
-    public function delKey($key) {
211
+	public function delKey($key) {
212 212
 	global $globalDebug, $globalNoImport, $globalNoDB;
213 213
 	// Delete old infos
214 214
 	if (isset($this->all_flights[$key]['id'])) {
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
 		if ($globalDebug) echo "\n";
231 231
 	}
232 232
 	unset($this->all_flights[$key]);
233
-    }
233
+	}
234 234
 
235
-    public function add($line) {
235
+	public function add($line) {
236 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;
237 237
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
238 238
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.01';
@@ -258,20 +258,20 @@  discard block
 block discarded – undo
258 258
 	
259 259
 	// SBS format is CSV format
260 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)) {
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 264
 
265 265
 		// Increment message number
266 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;
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 275
 		}
276 276
 		
277 277
 		/*
@@ -287,54 +287,54 @@  discard block
 block discarded – undo
287 287
 		//$this->db = $dbc;
288 288
 
289 289
 		//$hex = trim($line['hex']);
290
-	        if (!isset($line['id'])) $id = trim($line['hex']);
291
-	        else $id = trim($line['id']);
290
+			if (!isset($line['id'])) $id = trim($line['hex']);
291
+			else $id = trim($line['id']);
292 292
 		
293 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'])) {
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 300
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
301 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 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 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;
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 307
 		}
308 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']));
309
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
310 310
 		}
311 311
 		
312 312
 		//print_r($this->all_flights);
313 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'])) {
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 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') {
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 319
 			$timeelapsed = microtime(true);
320 320
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
321
-			    $Spotter = new Spotter($this->db);
322
-			    if (isset($this->all_flights[$id]['source_type'])) {
321
+				$Spotter = new Spotter($this->db);
322
+				if (isset($this->all_flights[$id]['source_type'])) {
323 323
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
324
-			    } else {
324
+				} else {
325 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));
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 330
 			}
331
-		    }
332
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
333
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
331
+			}
332
+			if ($globalAllFlights !== FALSE) $dataFound = true;
333
+			if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
334 334
 		}
335
-	        if (isset($line['id']) && !isset($line['hex'])) {
336
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
337
-	        }
335
+			if (isset($line['id']) && !isset($line['hex'])) {
336
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
337
+			}
338 338
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
339 339
 			$icao = $line['aircraft_icao'];
340 340
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -364,9 +364,9 @@  discard block
 block discarded – undo
364 364
 		}
365 365
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
366 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'])) {
367
+			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
368 368
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
369
-		    } else {
369
+			} else {
370 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 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 372
 				/*
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 				print_r($line);
376 376
 				*/
377 377
 				return '';
378
-		    }
378
+			}
379 379
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
380 380
 			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
381 381
 			return '';
@@ -391,21 +391,21 @@  discard block
 block discarded – undo
391 391
 		}
392 392
 
393 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']));
394
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
395 395
 		}
396 396
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
397
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
397
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
398 398
 		}
399 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'])));
400
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
401 401
 		}
402 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'])));
403
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
404 404
 		}
405 405
  
406 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 407
 
408
-		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
408
+			if ($this->all_flights[$id]['addedSpotter'] == 1) {
409 409
 			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
410 410
 				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
411 411
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
@@ -414,23 +414,23 @@  discard block
 block discarded – undo
414 414
 				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
415 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 416
 			} else {
417
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
418
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
417
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
418
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
419 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';
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 424
 				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
425 425
 				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
426 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']);
427
+						$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource,$this->all_flights[$id]['source_type']);
428 428
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
429 429
 				$Spotter->db = null;
430 430
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
431
-			    }
431
+				}
432 432
 			}
433
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
433
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
434 434
 		    
435 435
 /*
436 436
 		    if (!isset($line['id'])) {
@@ -440,63 +440,63 @@  discard block
 block discarded – undo
440 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 441
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
442 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']));
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 444
 
445
-		    //$putinarchive = true;
446
-		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
445
+			//$putinarchive = true;
446
+			if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
447 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) {
448
+			}
449
+			if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
450 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'])) {
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 455
 			$timeelapsed = microtime(true);
456 456
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
457 457
 				$Spotter = new Spotter($this->db);
458 458
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
459 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' => ''));
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 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') {
462
+						}
463
+			} elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
464 464
 			$timeelapsed = microtime(true);
465 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'])) {
466
+				$Spotter = new Spotter($this->db);
467
+				$route = $Spotter->getRouteInfo(trim($line['ident']));
468
+				if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) {
469 469
 				$Translation = new Translation($this->db);
470 470
 				$ident = $Translation->checkTranslation(trim($line['ident']));
471 471
 				$route = $Spotter->getRouteInfo($ident);
472 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
-                    	}
473
+				}
474
+				$Spotter->db = null;
475
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
476
+						}
477 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']) {
478
+				//if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
479
+				if ($route['fromairport_icao'] != $route['toairport_icao']) {
480 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
-		    	    }
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 483
 			}
484 484
 			if (!isset($globalFork)) $globalFork = TRUE;
485 485
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
486 486
 				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
487 487
 			}
488
-		    }
488
+			}
489 489
 		}
490 490
 
491 491
 		if (isset($line['speed']) && $line['speed'] != '' && $line['speed'] != 0) {
492 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;
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 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
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 500
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
501 501
 			$speed = $speed*3.6;
502 502
 			if ($speed < 1000) {
@@ -505,49 +505,49 @@  discard block
 block discarded – undo
505 505
 	  		} else {
506 506
 	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
507 507
 	  		}
508
-		    }
508
+			}
509 509
 		}
510 510
 
511 511
 
512 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
-	    	    	|| $timediff > $globalLiveInterval
541
-	    	    	|| $globalArchive
542
-	    	    	|| ($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
-	    	    	) {
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
+					|| $timediff > $globalLiveInterval
541
+					|| $globalArchive
542
+					|| ($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 548
 
549 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)
550
+				if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
551 551
 				|| (isset($line['format_source']) && $line['format_source'] == 'airwhere') 
552 552
 				|| !$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'])) {
553 553
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -556,9 +556,9 @@  discard block
 block discarded – undo
556 556
 				if ($this->tmd > 5 && $this->all_flights[$id]['putinarchive'] == 1) $updateinitial = true;
557 557
 				$this->tmd = 0;
558 558
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
559
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
560
-				    $timeelapsed = microtime(true);
561
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
559
+					if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
560
+					$timeelapsed = microtime(true);
561
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
562 562
 					$Spotter = new Spotter($this->db);
563 563
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
564 564
 					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
@@ -566,11 +566,11 @@  discard block
 block discarded – undo
566 566
 					$Spotter->db = null;
567 567
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
568 568
 					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
569
-				    }
569
+					}
570 570
 				}
571 571
 				$this->all_flights[$id]['time_last_archive_coord'] = time();
572
-			    } 
573
-			    /*
572
+				} 
573
+				/*
574 574
 			    else {
575 575
 				if (!isset($timediff)) echo 'NO TIMEDIFF';
576 576
 				else {
@@ -584,16 +584,16 @@  discard block
 block discarded – undo
584 584
 			}
585 585
 
586 586
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
587
-			    //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) {
587
+				//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) {
588 588
 				if (!isset($this->all_flights[$id]['archive_latitude'])) {
589 589
 					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
590 590
 					$this->all_flights[$id]['time_last_coord'] = time();
591 591
 				}
592 592
 				//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)) {
593 593
 				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)) {
594
-				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
595
-				    $dataFound = true;
596
-				    $this->all_flights[$id]['time_last_coord'] = time();
594
+					$this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
595
+					$dataFound = true;
596
+					$this->all_flights[$id]['time_last_coord'] = time();
597 597
 				}
598 598
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
599 599
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
@@ -604,25 +604,25 @@  discard block
 block discarded – undo
604 604
 				    //$putinarchive = true;
605 605
 				}
606 606
 				*/
607
-			    /*
607
+				/*
608 608
 			    } elseif (isset($this->all_flights[$id]['latitude'])) {
609 609
 				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";
610 610
 			    }
611 611
 			    */
612 612
 			}
613 613
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
614
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
615
-			    //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) {
614
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
615
+				//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) {
616 616
 				if (!isset($this->all_flights[$id]['archive_longitude'])) {
617 617
 					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
618 618
 					$this->all_flights[$id]['time_last_coord'] = time();
619 619
 				}
620 620
 				//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)) {
621 621
 				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)) {
622
-				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
623
-				    $dataFound = true;
624
-				    $this->all_flights[$id]['coordinates'] += 1;
625
-				    $this->all_flights[$id]['time_last_coord'] = time();
622
+					$this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
623
+					$dataFound = true;
624
+					$this->all_flights[$id]['coordinates'] += 1;
625
+					$this->all_flights[$id]['time_last_coord'] = time();
626 626
 				}
627 627
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
628 628
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
@@ -640,76 +640,76 @@  discard block
 block discarded – undo
640 640
 			    */
641 641
 			}
642 642
 			if ($globalDaemon === TRUE && isset($updateinitial) && $updateinitial && $this->all_flights[$id]['addedSpotter'] == 1) {
643
-			    if ($globalDebug) echo '>>> Update initial data !'."\n";
644
-			    unset($updateinitial);
645
-			    $SpotterArchive = new SpotterArchive();
646
-			    $SpotterArchive->deleteSpotterArchiveTrackDataByID($this->all_flights[$id]['id']);
647
-			    $SpotterArchive->db = null;
648
-			    $Spotter = new Spotter();
649
-			    $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']);
650
-			    $Spotter->db = null;
643
+				if ($globalDebug) echo '>>> Update initial data !'."\n";
644
+				unset($updateinitial);
645
+				$SpotterArchive = new SpotterArchive();
646
+				$SpotterArchive->deleteSpotterArchiveTrackDataByID($this->all_flights[$id]['id']);
647
+				$SpotterArchive->db = null;
648
+				$Spotter = new Spotter();
649
+				$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']);
650
+				$Spotter->db = null;
651 651
 			}
652
-		    } else if ($globalDebug && $timediff > 30) {
652
+			} else if ($globalDebug && $timediff > 30) {
653 653
 			$this->tmd = $this->tmd + 1;
654 654
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
655 655
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
656 656
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
657 657
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
658
-		    }
658
+			}
659 659
 		}
660 660
 		if (isset($line['last_update']) && $line['last_update'] != '') {
661
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
662
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
661
+			if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
662
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
663 663
 		}
664 664
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
665
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
666
-		    //$dataFound = true;
665
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
666
+			//$dataFound = true;
667 667
 		}
668 668
 		if (isset($line['format_source']) && $line['format_source'] != '') {
669
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
669
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
670 670
 		}
671 671
 		if (isset($line['source_name']) && $line['source_name'] != '') {
672
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
672
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
673 673
 		}
674 674
 		if (isset($line['emergency']) && $line['emergency'] != '') {
675
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
676
-		    //$dataFound = true;
675
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
676
+			//$dataFound = true;
677 677
 		}
678 678
 		if (isset($line['ground']) && $line['ground'] != '') {
679
-		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
679
+			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
680 680
 			// Here we force archive of flight because after ground it's a new one (or should be)
681 681
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
682 682
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
683 683
 			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')));
684
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
684
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
685 685
 			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']));
686
-		    }
687
-		    if ($line['ground'] != 1) $line['ground'] = 0;
688
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
689
-		    //$dataFound = true;
686
+			}
687
+			if ($line['ground'] != 1) $line['ground'] = 0;
688
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
689
+			//$dataFound = true;
690 690
 		}
691 691
 		if (isset($line['squawk']) && $line['squawk'] != '') {
692
-		    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'])) {
693
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
694
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
695
-			    $highlight = '';
696
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
697
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
698
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
699
-			    if ($highlight != '') {
692
+			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'])) {
693
+				if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
694
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
695
+				$highlight = '';
696
+				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
697
+				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
698
+				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
699
+				if ($highlight != '') {
700 700
 				$timeelapsed = microtime(true);
701 701
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
702
-				    $Spotter = new Spotter($this->db);
703
-				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
704
-				    $Spotter->db = null;
705
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
702
+					$Spotter = new Spotter($this->db);
703
+					$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
704
+					$Spotter->db = null;
705
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
706 706
 				}
707 707
 				//$putinarchive = true;
708 708
 				//$highlight = '';
709
-			    }
709
+				}
710 710
 			    
711
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
712
-		    //$dataFound = true;
711
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
712
+			//$dataFound = true;
713 713
 		}
714 714
 
715 715
 		if (isset($line['altitude']) && $line['altitude'] != '') {
@@ -720,13 +720,13 @@  discard block
 block discarded – undo
720 720
 					$line['altitude'] = $line['altitude'] - $geoid;
721 721
 				}
722 722
 			}
723
-		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
723
+			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
724 724
 			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;
725 725
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
726 726
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
727 727
 			//$dataFound = true;
728
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
729
-		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
728
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
729
+			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
730 730
 			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) {
731 731
 				if ($globalDebug) echo '--- Reset because of altitude'."\n";
732 732
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
@@ -735,27 +735,27 @@  discard block
 block discarded – undo
735 735
 				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
736 736
 				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']));
737 737
 			}
738
-		    }
739
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
738
+			}
739
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
740 740
 		}
741 741
 
742 742
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
743
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
743
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
744 744
 		}
745 745
 		
746 746
 		if (isset($line['heading']) && $line['heading'] != '') {
747
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
748
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
749
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
750
-		    //$dataFound = true;
747
+			if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
748
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
749
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
750
+			//$dataFound = true;
751 751
   		} 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']) {
752
-  		    $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']);
753
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
754
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
755
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
752
+  			$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']);
753
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
754
+			if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
755
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
756 756
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
757
-  		    // If not enough messages and ACARS set heading to 0
758
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
757
+  			// If not enough messages and ACARS set heading to 0
758
+  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
759 759
   		}
760 760
 		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
761 761
 		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
@@ -768,133 +768,133 @@  discard block
 block discarded – undo
768 768
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
769 769
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
770 770
 		if ($dataFound === true && isset($this->all_flights[$id]['id'])) {
771
-		    $this->all_flights[$id]['lastupdate'] = time();
772
-		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
773
-		        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'])) {
774
-			    //print_r($this->all_flights);
775
-			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
776
-			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
777
-			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
771
+			$this->all_flights[$id]['lastupdate'] = time();
772
+			if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
773
+				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'])) {
774
+				//print_r($this->all_flights);
775
+				//echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
776
+				//$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
777
+				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
778 778
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
779
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
780
-				    $timeelapsed = microtime(true);
781
-				    $SpotterLive = new SpotterLive($this->db);
782
-				    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')) {
779
+					if ($globalDebug) echo "Check if aircraft is already in DB...";
780
+					$timeelapsed = microtime(true);
781
+					$SpotterLive = new SpotterLive($this->db);
782
+					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')) {
783 783
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
784 784
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
785
-				    } elseif (isset($line['id'])) {
785
+					} elseif (isset($line['id'])) {
786 786
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
787 787
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
788
-				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
788
+					} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
789 789
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
790 790
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
791
-				    } else $recent_ident = '';
792
-				    $SpotterLive->db=null;
793
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
794
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
791
+					} else $recent_ident = '';
792
+					$SpotterLive->db=null;
793
+					if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
794
+					elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
795 795
 				} else $recent_ident = '';
796
-			    } else {
796
+				} else {
797 797
 				$recent_ident = '';
798 798
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
799
-			    }
800
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
801
-			    if($recent_ident == "")
802
-			    {
799
+				}
800
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
801
+				if($recent_ident == "")
802
+				{
803 803
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
804 804
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
805 805
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
806 806
 				//adds the spotter data for the archive
807 807
 				$ignoreImport = false;
808 808
 				foreach($globalAirportIgnore as $airportIgnore) {
809
-				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
809
+					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
810 810
 					$ignoreImport = true;
811
-				    }
811
+					}
812 812
 				}
813 813
 				if (count($globalAirportAccept) > 0) {
814
-				    $ignoreImport = true;
815
-				    foreach($globalAirportIgnore as $airportIgnore) {
814
+					$ignoreImport = true;
815
+					foreach($globalAirportIgnore as $airportIgnore) {
816 816
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
817
-					    $ignoreImport = false;
817
+						$ignoreImport = false;
818
+					}
818 819
 					}
819
-				    }
820 820
 				}
821 821
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
822
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
822
+					foreach($globalAirlineIgnore as $airlineIgnore) {
823 823
 					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)) {
824
-					    $ignoreImport = true;
824
+						$ignoreImport = true;
825
+					}
825 826
 					}
826
-				    }
827 827
 				}
828 828
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
829
-				    $ignoreImport = true;
830
-				    foreach($globalAirlineAccept as $airlineAccept) {
829
+					$ignoreImport = true;
830
+					foreach($globalAirlineAccept as $airlineAccept) {
831 831
 					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)) {
832
-					    $ignoreImport = false;
832
+						$ignoreImport = false;
833
+					}
833 834
 					}
834
-				    }
835 835
 				}
836 836
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
837
-				    $ignoreImport = true;
838
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
837
+					$ignoreImport = true;
838
+					foreach($globalPilotIdAccept as $pilotIdAccept) {
839 839
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
840
-					    $ignoreImport = false;
840
+						$ignoreImport = false;
841
+					}
841 842
 					}
842
-				    }
843 843
 				}
844 844
 				
845 845
 				if (!$ignoreImport) {
846
-				    $highlight = '';
847
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
848
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
849
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
850
-				    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')));
851
-				    $timeelapsed = microtime(true);
852
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
846
+					$highlight = '';
847
+					if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
848
+					if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
849
+					if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
850
+					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')));
851
+					$timeelapsed = microtime(true);
852
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
853 853
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
854
-					    $Spotter = new Spotter($this->db);
855
-					    $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']);
856
-					    $Spotter->db = null;
857
-					    if ($globalDebug) {
854
+						$Spotter = new Spotter($this->db);
855
+						$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']);
856
+						$Spotter->db = null;
857
+						if ($globalDebug) {
858 858
 						if (isset($result['error'])) echo 'Error: '.$result['error']."\n";
859 859
 						else echo 'Success';
860
-					    }
861
-					    if (count($result) > 1) {
862
-					    // ':airline_name' => $airline_name,':airline_icao' => $airline_icao,':airline_country' => $airline_country,':airline_type' => $airline_type,
860
+						}
861
+						if (count($result) > 1) {
862
+						// ':airline_name' => $airline_name,':airline_icao' => $airline_icao,':airline_country' => $airline_country,':airline_type' => $airline_type,
863 863
 						if ($this->all_flights[$id]['aircraft_icao'] == '') $this->all_flights[$id]['aircraft_icao'] = $result[':aircraft_icao'];
864 864
 						if ($this->all_flights[$id]['registration'] == '') $this->all_flights[$id]['registration'] = $result[':registration'];
865
-					    }
865
+						}
866 866
 					}
867
-				    }
868
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
869
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
867
+					}
868
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
869
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
870 870
 
871
-				    // Add source stat in DB
872
-				    $Stats = new Stats($this->db);
873
-				    if (!empty($this->stats)) {
871
+					// Add source stat in DB
872
+					$Stats = new Stats($this->db);
873
+					if (!empty($this->stats)) {
874 874
 					if ($globalDebug) echo 'Add source stats : ';
875
-				        foreach($this->stats as $date => $data) {
876
-					    foreach($data as $source => $sourced) {
877
-					        //print_r($sourced);
878
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
879
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
880
-				    		if (isset($sourced['msg'])) {
881
-				    		    if (time() - $sourced['msg']['date'] > 10) {
882
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
883
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
884
-			    			        unset($this->stats[$date][$source]['msg']);
885
-			    			    }
886
-			    			}
887
-			    		    }
888
-			    		    if ($date != date('Y-m-d')) {
889
-			    			unset($this->stats[$date]);
890
-			    		    }
891
-				    	}
892
-				    	if ($globalDebug) echo 'Done'."\n";
875
+						foreach($this->stats as $date => $data) {
876
+						foreach($data as $source => $sourced) {
877
+							//print_r($sourced);
878
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
879
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
880
+							if (isset($sourced['msg'])) {
881
+								if (time() - $sourced['msg']['date'] > 10) {
882
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
883
+									echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
884
+									unset($this->stats[$date][$source]['msg']);
885
+								}
886
+							}
887
+							}
888
+							if ($date != date('Y-m-d')) {
889
+							unset($this->stats[$date]);
890
+							}
891
+						}
892
+						if ($globalDebug) echo 'Done'."\n";
893 893
 
894
-				    }
895
-				    $Stats->db = null;
896
-				    }
897
-				    $this->del();
894
+					}
895
+					$Stats->db = null;
896
+					}
897
+					$this->del();
898 898
 				} elseif ($globalDebug) echo 'Ignore data'."\n";
899 899
 				//$ignoreImport = false;
900 900
 				$this->all_flights[$id]['addedSpotter'] = 1;
@@ -912,41 +912,41 @@  discard block
 block discarded – undo
912 912
 			*/
913 913
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
914 914
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
915
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
916
-				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
917
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
915
+					if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
916
+					//SpotterLive->deleteLiveSpotterDataNotUpdated();
917
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
918 918
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
919
-					    $SpotterLive = new SpotterLive($this->db);
920
-					    $SpotterLive->deleteLiveSpotterData();
921
-					    $SpotterLive->db=null;
919
+						$SpotterLive = new SpotterLive($this->db);
920
+						$SpotterLive->deleteLiveSpotterData();
921
+						$SpotterLive->db=null;
922 922
 					}
923
-				    }
924
-				    if ($globalDebug) echo " Done\n";
925
-				    $this->last_delete = time();
923
+					}
924
+					if ($globalDebug) echo " Done\n";
925
+					$this->last_delete = time();
926 926
 				}
927
-			    } else {
927
+				} else {
928 928
 				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')) {
929
-				    $this->all_flights[$id]['id'] = $recent_ident;
930
-				    $this->all_flights[$id]['addedSpotter'] = 1;
929
+					$this->all_flights[$id]['id'] = $recent_ident;
930
+					$this->all_flights[$id]['addedSpotter'] = 1;
931 931
 				}
932 932
 				if (isset($globalDaemon) && !$globalDaemon) {
933
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
933
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
934 934
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
935
-					    $Spotter = new Spotter($this->db);
936
-					    $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']);
937
-					    $Spotter->db = null;
935
+						$Spotter = new Spotter($this->db);
936
+						$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']);
937
+						$Spotter->db = null;
938
+					}
938 939
 					}
939
-				    }
940 940
 				}
941 941
 				
942
-			    }
942
+				}
943 943
 			}
944
-		    }
945
-		    //adds the spotter LIVE data
946
-		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
947
-		    //echo "\nAdd in Live !! \n";
948
-		    //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";
949
-		    if ($globalDebug) {
944
+			}
945
+			//adds the spotter LIVE data
946
+			//SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
947
+			//echo "\nAdd in Live !! \n";
948
+			//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";
949
+			if ($globalDebug) {
950 950
 			if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
951 951
 				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";
952 952
 				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";
@@ -954,60 +954,60 @@  discard block
 block discarded – undo
954 954
 				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";
955 955
 				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";
956 956
 			}
957
-		    }
958
-		    $ignoreImport = false;
959
-		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
960
-		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
957
+			}
958
+			$ignoreImport = false;
959
+			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
960
+			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
961 961
 
962
-		    foreach($globalAirportIgnore as $airportIgnore) {
963
-		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
964
-			    $ignoreImport = true;
962
+			foreach($globalAirportIgnore as $airportIgnore) {
963
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
964
+				$ignoreImport = true;
965
+			}
965 966
 			}
966
-		    }
967
-		    if (count($globalAirportAccept) > 0) {
968
-		        $ignoreImport = true;
969
-		        foreach($globalAirportIgnore as $airportIgnore) {
970
-			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
967
+			if (count($globalAirportAccept) > 0) {
968
+				$ignoreImport = true;
969
+				foreach($globalAirportIgnore as $airportIgnore) {
970
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
971 971
 				$ignoreImport = false;
972
-			    }
972
+				}
973 973
 			}
974
-		    }
975
-		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
974
+			}
975
+			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
976 976
 			foreach($globalAirlineIgnore as $airlineIgnore) {
977
-			    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)) {
977
+				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)) {
978 978
 				$ignoreImport = true;
979
-			    }
979
+				}
980 980
 			}
981
-		    }
982
-		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
981
+			}
982
+			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
983 983
 			$ignoreImport = true;
984 984
 			foreach($globalAirlineAccept as $airlineAccept) {
985
-			    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)) {
985
+				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)) {
986 986
 				$ignoreImport = false;
987
-			    }
987
+				}
988
+			}
988 989
 			}
989
-		    }
990
-		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
990
+			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
991 991
 			$ignoreImport = true;
992 992
 			foreach($globalPilotIdAccept as $pilotIdAccept) {
993
-			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
994
-			        $ignoreImport = false;
995
-			    }
993
+				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
994
+					$ignoreImport = false;
995
+				}
996
+			}
996 997
 			}
997
-		    }
998 998
 
999
-		    if (!$ignoreImport) {
999
+			if (!$ignoreImport) {
1000 1000
 			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'])) {
1001 1001
 				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')));
1002 1002
 				$timeelapsed = microtime(true);
1003 1003
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
1004
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
1004
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
1005 1005
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1006 1006
 					$SpotterLive = new SpotterLive($this->db);
1007 1007
 					$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']);
1008 1008
 					$SpotterLive->db = null;
1009 1009
 					if ($globalDebug) echo $result."\n";
1010
-				    }
1010
+					}
1011 1011
 				}
1012 1012
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
1013 1013
 					$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']);
@@ -1019,7 +1019,7 @@  discard block
 block discarded – undo
1019 1019
 				//if ($line['format_source'] != 'aprs') {
1020 1020
 				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
1021 1021
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
1022
-				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
1022
+					if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
1023 1023
 					$source = $this->all_flights[$id]['source_name'];
1024 1024
 					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1025 1025
 					if (!isset($this->source_location[$source])) {
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
 					if ($stats_heading == 16) $stats_heading = 0;
1046 1046
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
1047 1047
 						for ($i=0;$i<=15;$i++) {
1048
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
1048
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
1049 1049
 						}
1050 1050
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
1051 1051
 					} else {
@@ -1058,17 +1058,17 @@  discard block
 block discarded – undo
1058 1058
 					//var_dump($this->stats);
1059 1059
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
1060 1060
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1061
-						    end($this->stats[$current_date][$source]['hist']);
1062
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1061
+							end($this->stats[$current_date][$source]['hist']);
1062
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
1063 1063
 						} else $mini = 0;
1064 1064
 						for ($i=$mini;$i<=$distance;$i+=10) {
1065
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1065
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
1066 1066
 						}
1067 1067
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
1068 1068
 					} else {
1069 1069
 						$this->stats[$current_date][$source]['hist'][$distance] += 1;
1070 1070
 					}
1071
-				    }
1071
+					}
1072 1072
 				}
1073 1073
 
1074 1074
 				$this->all_flights[$id]['lastupdate'] = time();
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
 			//$this->del();
1079 1079
 			
1080 1080
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
1081
-			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1081
+				if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1082 1082
 				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1083 1083
 				$SpotterLive = new SpotterLive($this->db);
1084 1084
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
@@ -1086,19 +1086,19 @@  discard block
 block discarded – undo
1086 1086
 				//SpotterLive->deleteLiveSpotterData();
1087 1087
 				if ($globalDebug) echo " Done\n";
1088 1088
 				$this->last_delete_hourly = time();
1089
-			    } else {
1089
+				} else {
1090 1090
 				$this->del();
1091 1091
 				$this->last_delete_hourly = time();
1092
-			    }
1092
+				}
1093 1093
 			}
1094 1094
 			
1095
-		    }
1096
-		    //$ignoreImport = false;
1095
+			}
1096
+			//$ignoreImport = false;
1097 1097
 		}
1098 1098
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
1099 1099
 		if ($send) return $this->all_flights[$id];
1100
-	    }
1100
+		}
1101
+	}
1101 1102
 	}
1102
-    }
1103 1103
 }
1104 1104
 ?>
Please login to merge, or discard this patch.