Completed
Push — master ( 87953e...2ab225 )
by Yannick
08:10
created
require/class.SpotterImport.php 3 patches
Indentation   +354 added lines, -354 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 = 0;
14
-    private $last_delete = 0;
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 = 0;
14
+	private $last_delete = 0;
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
 	
@@ -60,42 +60,42 @@  discard block
 block discarded – undo
60 60
 	$operator = $Spotter->getOperator($ident);
61 61
 	$scheduleexist = false;
62 62
 	if ($Schedule->checkSchedule($operator) == 0) {
63
-	    $operator = $Translation->checkTranslation($ident);
64
-	    if ($Schedule->checkSchedule($operator) == 0) {
63
+		$operator = $Translation->checkTranslation($ident);
64
+		if ($Schedule->checkSchedule($operator) == 0) {
65 65
 		$schedule = $Schedule->fetchSchedule($operator);
66 66
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
67
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
68
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
69
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
70
-		    // Should also check if route schedule = route from DB
71
-		    if ($schedule['DepartureAirportIATA'] != '') {
67
+			if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
68
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
69
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
70
+			// Should also check if route schedule = route from DB
71
+			if ($schedule['DepartureAirportIATA'] != '') {
72 72
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
73
-			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
74
-			    if (trim($airport_icao) != '') {
73
+				$airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
74
+				if (trim($airport_icao) != '') {
75 75
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
76 76
 				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
77
-			    }
77
+				}
78
+			}
78 79
 			}
79
-		    }
80
-		    if ($schedule['ArrivalAirportIATA'] != '') {
80
+			if ($schedule['ArrivalAirportIATA'] != '') {
81 81
 			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) {
82
-			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
83
-			    if (trim($airport_icao) != '') {
82
+				$airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
83
+				if (trim($airport_icao) != '') {
84 84
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
85 85
 				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
86
-			    }
86
+				}
87
+			}
87 88
 			}
88
-		    }
89
-		    $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']);
89
+			$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']);
90 90
 		}
91
-	    } else $scheduleexist = true;
91
+		} else $scheduleexist = true;
92 92
 	} else $scheduleexist = true;
93 93
 	// close connection, at least one way will work ?
94
-       if ($scheduleexist) {
94
+	   if ($scheduleexist) {
95 95
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
96
-    		$sch = $Schedule->getSchedule($operator);
96
+			$sch = $Schedule->getSchedule($operator);
97 97
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
98
-       }
98
+	   }
99 99
 	$Spotter->db = null;
100 100
 	$Schedule->db = null;
101 101
 	$Translation->db = null;
@@ -110,92 +110,92 @@  discard block
 block discarded – undo
110 110
 	}
111 111
 	  */
112 112
 	}
113
-    }
113
+	}
114 114
 
115
-    public function checkAll() {
115
+	public function checkAll() {
116 116
 	global $globalDebug;
117 117
 	if ($globalDebug) echo "Update last seen flights data...\n";
118 118
 	foreach ($this->all_flights as $key => $flight) {
119
-	    if (isset($this->all_flights[$key]['id'])) {
119
+		if (isset($this->all_flights[$key]['id'])) {
120 120
 		//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
121
-    		$Spotter = new Spotter($this->db);
122
-        	$real_arrival = $this->arrival($key);
123
-        	$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']);
124
-            }
121
+			$Spotter = new Spotter($this->db);
122
+			$real_arrival = $this->arrival($key);
123
+			$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']);
124
+			}
125
+	}
125 126
 	}
126
-    }
127 127
 
128
-    public function arrival($key) {
128
+	public function arrival($key) {
129 129
 	global $globalClosestMinDist, $globalDebug;
130 130
 	if ($globalDebug) echo 'Update arrival...'."\n";
131 131
 	$Spotter = new Spotter($this->db);
132
-        $airport_icao = '';
133
-        $airport_time = '';
134
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
132
+		$airport_icao = '';
133
+		$airport_time = '';
134
+		if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
135 135
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
136
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
137
-    	    if (isset($closestAirports[0])) {
138
-        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
139
-        	    $airport_icao = $closestAirports[0]['icao'];
140
-        	    $airport_time = $this->all_flights[$key]['datetime'];
141
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
142
-        	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
143
-        	    foreach ($closestAirports as $airport) {
144
-        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
145
-        		    $airport_icao = $airport['icao'];
146
-        		    $airport_time = $this->all_flights[$key]['datetime'];
147
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
148
-        		    break;
149
-        		}
150
-        	    }
151
-        	} 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))) {
152
-        		$airport_icao = $closestAirports[0]['icao'];
153
-        		$airport_time = $this->all_flights[$key]['datetime'];
154
-        	} else {
155
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
156
-        	}
157
-    	    } else {
158
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
159
-    	    }
160
-
161
-        } else {
162
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
163
-        }
164
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
165
-    }
166
-
167
-
168
-
169
-    public function del() {
136
+		$closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
137
+			if (isset($closestAirports[0])) {
138
+			if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
139
+				$airport_icao = $closestAirports[0]['icao'];
140
+				$airport_time = $this->all_flights[$key]['datetime'];
141
+				if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
142
+			} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
143
+				foreach ($closestAirports as $airport) {
144
+				if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
145
+					$airport_icao = $airport['icao'];
146
+					$airport_time = $this->all_flights[$key]['datetime'];
147
+					if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
148
+					break;
149
+				}
150
+				}
151
+			} 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))) {
152
+				$airport_icao = $closestAirports[0]['icao'];
153
+				$airport_time = $this->all_flights[$key]['datetime'];
154
+			} else {
155
+				if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
156
+			}
157
+			} else {
158
+				if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
159
+			}
160
+
161
+		} else {
162
+			if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
163
+		}
164
+		return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
165
+	}
166
+
167
+
168
+
169
+	public function del() {
170 170
 	global $globalDebug;
171 171
 	// Delete old infos
172 172
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
173 173
 	foreach ($this->all_flights as $key => $flight) {
174
-    	    if (isset($flight['lastupdate'])) {
175
-        	if ($flight['lastupdate'] < (time()-3000)) {
176
-            	    if (isset($this->all_flights[$key]['id'])) {
177
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
174
+			if (isset($flight['lastupdate'])) {
175
+			if ($flight['lastupdate'] < (time()-3000)) {
176
+					if (isset($this->all_flights[$key]['id'])) {
177
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
178 178
 			/*
179 179
 			$SpotterLive = new SpotterLive();
180 180
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
181 181
 			$SpotterLive->db = null;
182 182
 			*/
183
-            		$real_arrival = $this->arrival($key);
184
-            		$Spotter = new Spotter($this->db);
185
-            		if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
183
+					$real_arrival = $this->arrival($key);
184
+					$Spotter = new Spotter($this->db);
185
+					if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
186 186
 				$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']);
187 187
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
188 188
 			}
189 189
 			// Put in archive
190 190
 //			$Spotter->db = null;
191
-            	    }
192
-            	    unset($this->all_flights[$key]);
193
-    	        }
194
-	    }
195
-        }
196
-    }
197
-
198
-    public function add($line) {
191
+					}
192
+					unset($this->all_flights[$key]);
193
+				}
194
+		}
195
+		}
196
+	}
197
+
198
+	public function add($line) {
199 199
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights;
200 200
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
201 201
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
@@ -220,18 +220,18 @@  discard block
 block discarded – undo
220 220
 	
221 221
 	// SBS format is CSV format
222 222
 	if(is_array($line) && isset($line['hex'])) {
223
-	    //print_r($line);
224
-  	    if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) {
223
+		//print_r($line);
224
+  		if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) {
225 225
 
226 226
 		// Increment message number
227 227
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
228
-		    $current_date = date('Y-m-d');
229
-		    $source = $line['source_name'];
230
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
231
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
232
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
233
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
234
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
228
+			$current_date = date('Y-m-d');
229
+			$source = $line['source_name'];
230
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
231
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
232
+				$this->stats[$current_date][$source]['msg']['date'] = time();
233
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
234
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
235 235
 		}
236 236
 		
237 237
 		/*
@@ -247,17 +247,17 @@  discard block
 block discarded – undo
247 247
 		//$this->db = $dbc;
248 248
 
249 249
 		$hex = trim($line['hex']);
250
-	        if (!isset($line['id'])) $id = trim($line['hex']);
251
-	        else $id = trim($line['id']);
250
+			if (!isset($line['id'])) $id = trim($line['hex']);
251
+			else $id = trim($line['id']);
252 252
 		
253 253
 		//print_r($this->all_flights);
254 254
 		if (!isset($this->all_flights[$id]['hex']) && ctype_xdigit($hex)) {
255
-		    $this->all_flights[$id] = array('hex' => $hex);
256
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
257
-		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
255
+			$this->all_flights[$id] = array('hex' => $hex);
256
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
257
+			//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
258 258
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
259
-		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
260
-		    if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????')) {
259
+			//} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
260
+			if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????')) {
261 261
 
262 262
 			$timeelapsed = microtime(true);
263 263
 			$Spotter = new Spotter($this->db);
@@ -266,39 +266,39 @@  discard block
 block discarded – undo
266 266
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
267 267
 
268 268
 			if ($aircraft_icao == '' && isset($line['aircraft_type'])) {
269
-			    if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
270
-			    elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
271
-			    elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
272
-			    elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
269
+				if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
270
+				elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
271
+				elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
272
+				elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
273 273
 			}
274 274
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
275
-		    } else if (isset($line['aircraft_name'])) {
275
+			} else if (isset($line['aircraft_name'])) {
276 276
 			// Get aircraft ICAO from aircraft name
277 277
 			$Spotter = new Spotter($this->db);
278 278
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
279 279
 			$Spotter->db = null;
280 280
 			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
281 281
 			else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
282
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
283
-		    $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' => true));
284
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
285
-		    if (!isset($line['id'])) {
282
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
283
+			$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' => true));
284
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
285
+			if (!isset($line['id'])) {
286 286
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
287 287
 //			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')));
288 288
 //			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')));
289 289
 			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')));
290
-		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
291
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
290
+				//else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
291
+			 } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
292 292
 
293
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n";
294
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
293
+			if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n";
294
+			if ($globalAllFlights !== FALSE) $dataFound = true;
295 295
 		}
296 296
 		
297 297
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
298 298
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60) {
299
-		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
299
+			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
300 300
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
301
-		    } else {
301
+			} else {
302 302
 				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";
303 303
 				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";
304 304
 				/*
@@ -307,41 +307,41 @@  discard block
 block discarded – undo
307 307
 				print_r($line);
308 308
 				*/
309 309
 				return '';
310
-		    }
310
+			}
311 311
 		} else {
312 312
 			date_default_timezone_set('UTC');
313 313
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
314 314
 		}
315 315
 
316 316
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
317
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
317
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
318 318
 		}
319 319
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
320
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
320
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
321 321
 		}
322 322
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
323
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
323
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
324 324
 		}
325 325
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
326
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
326
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
327 327
 		}
328 328
  
329 329
 		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'])) {
330
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
331
-		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
330
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
331
+			if ($this->all_flights[$id]['addedSpotter'] == 1) {
332 332
 			$timeelapsed = microtime(true);
333
-            		$Spotter = new Spotter($this->db);
334
-            		$fromsource = NULL;
335
-            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
336
-            		elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
333
+					$Spotter = new Spotter($this->db);
334
+					$fromsource = NULL;
335
+					if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
336
+					elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
337 337
 			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
338 338
 			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
339 339
 			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
340
-            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
340
+					$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
341 341
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
342 342
 			$Spotter->db = null;
343 343
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
344
-		    }
344
+			}
345 345
 
346 346
 /*
347 347
 		    if (!isset($line['id'])) {
@@ -351,26 +351,26 @@  discard block
 block discarded – undo
351 351
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
352 352
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
353 353
   */
354
-		    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']));
354
+			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']));
355 355
 
356
-		    //$putinarchive = true;
357
-		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
356
+			//$putinarchive = true;
357
+			if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
358 358
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
359
-		    }
360
-		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
359
+			}
360
+			if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
361 361
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
362
-		    }
363
-		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
364
-		    		$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' => ''));
365
-		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
362
+			}
363
+			if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
364
+					$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' => ''));
365
+			} elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
366 366
 				$timeelapsed = microtime(true);
367 367
 				$Spotter = new Spotter($this->db);
368 368
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
369 369
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
370
-		    		$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' => ''));
370
+					$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' => ''));
371 371
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
372 372
 
373
-		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
373
+			} elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
374 374
 			$timeelapsed = microtime(true);
375 375
 			$Spotter = new Spotter($this->db);
376 376
 			$route = $Spotter->getRouteInfo(trim($line['ident']));
@@ -384,43 +384,43 @@  discard block
 block discarded – undo
384 384
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
385 385
 
386 386
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
387
-			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
388
-			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
387
+				//if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
388
+				if ($route['fromairport_icao'] != $route['toairport_icao']) {
389 389
 				//    $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']));
390
-		    		$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']));
391
-		    	    }
390
+					$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']));
391
+					}
392 392
 			}
393 393
 			if (!isset($globalFork)) $globalFork = TRUE;
394 394
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
395 395
 				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
396 396
 			}
397
-		    }
397
+			}
398 398
 		}
399 399
 
400 400
 		if (isset($line['speed']) && $line['speed'] != '') {
401 401
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
402
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
403
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
404
-		    //$dataFound = true;
402
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
403
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
404
+			//$dataFound = true;
405 405
 		} 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'])) {
406
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
407
-		    if ($distance > 1000 && $distance < 10000) {
408
-		    // use datetime
406
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
407
+			if ($distance > 1000 && $distance < 10000) {
408
+			// use datetime
409 409
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
410 410
 			$speed = $speed*3.6;
411 411
 			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
412 412
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
413
-		    }
413
+			}
414 414
 		}
415 415
 
416 416
 
417 417
 
418
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
419
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
420
-	    	    else unset($timediff);
421
-	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !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')))) {
418
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
419
+				if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
420
+				else unset($timediff);
421
+				if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !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')))) {
422 422
 			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'])) {
423
-			    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'])) {
423
+				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'])) {
424 424
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
425 425
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
426 426
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -434,16 +434,16 @@  discard block
 block discarded – undo
434 434
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
435 435
 				$this->tmd = 0;
436 436
 				if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
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,53 +485,53 @@  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['last_update']) && $line['last_update'] != '') {
497
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
498
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
497
+			if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
498
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
499 499
 		}
500 500
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
501
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
502
-		    //$dataFound = true;
501
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
502
+			//$dataFound = true;
503 503
 		}
504 504
 		if (isset($line['format_source']) && $line['format_source'] != '') {
505
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
505
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
506 506
 		}
507 507
 		if (isset($line['source_name']) && $line['source_name'] != '') {
508
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
508
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
509 509
 		}
510 510
 		if (isset($line['emergency']) && $line['emergency'] != '') {
511
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
512
-		    //$dataFound = true;
511
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
512
+			//$dataFound = true;
513 513
 		}
514 514
 		if (isset($line['ground']) && $line['ground'] != '') {
515
-		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
515
+			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
516 516
 			// Here we force archive of flight because after ground it's a new one (or should be)
517 517
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
518 518
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
519 519
 			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')));
520
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
520
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
521 521
 			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']));
522
-		    }
523
-		    if ($line['ground'] != 1) $line['ground'] = 0;
524
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
525
-		    //$dataFound = true;
522
+			}
523
+			if ($line['ground'] != 1) $line['ground'] = 0;
524
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
525
+			//$dataFound = true;
526 526
 		}
527 527
 		if (isset($line['squawk']) && $line['squawk'] != '') {
528
-		    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'])) {
529
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
530
-			    $highlight = '';
531
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
532
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
533
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
534
-			    if ($highlight != '') {
528
+			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'])) {
529
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
530
+				$highlight = '';
531
+				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
532
+				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
533
+				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
534
+				if ($highlight != '') {
535 535
 				$timeelapsed = microtime(true);
536 536
 				$Spotter = new Spotter($this->db);
537 537
 				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
@@ -541,38 +541,38 @@  discard block
 block discarded – undo
541 541
 				$this->all_flights[$id]['putinarchive'] = true;
542 542
 				//$putinarchive = true;
543 543
 				//$highlight = '';
544
-			    }
544
+				}
545 545
 			    
546
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
547
-		    //$dataFound = true;
546
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
547
+			//$dataFound = true;
548 548
 		}
549 549
 
550 550
 		if (isset($line['altitude']) && $line['altitude'] != '') {
551
-		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
551
+			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
552 552
 			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 2) $this->all_flights[$id]['putinarchive'] = true;
553 553
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
554 554
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
555 555
 			//$dataFound = true;
556
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
556
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
557 557
   		}
558 558
 
559 559
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
560
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
560
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
561 561
 		}
562 562
 		
563 563
 		if (isset($line['heading']) && $line['heading'] != '') {
564
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true;
565
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
566
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
567
-		    //$dataFound = true;
564
+			if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true;
565
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
566
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
567
+			//$dataFound = true;
568 568
   		} 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']) {
569
-  		    $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']);
570
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
571
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true;
572
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
569
+  			$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']);
570
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
571
+			if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true;
572
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
573 573
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
574
-  		    // If not enough messages and ACARS set heading to 0
575
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
574
+  			// If not enough messages and ACARS set heading to 0
575
+  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
576 576
   		}
577 577
 		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
578 578
 		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
@@ -583,119 +583,119 @@  discard block
 block discarded – undo
583 583
 		//if ($dataFound == true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
584 584
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
585 585
 		if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
586
-		    $this->all_flights[$id]['lastupdate'] = time();
587
-		    if ($this->all_flights[$id]['addedSpotter'] == 0) {
588
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
589
-			    //print_r($this->all_flights);
590
-			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
591
-			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
592
-			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
586
+			$this->all_flights[$id]['lastupdate'] = time();
587
+			if ($this->all_flights[$id]['addedSpotter'] == 0) {
588
+				if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
589
+				//print_r($this->all_flights);
590
+				//echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
591
+				//$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
592
+				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
593 593
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
594 594
 				$timeelapsed = microtime(true);
595 595
 				$SpotterLive = new SpotterLive($this->db);
596 596
 				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')) {
597
-				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
598
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
597
+					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
598
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
599 599
 				} elseif (isset($line['id'])) {
600
-				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
601
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
600
+					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
601
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
602 602
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
603
-				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
604
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
603
+					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
604
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
605 605
 				} else $recent_ident = '';
606 606
 				$SpotterLive->db=null;
607 607
 
608 608
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
609 609
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
610
-			    } else {
610
+				} else {
611 611
 				$recent_ident = '';
612 612
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
613
-			    }
614
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
615
-			    if($recent_ident == "")
616
-			    {
613
+				}
614
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
615
+				if($recent_ident == "")
616
+				{
617 617
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
618 618
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
619 619
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
620 620
 				//adds the spotter data for the archive
621 621
 				$ignoreImport = false;
622 622
 				foreach($globalAirportIgnore as $airportIgnore) {
623
-				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
623
+					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
624 624
 					$ignoreImport = true;
625
-				    }
625
+					}
626 626
 				}
627 627
 				if (count($globalAirportAccept) > 0) {
628
-				    $ignoreImport = true;
629
-				    foreach($globalAirportIgnore as $airportIgnore) {
628
+					$ignoreImport = true;
629
+					foreach($globalAirportIgnore as $airportIgnore) {
630 630
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
631
-					    $ignoreImport = false;
631
+						$ignoreImport = false;
632
+					}
632 633
 					}
633
-				    }
634 634
 				}
635 635
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
636
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
636
+					foreach($globalAirlineIgnore as $airlineIgnore) {
637 637
 					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)) {
638
-					    $ignoreImport = true;
638
+						$ignoreImport = true;
639
+					}
639 640
 					}
640
-				    }
641 641
 				}
642 642
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
643
-				    $ignoreImport = true;
644
-				    foreach($globalAirlineAccept as $airlineAccept) {
643
+					$ignoreImport = true;
644
+					foreach($globalAirlineAccept as $airlineAccept) {
645 645
 					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)) {
646
-					    $ignoreImport = false;
646
+						$ignoreImport = false;
647
+					}
647 648
 					}
648
-				    }
649 649
 				}
650 650
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
651
-				    $ignoreImport = true;
652
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
651
+					$ignoreImport = true;
652
+					foreach($globalPilotIdAccept as $pilotIdAccept) {
653 653
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
654
-					    $ignoreImport = false;
654
+						$ignoreImport = false;
655
+					}
655 656
 					}
656
-				    }
657 657
 				}
658 658
 				
659 659
 				if (!$ignoreImport) {
660
-				    $highlight = '';
661
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
662
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
663
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
664
-				    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')));
665
-				    $timeelapsed = microtime(true);
666
-				    $Spotter = new Spotter($this->db);
667
-				    $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']);
668
-				    $Spotter->db = null;
669
-				    if ($globalDebug && isset($result)) echo $result."\n";
670
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
660
+					$highlight = '';
661
+					if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
662
+					if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
663
+					if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
664
+					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')));
665
+					$timeelapsed = microtime(true);
666
+					$Spotter = new Spotter($this->db);
667
+					$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']);
668
+					$Spotter->db = null;
669
+					if ($globalDebug && isset($result)) echo $result."\n";
670
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
671 671
 				    
672
-				    // Add source stat in DB
673
-				    $Stats = new Stats($this->db);
674
-				    if (!empty($this->stats)) {
672
+					// Add source stat in DB
673
+					$Stats = new Stats($this->db);
674
+					if (!empty($this->stats)) {
675 675
 					if ($globalDebug) echo 'Add source stats : ';
676
-				        foreach($this->stats as $date => $data) {
677
-					    foreach($data as $source => $sourced) {
678
-					        //print_r($sourced);
679
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
680
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
681
-				    		if (isset($sourced['msg'])) {
682
-				    		    if (time() - $sourced['msg']['date'] > 10) {
683
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
684
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
685
-			    			        unset($this->stats[$date][$source]['msg']);
686
-			    			    }
687
-			    			}
688
-			    		    }
689
-			    		    if ($date != date('Y-m-d')) {
690
-			    			unset($this->stats[$date]);
691
-			    		    }
692
-				    	}
693
-				    	if ($globalDebug) echo 'Done'."\n";
694
-
695
-				    }
696
-				    $Stats->db = null;
676
+						foreach($this->stats as $date => $data) {
677
+						foreach($data as $source => $sourced) {
678
+							//print_r($sourced);
679
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
680
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
681
+							if (isset($sourced['msg'])) {
682
+								if (time() - $sourced['msg']['date'] > 10) {
683
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
684
+									echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
685
+									unset($this->stats[$date][$source]['msg']);
686
+								}
687
+							}
688
+							}
689
+							if ($date != date('Y-m-d')) {
690
+							unset($this->stats[$date]);
691
+							}
692
+						}
693
+						if ($globalDebug) echo 'Done'."\n";
694
+
695
+					}
696
+					$Stats->db = null;
697 697
 				    
698
-				    $this->del();
698
+					$this->del();
699 699
 				} elseif ($globalDebug) echo 'Ignore data'."\n";
700 700
 				//$ignoreImport = false;
701 701
 				$this->all_flights[$id]['addedSpotter'] = 1;
@@ -713,18 +713,18 @@  discard block
 block discarded – undo
713 713
 			*/
714 714
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
715 715
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
716
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
717
-				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
718
-				    $SpotterLive = new SpotterLive($this->db);
719
-				    $SpotterLive->deleteLiveSpotterData();
720
-				    $SpotterLive->db=null;
721
-				    if ($globalDebug) echo " Done\n";
722
-				    $this->last_delete = time();
716
+					if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
717
+					//SpotterLive->deleteLiveSpotterDataNotUpdated();
718
+					$SpotterLive = new SpotterLive($this->db);
719
+					$SpotterLive->deleteLiveSpotterData();
720
+					$SpotterLive->db=null;
721
+					if ($globalDebug) echo " Done\n";
722
+					$this->last_delete = time();
723 723
 				}
724
-			    } else {
724
+				} else {
725 725
 				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')) {
726
-				    $this->all_flights[$id]['id'] = $recent_ident;
727
-				    $this->all_flights[$id]['addedSpotter'] = 1;
726
+					$this->all_flights[$id]['id'] = $recent_ident;
727
+					$this->all_flights[$id]['addedSpotter'] = 1;
728 728
 				}
729 729
 				if (isset($globalDaemon) && !$globalDaemon) {
730 730
 					$Spotter = new Spotter($this->db);
@@ -732,14 +732,14 @@  discard block
 block discarded – undo
732 732
 					$Spotter->db = null;
733 733
 				}
734 734
 				
735
-			    }
735
+				}
736
+			}
736 737
 			}
737
-		    }
738
-		    //adds the spotter LIVE data
739
-		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
740
-		    //echo "\nAdd in Live !! \n";
741
-		    //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";
742
-		    if ($globalDebug) {
738
+			//adds the spotter LIVE data
739
+			//SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
740
+			//echo "\nAdd in Live !! \n";
741
+			//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";
742
+			if ($globalDebug) {
743 743
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
744 744
 				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";
745 745
 				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";
@@ -747,49 +747,49 @@  discard block
 block discarded – undo
747 747
 				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";
748 748
 				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";
749 749
 			}
750
-		    }
751
-		    $ignoreImport = false;
752
-		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
753
-		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
750
+			}
751
+			$ignoreImport = false;
752
+			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
753
+			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
754 754
 
755
-		    foreach($globalAirportIgnore as $airportIgnore) {
756
-		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
757
-			    $ignoreImport = true;
755
+			foreach($globalAirportIgnore as $airportIgnore) {
756
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
757
+				$ignoreImport = true;
758
+			}
758 759
 			}
759
-		    }
760
-		    if (count($globalAirportAccept) > 0) {
761
-		        $ignoreImport = true;
762
-		        foreach($globalAirportIgnore as $airportIgnore) {
763
-			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
760
+			if (count($globalAirportAccept) > 0) {
761
+				$ignoreImport = true;
762
+				foreach($globalAirportIgnore as $airportIgnore) {
763
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
764 764
 				$ignoreImport = false;
765
-			    }
765
+				}
766 766
 			}
767
-		    }
768
-		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
767
+			}
768
+			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
769 769
 			foreach($globalAirlineIgnore as $airlineIgnore) {
770
-			    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)) {
770
+				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)) {
771 771
 				$ignoreImport = true;
772
-			    }
772
+				}
773 773
 			}
774
-		    }
775
-		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
774
+			}
775
+			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
776 776
 			$ignoreImport = true;
777 777
 			foreach($globalAirlineAccept as $airlineAccept) {
778
-			    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)) {
778
+				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)) {
779 779
 				$ignoreImport = false;
780
-			    }
780
+				}
781 781
 			}
782
-		    }
783
-		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
782
+			}
783
+			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
784 784
 			$ignoreImport = true;
785 785
 			foreach($globalPilotIdAccept as $pilotIdAccept) {
786
-			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
787
-			        $ignoreImport = false;
788
-			    }
786
+				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
787
+					$ignoreImport = false;
788
+				}
789
+			}
789 790
 			}
790
-		    }
791 791
 
792
-		    if (!$ignoreImport) {
792
+			if (!$ignoreImport) {
793 793
 			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'])) {
794 794
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
795 795
 				$timeelapsed = microtime(true);
@@ -827,7 +827,7 @@  discard block
 block discarded – undo
827 827
 					if ($stats_heading == 16) $stats_heading = 0;
828 828
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
829 829
 						for ($i=0;$i<=15;$i++) {
830
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
830
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
831 831
 						}
832 832
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
833 833
 					} else {
@@ -840,11 +840,11 @@  discard block
 block discarded – undo
840 840
 					//var_dump($this->stats);
841 841
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
842 842
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
843
-						    end($this->stats[$current_date][$source]['hist']);
844
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
843
+							end($this->stats[$current_date][$source]['hist']);
844
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
845 845
 						} else $mini = 0;
846 846
 						for ($i=$mini;$i<=$distance;$i+=10) {
847
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
847
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
848 848
 						}
849 849
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
850 850
 					} else {
@@ -861,22 +861,22 @@  discard block
 block discarded – undo
861 861
 			
862 862
 			
863 863
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
864
-			    if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
865
-			    $SpotterLive = new SpotterLive($this->db);
866
-			    $SpotterLive->deleteLiveSpotterDataNotUpdated();
867
-			    $SpotterLive->db = null;
868
-			    //SpotterLive->deleteLiveSpotterData();
869
-			    if ($globalDebug) echo " Done\n";
870
-			    $this->last_delete_hourly = time();
864
+				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
865
+				$SpotterLive = new SpotterLive($this->db);
866
+				$SpotterLive->deleteLiveSpotterDataNotUpdated();
867
+				$SpotterLive->db = null;
868
+				//SpotterLive->deleteLiveSpotterData();
869
+				if ($globalDebug) echo " Done\n";
870
+				$this->last_delete_hourly = time();
871 871
 			}
872 872
 			
873
-		    }
874
-		    //$ignoreImport = false;
873
+			}
874
+			//$ignoreImport = false;
875 875
 		}
876 876
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
877 877
 		if ($send) return $this->all_flights[$id];
878
-	    }
878
+		}
879
+	}
879 880
 	}
880
-    }
881 881
 }
882 882
 ?>
Please login to merge, or discard this patch.
Spacing   +128 added lines, -128 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
 	
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 		$schedule = $Schedule->fetchSchedule($operator);
66 66
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
67 67
 		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
68
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
69
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
68
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $schedule['DepartureTime']));
69
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $schedule['ArrivalTime']));
70 70
 		    // Should also check if route schedule = route from DB
71 71
 		    if ($schedule['DepartureAirportIATA'] != '') {
72 72
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 			    }
87 87
 			}
88 88
 		    }
89
-		    $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']);
89
+		    $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']);
90 90
 		}
91 91
 	    } else $scheduleexist = true;
92 92
 	} else $scheduleexist = true;
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
        if ($scheduleexist) {
95 95
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
96 96
     		$sch = $Schedule->getSchedule($operator);
97
-		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
97
+		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport' => $sch['arrival_airport_icao'], 'departure_airport' => $sch['departure_airport_icao'], 'departure_airport_time' => $sch['departure_airport_time'], 'arrival_airport_time' => $sch['arrival_airport_time']));
98 98
        }
99 99
 	$Spotter->db = null;
100 100
 	$Schedule->db = null;
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 		//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
121 121
     		$Spotter = new Spotter($this->db);
122 122
         	$real_arrival = $this->arrival($key);
123
-        	$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']);
123
+        	$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']);
124 124
             }
125 125
 	}
126 126
     }
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
         $airport_time = '';
134 134
         if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
135 135
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
136
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
136
+	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $globalClosestMinDist);
137 137
     	    if (isset($closestAirports[0])) {
138 138
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
139 139
         	    $airport_icao = $closestAirports[0]['icao'];
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
         		    break;
149 149
         		}
150 150
         	    }
151
-        	} 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))) {
151
+        	} 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))) {
152 152
         		$airport_icao = $closestAirports[0]['icao'];
153 153
         		$airport_time = $this->all_flights[$key]['datetime'];
154 154
         	} else {
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
         } else {
162 162
         	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
163 163
         }
164
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
164
+        return array('airport_icao' => $airport_icao, 'airport_time' => $airport_time);
165 165
     }
166 166
 
167 167
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
173 173
 	foreach ($this->all_flights as $key => $flight) {
174 174
     	    if (isset($flight['lastupdate'])) {
175
-        	if ($flight['lastupdate'] < (time()-3000)) {
175
+        	if ($flight['lastupdate'] < (time() - 3000)) {
176 176
             	    if (isset($this->all_flights[$key]['id'])) {
177 177
             		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
178 178
 			/*
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
             		$real_arrival = $this->arrival($key);
184 184
             		$Spotter = new Spotter($this->db);
185 185
             		if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
186
-				$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']);
186
+				$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']);
187 187
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
188 188
 			}
189 189
 			// Put in archive
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 	$send = false;
220 220
 	
221 221
 	// SBS format is CSV format
222
-	if(is_array($line) && isset($line['hex'])) {
222
+	if (is_array($line) && isset($line['hex'])) {
223 223
 	    //print_r($line);
224 224
   	    if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) {
225 225
 
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 		//print_r($this->all_flights);
254 254
 		if (!isset($this->all_flights[$id]['hex']) && ctype_xdigit($hex)) {
255 255
 		    $this->all_flights[$id] = array('hex' => $hex);
256
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
256
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
257 257
 		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
258 258
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
259 259
 		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 			$Spotter = new Spotter($this->db);
264 264
 			$aircraft_icao = $Spotter->getAllAircraftType($hex);
265 265
 			$Spotter->db = null;
266
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
266
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
267 267
 
268 268
 			if ($aircraft_icao == '' && isset($line['aircraft_type'])) {
269 269
 			    if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
@@ -271,33 +271,33 @@  discard block
 block discarded – undo
271 271
 			    elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
272 272
 			    elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
273 273
 			}
274
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
274
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
275 275
 		    } else if (isset($line['aircraft_name'])) {
276 276
 			// Get aircraft ICAO from aircraft name
277 277
 			$Spotter = new Spotter($this->db);
278 278
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
279 279
 			$Spotter->db = null;
280
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
281
-			else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
282
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
283
-		    $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' => true));
284
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
280
+			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
281
+			else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => 'NA'));
282
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $line['aircraft_icao']));
283
+		    $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' => true));
284
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('lastupdate' => time()));
285 285
 		    if (!isset($line['id'])) {
286 286
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
287 287
 //			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')));
288 288
 //			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')));
289
-			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')));
289
+			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')));
290 290
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
291
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
291
+		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
292 292
 
293 293
 		    if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n";
294 294
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
295 295
 		}
296 296
 		
297 297
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
298
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60) {
298
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 20*60) {
299 299
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
300
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
300
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => $line['datetime']));
301 301
 		    } else {
302 302
 				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";
303 303
 				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";
@@ -310,24 +310,24 @@  discard block
 block discarded – undo
310 310
 		    }
311 311
 		} else {
312 312
 			date_default_timezone_set('UTC');
313
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
313
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => date('Y-m-d H:i:s')));
314 314
 		}
315 315
 
316 316
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
317
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
317
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('registration' => $line['registration']));
318 318
 		}
319 319
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
320
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
320
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('waypoints' => $line['waypoints']));
321 321
 		}
322 322
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
323
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
323
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_id' => $line['pilot_id']));
324 324
 		}
325 325
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
326
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
326
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_name' => $line['pilot_name']));
327 327
 		}
328 328
  
329 329
 		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'])) {
330
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
330
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident'])));
331 331
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
332 332
 			$timeelapsed = microtime(true);
333 333
             		$Spotter = new Spotter($this->db);
@@ -337,10 +337,10 @@  discard block
 block discarded – undo
337 337
 			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
338 338
 			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
339 339
 			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
340
-            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
340
+            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $fromsource);
341 341
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
342 342
 			$Spotter->db = null;
343
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
343
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
344 344
 		    }
345 345
 
346 346
 /*
@@ -351,24 +351,24 @@  discard block
 block discarded – undo
351 351
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
352 352
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
353 353
   */
354
-		    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']));
354
+		    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']));
355 355
 
356 356
 		    //$putinarchive = true;
357 357
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
358
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
358
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $line['departure_airport_time']));
359 359
 		    }
360 360
 		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
361
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
361
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $line['arrival_airport_time']));
362 362
 		    }
363 363
 		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
364
-		    		$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' => ''));
364
+		    		$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' => ''));
365 365
 		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
366 366
 				$timeelapsed = microtime(true);
367 367
 				$Spotter = new Spotter($this->db);
368 368
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
369 369
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
370
-		    		$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' => ''));
371
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
370
+		    		$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' => ''));
371
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
372 372
 
373 373
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
374 374
 			$timeelapsed = microtime(true);
@@ -381,34 +381,34 @@  discard block
 block discarded – undo
381 381
 				$Translation->db = null;
382 382
 			}
383 383
 			$Spotter->db = null;
384
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
384
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
385 385
 
386 386
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
387 387
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
388 388
 			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
389 389
 				//    $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']));
390
-		    		$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']));
390
+		    		$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']));
391 391
 		    	    }
392 392
 			}
393 393
 			if (!isset($globalFork)) $globalFork = TRUE;
394 394
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
395
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
395
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id, trim($line['ident']));
396 396
 			}
397 397
 		    }
398 398
 		}
399 399
 
400 400
 		if (isset($line['speed']) && $line['speed'] != '') {
401 401
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
402
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
403
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
402
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($line['speed'])));
403
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed_fromsrc' => true));
404 404
 		    //$dataFound = true;
405 405
 		} 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'])) {
406
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
406
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm');
407 407
 		    if ($distance > 1000 && $distance < 10000) {
408 408
 		    // use datetime
409 409
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
410 410
 			$speed = $speed*3.6;
411
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
411
+			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($speed)));
412 412
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
413 413
 		    }
414 414
 		}
@@ -416,11 +416,11 @@  discard block
 block discarded – undo
416 416
 
417 417
 
418 418
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
419
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
419
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time() - $this->all_flights[$id]['time_last_coord']);
420 420
 	    	    else unset($timediff);
421
-	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !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')))) {
421
+	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !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')))) {
422 422
 			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'])) {
423
-			    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'])) {
423
+			    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'])) {
424 424
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
425 425
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
426 426
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -428,10 +428,10 @@  discard block
 block discarded – undo
428 428
 				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
429 429
 				$timeelapsed = microtime(true);
430 430
 				$Spotter = new Spotter($this->db);
431
-				$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
431
+				$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
432 432
 				if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
433 433
 				$Spotter->db = null;
434
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
434
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
435 435
 				$this->tmd = 0;
436 436
 				if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
437 437
 			    }
@@ -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,45 +488,45 @@  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['last_update']) && $line['last_update'] != '') {
497 497
 		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
498
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
498
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('last_update' => $line['last_update']));
499 499
 		}
500 500
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
501
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
501
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('verticalrate' => $line['verticalrate']));
502 502
 		    //$dataFound = true;
503 503
 		}
504 504
 		if (isset($line['format_source']) && $line['format_source'] != '') {
505
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
505
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('format_source' => $line['format_source']));
506 506
 		}
507 507
 		if (isset($line['source_name']) && $line['source_name'] != '') {
508
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
508
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_name' => $line['source_name']));
509 509
 		}
510 510
 		if (isset($line['emergency']) && $line['emergency'] != '') {
511
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
511
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('emergency' => $line['emergency']));
512 512
 		    //$dataFound = true;
513 513
 		}
514 514
 		if (isset($line['ground']) && $line['ground'] != '') {
515 515
 		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
516 516
 			// Here we force archive of flight because after ground it's a new one (or should be)
517
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
518
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
519
-			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')));
520
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
521
-			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']));
517
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
518
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
519
+			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')));
520
+		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
521
+			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']));
522 522
 		    }
523 523
 		    if ($line['ground'] != 1) $line['ground'] = 0;
524
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
524
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ground' => $line['ground']));
525 525
 		    //$dataFound = true;
526 526
 		}
527 527
 		if (isset($line['squawk']) && $line['squawk'] != '') {
528 528
 		    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'])) {
529
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
529
+			    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
530 530
 			    $highlight = '';
531 531
 			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
532 532
 			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
@@ -534,48 +534,48 @@  discard block
 block discarded – undo
534 534
 			    if ($highlight != '') {
535 535
 				$timeelapsed = microtime(true);
536 536
 				$Spotter = new Spotter($this->db);
537
-				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
537
+				$Spotter->setHighlightFlight($this->all_flights[$id]['id'], $highlight);
538 538
 				$Spotter->db = null;
539
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
539
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
540 540
 
541 541
 				$this->all_flights[$id]['putinarchive'] = true;
542 542
 				//$putinarchive = true;
543 543
 				//$highlight = '';
544 544
 			    }
545 545
 			    
546
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
546
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
547 547
 		    //$dataFound = true;
548 548
 		}
549 549
 
550 550
 		if (isset($line['altitude']) && $line['altitude'] != '') {
551 551
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
552
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 2) $this->all_flights[$id]['putinarchive'] = true;
553
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
554
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
552
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100) - $this->all_flights[$id]['altitude']) > 2) $this->all_flights[$id]['putinarchive'] = true;
553
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude' => round($line['altitude']/100)));
554
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_real' => $line['altitude']));
555 555
 			//$dataFound = true;
556 556
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
557 557
   		}
558 558
 
559 559
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
560
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
560
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('noarchive' => true));
561 561
 		}
562 562
 		
563 563
 		if (isset($line['heading']) && $line['heading'] != '') {
564
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true;
565
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
566
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
564
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading'] - round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true;
565
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($line['heading'])));
566
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading_fromsrc' => true));
567 567
 		    //$dataFound = true;
568 568
   		} 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']) {
569
-  		    $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']);
570
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
571
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true;
569
+  		    $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']);
570
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($heading)));
571
+		    if (abs($this->all_flights[$id]['heading'] - round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true;
572 572
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
573 573
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
574 574
   		    // If not enough messages and ACARS set heading to 0
575
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
575
+  		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => 0));
576 576
   		}
577
-		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
578
-		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
577
+		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
578
+		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
579 579
 
580 580
 //		print_r($this->all_flights[$id]);
581 581
 		//gets the callsign from the last hour
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
 		if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
586 586
 		    $this->all_flights[$id]['lastupdate'] = time();
587 587
 		    if ($this->all_flights[$id]['addedSpotter'] == 0) {
588
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
588
+		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == '' || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
589 589
 			    //print_r($this->all_flights);
590 590
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
591 591
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
@@ -595,61 +595,61 @@  discard block
 block discarded – undo
595 595
 				$SpotterLive = new SpotterLive($this->db);
596 596
 				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')) {
597 597
 				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
598
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
598
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
599 599
 				} elseif (isset($line['id'])) {
600 600
 				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
601
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
601
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
602 602
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
603 603
 				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
604
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
604
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
605 605
 				} else $recent_ident = '';
606
-				$SpotterLive->db=null;
606
+				$SpotterLive->db = null;
607 607
 
608 608
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
609 609
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
610 610
 			    } else {
611 611
 				$recent_ident = '';
612
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
612
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 0));
613 613
 			    }
614 614
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
615
-			    if($recent_ident == "")
615
+			    if ($recent_ident == "")
616 616
 			    {
617 617
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
618 618
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
619 619
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
620 620
 				//adds the spotter data for the archive
621 621
 				$ignoreImport = false;
622
-				foreach($globalAirportIgnore as $airportIgnore) {
622
+				foreach ($globalAirportIgnore as $airportIgnore) {
623 623
 				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
624 624
 					$ignoreImport = true;
625 625
 				    }
626 626
 				}
627 627
 				if (count($globalAirportAccept) > 0) {
628 628
 				    $ignoreImport = true;
629
-				    foreach($globalAirportIgnore as $airportIgnore) {
629
+				    foreach ($globalAirportIgnore as $airportIgnore) {
630 630
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
631 631
 					    $ignoreImport = false;
632 632
 					}
633 633
 				    }
634 634
 				}
635 635
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
636
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
637
-					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)) {
636
+				    foreach ($globalAirlineIgnore as $airlineIgnore) {
637
+					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)) {
638 638
 					    $ignoreImport = true;
639 639
 					}
640 640
 				    }
641 641
 				}
642 642
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
643 643
 				    $ignoreImport = true;
644
-				    foreach($globalAirlineAccept as $airlineAccept) {
645
-					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)) {
644
+				    foreach ($globalAirlineAccept as $airlineAccept) {
645
+					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)) {
646 646
 					    $ignoreImport = false;
647 647
 					}
648 648
 				    }
649 649
 				}
650 650
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
651 651
 				    $ignoreImport = true;
652
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
652
+				    foreach ($globalPilotIdAccept as $pilotIdAccept) {
653 653
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
654 654
 					    $ignoreImport = false;
655 655
 					}
@@ -661,27 +661,27 @@  discard block
 block discarded – undo
661 661
 				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
662 662
 				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
663 663
 				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
664
-				    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')));
664
+				    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')));
665 665
 				    $timeelapsed = microtime(true);
666 666
 				    $Spotter = new Spotter($this->db);
667
-				    $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']);
667
+				    $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']);
668 668
 				    $Spotter->db = null;
669 669
 				    if ($globalDebug && isset($result)) echo $result."\n";
670
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
670
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
671 671
 				    
672 672
 				    // Add source stat in DB
673 673
 				    $Stats = new Stats($this->db);
674 674
 				    if (!empty($this->stats)) {
675 675
 					if ($globalDebug) echo 'Add source stats : ';
676
-				        foreach($this->stats as $date => $data) {
677
-					    foreach($data as $source => $sourced) {
676
+				        foreach ($this->stats as $date => $data) {
677
+					    foreach ($data as $source => $sourced) {
678 678
 					        //print_r($sourced);
679
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
680
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
679
+				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar', $date);
680
+				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist', $date);
681 681
 				    		if (isset($sourced['msg'])) {
682 682
 				    		    if (time() - $sourced['msg']['date'] > 10) {
683 683
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
684
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
684
+				    		        echo $Stats->addStatSource($nbmsg, $source, 'msg', $date);
685 685
 			    			        unset($this->stats[$date][$source]['msg']);
686 686
 			    			    }
687 687
 			    			}
@@ -717,18 +717,18 @@  discard block
 block discarded – undo
717 717
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
718 718
 				    $SpotterLive = new SpotterLive($this->db);
719 719
 				    $SpotterLive->deleteLiveSpotterData();
720
-				    $SpotterLive->db=null;
720
+				    $SpotterLive->db = null;
721 721
 				    if ($globalDebug) echo " Done\n";
722 722
 				    $this->last_delete = time();
723 723
 				}
724 724
 			    } else {
725
-				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')) {
725
+				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')) {
726 726
 				    $this->all_flights[$id]['id'] = $recent_ident;
727 727
 				    $this->all_flights[$id]['addedSpotter'] = 1;
728 728
 				}
729 729
 				if (isset($globalDaemon) && !$globalDaemon) {
730 730
 					$Spotter = new Spotter($this->db);
731
-					$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']);
731
+					$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']);
732 732
 					$Spotter->db = null;
733 733
 				}
734 734
 				
@@ -752,37 +752,37 @@  discard block
 block discarded – undo
752 752
 		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
753 753
 		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
754 754
 
755
-		    foreach($globalAirportIgnore as $airportIgnore) {
755
+		    foreach ($globalAirportIgnore as $airportIgnore) {
756 756
 		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
757 757
 			    $ignoreImport = true;
758 758
 			}
759 759
 		    }
760 760
 		    if (count($globalAirportAccept) > 0) {
761 761
 		        $ignoreImport = true;
762
-		        foreach($globalAirportIgnore as $airportIgnore) {
762
+		        foreach ($globalAirportIgnore as $airportIgnore) {
763 763
 			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
764 764
 				$ignoreImport = false;
765 765
 			    }
766 766
 			}
767 767
 		    }
768 768
 		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
769
-			foreach($globalAirlineIgnore as $airlineIgnore) {
770
-			    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)) {
769
+			foreach ($globalAirlineIgnore as $airlineIgnore) {
770
+			    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)) {
771 771
 				$ignoreImport = true;
772 772
 			    }
773 773
 			}
774 774
 		    }
775 775
 		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
776 776
 			$ignoreImport = true;
777
-			foreach($globalAirlineAccept as $airlineAccept) {
778
-			    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)) {
777
+			foreach ($globalAirlineAccept as $airlineAccept) {
778
+			    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)) {
779 779
 				$ignoreImport = false;
780 780
 			    }
781 781
 			}
782 782
 		    }
783 783
 		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
784 784
 			$ignoreImport = true;
785
-			foreach($globalPilotIdAccept as $pilotIdAccept) {
785
+			foreach ($globalPilotIdAccept as $pilotIdAccept) {
786 786
 			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
787 787
 			        $ignoreImport = false;
788 788
 			    }
@@ -790,13 +790,13 @@  discard block
 block discarded – undo
790 790
 		    }
791 791
 
792 792
 		    if (!$ignoreImport) {
793
-			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'])) {
793
+			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'])) {
794 794
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
795 795
 				$timeelapsed = microtime(true);
796 796
 				$SpotterLive = new SpotterLive($this->db);
797
-				$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']);
797
+				$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']);
798 798
 				$SpotterLive->db = null;
799
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
799
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
800 800
 
801 801
 				// Put statistics in $this->stats variable
802 802
 				//if ($line['format_source'] != 'aprs') {
@@ -814,19 +814,19 @@  discard block
 block discarded – undo
814 814
 							$latitude = $globalCenterLatitude;
815 815
 							$longitude = $globalCenterLongitude;
816 816
 						}
817
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
817
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
818 818
 					} else {
819 819
 						$latitude = $this->source_location[$source]['latitude'];
820 820
 						$longitude = $this->source_location[$source]['longitude'];
821 821
 					}
822
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
822
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
823 823
 					//$stats_heading = $stats_heading%22.5;
824 824
 					$stats_heading = round($stats_heading/22.5);
825
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
825
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
826 826
 					$current_date = date('Y-m-d');
827 827
 					if ($stats_heading == 16) $stats_heading = 0;
828 828
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
829
-						for ($i=0;$i<=15;$i++) {
829
+						for ($i = 0; $i <= 15; $i++) {
830 830
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
831 831
 						}
832 832
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -841,9 +841,9 @@  discard block
 block discarded – undo
841 841
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
842 842
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
843 843
 						    end($this->stats[$current_date][$source]['hist']);
844
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
844
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
845 845
 						} else $mini = 0;
846
-						for ($i=$mini;$i<=$distance;$i+=10) {
846
+						for ($i = $mini; $i <= $distance; $i += 10) {
847 847
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
848 848
 						}
849 849
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
 				if ($this->all_flights[$id]['putinarchive']) $send = true;
857 857
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
858 858
 				if ($globalDebug) echo $result."\n";
859
-			} 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";
859
+			} 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";
860 860
 			//$this->del();
861 861
 			
862 862
 			
Please login to merge, or discard this patch.
Braces   +324 added lines, -115 removed lines patch added patch discarded remove patch
@@ -53,7 +53,9 @@  discard block
 block discarded – undo
53 53
 	$dbc = $this->db;
54 54
 	$this->all_flights[$id]['schedule_check'] = true;
55 55
 	if ($globalSchedulesFetch) {
56
-	if ($globalDebug) echo 'Getting schedule info...'."\n";
56
+	if ($globalDebug) {
57
+		echo 'Getting schedule info...'."\n";
58
+	}
57 59
 	$Spotter = new Spotter($dbc);
58 60
 	$Schedule = new Schedule($dbc);
59 61
 	$Translation = new Translation($dbc);
@@ -64,7 +66,9 @@  discard block
 block discarded – undo
64 66
 	    if ($Schedule->checkSchedule($operator) == 0) {
65 67
 		$schedule = $Schedule->fetchSchedule($operator);
66 68
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
67
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
69
+		    if ($globalDebug) {
70
+		    	echo "-> Schedule info for ".$operator." (".$ident.")\n";
71
+		    }
68 72
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
69 73
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
70 74
 		    // Should also check if route schedule = route from DB
@@ -73,7 +77,9 @@  discard block
 block discarded – undo
73 77
 			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
74 78
 			    if (trim($airport_icao) != '') {
75 79
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
76
-				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
80
+				if ($globalDebug) {
81
+					echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
82
+				}
77 83
 			    }
78 84
 			}
79 85
 		    }
@@ -82,17 +88,25 @@  discard block
 block discarded – undo
82 88
 			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
83 89
 			    if (trim($airport_icao) != '') {
84 90
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
85
-				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
91
+				if ($globalDebug) {
92
+					echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
93
+				}
86 94
 			    }
87 95
 			}
88 96
 		    }
89 97
 		    $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']);
90 98
 		}
91
-	    } else $scheduleexist = true;
92
-	} else $scheduleexist = true;
99
+	    } else {
100
+	    	$scheduleexist = true;
101
+	    }
102
+	} else {
103
+		$scheduleexist = true;
104
+	}
93 105
 	// close connection, at least one way will work ?
94 106
        if ($scheduleexist) {
95
-		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
107
+		if ($globalDebug) {
108
+			echo "-> get arrival/departure airport info for ".$ident."\n";
109
+		}
96 110
     		$sch = $Schedule->getSchedule($operator);
97 111
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
98 112
        }
@@ -114,7 +128,9 @@  discard block
 block discarded – undo
114 128
 
115 129
     public function checkAll() {
116 130
 	global $globalDebug;
117
-	if ($globalDebug) echo "Update last seen flights data...\n";
131
+	if ($globalDebug) {
132
+		echo "Update last seen flights data...\n";
133
+	}
118 134
 	foreach ($this->all_flights as $key => $flight) {
119 135
 	    if (isset($this->all_flights[$key]['id'])) {
120 136
 		//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
@@ -127,24 +143,32 @@  discard block
 block discarded – undo
127 143
 
128 144
     public function arrival($key) {
129 145
 	global $globalClosestMinDist, $globalDebug;
130
-	if ($globalDebug) echo 'Update arrival...'."\n";
146
+	if ($globalDebug) {
147
+		echo 'Update arrival...'."\n";
148
+	}
131 149
 	$Spotter = new Spotter($this->db);
132 150
         $airport_icao = '';
133 151
         $airport_time = '';
134
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
152
+        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') {
153
+        	$globalClosestMinDist = 50;
154
+        }
135 155
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
136 156
 	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
137 157
     	    if (isset($closestAirports[0])) {
138 158
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
139 159
         	    $airport_icao = $closestAirports[0]['icao'];
140 160
         	    $airport_time = $this->all_flights[$key]['datetime'];
141
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
161
+        	    if ($globalDebug) {
162
+        	    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
163
+        	    }
142 164
         	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
143 165
         	    foreach ($closestAirports as $airport) {
144 166
         		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
145 167
         		    $airport_icao = $airport['icao'];
146 168
         		    $airport_time = $this->all_flights[$key]['datetime'];
147
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
169
+        		    if ($globalDebug) {
170
+        		    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
171
+        		    }
148 172
         		    break;
149 173
         		}
150 174
         	    }
@@ -152,14 +176,20 @@  discard block
 block discarded – undo
152 176
         		$airport_icao = $closestAirports[0]['icao'];
153 177
         		$airport_time = $this->all_flights[$key]['datetime'];
154 178
         	} else {
155
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
179
+        		if ($globalDebug) {
180
+        			echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
181
+        		}
156 182
         	}
157 183
     	    } else {
158
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
184
+    		    if ($globalDebug) {
185
+    		    	echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
186
+    		    }
159 187
     	    }
160 188
 
161 189
         } else {
162
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
190
+        	if ($globalDebug) {
191
+        		echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
192
+        	}
163 193
         }
164 194
         return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
165 195
     }
@@ -169,12 +199,16 @@  discard block
 block discarded – undo
169 199
     public function del() {
170 200
 	global $globalDebug;
171 201
 	// Delete old infos
172
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
202
+	if ($globalDebug) {
203
+		echo 'Delete old values and update latest data...'."\n";
204
+	}
173 205
 	foreach ($this->all_flights as $key => $flight) {
174 206
     	    if (isset($flight['lastupdate'])) {
175 207
         	if ($flight['lastupdate'] < (time()-3000)) {
176 208
             	    if (isset($this->all_flights[$key]['id'])) {
177
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
209
+            		if ($globalDebug) {
210
+            			echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
211
+            		}
178 212
 			/*
179 213
 			$SpotterLive = new SpotterLive();
180 214
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
@@ -184,7 +218,9 @@  discard block
 block discarded – undo
184 218
             		$Spotter = new Spotter($this->db);
185 219
             		if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
186 220
 				$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']);
187
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
221
+				if ($globalDebug && $result != 'success') {
222
+					echo '!!! ERROR : '.$result."\n";
223
+				}
188 224
 			}
189 225
 			// Put in archive
190 226
 //			$Spotter->db = null;
@@ -198,8 +234,10 @@  discard block
 block discarded – undo
198 234
     public function add($line) {
199 235
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights;
200 236
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
201
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
202
-/*
237
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
238
+		$globalCoordMinChange = '0.02';
239
+	}
240
+	/*
203 241
 	$Spotter = new Spotter();
204 242
 	$dbc = $Spotter->db;
205 243
 	$SpotterLive = new SpotterLive($dbc);
@@ -227,11 +265,15 @@  discard block
 block discarded – undo
227 265
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
228 266
 		    $current_date = date('Y-m-d');
229 267
 		    $source = $line['source_name'];
230
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
268
+		    if ($source == '' || $line['format_source'] == 'aprs') {
269
+		    	$source = $line['format_source'];
270
+		    }
231 271
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
232 272
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
233 273
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
234
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
274
+		    } else {
275
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
276
+		    }
235 277
 		}
236 278
 		
237 279
 		/*
@@ -247,8 +289,11 @@  discard block
 block discarded – undo
247 289
 		//$this->db = $dbc;
248 290
 
249 291
 		$hex = trim($line['hex']);
250
-	        if (!isset($line['id'])) $id = trim($line['hex']);
251
-	        else $id = trim($line['id']);
292
+	        if (!isset($line['id'])) {
293
+	        	$id = trim($line['hex']);
294
+	        } else {
295
+	        	$id = trim($line['id']);
296
+	        }
252 297
 		
253 298
 		//print_r($this->all_flights);
254 299
 		if (!isset($this->all_flights[$id]['hex']) && ctype_xdigit($hex)) {
@@ -263,13 +308,20 @@  discard block
 block discarded – undo
263 308
 			$Spotter = new Spotter($this->db);
264 309
 			$aircraft_icao = $Spotter->getAllAircraftType($hex);
265 310
 			$Spotter->db = null;
266
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
311
+			if ($globalDebugTimeElapsed) {
312
+				echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
313
+			}
267 314
 
268 315
 			if ($aircraft_icao == '' && isset($line['aircraft_type'])) {
269
-			    if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
270
-			    elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
271
-			    elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
272
-			    elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
316
+			    if ($line['aircraft_type'] == 'PARA_GLIDER') {
317
+			    	$aircraft_icao = 'GLID';
318
+			    } elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') {
319
+			    	$aircraft_icao = 'UHEL';
320
+			    } elseif ($line['aircraft_type'] == 'TOW_PLANE') {
321
+			    	$aircraft_icao = 'TOWPLANE';
322
+			    } elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') {
323
+			    	$aircraft_icao = 'POWAIRC';
324
+			    }
273 325
 			}
274 326
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
275 327
 		    } else if (isset($line['aircraft_name'])) {
@@ -277,21 +329,36 @@  discard block
 block discarded – undo
277 329
 			$Spotter = new Spotter($this->db);
278 330
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
279 331
 			$Spotter->db = null;
280
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
281
-			else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
282
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
332
+			if ($aircraft_icao != '') {
333
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
334
+			} else {
335
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
336
+			}
337
+		    } else {
338
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
339
+		    }
283 340
 		    $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' => true));
284 341
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
285 342
 		    if (!isset($line['id'])) {
286
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
287
-//			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')));
343
+			if (!isset($globalDaemon)) {
344
+				$globalDaemon = TRUE;
345
+			}
346
+			//			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')));
288 347
 //			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')));
289
-			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')));
348
+			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')) {
349
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
350
+			}
290 351
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
291
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
352
+		     } else {
353
+		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
354
+		     }
292 355
 
293
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n";
294
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
356
+		    if ($globalDebug) {
357
+		    	echo "*********** New aircraft hex : ".$hex." ***********\n";
358
+		    }
359
+		    if ($globalAllFlights !== FALSE) {
360
+		    	$dataFound = true;
361
+		    }
295 362
 		}
296 363
 		
297 364
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
@@ -299,8 +366,11 @@  discard block
 block discarded – undo
299 366
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
300 367
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
301 368
 		    } else {
302
-				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";
303
-				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";
369
+				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
370
+					echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
371
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
372
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
373
+				}
304 374
 				/*
305 375
 				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
306 376
 				print_r($this->all_flights[$id]);
@@ -332,15 +402,25 @@  discard block
 block discarded – undo
332 402
 			$timeelapsed = microtime(true);
333 403
             		$Spotter = new Spotter($this->db);
334 404
             		$fromsource = NULL;
335
-            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
336
-            		elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
337
-			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
338
-			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
339
-			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
405
+            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') {
406
+            			$fromsource = $globalAirlinesSource;
407
+            		} elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') {
408
+            			$fromsource = 'vatsim';
409
+            		} elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') {
410
+				$fromsource = 'ivao';
411
+			} elseif (isset($globalVATSIM) && $globalVATSIM) {
412
+				$fromsource = 'vatsim';
413
+			} elseif (isset($globalIVAO) && $globalIVAO) {
414
+				$fromsource = 'ivao';
415
+			}
340 416
             		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
341
-			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
417
+			if ($globalDebug && $result != 'success') {
418
+				echo '!!! ERROR : '.$result."\n";
419
+			}
342 420
 			$Spotter->db = null;
343
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
421
+			if ($globalDebugTimeElapsed) {
422
+				echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
423
+			}
344 424
 		    }
345 425
 
346 426
 /*
@@ -351,7 +431,9 @@  discard block
 block discarded – undo
351 431
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
352 432
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
353 433
   */
354
-		    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']));
434
+		    if (!isset($this->all_flights[$id]['id'])) {
435
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
436
+		    }
355 437
 
356 438
 		    //$putinarchive = true;
357 439
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
@@ -368,7 +450,9 @@  discard block
 block discarded – undo
368 450
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
369 451
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
370 452
 		    		$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' => ''));
371
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
453
+				if ($globalDebugTimeElapsed) {
454
+					echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
455
+				}
372 456
 
373 457
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
374 458
 			$timeelapsed = microtime(true);
@@ -381,7 +465,9 @@  discard block
 block discarded – undo
381 465
 				$Translation->db = null;
382 466
 			}
383 467
 			$Spotter->db = null;
384
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
468
+			if ($globalDebugTimeElapsed) {
469
+				echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
470
+			}
385 471
 
386 472
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
387 473
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
@@ -390,9 +476,13 @@  discard block
 block discarded – undo
390 476
 		    		$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']));
391 477
 		    	    }
392 478
 			}
393
-			if (!isset($globalFork)) $globalFork = TRUE;
479
+			if (!isset($globalFork)) {
480
+				$globalFork = TRUE;
481
+			}
394 482
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
395
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
483
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) {
484
+					$this->get_Schedule($id,trim($line['ident']));
485
+				}
396 486
 			}
397 487
 		    }
398 488
 		}
@@ -408,16 +498,23 @@  discard block
 block discarded – undo
408 498
 		    // use datetime
409 499
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
410 500
 			$speed = $speed*3.6;
411
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
412
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
501
+			if ($speed < 1000) {
502
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
503
+			}
504
+  			if ($globalDebug) {
505
+  				echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
506
+  			}
413 507
 		    }
414 508
 		}
415 509
 
416 510
 
417 511
 
418 512
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
419
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
420
-	    	    else unset($timediff);
513
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) {
514
+	    	    	$timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
515
+	    	    } else {
516
+	    	    	unset($timediff);
517
+	    	    }
421 518
 	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !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')))) {
422 519
 			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'])) {
423 520
 			    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'])) {
@@ -425,21 +522,31 @@  discard block
 block discarded – undo
425 522
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
426 523
 				$this->all_flights[$id]['putinarchive'] = true;
427 524
 				
428
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
525
+				if ($globalDebug) {
526
+					echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
527
+				}
429 528
 				$timeelapsed = microtime(true);
430 529
 				$Spotter = new Spotter($this->db);
431 530
 				$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
432
-				if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
531
+				if (!empty($all_country)) {
532
+					$this->all_flights[$id]['over_country'] = $all_country['iso2'];
533
+				}
433 534
 				$Spotter->db = null;
434
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
535
+				if ($globalDebugTimeElapsed) {
536
+					echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
537
+				}
435 538
 				$this->tmd = 0;
436
-				if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
539
+				if ($globalDebug) {
540
+					echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
541
+				}
437 542
 			    }
438 543
 			}
439 544
 
440 545
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
441 546
 			    //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
-				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
547
+				if (!isset($this->all_flights[$id]['archive_latitude'])) {
548
+					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
549
+				}
443 550
 				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 551
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
445 552
 				    $dataFound = true;
@@ -461,9 +568,13 @@  discard block
 block discarded – undo
461 568
 			    */
462 569
 			}
463 570
 			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;
571
+			    if ($line['longitude'] > 180) {
572
+			    	$line['longitude'] = $line['longitude'] - 360;
573
+			    }
465 574
 			    //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
-				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
575
+				if (!isset($this->all_flights[$id]['archive_longitude'])) {
576
+					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
577
+				}
467 578
 				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 579
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
469 580
 				    $dataFound = true;
@@ -494,7 +605,9 @@  discard block
 block discarded – undo
494 605
 		    }
495 606
 		}
496 607
 		if (isset($line['last_update']) && $line['last_update'] != '') {
497
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
608
+		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) {
609
+		    	$dataFound = true;
610
+		    }
498 611
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
499 612
 		}
500 613
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
@@ -516,11 +629,17 @@  discard block
 block discarded – undo
516 629
 			// Here we force archive of flight because after ground it's a new one (or should be)
517 630
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
518 631
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
519
-			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')));
520
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
521
-			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']));
632
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) {
633
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
634
+			} elseif (isset($line['id'])) {
635
+		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
636
+		        } elseif (isset($this->all_flights[$id]['ident'])) {
637
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
638
+			}
639
+		    }
640
+		    if ($line['ground'] != 1) {
641
+		    	$line['ground'] = 0;
522 642
 		    }
523
-		    if ($line['ground'] != 1) $line['ground'] = 0;
524 643
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
525 644
 		    //$dataFound = true;
526 645
 		}
@@ -528,28 +647,40 @@  discard block
 block discarded – undo
528 647
 		    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'])) {
529 648
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
530 649
 			    $highlight = '';
531
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
532
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
533
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
650
+			    if ($this->all_flights[$id]['squawk'] == '7500') {
651
+			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
652
+			    }
653
+			    if ($this->all_flights[$id]['squawk'] == '7600') {
654
+			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
655
+			    }
656
+			    if ($this->all_flights[$id]['squawk'] == '7700') {
657
+			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
658
+			    }
534 659
 			    if ($highlight != '') {
535 660
 				$timeelapsed = microtime(true);
536 661
 				$Spotter = new Spotter($this->db);
537 662
 				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
538 663
 				$Spotter->db = null;
539
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
664
+				if ($globalDebugTimeElapsed) {
665
+					echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
666
+				}
540 667
 
541 668
 				$this->all_flights[$id]['putinarchive'] = true;
542 669
 				//$putinarchive = true;
543 670
 				//$highlight = '';
544 671
 			    }
545 672
 			    
546
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
673
+		    } else {
674
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
675
+		    }
547 676
 		    //$dataFound = true;
548 677
 		}
549 678
 
550 679
 		if (isset($line['altitude']) && $line['altitude'] != '') {
551 680
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
552
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 2) $this->all_flights[$id]['putinarchive'] = true;
681
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 2) {
682
+				$this->all_flights[$id]['putinarchive'] = true;
683
+			}
553 684
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
554 685
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
555 686
 			//$dataFound = true;
@@ -561,21 +692,30 @@  discard block
 block discarded – undo
561 692
 		}
562 693
 		
563 694
 		if (isset($line['heading']) && $line['heading'] != '') {
564
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true;
695
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) {
696
+		    	$this->all_flights[$id]['putinarchive'] = true;
697
+		    }
565 698
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
566 699
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
567 700
 		    //$dataFound = true;
568 701
   		} 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']) {
569 702
   		    $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']);
570 703
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
571
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true;
572
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
704
+		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) {
705
+		    	$this->all_flights[$id]['putinarchive'] = true;
706
+		    }
707
+  		    if ($globalDebug) {
708
+  		    	echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
709
+  		    }
573 710
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
574 711
   		    // If not enough messages and ACARS set heading to 0
575 712
   		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
576 713
   		}
577
-		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
578
-		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
714
+		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) {
715
+			$dataFound = false;
716
+		} elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) {
717
+			$dataFound = false;
718
+		}
579 719
 
580 720
 //		print_r($this->all_flights[$id]);
581 721
 		//gets the callsign from the last hour
@@ -590,23 +730,36 @@  discard block
 block discarded – undo
590 730
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
591 731
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
592 732
 			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
593
-				if ($globalDebug) echo "Check if aircraft is already in DB...";
733
+				if ($globalDebug) {
734
+					echo "Check if aircraft is already in DB...";
735
+				}
594 736
 				$timeelapsed = microtime(true);
595 737
 				$SpotterLive = new SpotterLive($this->db);
596 738
 				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')) {
597 739
 				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
598
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
740
+				    if ($globalDebugTimeElapsed) {
741
+				    	echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
742
+				    }
599 743
 				} elseif (isset($line['id'])) {
600 744
 				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
601
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
745
+				    if ($globalDebugTimeElapsed) {
746
+				    	echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
747
+				    }
602 748
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
603 749
 				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
604
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
605
-				} else $recent_ident = '';
750
+				    if ($globalDebugTimeElapsed) {
751
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
752
+				    }
753
+				} else {
754
+					$recent_ident = '';
755
+				}
606 756
 				$SpotterLive->db=null;
607 757
 
608
-				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
609
-				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
758
+				if ($globalDebug && $recent_ident == '') {
759
+					echo " Not in DB.\n";
760
+				} elseif ($globalDebug && $recent_ident != '') {
761
+					echo " Already in DB.\n";
762
+				}
610 763
 			    } else {
611 764
 				$recent_ident = '';
612 765
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
@@ -614,7 +767,9 @@  discard block
 block discarded – undo
614 767
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
615 768
 			    if($recent_ident == "")
616 769
 			    {
617
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
770
+				if ($globalDebug) {
771
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
772
+				}
618 773
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
619 774
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
620 775
 				//adds the spotter data for the archive
@@ -658,26 +813,44 @@  discard block
 block discarded – undo
658 813
 				
659 814
 				if (!$ignoreImport) {
660 815
 				    $highlight = '';
661
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
662
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
663
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
664
-				    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')));
816
+				    if ($this->all_flights[$id]['squawk'] == '7500') {
817
+				    	$highlight = 'Squawk 7500 : Hijack';
818
+				    }
819
+				    if ($this->all_flights[$id]['squawk'] == '7600') {
820
+				    	$highlight = 'Squawk 7600 : Lost Comm (radio failure)';
821
+				    }
822
+				    if ($this->all_flights[$id]['squawk'] == '7700') {
823
+				    	$highlight = 'Squawk 7700 : Emergency';
824
+				    }
825
+				    if (!isset($this->all_flights[$id]['id'])) {
826
+				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
827
+				    }
665 828
 				    $timeelapsed = microtime(true);
666 829
 				    $Spotter = new Spotter($this->db);
667 830
 				    $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']);
668 831
 				    $Spotter->db = null;
669
-				    if ($globalDebug && isset($result)) echo $result."\n";
670
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
832
+				    if ($globalDebug && isset($result)) {
833
+				    	echo $result."\n";
834
+				    }
835
+				    if ($globalDebugTimeElapsed) {
836
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
837
+				    }
671 838
 				    
672 839
 				    // Add source stat in DB
673 840
 				    $Stats = new Stats($this->db);
674 841
 				    if (!empty($this->stats)) {
675
-					if ($globalDebug) echo 'Add source stats : ';
842
+					if ($globalDebug) {
843
+						echo 'Add source stats : ';
844
+					}
676 845
 				        foreach($this->stats as $date => $data) {
677 846
 					    foreach($data as $source => $sourced) {
678 847
 					        //print_r($sourced);
679
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
680
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
848
+				    	        if (isset($sourced['polar'])) {
849
+				    	        	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
850
+				    	        }
851
+				    	        if (isset($sourced['hist'])) {
852
+				    	        	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
853
+				    	        }
681 854
 				    		if (isset($sourced['msg'])) {
682 855
 				    		    if (time() - $sourced['msg']['date'] > 10) {
683 856
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -690,13 +863,17 @@  discard block
 block discarded – undo
690 863
 			    			unset($this->stats[$date]);
691 864
 			    		    }
692 865
 				    	}
693
-				    	if ($globalDebug) echo 'Done'."\n";
866
+				    	if ($globalDebug) {
867
+				    		echo 'Done'."\n";
868
+				    	}
694 869
 
695 870
 				    }
696 871
 				    $Stats->db = null;
697 872
 				    
698 873
 				    $this->del();
699
-				} elseif ($globalDebug) echo 'Ignore data'."\n";
874
+				} elseif ($globalDebug) {
875
+					echo 'Ignore data'."\n";
876
+				}
700 877
 				//$ignoreImport = false;
701 878
 				$this->all_flights[$id]['addedSpotter'] = 1;
702 879
 				//print_r($this->all_flights[$id]);
@@ -713,12 +890,16 @@  discard block
 block discarded – undo
713 890
 			*/
714 891
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
715 892
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
716
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
893
+				    if ($globalDebug) {
894
+				    	echo "---- Deleting Live Spotter data older than 9 hours...";
895
+				    }
717 896
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
718 897
 				    $SpotterLive = new SpotterLive($this->db);
719 898
 				    $SpotterLive->deleteLiveSpotterData();
720 899
 				    $SpotterLive->db=null;
721
-				    if ($globalDebug) echo " Done\n";
900
+				    if ($globalDebug) {
901
+				    	echo " Done\n";
902
+				    }
722 903
 				    $this->last_delete = time();
723 904
 				}
724 905
 			    } else {
@@ -741,11 +922,17 @@  discard block
 block discarded – undo
741 922
 		    //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";
742 923
 		    if ($globalDebug) {
743 924
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
744
-				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";
745
-				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";
925
+				if (isset($this->all_flights[$id]['source_name'])) {
926
+					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";
927
+				} else {
928
+					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";
929
+				}
746 930
 			} else {
747
-				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";
748
-				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";
931
+				if (isset($this->all_flights[$id]['source_name'])) {
932
+					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";
933
+				} else {
934
+					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";
935
+				}
749 936
 			}
750 937
 		    }
751 938
 		    $ignoreImport = false;
@@ -791,19 +978,25 @@  discard block
 block discarded – undo
791 978
 
792 979
 		    if (!$ignoreImport) {
793 980
 			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'])) {
794
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
981
+				if ($globalDebug) {
982
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
983
+				}
795 984
 				$timeelapsed = microtime(true);
796 985
 				$SpotterLive = new SpotterLive($this->db);
797 986
 				$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']);
798 987
 				$SpotterLive->db = null;
799
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
988
+				if ($globalDebugTimeElapsed) {
989
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
990
+				}
800 991
 
801 992
 				// Put statistics in $this->stats variable
802 993
 				//if ($line['format_source'] != 'aprs') {
803 994
 				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
804 995
 				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
805 996
 					$source = $this->all_flights[$id]['source_name'];
806
-					if ($source == '') $source = $this->all_flights[$id]['format_source'];
997
+					if ($source == '') {
998
+						$source = $this->all_flights[$id]['format_source'];
999
+					}
807 1000
 					if (!isset($this->source_location[$source])) {
808 1001
 						$Location = new Source();
809 1002
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -824,7 +1017,9 @@  discard block
 block discarded – undo
824 1017
 					$stats_heading = round($stats_heading/22.5);
825 1018
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
826 1019
 					$current_date = date('Y-m-d');
827
-					if ($stats_heading == 16) $stats_heading = 0;
1020
+					if ($stats_heading == 16) {
1021
+						$stats_heading = 0;
1022
+					}
828 1023
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
829 1024
 						for ($i=0;$i<=15;$i++) {
830 1025
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -842,7 +1037,9 @@  discard block
 block discarded – undo
842 1037
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
843 1038
 						    end($this->stats[$current_date][$source]['hist']);
844 1039
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
845
-						} else $mini = 0;
1040
+						} else {
1041
+							$mini = 0;
1042
+						}
846 1043
 						for ($i=$mini;$i<=$distance;$i+=10) {
847 1044
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
848 1045
 						}
@@ -853,20 +1050,30 @@  discard block
 block discarded – undo
853 1050
 				}
854 1051
 
855 1052
 				$this->all_flights[$id]['lastupdate'] = time();
856
-				if ($this->all_flights[$id]['putinarchive']) $send = true;
1053
+				if ($this->all_flights[$id]['putinarchive']) {
1054
+					$send = true;
1055
+				}
857 1056
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
858
-				if ($globalDebug) echo $result."\n";
859
-			} 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";
1057
+				if ($globalDebug) {
1058
+					echo $result."\n";
1059
+				}
1060
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
1061
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1062
+			}
860 1063
 			//$this->del();
861 1064
 			
862 1065
 			
863 1066
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
864
-			    if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1067
+			    if ($globalDebug) {
1068
+			    	echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1069
+			    }
865 1070
 			    $SpotterLive = new SpotterLive($this->db);
866 1071
 			    $SpotterLive->deleteLiveSpotterDataNotUpdated();
867 1072
 			    $SpotterLive->db = null;
868 1073
 			    //SpotterLive->deleteLiveSpotterData();
869
-			    if ($globalDebug) echo " Done\n";
1074
+			    if ($globalDebug) {
1075
+			    	echo " Done\n";
1076
+			    }
870 1077
 			    $this->last_delete_hourly = time();
871 1078
 			}
872 1079
 			
@@ -874,7 +1081,9 @@  discard block
 block discarded – undo
874 1081
 		    //$ignoreImport = false;
875 1082
 		}
876 1083
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
877
-		if ($send) return $this->all_flights[$id];
1084
+		if ($send) {
1085
+			return $this->all_flights[$id];
1086
+		}
878 1087
 	    }
879 1088
 	}
880 1089
     }
Please login to merge, or discard this patch.