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