Completed
Push — master ( 356f6a...2fda11 )
by Yannick
06:02
created
require/class.SpotterImport.php 2 patches
Indentation   +345 added lines, -345 removed lines patch added patch discarded remove patch
@@ -9,16 +9,16 @@  discard block
 block discarded – undo
9 9
 require_once(dirname(__FILE__).'/class.Source.php');
10 10
 
11 11
 class SpotterImport {
12
-    private $all_flights = array();
13
-    private $last_delete_hourly = '';
14
-    private $last_delete = '';
15
-    private $stats = array();
16
-    private $tmd = 0;
17
-    private $source_location = array();
18
-    public $db = null;
19
-    public $nb = 0;
20
-
21
-    public function __construct($dbc = null) {
12
+	private $all_flights = array();
13
+	private $last_delete_hourly = '';
14
+	private $last_delete = '';
15
+	private $stats = array();
16
+	private $tmd = 0;
17
+	private $source_location = array();
18
+	public $db = null;
19
+	public $nb = 0;
20
+
21
+	public function __construct($dbc = null) {
22 22
 	global $globalBeta;
23 23
 	$Connection = new Connection($dbc);
24 24
 	$this->db = $Connection->db();
@@ -29,18 +29,18 @@  discard block
 block discarded – undo
29 29
 	$currentdate = date('Y-m-d');
30 30
 	$sourcestat = $Stats->getStatsSource($currentdate);
31 31
 	if (!empty($sourcestat)) {
32
-	    foreach($sourcestat as $srcst) {
33
-	    	$type = $srcst['stats_type'];
32
+		foreach($sourcestat as $srcst) {
33
+			$type = $srcst['stats_type'];
34 34
 		if ($type == 'polar' || $type == 'hist') {
35
-		    $source = $srcst['source_name'];
36
-		    $data = $srcst['source_data'];
37
-		    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
38
-	        }
39
-	    }
35
+			$source = $srcst['source_name'];
36
+			$data = $srcst['source_data'];
37
+			$this->stats[$currentdate][$source][$type] = json_decode($data,true);
38
+			}
39
+		}
40
+	}
40 41
 	}
41
-    }
42 42
 
43
-    public function get_Schedule($id,$ident) {
43
+	public function get_Schedule($id,$ident) {
44 44
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
45 45
 	// Get schedule here, so it's done only one time
46 46
 	
@@ -58,35 +58,35 @@  discard block
 block discarded – undo
58 58
 	$Translation = new Translation($dbc);
59 59
 	$operator = $Spotter->getOperator($ident);
60 60
 	if ($Schedule->checkSchedule($operator) == 0) {
61
-	    $operator = $Translation->checkTranslation($ident);
62
-	    if ($Schedule->checkSchedule($operator) == 0) {
61
+		$operator = $Translation->checkTranslation($ident);
62
+		if ($Schedule->checkSchedule($operator) == 0) {
63 63
 		$schedule = $Schedule->fetchSchedule($operator);
64 64
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
65
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
66
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
67
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
68
-		    // Should also check if route schedule = route from DB
69
-		    if ($schedule['DepartureAirportIATA'] != '') {
65
+			if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
66
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
67
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
68
+			// Should also check if route schedule = route from DB
69
+			if ($schedule['DepartureAirportIATA'] != '') {
70 70
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
71
-			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
72
-			    if ($airport_icao != '') {
71
+				$airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
72
+				if ($airport_icao != '') {
73 73
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
74 74
 				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
75
-			    }
75
+				}
76
+			}
76 77
 			}
77
-		    }
78
-		    if ($schedule['ArrivalAirportIATA'] != '') {
78
+			if ($schedule['ArrivalAirportIATA'] != '') {
79 79
 			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) {
80
-			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
81
-			    if ($airport_icao != '') {
80
+				$airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
81
+				if ($airport_icao != '') {
82 82
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
83 83
 				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
84
-			    }
84
+				}
85
+			}
85 86
 			}
86
-		    }
87
-		    $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']);
87
+			$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']);
88
+		}
88 89
 		}
89
-	    }
90 90
 	}
91 91
 	// close connection, at least one way will work ?
92 92
        
@@ -104,90 +104,90 @@  discard block
 block discarded – undo
104 104
 	}
105 105
 	  */
106 106
 	}
107
-    }
107
+	}
108 108
 
109
-    public function checkAll() {
109
+	public function checkAll() {
110 110
 	global $globalDebug;
111 111
 	if ($globalDebug) echo "Update last seen flights data...\n";
112 112
 	foreach ($this->all_flights as $key => $flight) {
113
-	    if (isset($this->all_flights[$key]['id'])) {
113
+		if (isset($this->all_flights[$key]['id'])) {
114 114
 		//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
115
-    		$Spotter = new Spotter($this->db);
116
-        	$real_arrival = $this->arrival($key);
117
-        	$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']);
118
-            }
115
+			$Spotter = new Spotter($this->db);
116
+			$real_arrival = $this->arrival($key);
117
+			$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']);
118
+			}
119
+	}
119 120
 	}
120
-    }
121 121
 
122
-    public function arrival($key) {
122
+	public function arrival($key) {
123 123
 	global $globalClosestMinDist, $globalDebug;
124 124
 	$Spotter = new Spotter($this->db);
125
-        $airport_icao = '';
126
-        $airport_time = '';
127
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
125
+		$airport_icao = '';
126
+		$airport_time = '';
127
+		if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
128 128
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
129
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
130
-    	    if (isset($closestAirports[0])) {
131
-        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
132
-        	    $airport_icao = $closestAirports[0]['icao'];
133
-        	    $airport_time = $this->all_flights[$key]['datetime'];
134
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
135
-        	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
136
-        	    foreach ($closestAirports as $airport) {
137
-        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
138
-        		    $airport_icao = $airport['icao'];
139
-        		    $airport_time = $this->all_flights[$key]['datetime'];
140
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
141
-        		    break;
142
-        		}
143
-        	    }
144
-        	} 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))) {
145
-        		$airport_icao = $closestAirports[0]['icao'];
146
-        		$airport_time = $this->all_flights[$key]['datetime'];
147
-        	} else {
148
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
149
-        	}
150
-    	    } else {
151
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
152
-    	    }
153
-
154
-        } else {
155
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
156
-        }
157
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
158
-    }
159
-
160
-
161
-
162
-    public function del() {
129
+		$closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
130
+			if (isset($closestAirports[0])) {
131
+			if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
132
+				$airport_icao = $closestAirports[0]['icao'];
133
+				$airport_time = $this->all_flights[$key]['datetime'];
134
+				if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
135
+			} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
136
+				foreach ($closestAirports as $airport) {
137
+				if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
138
+					$airport_icao = $airport['icao'];
139
+					$airport_time = $this->all_flights[$key]['datetime'];
140
+					if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
141
+					break;
142
+				}
143
+				}
144
+			} 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))) {
145
+				$airport_icao = $closestAirports[0]['icao'];
146
+				$airport_time = $this->all_flights[$key]['datetime'];
147
+			} else {
148
+				if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
149
+			}
150
+			} else {
151
+				if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
152
+			}
153
+
154
+		} else {
155
+			if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
156
+		}
157
+		return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
158
+	}
159
+
160
+
161
+
162
+	public function del() {
163 163
 	global $globalDebug;
164 164
 	// Delete old infos
165 165
 	foreach ($this->all_flights as $key => $flight) {
166
-    	    if (isset($flight['lastupdate'])) {
167
-        	if ($flight['lastupdate'] < (time()-3000)) {
168
-            	    if (isset($this->all_flights[$key]['id'])) {
169
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
166
+			if (isset($flight['lastupdate'])) {
167
+			if ($flight['lastupdate'] < (time()-3000)) {
168
+					if (isset($this->all_flights[$key]['id'])) {
169
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
170 170
 			/*
171 171
 			$SpotterLive = new SpotterLive();
172 172
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
173 173
 			$SpotterLive->db = null;
174 174
 			*/
175
-            		$real_arrival = $this->arrival($key);
176
-            		$Spotter = new Spotter($this->db);
177
-            		if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
175
+					$real_arrival = $this->arrival($key);
176
+					$Spotter = new Spotter($this->db);
177
+					if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
178 178
 				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
179 179
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
180 180
 			}
181 181
 			// Put in archive
182 182
 //			$Spotter->db = null;
183
-            	    }
184
-            	    unset($this->all_flights[$key]);
185
-    	        }
186
-	    }
187
-        }
188
-    }
189
-
190
-    public function add($line) {
183
+					}
184
+					unset($this->all_flights[$key]);
185
+				}
186
+		}
187
+		}
188
+	}
189
+
190
+	public function add($line) {
191 191
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate;
192 192
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
193 193
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
@@ -212,18 +212,18 @@  discard block
 block discarded – undo
212 212
 	
213 213
 	// SBS format is CSV format
214 214
 	if(is_array($line) && isset($line['hex'])) {
215
-	    //print_r($line);
216
-  	    if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) {
215
+		//print_r($line);
216
+  		if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) {
217 217
 
218 218
 		// Increment message number
219 219
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
220
-		    $current_date = date('Y-m-d');
221
-		    $source = $line['source_name'];
222
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
223
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
224
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
225
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
226
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
220
+			$current_date = date('Y-m-d');
221
+			$source = $line['source_name'];
222
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
223
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
224
+				$this->stats[$current_date][$source]['msg']['date'] = time();
225
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
226
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
227 227
 		}
228 228
 		
229 229
 		/*
@@ -239,17 +239,17 @@  discard block
 block discarded – undo
239 239
 		//$this->db = $dbc;
240 240
 
241 241
 		$hex = trim($line['hex']);
242
-	        if (!isset($line['id'])) $id = trim($line['hex']);
243
-	        else $id = trim($line['id']);
242
+			if (!isset($line['id'])) $id = trim($line['hex']);
243
+			else $id = trim($line['id']);
244 244
 		
245 245
 		//print_r($this->all_flights);
246 246
 		if (!isset($this->all_flights[$id]['hex']) && ctype_xdigit($hex)) {
247
-		    $this->all_flights[$id] = array('hex' => $hex);
248
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
249
-		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
247
+			$this->all_flights[$id] = array('hex' => $hex);
248
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
249
+			//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
250 250
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
251
-		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
252
-		    if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????')) {
251
+			//} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
252
+			if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????')) {
253 253
 
254 254
 			$timeelapsed = microtime(true);
255 255
 			$Spotter = new Spotter($this->db);
@@ -258,37 +258,37 @@  discard block
 block discarded – undo
258 258
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
259 259
 
260 260
 			if ($aircraft_icao == '' && isset($line['aircraft_type'])) {
261
-			    if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
262
-			    elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
263
-			    elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
264
-			    elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
261
+				if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
262
+				elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
263
+				elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
264
+				elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
265 265
 			}
266 266
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
267
-		    } else if (isset($line['aircraft_name'])) {
267
+			} else if (isset($line['aircraft_name'])) {
268 268
 			// Get aircraft ICAO from aircraft name
269 269
 			$Spotter = new Spotter($this->db);
270 270
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
271 271
 			$Spotter->db = null;
272 272
 			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
273 273
 			else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
274
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
275
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', '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' => false));
276
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
277
-		    if (!isset($line['id'])) {
274
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
275
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', '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' => false));
276
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
277
+			if (!isset($line['id'])) {
278 278
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
279 279
 //			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')));
280 280
 //			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')));
281 281
 			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' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
282
-		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
283
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
282
+				//else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
283
+			 } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
284 284
 
285
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n";
285
+			if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n";
286 286
 		}
287 287
 		
288 288
 		if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
289
-		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
289
+			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
290 290
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
291
-		    } else {
291
+			} else {
292 292
 				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";
293 293
 				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";
294 294
 				/*
@@ -297,32 +297,32 @@  discard block
 block discarded – undo
297 297
 				print_r($line);
298 298
 				*/
299 299
 				return '';
300
-		    }
300
+			}
301 301
 		} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
302 302
 
303 303
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
304
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
304
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
305 305
 		}
306 306
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
307
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
307
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
308 308
 		}
309 309
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
310
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
310
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
311 311
 		}
312 312
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
313
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
313
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
314 314
 		}
315 315
  
316 316
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
317
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
318
-		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
317
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
318
+			if ($this->all_flights[$id]['addedSpotter'] == 1) {
319 319
 			$timeelapsed = microtime(true);
320
-            		$Spotter = new Spotter($this->db);
321
-            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident']);
320
+					$Spotter = new Spotter($this->db);
321
+					$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident']);
322 322
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
323 323
 			$Spotter->db = null;
324 324
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
325
-		    }
325
+			}
326 326
 
327 327
 /*
328 328
 		    if (!isset($line['id'])) {
@@ -332,26 +332,26 @@  discard block
 block discarded – undo
332 332
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
333 333
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
334 334
   */
335
-		    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']));
335
+			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']));
336 336
 
337
-		    //$putinarchive = true;
338
-		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
337
+			//$putinarchive = true;
338
+			if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
339 339
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
340
-		    }
341
-		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
340
+			}
341
+			if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
342 342
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
343
-		    }
344
-		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
345
-		    		$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' => ''));
346
-		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
343
+			}
344
+			if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
345
+					$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' => ''));
346
+			} elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
347 347
 				$timeelapsed = microtime(true);
348 348
 				$Spotter = new Spotter($this->db);
349 349
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
350 350
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
351
-		    		$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' => ''));
351
+					$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' => ''));
352 352
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
353 353
 
354
-		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
354
+			} elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
355 355
 			$timeelapsed = microtime(true);
356 356
 			$Spotter = new Spotter($this->db);
357 357
 			$route = $Spotter->getRouteInfo(trim($line['ident']));
@@ -365,11 +365,11 @@  discard block
 block discarded – undo
365 365
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
366 366
 
367 367
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
368
-			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
369
-			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
368
+				//if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
369
+				if ($route['fromairport_icao'] != $route['toairport_icao']) {
370 370
 				//    $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']));
371
-		    		$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']));
372
-		    	    }
371
+					$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']));
372
+					}
373 373
 			}
374 374
 			if (!isset($globalFork)) $globalFork = TRUE;
375 375
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
@@ -387,33 +387,33 @@  discard block
 block discarded – undo
387 387
 				$this->get_Schedule($id,trim($line['ident']));
388 388
 			//    }
389 389
 			}
390
-		    }
390
+			}
391 391
 		}
392 392
 
393 393
 		if (isset($line['speed']) && $line['speed'] != '') {
394 394
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
395
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
396
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
397
-		    //$dataFound = true;
395
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
396
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
397
+			//$dataFound = true;
398 398
 		} 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'])) {
399
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
400
-		    if ($distance > 1000 && $distance < 10000) {
401
-		    // use datetime
399
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
400
+			if ($distance > 1000 && $distance < 10000) {
401
+			// use datetime
402 402
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
403 403
 			$speed = $speed*3.6;
404 404
 			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
405 405
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
406
-		    }
406
+			}
407 407
 		}
408 408
 
409 409
 
410 410
 
411
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
412
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
413
-	    	    else unset($timediff);
414
-	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || !isset($timediff) || $timediff > 800 || ($timediff > 10 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
411
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
412
+				if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
413
+				else unset($timediff);
414
+				if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || !isset($timediff) || $timediff > 800 || ($timediff > 10 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
415 415
 			if (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'])) {
416
-			    if (!$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'])) {
416
+				if (!$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'])) {
417 417
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
418 418
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
419 419
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -429,21 +429,21 @@  discard block
 block discarded – undo
429 429
 				$this->tmd = 0;
430 430
 				//echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
431 431
 				//$putinarchive = true;
432
-			    } else {
433
-			    /*
432
+				} else {
433
+				/*
434 434
 				echo '//////// checkLine FALSE'."\n";
435 435
 				echo 'Check DATA : '.$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']."\n";
436 436
 			    */
437
-			    }
437
+				}
438 438
 			}
439 439
 
440 440
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
441
-			    //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) {
441
+				//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) {
442 442
 				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
443 443
 				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') {
444
-				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
445
-				    $dataFound = true;
446
-				    $this->all_flights[$id]['time_last_coord'] = time();
444
+					$this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
445
+					$dataFound = true;
446
+					$this->all_flights[$id]['time_last_coord'] = time();
447 447
 				}
448 448
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
449 449
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
@@ -454,20 +454,20 @@  discard block
 block discarded – undo
454 454
 				    //$putinarchive = true;
455 455
 				}
456 456
 				*/
457
-			    /*
457
+				/*
458 458
 			    } elseif (isset($this->all_flights[$id]['latitude'])) {
459 459
 				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";
460 460
 			    }
461 461
 			    */
462 462
 			}
463 463
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
464
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
465
-			    //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) {
464
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
465
+				//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) {
466 466
 				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
467 467
 				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') {
468
-				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
469
-				    $dataFound = true;
470
-				    $this->all_flights[$id]['time_last_coord'] = time();
468
+					$this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
469
+					$dataFound = true;
470
+					$this->all_flights[$id]['time_last_coord'] = time();
471 471
 				}
472 472
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
473 473
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
@@ -485,49 +485,49 @@  discard block
 block discarded – undo
485 485
 			    */
486 486
 			}
487 487
 
488
-		    } else if ($globalDebug && $timediff > 20) {
488
+			} else if ($globalDebug && $timediff > 20) {
489 489
 			$this->tmd = $this->tmd + 1;
490 490
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
491 491
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
492 492
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
493 493
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
494
-		    }
494
+			}
495 495
 		}
496 496
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
497
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
498
-		    //$dataFound = true;
497
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
498
+			//$dataFound = true;
499 499
 		}
500 500
 		if (isset($line['format_source']) && $line['format_source'] != '') {
501
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
501
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
502 502
 		}
503 503
 		if (isset($line['source_name']) && $line['source_name'] != '') {
504
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
504
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
505 505
 		}
506 506
 		if (isset($line['emergency']) && $line['emergency'] != '') {
507
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
508
-		    //$dataFound = true;
507
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
508
+			//$dataFound = true;
509 509
 		}
510 510
 		if (isset($line['ground']) && $line['ground'] != '') {
511
-		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
511
+			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
512 512
 			// Here we force archive of flight because after ground it's a new one (or should be)
513 513
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
514 514
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
515 515
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
516
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
516
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
517 517
 			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']));
518
-		    }
519
-		    if ($line['ground'] != 1) $line['ground'] = 0;
520
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
521
-		    //$dataFound = true;
518
+			}
519
+			if ($line['ground'] != 1) $line['ground'] = 0;
520
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
521
+			//$dataFound = true;
522 522
 		}
523 523
 		if (isset($line['squawk']) && $line['squawk'] != '') {
524
-		    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'])) {
525
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
526
-			    $highlight = '';
527
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
528
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
529
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
530
-			    if ($highlight != '') {
524
+			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'])) {
525
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
526
+				$highlight = '';
527
+				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
528
+				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
529
+				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
530
+				if ($highlight != '') {
531 531
 				$timeelapsed = microtime(true);
532 532
 				$Spotter = new Spotter($this->db);
533 533
 				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
@@ -537,38 +537,38 @@  discard block
 block discarded – undo
537 537
 				$this->all_flights[$id]['putinarchive'] = true;
538 538
 				//$putinarchive = true;
539 539
 				$highlight = '';
540
-			    }
540
+				}
541 541
 			    
542
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
543
-		    //$dataFound = true;
542
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
543
+			//$dataFound = true;
544 544
 		}
545 545
 
546 546
 		if (isset($line['altitude']) && $line['altitude'] != '') {
547
-		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
547
+			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
548 548
 			if (abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 2) $this->all_flights[$id]['putinarchive'] = true;
549 549
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
550 550
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
551 551
 			//$dataFound = true;
552
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
552
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
553 553
   		}
554 554
 
555 555
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
556
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
556
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
557 557
 		}
558 558
 		
559 559
 		if (isset($line['heading']) && $line['heading'] != '') {
560
-		    if (abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true;
561
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
562
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
563
-		    //$dataFound = true;
560
+			if (abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true;
561
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
562
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
563
+			//$dataFound = true;
564 564
   		} 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']) {
565
-  		    $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']);
566
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
567
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true;
568
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
565
+  			$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']);
566
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
567
+			if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true;
568
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
569 569
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
570
-  		    // If not enough messages and ACARS set heading to 0
571
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
570
+  			// If not enough messages and ACARS set heading to 0
571
+  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
572 572
   		}
573 573
 		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
574 574
 		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
@@ -578,118 +578,118 @@  discard block
 block discarded – undo
578 578
 		//if (time()-$this->all_flights[$id]['lastupdate'] > 30 && $dataFound == true && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
579 579
 		//if ($dataFound == true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
580 580
 		if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
581
-		    $this->all_flights[$id]['lastupdate'] = time();
582
-		    if ($this->all_flights[$id]['addedSpotter'] == 0) {
583
-		        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'])) {
584
-			    //print_r($this->all_flights);
585
-			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
586
-			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
587
-			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
581
+			$this->all_flights[$id]['lastupdate'] = time();
582
+			if ($this->all_flights[$id]['addedSpotter'] == 0) {
583
+				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'])) {
584
+				//print_r($this->all_flights);
585
+				//echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
586
+				//$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
587
+				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
588 588
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
589 589
 				$timeelapsed = microtime(true);
590 590
 				$SpotterLive = new SpotterLive($this->db);
591 591
 				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' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
592
-				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
593
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
592
+					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
593
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
594 594
 
595 595
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
596
-				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
597
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
596
+					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
597
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
598 598
 
599 599
 				} else $recent_ident = '';
600 600
 				$SpotterLive->db=null;
601 601
 
602 602
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
603 603
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
604
-			    } else {
604
+				} else {
605 605
 				$recent_ident = '';
606 606
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
607
-			    }
608
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
609
-			    if($recent_ident == "")
610
-			    {
607
+				}
608
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
609
+				if($recent_ident == "")
610
+				{
611 611
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
612 612
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
613 613
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
614 614
 				//adds the spotter data for the archive
615 615
 				$ignoreImport = false;
616 616
 				foreach($globalAirportIgnore as $airportIgnore) {
617
-				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
617
+					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
618 618
 					$ignoreImport = true;
619
-				    }
619
+					}
620 620
 				}
621 621
 				if (count($globalAirportAccept) > 0) {
622
-				    $ignoreImport = true;
623
-				    foreach($globalAirportIgnore as $airportIgnore) {
622
+					$ignoreImport = true;
623
+					foreach($globalAirportIgnore as $airportIgnore) {
624 624
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
625
-					    $ignoreImport = false;
625
+						$ignoreImport = false;
626
+					}
626 627
 					}
627
-				    }
628 628
 				}
629 629
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
630
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
630
+					foreach($globalAirlineIgnore as $airlineIgnore) {
631 631
 					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)) {
632
-					    $ignoreImport = true;
632
+						$ignoreImport = true;
633
+					}
633 634
 					}
634
-				    }
635 635
 				}
636 636
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
637
-				    $ignoreImport = true;
638
-				    foreach($globalAirlineAccept as $airlineAccept) {
637
+					$ignoreImport = true;
638
+					foreach($globalAirlineAccept as $airlineAccept) {
639 639
 					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)) {
640
-					    $ignoreImport = false;
640
+						$ignoreImport = false;
641
+					}
641 642
 					}
642
-				    }
643 643
 				}
644 644
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
645
-				    $ignoreImport = true;
646
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
645
+					$ignoreImport = true;
646
+					foreach($globalPilotIdAccept as $pilotIdAccept) {
647 647
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
648
-					    $ignoreImport = false;
648
+						$ignoreImport = false;
649
+					}
649 650
 					}
650
-				    }
651 651
 				}
652 652
 				
653 653
 				if (!$ignoreImport) {
654
-				    $highlight = '';
655
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
656
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
657
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
658
-				    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')));
659
-				    $timeelapsed = microtime(true);
660
-				    $Spotter = new Spotter($this->db);
661
-				    $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]['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']);
662
-				    $Spotter->db = null;
663
-				    if ($globalDebug && isset($result)) echo $result."\n";
664
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
654
+					$highlight = '';
655
+					if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
656
+					if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
657
+					if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
658
+					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')));
659
+					$timeelapsed = microtime(true);
660
+					$Spotter = new Spotter($this->db);
661
+					$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]['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']);
662
+					$Spotter->db = null;
663
+					if ($globalDebug && isset($result)) echo $result."\n";
664
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
665 665
 				    
666
-				    // Add source stat in DB
667
-				    $Stats = new Stats($this->db);
668
-				    if (!empty($this->stats)) {
666
+					// Add source stat in DB
667
+					$Stats = new Stats($this->db);
668
+					if (!empty($this->stats)) {
669 669
 					if ($globalDebug) echo 'Add source stats : ';
670
-				        foreach($this->stats as $date => $data) {
671
-					    foreach($data as $source => $sourced) {
672
-					        //print_r($sourced);
673
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
674
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
675
-				    		if (isset($sourced['msg'])) {
676
-				    		    if (time() - $sourced['msg']['date'] > 10) {
677
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
678
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
679
-			    			        unset($this->stats[$date][$source]['msg']);
680
-			    			    }
681
-			    			}
682
-			    		    }
683
-			    		    if ($date != date('Y-m-d')) {
684
-			    			unset($this->stats[$date]);
685
-			    		    }
686
-				    	}
687
-				    	if ($globalDebug) echo 'Done'."\n";
688
-
689
-				    }
690
-				    $Stats->db = null;
670
+						foreach($this->stats as $date => $data) {
671
+						foreach($data as $source => $sourced) {
672
+							//print_r($sourced);
673
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
674
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
675
+							if (isset($sourced['msg'])) {
676
+								if (time() - $sourced['msg']['date'] > 10) {
677
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
678
+									echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
679
+									unset($this->stats[$date][$source]['msg']);
680
+								}
681
+							}
682
+							}
683
+							if ($date != date('Y-m-d')) {
684
+							unset($this->stats[$date]);
685
+							}
686
+						}
687
+						if ($globalDebug) echo 'Done'."\n";
688
+
689
+					}
690
+					$Stats->db = null;
691 691
 				    
692
-				    $this->del();
692
+					$this->del();
693 693
 				} elseif ($globalDebug) echo 'Ignore data'."\n";
694 694
 				$ignoreImport = false;
695 695
 				$this->all_flights[$id]['addedSpotter'] = 1;
@@ -707,18 +707,18 @@  discard block
 block discarded – undo
707 707
 			*/
708 708
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
709 709
 				if ($this->last_delete == '' || time() - $this->last_delete > 1800) {
710
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
711
-				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
712
-				    $SpotterLive = new SpotterLive($this->db);
713
-				    $SpotterLive->deleteLiveSpotterData();
714
-				    $SpotterLive->db=null;
715
-				    if ($globalDebug) echo " Done\n";
716
-				    $this->last_delete = time();
710
+					if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
711
+					//SpotterLive->deleteLiveSpotterDataNotUpdated();
712
+					$SpotterLive = new SpotterLive($this->db);
713
+					$SpotterLive->deleteLiveSpotterData();
714
+					$SpotterLive->db=null;
715
+					if ($globalDebug) echo " Done\n";
716
+					$this->last_delete = time();
717 717
 				}
718
-			    } else {
718
+				} else {
719 719
 				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' || $line['format_source'] === 'aircraftlistjson')) {
720
-				    $this->all_flights[$id]['id'] = $recent_ident;
721
-				    $this->all_flights[$id]['addedSpotter'] = 1;
720
+					$this->all_flights[$id]['id'] = $recent_ident;
721
+					$this->all_flights[$id]['addedSpotter'] = 1;
722 722
 				}
723 723
 				if (isset($globalDaemon) && !$globalDaemon) {
724 724
 					$Spotter = new Spotter($this->db);
@@ -726,14 +726,14 @@  discard block
 block discarded – undo
726 726
 					$Spotter->db = null;
727 727
 				}
728 728
 				
729
-			    }
729
+				}
730
+			}
730 731
 			}
731
-		    }
732
-		    //adds the spotter LIVE data
733
-		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
734
-		    //echo "\nAdd in Live !! \n";
735
-		    //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";
736
-		    if ($globalDebug) {
732
+			//adds the spotter LIVE data
733
+			//SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
734
+			//echo "\nAdd in Live !! \n";
735
+			//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";
736
+			if ($globalDebug) {
737 737
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS)) {
738 738
 				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";
739 739
 				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";
@@ -741,49 +741,49 @@  discard block
 block discarded – undo
741 741
 				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";
742 742
 				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";
743 743
 			}
744
-		    }
745
-		    $ignoreImport = false;
746
-		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
747
-		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
744
+			}
745
+			$ignoreImport = false;
746
+			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
747
+			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
748 748
 
749
-		    foreach($globalAirportIgnore as $airportIgnore) {
750
-		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
751
-			    $ignoreImport = true;
749
+			foreach($globalAirportIgnore as $airportIgnore) {
750
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
751
+				$ignoreImport = true;
752
+			}
752 753
 			}
753
-		    }
754
-		    if (count($globalAirportAccept) > 0) {
755
-		        $ignoreImport = true;
756
-		        foreach($globalAirportIgnore as $airportIgnore) {
757
-			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
754
+			if (count($globalAirportAccept) > 0) {
755
+				$ignoreImport = true;
756
+				foreach($globalAirportIgnore as $airportIgnore) {
757
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
758 758
 				$ignoreImport = false;
759
-			    }
759
+				}
760
+			}
760 761
 			}
761
-		    }
762
-		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
762
+			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
763 763
 			foreach($globalAirlineIgnore as $airlineIgnore) {
764
-			    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)) {
764
+				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)) {
765 765
 				$ignoreImport = true;
766
-			    }
766
+				}
767
+			}
767 768
 			}
768
-		    }
769
-		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
769
+			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
770 770
 			$ignoreImport = true;
771 771
 			foreach($globalAirlineAccept as $airlineAccept) {
772
-			    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)) {
772
+				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)) {
773 773
 				$ignoreImport = false;
774
-			    }
774
+				}
775 775
 			}
776
-		    }
777
-		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
776
+			}
777
+			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
778 778
 			$ignoreImport = true;
779 779
 			foreach($globalPilotIdAccept as $pilotIdAccept) {
780
-			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
781
-			        $ignoreImport = false;
782
-			    }
780
+				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
781
+					$ignoreImport = false;
782
+				}
783
+			}
783 784
 			}
784
-		    }
785 785
 
786
-		    if (!$ignoreImport) {
786
+			if (!$ignoreImport) {
787 787
 			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'])) {
788 788
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
789 789
 				$timeelapsed = microtime(true);
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
 					if ($stats_heading == 16) $stats_heading = 0;
822 822
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
823 823
 						for ($i=0;$i<=15;$i++) {
824
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
824
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
825 825
 						}
826 826
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
827 827
 					} else {
@@ -834,11 +834,11 @@  discard block
 block discarded – undo
834 834
 					//var_dump($this->stats);
835 835
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
836 836
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
837
-						    end($this->stats[$current_date][$source]['hist']);
838
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
837
+							end($this->stats[$current_date][$source]['hist']);
838
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
839 839
 						} else $mini = 0;
840 840
 						for ($i=$mini;$i<=$distance;$i+=10) {
841
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
841
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
842 842
 						}
843 843
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
844 844
 					} else {
@@ -855,22 +855,22 @@  discard block
 block discarded – undo
855 855
 			
856 856
 			
857 857
 			if ($this->last_delete_hourly == '' || time() - $this->last_delete_hourly > 900) {
858
-			    if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
859
-			    $SpotterLive = new SpotterLive($this->db);
860
-			    $SpotterLive->deleteLiveSpotterDataNotUpdated();
861
-			    $SpotterLive->db = null;
862
-			    //SpotterLive->deleteLiveSpotterData();
863
-			    if ($globalDebug) echo " Done\n";
864
-			    $this->last_delete_hourly = time();
858
+				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
859
+				$SpotterLive = new SpotterLive($this->db);
860
+				$SpotterLive->deleteLiveSpotterDataNotUpdated();
861
+				$SpotterLive->db = null;
862
+				//SpotterLive->deleteLiveSpotterData();
863
+				if ($globalDebug) echo " Done\n";
864
+				$this->last_delete_hourly = time();
865 865
 			}
866 866
 			
867
-		    }
868
-		    $ignoreImport = false;
867
+			}
868
+			$ignoreImport = false;
869 869
 		}
870 870
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
871 871
 		if ($send) return $this->all_flights[$id];
872
-	    }
872
+		}
873
+	}
873 874
 	}
874
-    }
875 875
 }
876 876
 ?>
Please login to merge, or discard this patch.
Spacing   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -29,18 +29,18 @@  discard block
 block discarded – undo
29 29
 	$currentdate = date('Y-m-d');
30 30
 	$sourcestat = $Stats->getStatsSource($currentdate);
31 31
 	if (!empty($sourcestat)) {
32
-	    foreach($sourcestat as $srcst) {
32
+	    foreach ($sourcestat as $srcst) {
33 33
 	    	$type = $srcst['stats_type'];
34 34
 		if ($type == 'polar' || $type == 'hist') {
35 35
 		    $source = $srcst['source_name'];
36 36
 		    $data = $srcst['source_data'];
37
-		    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
37
+		    $this->stats[$currentdate][$source][$type] = json_decode($data, true);
38 38
 	        }
39 39
 	    }
40 40
 	}
41 41
     }
42 42
 
43
-    public function get_Schedule($id,$ident) {
43
+    public function get_Schedule($id, $ident) {
44 44
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
45 45
 	// Get schedule here, so it's done only one time
46 46
 	
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 		$schedule = $Schedule->fetchSchedule($operator);
64 64
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
65 65
 		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
66
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
67
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
66
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $schedule['DepartureTime']));
67
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $schedule['ArrivalTime']));
68 68
 		    // Should also check if route schedule = route from DB
69 69
 		    if ($schedule['DepartureAirportIATA'] != '') {
70 70
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 			    }
85 85
 			}
86 86
 		    }
87
-		    $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']);
87
+		    $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']);
88 88
 		}
89 89
 	    }
90 90
 	}
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 		//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
115 115
     		$Spotter = new Spotter($this->db);
116 116
         	$real_arrival = $this->arrival($key);
117
-        	$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']);
117
+        	$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']);
118 118
             }
119 119
 	}
120 120
     }
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
         $airport_time = '';
127 127
         if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
128 128
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
129
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
129
+	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $globalClosestMinDist);
130 130
     	    if (isset($closestAirports[0])) {
131 131
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
132 132
         	    $airport_icao = $closestAirports[0]['icao'];
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
         		    break;
142 142
         		}
143 143
         	    }
144
-        	} 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))) {
144
+        	} 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))) {
145 145
         		$airport_icao = $closestAirports[0]['icao'];
146 146
         		$airport_time = $this->all_flights[$key]['datetime'];
147 147
         	} else {
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
         } else {
155 155
         	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
156 156
         }
157
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
157
+        return array('airport_icao' => $airport_icao, 'airport_time' => $airport_time);
158 158
     }
159 159
 
160 160
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	// Delete old infos
165 165
 	foreach ($this->all_flights as $key => $flight) {
166 166
     	    if (isset($flight['lastupdate'])) {
167
-        	if ($flight['lastupdate'] < (time()-3000)) {
167
+        	if ($flight['lastupdate'] < (time() - 3000)) {
168 168
             	    if (isset($this->all_flights[$key]['id'])) {
169 169
             		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
170 170
 			/*
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
             		$real_arrival = $this->arrival($key);
176 176
             		$Spotter = new Spotter($this->db);
177 177
             		if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
178
-				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
178
+				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $real_arrival['airport_icao'], $real_arrival['airport_time']);
179 179
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
180 180
 			}
181 181
 			// Put in archive
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 	$send = false;
212 212
 	
213 213
 	// SBS format is CSV format
214
-	if(is_array($line) && isset($line['hex'])) {
214
+	if (is_array($line) && isset($line['hex'])) {
215 215
 	    //print_r($line);
216 216
   	    if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) {
217 217
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 		//print_r($this->all_flights);
246 246
 		if (!isset($this->all_flights[$id]['hex']) && ctype_xdigit($hex)) {
247 247
 		    $this->all_flights[$id] = array('hex' => $hex);
248
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
248
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
249 249
 		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
250 250
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
251 251
 		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 			$Spotter = new Spotter($this->db);
256 256
 			$aircraft_icao = $Spotter->getAllAircraftType($hex);
257 257
 			$Spotter->db = null;
258
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
258
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
259 259
 
260 260
 			if ($aircraft_icao == '' && isset($line['aircraft_type'])) {
261 261
 			    if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
@@ -263,31 +263,31 @@  discard block
 block discarded – undo
263 263
 			    elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
264 264
 			    elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
265 265
 			}
266
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
266
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
267 267
 		    } else if (isset($line['aircraft_name'])) {
268 268
 			// Get aircraft ICAO from aircraft name
269 269
 			$Spotter = new Spotter($this->db);
270 270
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
271 271
 			$Spotter->db = null;
272
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
273
-			else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
274
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
275
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', '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' => false));
276
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
272
+			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
273
+			else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => 'NA'));
274
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $line['aircraft_icao']));
275
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => '', 'departure_airport' => '', 'arrival_airport' => '', 'latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'altitude_real' => '', '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' => false));
276
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('lastupdate' => time()));
277 277
 		    if (!isset($line['id'])) {
278 278
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
279 279
 //			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')));
280 280
 //			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')));
281
-			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' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
281
+			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' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
282 282
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
283
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
283
+		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
284 284
 
285 285
 		    if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n";
286 286
 		}
287 287
 		
288
-		if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
288
+		if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/', $line['datetime'])) {
289 289
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
290
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
290
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => $line['datetime']));
291 291
 		    } else {
292 292
 				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";
293 293
 				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";
@@ -298,30 +298,30 @@  discard block
 block discarded – undo
298 298
 				*/
299 299
 				return '';
300 300
 		    }
301
-		} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
301
+		} else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => date('Y-m-d H:i:s')));
302 302
 
303 303
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
304
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
304
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('registration' => $line['registration']));
305 305
 		}
306 306
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
307
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
307
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('waypoints' => $line['waypoints']));
308 308
 		}
309 309
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
310
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
310
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_id' => $line['pilot_id']));
311 311
 		}
312 312
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
313
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
313
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_name' => $line['pilot_name']));
314 314
 		}
315 315
  
316 316
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
317
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
317
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident'])));
318 318
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
319 319
 			$timeelapsed = microtime(true);
320 320
             		$Spotter = new Spotter($this->db);
321
-            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident']);
321
+            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident']);
322 322
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
323 323
 			$Spotter->db = null;
324
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
324
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
325 325
 		    }
326 326
 
327 327
 /*
@@ -332,24 +332,24 @@  discard block
 block discarded – undo
332 332
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
333 333
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
334 334
   */
335
-		    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']));
335
+		    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']));
336 336
 
337 337
 		    //$putinarchive = true;
338 338
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
339
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
339
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $line['departure_airport_time']));
340 340
 		    }
341 341
 		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
342
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
342
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $line['arrival_airport_time']));
343 343
 		    }
344 344
 		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
345
-		    		$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' => ''));
345
+		    		$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' => ''));
346 346
 		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
347 347
 				$timeelapsed = microtime(true);
348 348
 				$Spotter = new Spotter($this->db);
349 349
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
350 350
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
351
-		    		$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' => ''));
352
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
351
+		    		$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' => ''));
352
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
353 353
 
354 354
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
355 355
 			$timeelapsed = microtime(true);
@@ -362,13 +362,13 @@  discard block
 block discarded – undo
362 362
 				$Translation->db = null;
363 363
 			}
364 364
 			$Spotter->db = null;
365
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
365
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
366 366
 
367 367
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
368 368
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
369 369
 			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
370 370
 				//    $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']));
371
-		    		$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']));
371
+		    		$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']));
372 372
 		    	    }
373 373
 			}
374 374
 			if (!isset($globalFork)) $globalFork = TRUE;
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 				}
385 385
 			    } else {
386 386
 			    */
387
-				$this->get_Schedule($id,trim($line['ident']));
387
+				$this->get_Schedule($id, trim($line['ident']));
388 388
 			//    }
389 389
 			}
390 390
 		    }
@@ -392,16 +392,16 @@  discard block
 block discarded – undo
392 392
 
393 393
 		if (isset($line['speed']) && $line['speed'] != '') {
394 394
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
395
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
396
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
395
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($line['speed'])));
396
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed_fromsrc' => true));
397 397
 		    //$dataFound = true;
398 398
 		} 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'])) {
399
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
399
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm');
400 400
 		    if ($distance > 1000 && $distance < 10000) {
401 401
 		    // use datetime
402 402
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
403 403
 			$speed = $speed*3.6;
404
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
404
+			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($speed)));
405 405
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
406 406
 		    }
407 407
 		}
@@ -409,11 +409,11 @@  discard block
 block discarded – undo
409 409
 
410 410
 
411 411
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
412
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
412
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time() - $this->all_flights[$id]['time_last_coord']);
413 413
 	    	    else unset($timediff);
414
-	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || !isset($timediff) || $timediff > 800 || ($timediff > 10 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
414
+	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || !isset($timediff) || $timediff > 800 || ($timediff > 10 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')))) {
415 415
 			if (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'])) {
416
-			    if (!$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'])) {
416
+			    if (!$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'])) {
417 417
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
418 418
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
419 419
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -422,10 +422,10 @@  discard block
 block discarded – undo
422 422
 				//echo "\n".' ------- Check Country.... ';
423 423
 				$timeelapsed = microtime(true);
424 424
 				$Spotter = new Spotter($this->db);
425
-				$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
425
+				$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
426 426
 				if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
427 427
 				$Spotter->db = null;
428
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
428
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
429 429
 				$this->tmd = 0;
430 430
 				//echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
431 431
 				//$putinarchive = true;
@@ -440,13 +440,13 @@  discard block
 block discarded – undo
440 440
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
441 441
 			    //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) {
442 442
 				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
443
-				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') {
443
+				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') {
444 444
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
445 445
 				    $dataFound = true;
446 446
 				    $this->all_flights[$id]['time_last_coord'] = time();
447 447
 				}
448 448
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
449
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
449
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('latitude' => $line['latitude']));
450 450
 				/*
451 451
 				if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) {
452 452
 				    $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -464,13 +464,13 @@  discard block
 block discarded – undo
464 464
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
465 465
 			    //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) {
466 466
 				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
467
-				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') {
467
+				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') {
468 468
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
469 469
 				    $dataFound = true;
470 470
 				    $this->all_flights[$id]['time_last_coord'] = time();
471 471
 				}
472 472
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
473
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
473
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('longitude' => $line['longitude']));
474 474
 				/*
475 475
 				if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) {
476 476
 				    $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
@@ -488,41 +488,41 @@  discard block
 block discarded – undo
488 488
 		    } else if ($globalDebug && $timediff > 20) {
489 489
 			$this->tmd = $this->tmd + 1;
490 490
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
491
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
492
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
491
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')."m -";
492
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
493 493
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
494 494
 		    }
495 495
 		}
496 496
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
497
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
497
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('verticalrate' => $line['verticalrate']));
498 498
 		    //$dataFound = true;
499 499
 		}
500 500
 		if (isset($line['format_source']) && $line['format_source'] != '') {
501
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
501
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('format_source' => $line['format_source']));
502 502
 		}
503 503
 		if (isset($line['source_name']) && $line['source_name'] != '') {
504
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
504
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_name' => $line['source_name']));
505 505
 		}
506 506
 		if (isset($line['emergency']) && $line['emergency'] != '') {
507
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
507
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('emergency' => $line['emergency']));
508 508
 		    //$dataFound = true;
509 509
 		}
510 510
 		if (isset($line['ground']) && $line['ground'] != '') {
511 511
 		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
512 512
 			// Here we force archive of flight because after ground it's a new one (or should be)
513
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
514
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
515
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
516
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
517
-			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']));
513
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
514
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
515
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
516
+		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
517
+			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']));
518 518
 		    }
519 519
 		    if ($line['ground'] != 1) $line['ground'] = 0;
520
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
520
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ground' => $line['ground']));
521 521
 		    //$dataFound = true;
522 522
 		}
523 523
 		if (isset($line['squawk']) && $line['squawk'] != '') {
524 524
 		    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'])) {
525
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
525
+			    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
526 526
 			    $highlight = '';
527 527
 			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
528 528
 			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
@@ -530,48 +530,48 @@  discard block
 block discarded – undo
530 530
 			    if ($highlight != '') {
531 531
 				$timeelapsed = microtime(true);
532 532
 				$Spotter = new Spotter($this->db);
533
-				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
533
+				$Spotter->setHighlightFlight($this->all_flights[$id]['id'], $highlight);
534 534
 				$Spotter->db = null;
535
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
535
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
536 536
 
537 537
 				$this->all_flights[$id]['putinarchive'] = true;
538 538
 				//$putinarchive = true;
539 539
 				$highlight = '';
540 540
 			    }
541 541
 			    
542
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
542
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
543 543
 		    //$dataFound = true;
544 544
 		}
545 545
 
546 546
 		if (isset($line['altitude']) && $line['altitude'] != '') {
547 547
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
548
-			if (abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 2) $this->all_flights[$id]['putinarchive'] = true;
549
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
550
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
548
+			if (abs(round($line['altitude']/100) - $this->all_flights[$id]['altitude']) > 2) $this->all_flights[$id]['putinarchive'] = true;
549
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude' => round($line['altitude']/100)));
550
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_real' => $line['altitude']));
551 551
 			//$dataFound = true;
552 552
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
553 553
   		}
554 554
 
555 555
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
556
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
556
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('noarchive' => true));
557 557
 		}
558 558
 		
559 559
 		if (isset($line['heading']) && $line['heading'] != '') {
560
-		    if (abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true;
561
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
562
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
560
+		    if (abs($this->all_flights[$id]['heading'] - round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true;
561
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($line['heading'])));
562
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading_fromsrc' => true));
563 563
 		    //$dataFound = true;
564 564
   		} 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']) {
565
-  		    $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']);
566
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
567
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true;
565
+  		    $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']);
566
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($heading)));
567
+		    if (abs($this->all_flights[$id]['heading'] - round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true;
568 568
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
569 569
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
570 570
   		    // If not enough messages and ACARS set heading to 0
571
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
571
+  		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => 0));
572 572
   		}
573
-		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
574
-		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
573
+		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
574
+		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
575 575
 
576 576
 //		print_r($this->all_flights[$id]);
577 577
 		//gets the callsign from the last hour
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 		if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
581 581
 		    $this->all_flights[$id]['lastupdate'] = time();
582 582
 		    if ($this->all_flights[$id]['addedSpotter'] == 0) {
583
-		        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'])) {
583
+		        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'])) {
584 584
 			    //print_r($this->all_flights);
585 585
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
586 586
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
@@ -590,60 +590,60 @@  discard block
 block discarded – undo
590 590
 				$SpotterLive = new SpotterLive($this->db);
591 591
 				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' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
592 592
 				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
593
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
593
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
594 594
 
595 595
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
596 596
 				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
597
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
597
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
598 598
 
599 599
 				} else $recent_ident = '';
600
-				$SpotterLive->db=null;
600
+				$SpotterLive->db = null;
601 601
 
602 602
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
603 603
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
604 604
 			    } else {
605 605
 				$recent_ident = '';
606
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
606
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 0));
607 607
 			    }
608 608
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
609
-			    if($recent_ident == "")
609
+			    if ($recent_ident == "")
610 610
 			    {
611 611
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
612 612
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
613 613
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
614 614
 				//adds the spotter data for the archive
615 615
 				$ignoreImport = false;
616
-				foreach($globalAirportIgnore as $airportIgnore) {
616
+				foreach ($globalAirportIgnore as $airportIgnore) {
617 617
 				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
618 618
 					$ignoreImport = true;
619 619
 				    }
620 620
 				}
621 621
 				if (count($globalAirportAccept) > 0) {
622 622
 				    $ignoreImport = true;
623
-				    foreach($globalAirportIgnore as $airportIgnore) {
623
+				    foreach ($globalAirportIgnore as $airportIgnore) {
624 624
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
625 625
 					    $ignoreImport = false;
626 626
 					}
627 627
 				    }
628 628
 				}
629 629
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
630
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
631
-					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)) {
630
+				    foreach ($globalAirlineIgnore as $airlineIgnore) {
631
+					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)) {
632 632
 					    $ignoreImport = true;
633 633
 					}
634 634
 				    }
635 635
 				}
636 636
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
637 637
 				    $ignoreImport = true;
638
-				    foreach($globalAirlineAccept as $airlineAccept) {
639
-					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)) {
638
+				    foreach ($globalAirlineAccept as $airlineAccept) {
639
+					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)) {
640 640
 					    $ignoreImport = false;
641 641
 					}
642 642
 				    }
643 643
 				}
644 644
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
645 645
 				    $ignoreImport = true;
646
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
646
+				    foreach ($globalPilotIdAccept as $pilotIdAccept) {
647 647
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
648 648
 					    $ignoreImport = false;
649 649
 					}
@@ -655,27 +655,27 @@  discard block
 block discarded – undo
655 655
 				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
656 656
 				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
657 657
 				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
658
-				    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')));
658
+				    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')));
659 659
 				    $timeelapsed = microtime(true);
660 660
 				    $Spotter = new Spotter($this->db);
661
-				    $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]['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']);
661
+				    $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]['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']);
662 662
 				    $Spotter->db = null;
663 663
 				    if ($globalDebug && isset($result)) echo $result."\n";
664
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
664
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
665 665
 				    
666 666
 				    // Add source stat in DB
667 667
 				    $Stats = new Stats($this->db);
668 668
 				    if (!empty($this->stats)) {
669 669
 					if ($globalDebug) echo 'Add source stats : ';
670
-				        foreach($this->stats as $date => $data) {
671
-					    foreach($data as $source => $sourced) {
670
+				        foreach ($this->stats as $date => $data) {
671
+					    foreach ($data as $source => $sourced) {
672 672
 					        //print_r($sourced);
673
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
674
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
673
+				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar', $date);
674
+				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist', $date);
675 675
 				    		if (isset($sourced['msg'])) {
676 676
 				    		    if (time() - $sourced['msg']['date'] > 10) {
677 677
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
678
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
678
+				    		        echo $Stats->addStatSource($nbmsg, $source, 'msg', $date);
679 679
 			    			        unset($this->stats[$date][$source]['msg']);
680 680
 			    			    }
681 681
 			    			}
@@ -711,18 +711,18 @@  discard block
 block discarded – undo
711 711
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
712 712
 				    $SpotterLive = new SpotterLive($this->db);
713 713
 				    $SpotterLive->deleteLiveSpotterData();
714
-				    $SpotterLive->db=null;
714
+				    $SpotterLive->db = null;
715 715
 				    if ($globalDebug) echo " Done\n";
716 716
 				    $this->last_delete = time();
717 717
 				}
718 718
 			    } else {
719
-				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' || $line['format_source'] === 'aircraftlistjson')) {
719
+				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' || $line['format_source'] === 'aircraftlistjson')) {
720 720
 				    $this->all_flights[$id]['id'] = $recent_ident;
721 721
 				    $this->all_flights[$id]['addedSpotter'] = 1;
722 722
 				}
723 723
 				if (isset($globalDaemon) && !$globalDaemon) {
724 724
 					$Spotter = new Spotter($this->db);
725
-					$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]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
725
+					$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]['ground'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time']);
726 726
 					$Spotter->db = null;
727 727
 				}
728 728
 				
@@ -746,37 +746,37 @@  discard block
 block discarded – undo
746 746
 		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
747 747
 		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
748 748
 
749
-		    foreach($globalAirportIgnore as $airportIgnore) {
749
+		    foreach ($globalAirportIgnore as $airportIgnore) {
750 750
 		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
751 751
 			    $ignoreImport = true;
752 752
 			}
753 753
 		    }
754 754
 		    if (count($globalAirportAccept) > 0) {
755 755
 		        $ignoreImport = true;
756
-		        foreach($globalAirportIgnore as $airportIgnore) {
756
+		        foreach ($globalAirportIgnore as $airportIgnore) {
757 757
 			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
758 758
 				$ignoreImport = false;
759 759
 			    }
760 760
 			}
761 761
 		    }
762 762
 		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
763
-			foreach($globalAirlineIgnore as $airlineIgnore) {
764
-			    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)) {
763
+			foreach ($globalAirlineIgnore as $airlineIgnore) {
764
+			    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)) {
765 765
 				$ignoreImport = true;
766 766
 			    }
767 767
 			}
768 768
 		    }
769 769
 		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
770 770
 			$ignoreImport = true;
771
-			foreach($globalAirlineAccept as $airlineAccept) {
772
-			    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)) {
771
+			foreach ($globalAirlineAccept as $airlineAccept) {
772
+			    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)) {
773 773
 				$ignoreImport = false;
774 774
 			    }
775 775
 			}
776 776
 		    }
777 777
 		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
778 778
 			$ignoreImport = true;
779
-			foreach($globalPilotIdAccept as $pilotIdAccept) {
779
+			foreach ($globalPilotIdAccept as $pilotIdAccept) {
780 780
 			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
781 781
 			        $ignoreImport = false;
782 782
 			    }
@@ -784,13 +784,13 @@  discard block
 block discarded – undo
784 784
 		    }
785 785
 
786 786
 		    if (!$ignoreImport) {
787
-			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'])) {
787
+			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'])) {
788 788
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
789 789
 				$timeelapsed = microtime(true);
790 790
 				$SpotterLive = new SpotterLive($this->db);
791
-				$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]['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']);
791
+				$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]['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']);
792 792
 				$SpotterLive->db = null;
793
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
793
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
794 794
 
795 795
 				// Put statistics in $this->stats variable
796 796
 				//if ($line['format_source'] != 'aprs') {
@@ -808,19 +808,19 @@  discard block
 block discarded – undo
808 808
 							$latitude = $globalCenterLatitude;
809 809
 							$longitude = $globalCenterLongitude;
810 810
 						}
811
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
811
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
812 812
 					} else {
813 813
 						$latitude = $this->source_location[$source]['latitude'];
814 814
 						$longitude = $this->source_location[$source]['longitude'];
815 815
 					}
816
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
816
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
817 817
 					//$stats_heading = $stats_heading%22.5;
818 818
 					$stats_heading = round($stats_heading/22.5);
819
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
819
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
820 820
 					$current_date = date('Y-m-d');
821 821
 					if ($stats_heading == 16) $stats_heading = 0;
822 822
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
823
-						for ($i=0;$i<=15;$i++) {
823
+						for ($i = 0; $i <= 15; $i++) {
824 824
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
825 825
 						}
826 826
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -835,9 +835,9 @@  discard block
 block discarded – undo
835 835
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
836 836
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
837 837
 						    end($this->stats[$current_date][$source]['hist']);
838
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
838
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
839 839
 						} else $mini = 0;
840
-						for ($i=$mini;$i<=$distance;$i+=10) {
840
+						for ($i = $mini; $i <= $distance; $i += 10) {
841 841
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
842 842
 						}
843 843
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
 				if ($this->all_flights[$id]['putinarchive']) $send = true;
851 851
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
852 852
 				if ($globalDebug) echo $result."\n";
853
-			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
853
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n";
854 854
 			//$this->del();
855 855
 			
856 856
 			
Please login to merge, or discard this patch.