Completed
Push — master ( b17dc0...e7edc5 )
by Yannick
07:05
created
require/class.SpotterImport.php 2 patches
Indentation   +422 added lines, -422 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;
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 23
 
24
-    public function __construct($dbc = null) {
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']) && isset($this->all_flights[$key]['datetime'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
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']) && isset($this->all_flights[$key]['datetime'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
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
-    	    }
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 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
-    }
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 178
 
179 179
 
180 180
 
181
-    public function del() {
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,54 +263,54 @@  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
-		    if ($globalDebug) echo 'New flight...'."\n";
271
-		    $this->all_flights[$id] = array();
272
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
273
-		    $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' => ''));
274
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
275
-		    if (!isset($line['id'])) {
270
+			if ($globalDebug) echo 'New flight...'."\n";
271
+			$this->all_flights[$id] = array();
272
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
273
+			$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' => ''));
274
+			if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
275
+			if (!isset($line['id'])) {
276 276
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
277 277
 //			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')));
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') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
279 279
 			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')));
280
-		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
281
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
282
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
280
+				//else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
281
+			 } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
282
+			if ($globalAllFlights !== FALSE) $dataFound = true;
283 283
 		}
284 284
 		if (isset($line['source_type']) && $line['source_type'] != '') {
285
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
285
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
286 286
 		}
287 287
 		
288 288
 		//print_r($this->all_flights);
289 289
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
290
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
291
-		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
290
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
291
+			//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
292 292
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
293
-		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
294
-		    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') {
293
+			//} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
294
+			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') {
295 295
 			$timeelapsed = microtime(true);
296 296
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
297
-			    $Spotter = new Spotter($this->db);
298
-			    if (isset($this->all_flights[$id]['source_type'])) {
297
+				$Spotter = new Spotter($this->db);
298
+				if (isset($this->all_flights[$id]['source_type'])) {
299 299
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
300
-			    } else {
300
+				} else {
301 301
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
302
-			    }
303
-			    $Spotter->db = null;
304
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
305
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
302
+				}
303
+				$Spotter->db = null;
304
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
305
+				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
306 306
 			}
307
-		    }
308
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
309
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
307
+			}
308
+			if ($globalAllFlights !== FALSE) $dataFound = true;
309
+			if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
310 310
 		}
311
-	        if (isset($line['id']) && !isset($line['hex'])) {
312
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
313
-	        }
311
+			if (isset($line['id']) && !isset($line['hex'])) {
312
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
313
+			}
314 314
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
315 315
 			$icao = $line['aircraft_icao'];
316 316
 			$Spotter = new Spotter($this->db);
@@ -339,9 +339,9 @@  discard block
 block discarded – undo
339 339
 		}
340 340
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
341 341
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) {
342
-		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
342
+			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
343 343
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
344
-		    } else {
344
+			} else {
345 345
 				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";
346 346
 				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";
347 347
 				/*
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 				print_r($line);
351 351
 				*/
352 352
 				return '';
353
-		    }
353
+			}
354 354
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
355 355
 			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
356 356
 			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,63 +415,63 @@  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'] != '' && $line['speed'] != 0) {
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) {
@@ -480,48 +480,48 @@  discard block
 block discarded – undo
480 480
 	  		} else {
481 481
 	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
482 482
 	  		}
483
-		    }
483
+			}
484 484
 		}
485 485
 
486 486
 
487 487
 
488
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
489
-	    	    if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
490
-	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
491
-	    	    	return false;
492
-	    	    }
493
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
494
-	    	    else unset($timediff);
495
-	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
496
-	    	    else unset($timediff_archive);
497
-	    	    if ($this->tmd > 5
498
-	    	        || (isset($line['format_source']) 
499
-	    	    	    && $line['format_source'] == 'airwhere' 
500
-	    	    	    && ((!isset($this->all_flights[$id]['latitude']) 
501
-	    	    		|| !isset($this->all_flights[$id]['longitude'])) 
502
-	    	    		|| (isset($this->all_flights[$id]['latitude']) 
503
-	    	    		    && isset($this->all_flights[$id]['longitude']) 
504
-	    	    		    && $this->all_flights[$id]['latitude'] != $line['latitude'] 
505
-	    	    		    && $this->all_flights[$id]['longitude'] != $line['longitude']
506
-	    	    		)
507
-	    	    	    )
508
-	    	    	)
509
-	    		|| (isset($globalVA) && $globalVA) 
510
-	    	    	|| (isset($globalIVAO) && $globalIVAO)
511
-	    	    	|| (isset($globalVATSIM) && $globalVATSIM)
512
-	    	    	|| (isset($globalphpVMS) && $globalphpVMS)
513
-	    	    	|| (isset($globalVAM) && $globalVAM)
514
-	    	    	|| !isset($timediff)
515
-	    	    	|| $timediff > $globalLiveInterval
516
-	    	    	|| ($timediff > 30 
517
-	    	    	    && isset($this->all_flights[$id]['latitude']) 
518
-	    	    	    && isset($this->all_flights[$id]['longitude']) 
519
-	    	    	    && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
520
-	    	    	    )
521
-	    	    	) {
488
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
489
+				if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
490
+					if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
491
+					return false;
492
+				}
493
+				if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
494
+				else unset($timediff);
495
+				if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
496
+				else unset($timediff_archive);
497
+				if ($this->tmd > 5
498
+					|| (isset($line['format_source']) 
499
+						&& $line['format_source'] == 'airwhere' 
500
+						&& ((!isset($this->all_flights[$id]['latitude']) 
501
+						|| !isset($this->all_flights[$id]['longitude'])) 
502
+						|| (isset($this->all_flights[$id]['latitude']) 
503
+							&& isset($this->all_flights[$id]['longitude']) 
504
+							&& $this->all_flights[$id]['latitude'] != $line['latitude'] 
505
+							&& $this->all_flights[$id]['longitude'] != $line['longitude']
506
+						)
507
+						)
508
+					)
509
+				|| (isset($globalVA) && $globalVA) 
510
+					|| (isset($globalIVAO) && $globalIVAO)
511
+					|| (isset($globalVATSIM) && $globalVATSIM)
512
+					|| (isset($globalphpVMS) && $globalphpVMS)
513
+					|| (isset($globalVAM) && $globalVAM)
514
+					|| !isset($timediff)
515
+					|| $timediff > $globalLiveInterval
516
+					|| ($timediff > 30 
517
+						&& isset($this->all_flights[$id]['latitude']) 
518
+						&& isset($this->all_flights[$id]['longitude']) 
519
+						&& $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
520
+						)
521
+					) {
522 522
 
523 523
 			if ((isset($timediff) && !isset($timediff_archive)) || (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude']))) {
524
-			    if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
524
+				if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
525 525
 				|| (isset($line['format_source']) && $line['format_source'] == 'airwhere') 
526 526
 				|| !$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'])) {
527 527
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -529,9 +529,9 @@  discard block
 block discarded – undo
529 529
 				$this->all_flights[$id]['putinarchive'] = true;
530 530
 				$this->tmd = 0;
531 531
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
532
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
533
-				    $timeelapsed = microtime(true);
534
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
532
+					if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
533
+					$timeelapsed = microtime(true);
534
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
535 535
 					$Spotter = new Spotter($this->db);
536 536
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
537 537
 					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
@@ -539,11 +539,11 @@  discard block
 block discarded – undo
539 539
 					$Spotter->db = null;
540 540
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
541 541
 					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
542
-				    }
542
+					}
543 543
 				}
544 544
 				$this->all_flights[$id]['time_last_archive_coord'] = time();
545
-			    } 
546
-			    /*
545
+				} 
546
+				/*
547 547
 			    else {
548 548
 				if (!isset($timediff)) echo 'NO TIMEDIFF';
549 549
 				else {
@@ -557,16 +557,16 @@  discard block
 block discarded – undo
557 557
 			}
558 558
 
559 559
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
560
-			    //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) {
560
+				//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) {
561 561
 				if (!isset($this->all_flights[$id]['archive_latitude'])) {
562 562
 					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
563 563
 					$this->all_flights[$id]['time_last_coord'] = time();
564 564
 				}
565 565
 				//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)) {
566 566
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
567
-				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
568
-				    $dataFound = true;
569
-				    $this->all_flights[$id]['time_last_coord'] = time();
567
+					$this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
568
+					$dataFound = true;
569
+					$this->all_flights[$id]['time_last_coord'] = time();
570 570
 				}
571 571
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
572 572
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
@@ -577,24 +577,24 @@  discard block
 block discarded – undo
577 577
 				    //$putinarchive = true;
578 578
 				}
579 579
 				*/
580
-			    /*
580
+				/*
581 581
 			    } elseif (isset($this->all_flights[$id]['latitude'])) {
582 582
 				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";
583 583
 			    }
584 584
 			    */
585 585
 			}
586 586
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
587
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
588
-			    //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) {
587
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
588
+				//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) {
589 589
 				if (!isset($this->all_flights[$id]['archive_longitude'])) {
590 590
 					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
591 591
 					$this->all_flights[$id]['time_last_coord'] = time();
592 592
 				}
593 593
 				//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)) {
594 594
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
595
-				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
596
-				    $dataFound = true;
597
-				    $this->all_flights[$id]['time_last_coord'] = time();
595
+					$this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
596
+					$dataFound = true;
597
+					$this->all_flights[$id]['time_last_coord'] = time();
598 598
 				}
599 599
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
600 600
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
@@ -612,77 +612,77 @@  discard block
 block discarded – undo
612 612
 			    */
613 613
 			}
614 614
 
615
-		    } else if ($globalDebug && $timediff > 30) {
615
+			} else if ($globalDebug && $timediff > 30) {
616 616
 			$this->tmd = $this->tmd + 1;
617 617
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
618 618
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
619 619
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
620 620
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
621
-		    }
621
+			}
622 622
 		}
623 623
 		if (isset($line['last_update']) && $line['last_update'] != '') {
624
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
625
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
624
+			if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
625
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
626 626
 		}
627 627
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
628
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
629
-		    //$dataFound = true;
628
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
629
+			//$dataFound = true;
630 630
 		}
631 631
 		if (isset($line['format_source']) && $line['format_source'] != '') {
632
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
632
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
633 633
 		}
634 634
 		if (isset($line['source_name']) && $line['source_name'] != '') {
635
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
635
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
636 636
 		}
637 637
 		if (isset($line['emergency']) && $line['emergency'] != '') {
638
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
639
-		    //$dataFound = true;
638
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
639
+			//$dataFound = true;
640 640
 		}
641 641
 		if (isset($line['ground']) && $line['ground'] != '') {
642
-		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
642
+			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
643 643
 			// Here we force archive of flight because after ground it's a new one (or should be)
644 644
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
645 645
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
646 646
 			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')));
647
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
647
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
648 648
 			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']));
649
-		    }
650
-		    if ($line['ground'] != 1) $line['ground'] = 0;
651
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
652
-		    //$dataFound = true;
649
+			}
650
+			if ($line['ground'] != 1) $line['ground'] = 0;
651
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
652
+			//$dataFound = true;
653 653
 		}
654 654
 		if (isset($line['squawk']) && $line['squawk'] != '') {
655
-		    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'])) {
656
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
657
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
658
-			    $highlight = '';
659
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
660
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
661
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
662
-			    if ($highlight != '') {
655
+			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'])) {
656
+				if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
657
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
658
+				$highlight = '';
659
+				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
660
+				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
661
+				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
662
+				if ($highlight != '') {
663 663
 				$timeelapsed = microtime(true);
664 664
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
665
-				    $Spotter = new Spotter($this->db);
666
-				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
667
-				    $Spotter->db = null;
668
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
665
+					$Spotter = new Spotter($this->db);
666
+					$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
667
+					$Spotter->db = null;
668
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
669 669
 				}
670 670
 				//$putinarchive = true;
671 671
 				//$highlight = '';
672
-			    }
672
+				}
673 673
 			    
674
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
675
-		    //$dataFound = true;
674
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
675
+			//$dataFound = true;
676 676
 		}
677 677
 
678 678
 		if (isset($line['altitude']) && $line['altitude'] != '') {
679
-		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
679
+			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
680 680
 			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;
681 681
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
682 682
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
683 683
 			//$dataFound = true;
684
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
685
-		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
684
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
685
+			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
686 686
 			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) {
687 687
 				if ($globalDebug) echo '--- Reset because of altitude'."\n";
688 688
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
@@ -691,27 +691,27 @@  discard block
 block discarded – undo
691 691
 				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
692 692
 				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']));
693 693
 			}
694
-		    }
695
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
694
+			}
695
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
696 696
 		}
697 697
 
698 698
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
699
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
699
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
700 700
 		}
701 701
 		
702 702
 		if (isset($line['heading']) && $line['heading'] != '') {
703
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
704
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
705
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
706
-		    //$dataFound = true;
703
+			if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
704
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
705
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
706
+			//$dataFound = true;
707 707
   		} 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']) {
708
-  		    $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']);
709
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
710
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
711
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
708
+  			$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']);
709
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
710
+			if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
711
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
712 712
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
713
-  		    // If not enough messages and ACARS set heading to 0
714
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
713
+  			// If not enough messages and ACARS set heading to 0
714
+  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
715 715
   		}
716 716
 		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
717 717
 		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
@@ -724,125 +724,125 @@  discard block
 block discarded – undo
724 724
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
725 725
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
726 726
 		if ($dataFound === true && isset($this->all_flights[$id]['id'])) {
727
-		    $this->all_flights[$id]['lastupdate'] = time();
728
-		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
729
-		        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'])) {
730
-			    //print_r($this->all_flights);
731
-			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
732
-			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
733
-			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
727
+			$this->all_flights[$id]['lastupdate'] = time();
728
+			if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
729
+				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'])) {
730
+				//print_r($this->all_flights);
731
+				//echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
732
+				//$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
733
+				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
734 734
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
735
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
736
-				    $timeelapsed = microtime(true);
737
-				    $SpotterLive = new SpotterLive($this->db);
738
-				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
735
+					if ($globalDebug) echo "Check if aircraft is already in DB...";
736
+					$timeelapsed = microtime(true);
737
+					$SpotterLive = new SpotterLive($this->db);
738
+					if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
739 739
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
740 740
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
741
-				    } elseif (isset($line['id'])) {
741
+					} elseif (isset($line['id'])) {
742 742
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
743 743
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
744
-				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
744
+					} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
745 745
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
746 746
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
747
-				    } else $recent_ident = '';
748
-				    $SpotterLive->db=null;
749
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
750
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
747
+					} else $recent_ident = '';
748
+					$SpotterLive->db=null;
749
+					if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
750
+					elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
751 751
 				} else $recent_ident = '';
752
-			    } else {
752
+				} else {
753 753
 				$recent_ident = '';
754 754
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
755
-			    }
756
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
757
-			    if($recent_ident == "")
758
-			    {
755
+				}
756
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
757
+				if($recent_ident == "")
758
+				{
759 759
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
760 760
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
761 761
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
762 762
 				//adds the spotter data for the archive
763 763
 				$ignoreImport = false;
764 764
 				foreach($globalAirportIgnore as $airportIgnore) {
765
-				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
765
+					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
766 766
 					$ignoreImport = true;
767
-				    }
767
+					}
768 768
 				}
769 769
 				if (count($globalAirportAccept) > 0) {
770
-				    $ignoreImport = true;
771
-				    foreach($globalAirportIgnore as $airportIgnore) {
770
+					$ignoreImport = true;
771
+					foreach($globalAirportIgnore as $airportIgnore) {
772 772
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
773
-					    $ignoreImport = false;
773
+						$ignoreImport = false;
774
+					}
774 775
 					}
775
-				    }
776 776
 				}
777 777
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
778
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
778
+					foreach($globalAirlineIgnore as $airlineIgnore) {
779 779
 					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)) {
780
-					    $ignoreImport = true;
780
+						$ignoreImport = true;
781
+					}
781 782
 					}
782
-				    }
783 783
 				}
784 784
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
785
-				    $ignoreImport = true;
786
-				    foreach($globalAirlineAccept as $airlineAccept) {
785
+					$ignoreImport = true;
786
+					foreach($globalAirlineAccept as $airlineAccept) {
787 787
 					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)) {
788
-					    $ignoreImport = false;
788
+						$ignoreImport = false;
789
+					}
789 790
 					}
790
-				    }
791 791
 				}
792 792
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
793
-				    $ignoreImport = true;
794
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
793
+					$ignoreImport = true;
794
+					foreach($globalPilotIdAccept as $pilotIdAccept) {
795 795
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
796
-					    $ignoreImport = false;
796
+						$ignoreImport = false;
797
+					}
797 798
 					}
798
-				    }
799 799
 				}
800 800
 				
801 801
 				if (!$ignoreImport) {
802
-				    $highlight = '';
803
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
804
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
805
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
806
-				    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')));
807
-				    $timeelapsed = microtime(true);
808
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
802
+					$highlight = '';
803
+					if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
804
+					if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
805
+					if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
806
+					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')));
807
+					$timeelapsed = microtime(true);
808
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
809 809
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
810
-					    $Spotter = new Spotter($this->db);
811
-					    $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']);
812
-					    $Spotter->db = null;
813
-					    if ($globalDebug && isset($result)) echo $result."\n";
810
+						$Spotter = new Spotter($this->db);
811
+						$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']);
812
+						$Spotter->db = null;
813
+						if ($globalDebug && isset($result)) echo $result."\n";
814 814
 					}
815
-				    }
816
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
817
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
815
+					}
816
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
817
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
818 818
 
819
-				    // Add source stat in DB
820
-				    $Stats = new Stats($this->db);
821
-				    if (!empty($this->stats)) {
819
+					// Add source stat in DB
820
+					$Stats = new Stats($this->db);
821
+					if (!empty($this->stats)) {
822 822
 					if ($globalDebug) echo 'Add source stats : ';
823
-				        foreach($this->stats as $date => $data) {
824
-					    foreach($data as $source => $sourced) {
825
-					        //print_r($sourced);
826
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
827
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
828
-				    		if (isset($sourced['msg'])) {
829
-				    		    if (time() - $sourced['msg']['date'] > 10) {
830
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
831
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
832
-			    			        unset($this->stats[$date][$source]['msg']);
833
-			    			    }
834
-			    			}
835
-			    		    }
836
-			    		    if ($date != date('Y-m-d')) {
837
-			    			unset($this->stats[$date]);
838
-			    		    }
839
-				    	}
840
-				    	if ($globalDebug) echo 'Done'."\n";
823
+						foreach($this->stats as $date => $data) {
824
+						foreach($data as $source => $sourced) {
825
+							//print_r($sourced);
826
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
827
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
828
+							if (isset($sourced['msg'])) {
829
+								if (time() - $sourced['msg']['date'] > 10) {
830
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
831
+									echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
832
+									unset($this->stats[$date][$source]['msg']);
833
+								}
834
+							}
835
+							}
836
+							if ($date != date('Y-m-d')) {
837
+							unset($this->stats[$date]);
838
+							}
839
+						}
840
+						if ($globalDebug) echo 'Done'."\n";
841 841
 
842
-				    }
843
-				    $Stats->db = null;
844
-				    }
845
-				    $this->del();
842
+					}
843
+					$Stats->db = null;
844
+					}
845
+					$this->del();
846 846
 				} elseif ($globalDebug) echo 'Ignore data'."\n";
847 847
 				//$ignoreImport = false;
848 848
 				$this->all_flights[$id]['addedSpotter'] = 1;
@@ -860,41 +860,41 @@  discard block
 block discarded – undo
860 860
 			*/
861 861
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
862 862
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
863
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
864
-				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
865
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
863
+					if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
864
+					//SpotterLive->deleteLiveSpotterDataNotUpdated();
865
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
866 866
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
867
-					    $SpotterLive = new SpotterLive($this->db);
868
-					    $SpotterLive->deleteLiveSpotterData();
869
-					    $SpotterLive->db=null;
867
+						$SpotterLive = new SpotterLive($this->db);
868
+						$SpotterLive->deleteLiveSpotterData();
869
+						$SpotterLive->db=null;
870 870
 					}
871
-				    }
872
-				    if ($globalDebug) echo " Done\n";
873
-				    $this->last_delete = time();
871
+					}
872
+					if ($globalDebug) echo " Done\n";
873
+					$this->last_delete = time();
874 874
 				}
875
-			    } else {
875
+				} else {
876 876
 				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')) {
877
-				    $this->all_flights[$id]['id'] = $recent_ident;
878
-				    $this->all_flights[$id]['addedSpotter'] = 1;
877
+					$this->all_flights[$id]['id'] = $recent_ident;
878
+					$this->all_flights[$id]['addedSpotter'] = 1;
879 879
 				}
880 880
 				if (isset($globalDaemon) && !$globalDaemon) {
881
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
881
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
882 882
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
883
-					    $Spotter = new Spotter($this->db);
884
-					    $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']);
885
-					    $Spotter->db = null;
883
+						$Spotter = new Spotter($this->db);
884
+						$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']);
885
+						$Spotter->db = null;
886
+					}
886 887
 					}
887
-				    }
888 888
 				}
889 889
 				
890
-			    }
890
+				}
891 891
 			}
892
-		    }
893
-		    //adds the spotter LIVE data
894
-		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
895
-		    //echo "\nAdd in Live !! \n";
896
-		    //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";
897
-		    if ($globalDebug) {
892
+			}
893
+			//adds the spotter LIVE data
894
+			//SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
895
+			//echo "\nAdd in Live !! \n";
896
+			//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";
897
+			if ($globalDebug) {
898 898
 			if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
899 899
 				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";
900 900
 				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";
@@ -902,60 +902,60 @@  discard block
 block discarded – undo
902 902
 				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";
903 903
 				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";
904 904
 			}
905
-		    }
906
-		    $ignoreImport = false;
907
-		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
908
-		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
905
+			}
906
+			$ignoreImport = false;
907
+			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
908
+			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
909 909
 
910
-		    foreach($globalAirportIgnore as $airportIgnore) {
911
-		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
912
-			    $ignoreImport = true;
910
+			foreach($globalAirportIgnore as $airportIgnore) {
911
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
912
+				$ignoreImport = true;
913
+			}
913 914
 			}
914
-		    }
915
-		    if (count($globalAirportAccept) > 0) {
916
-		        $ignoreImport = true;
917
-		        foreach($globalAirportIgnore as $airportIgnore) {
918
-			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
915
+			if (count($globalAirportAccept) > 0) {
916
+				$ignoreImport = true;
917
+				foreach($globalAirportIgnore as $airportIgnore) {
918
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
919 919
 				$ignoreImport = false;
920
-			    }
920
+				}
921 921
 			}
922
-		    }
923
-		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
922
+			}
923
+			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
924 924
 			foreach($globalAirlineIgnore as $airlineIgnore) {
925
-			    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)) {
925
+				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)) {
926 926
 				$ignoreImport = true;
927
-			    }
927
+				}
928 928
 			}
929
-		    }
930
-		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
929
+			}
930
+			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
931 931
 			$ignoreImport = true;
932 932
 			foreach($globalAirlineAccept as $airlineAccept) {
933
-			    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)) {
933
+				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)) {
934 934
 				$ignoreImport = false;
935
-			    }
935
+				}
936
+			}
936 937
 			}
937
-		    }
938
-		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
938
+			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
939 939
 			$ignoreImport = true;
940 940
 			foreach($globalPilotIdAccept as $pilotIdAccept) {
941
-			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
942
-			        $ignoreImport = false;
943
-			    }
941
+				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
942
+					$ignoreImport = false;
943
+				}
944
+			}
944 945
 			}
945
-		    }
946 946
 
947
-		    if (!$ignoreImport) {
947
+			if (!$ignoreImport) {
948 948
 			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'])) {
949 949
 				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')));
950 950
 				$timeelapsed = microtime(true);
951 951
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
952
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
952
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
953 953
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
954 954
 					$SpotterLive = new SpotterLive($this->db);
955 955
 					$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']);
956 956
 					$SpotterLive->db = null;
957 957
 					if ($globalDebug) echo $result."\n";
958
-				    }
958
+					}
959 959
 				}
960 960
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
961 961
 					$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']);
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
 				//if ($line['format_source'] != 'aprs') {
968 968
 				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
969 969
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
970
-				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
970
+					if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
971 971
 					$source = $this->all_flights[$id]['source_name'];
972 972
 					if ($source == '') $source = $this->all_flights[$id]['format_source'];
973 973
 					if (!isset($this->source_location[$source])) {
@@ -993,7 +993,7 @@  discard block
 block discarded – undo
993 993
 					if ($stats_heading == 16) $stats_heading = 0;
994 994
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
995 995
 						for ($i=0;$i<=15;$i++) {
996
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
996
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
997 997
 						}
998 998
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
999 999
 					} else {
@@ -1006,17 +1006,17 @@  discard block
 block discarded – undo
1006 1006
 					//var_dump($this->stats);
1007 1007
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
1008 1008
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1009
-						    end($this->stats[$current_date][$source]['hist']);
1010
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1009
+							end($this->stats[$current_date][$source]['hist']);
1010
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
1011 1011
 						} else $mini = 0;
1012 1012
 						for ($i=$mini;$i<=$distance;$i+=10) {
1013
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1013
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
1014 1014
 						}
1015 1015
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
1016 1016
 					} else {
1017 1017
 						$this->stats[$current_date][$source]['hist'][$distance] += 1;
1018 1018
 					}
1019
-				    }
1019
+					}
1020 1020
 				}
1021 1021
 
1022 1022
 				$this->all_flights[$id]['lastupdate'] = time();
@@ -1026,7 +1026,7 @@  discard block
 block discarded – undo
1026 1026
 			//$this->del();
1027 1027
 			
1028 1028
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
1029
-			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1029
+				if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1030 1030
 				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1031 1031
 				$SpotterLive = new SpotterLive($this->db);
1032 1032
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
@@ -1034,19 +1034,19 @@  discard block
 block discarded – undo
1034 1034
 				//SpotterLive->deleteLiveSpotterData();
1035 1035
 				if ($globalDebug) echo " Done\n";
1036 1036
 				$this->last_delete_hourly = time();
1037
-			    } else {
1037
+				} else {
1038 1038
 				$this->del();
1039 1039
 				$this->last_delete_hourly = time();
1040
-			    }
1040
+				}
1041 1041
 			}
1042 1042
 			
1043
-		    }
1044
-		    //$ignoreImport = false;
1043
+			}
1044
+			//$ignoreImport = false;
1045 1045
 		}
1046 1046
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
1047 1047
 		if ($send) return $this->all_flights[$id];
1048
-	    }
1048
+		}
1049
+	}
1049 1050
 	}
1050
-    }
1051 1051
 }
1052 1052
 ?>
Please login to merge, or discard this patch.
Braces   +398 added lines, -142 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']) && isset($this->all_flights[$key]['datetime'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
150
+        	    if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) {
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 = 3000;
216
-/*
252
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
253
+		$globalCoordMinChange = '0.02';
254
+	}
255
+	if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') {
256
+		$globalAircraftMaxUpdate = 3000;
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,23 +314,38 @@  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
-		    if ($globalDebug) echo 'New flight...'."\n";
324
+		    if ($globalDebug) {
325
+		    	echo 'New flight...'."\n";
326
+		    }
271 327
 		    $this->all_flights[$id] = array();
272 328
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
273 329
 		    $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' => ''));
274
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
330
+		    if (isset($globalDaemon) && $globalDaemon === FALSE) {
331
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
332
+		    }
275 333
 		    if (!isset($line['id'])) {
276
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
277
-//			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')));
334
+			if (!isset($globalDaemon)) {
335
+				$globalDaemon = TRUE;
336
+			}
337
+			//			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')));
278 338
 //			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')));
279
-			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')));
339
+			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')) {
340
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
341
+			}
280 342
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
281
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
282
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
343
+		     } else {
344
+		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
345
+		     }
346
+		    if ($globalAllFlights !== FALSE) {
347
+		    	$dataFound = true;
348
+		    }
283 349
 		}
284 350
 		if (isset($line['source_type']) && $line['source_type'] != '') {
285 351
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
@@ -301,12 +367,20 @@  discard block
 block discarded – undo
301 367
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
302 368
 			    }
303 369
 			    $Spotter->db = null;
304
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
305
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
370
+			    if ($globalDebugTimeElapsed) {
371
+			    	echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
372
+			    }
373
+			    if ($aircraft_icao != '') {
374
+			    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
375
+			    }
306 376
 			}
307 377
 		    }
308
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
309
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
378
+		    if ($globalAllFlights !== FALSE) {
379
+		    	$dataFound = true;
380
+		    }
381
+		    if ($globalDebug) {
382
+		    	echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
383
+		    }
310 384
 		}
311 385
 	        if (isset($line['id']) && !isset($line['hex'])) {
312 386
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
@@ -314,7 +388,9 @@  discard block
 block discarded – undo
314 388
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
315 389
 			$icao = $line['aircraft_icao'];
316 390
 			$Spotter = new Spotter($this->db);
317
-			if (isset($Spotter->aircraft_correct_icaotype[$icao])) $icao = $Spotter->aircraft_correct_icaotype[$icao];
391
+			if (isset($Spotter->aircraft_correct_icaotype[$icao])) {
392
+				$icao = $Spotter->aircraft_correct_icaotype[$icao];
393
+			}
318 394
 			$Spotter->db = null;
319 395
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $icao));
320 396
 		}
@@ -324,15 +400,24 @@  discard block
 block discarded – undo
324 400
 				$Spotter = new Spotter($this->db);
325 401
 				$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
326 402
 				$Spotter->db = null;
327
-				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
403
+				if ($aircraft_icao != '') {
404
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
405
+				}
328 406
 			}
329 407
 		}
330 408
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
331
-			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
332
-			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
333
-			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
334
-			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
335
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
409
+			if ($line['aircraft_type'] == 'PARA_GLIDER') {
410
+				$aircraft_icao = 'GLID';
411
+			} elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') {
412
+				$aircraft_icao = 'UHEL';
413
+			} elseif ($line['aircraft_type'] == 'TOW_PLANE') {
414
+				$aircraft_icao = 'TOWPLANE';
415
+			} elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') {
416
+				$aircraft_icao = 'POWAIRC';
417
+			}
418
+			if (isset($aircraft_icao)) {
419
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
420
+			}
336 421
 		}
337 422
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
338 423
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
@@ -342,8 +427,11 @@  discard block
 block discarded – undo
342 427
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
343 428
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
344 429
 		    } else {
345
-				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";
346
-				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";
430
+				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
431
+					echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
432
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
433
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
434
+				}
347 435
 				/*
348 436
 				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
349 437
 				print_r($this->all_flights[$id]);
@@ -352,16 +440,22 @@  discard block
 block discarded – undo
352 440
 				return '';
353 441
 		    }
354 442
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
355
-			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
443
+			if ($globalDebug) {
444
+				echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
445
+			}
356 446
 			return '';
357 447
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) {
358
-			if ($globalDebug) echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
448
+			if ($globalDebug) {
449
+				echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
450
+			}
359 451
 			return '';
360 452
 		} elseif (!isset($line['datetime'])) {
361 453
 			date_default_timezone_set('UTC');
362 454
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
363 455
 		} else {
364
-			if ($globalDebug) echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
456
+			if ($globalDebug) {
457
+				echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
458
+			}
365 459
 			return '';
366 460
 		}
367 461
 
@@ -382,30 +476,48 @@  discard block
 block discarded – undo
382 476
 
383 477
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
384 478
 			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";
479
+				if ($globalDebug) {
480
+					echo '---!!!! New ident, reset aircraft data...'."\n";
481
+				}
386 482
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
387 483
 				$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']));
484
+				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')) {
485
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
486
+				} elseif (isset($line['id'])) {
487
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
488
+				} elseif (isset($this->all_flights[$id]['ident'])) {
489
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
490
+				}
391 491
 			} else {
392 492
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
393 493
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
394 494
 				$timeelapsed = microtime(true);
395 495
             			$Spotter = new Spotter($this->db);
396 496
             			$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';
497
+            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') {
498
+            				$fromsource = $globalAirlinesSource;
499
+            			} elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') {
500
+            				$fromsource = 'vatsim';
501
+            			} elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') {
502
+					$fromsource = 'ivao';
503
+				} elseif (isset($globalVATSIM) && $globalVATSIM) {
504
+					$fromsource = 'vatsim';
505
+				} elseif (isset($globalIVAO) && $globalIVAO) {
506
+					$fromsource = 'ivao';
507
+				}
402 508
             			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
403
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
509
+				if ($globalDebug && $result != 'success') {
510
+					echo '!!! ERROR : '.$result."\n";
511
+				}
404 512
 				$Spotter->db = null;
405
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
513
+				if ($globalDebugTimeElapsed) {
514
+					echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
515
+				}
406 516
 			    }
407 517
 			}
408
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
518
+		    } else {
519
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
520
+		    }
409 521
 		    
410 522
 /*
411 523
 		    if (!isset($line['id'])) {
@@ -415,7 +527,9 @@  discard block
 block discarded – undo
415 527
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
416 528
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
417 529
   */
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']));
530
+		    if (!isset($this->all_flights[$id]['id'])) {
531
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
532
+		    }
419 533
 
420 534
 		    //$putinarchive = true;
421 535
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
@@ -433,7 +547,9 @@  discard block
 block discarded – undo
433 547
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
434 548
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
435 549
 		    		$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";
550
+				if ($globalDebugTimeElapsed) {
551
+					echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
552
+				}
437 553
                         }
438 554
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
439 555
 			$timeelapsed = microtime(true);
@@ -447,7 +563,9 @@  discard block
 block discarded – undo
447 563
 				$Translation->db = null;
448 564
 			    }
449 565
 			    $Spotter->db = null;
450
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
566
+			    if ($globalDebugTimeElapsed) {
567
+			    	echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
568
+			    }
451 569
                     	}
452 570
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
453 571
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
@@ -456,9 +574,13 @@  discard block
 block discarded – undo
456 574
 		    		$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 575
 		    	    }
458 576
 			}
459
-			if (!isset($globalFork)) $globalFork = TRUE;
577
+			if (!isset($globalFork)) {
578
+				$globalFork = TRUE;
579
+			}
460 580
 			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']));
581
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) {
582
+					$this->get_Schedule($id,trim($line['ident']));
583
+				}
462 584
 			}
463 585
 		    }
464 586
 		}
@@ -476,9 +598,13 @@  discard block
 block discarded – undo
476 598
 			$speed = $speed*3.6;
477 599
 			if ($speed < 1000) {
478 600
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
479
-	  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
601
+	  			if ($globalDebug) {
602
+	  				echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
603
+	  			}
480 604
 	  		} else {
481
-	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
605
+	  			if ($globalDebug) {
606
+	  				echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
607
+	  			}
482 608
 	  		}
483 609
 		    }
484 610
 		}
@@ -487,13 +613,21 @@  discard block
 block discarded – undo
487 613
 
488 614
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
489 615
 	    	    if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
490
-	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
616
+	    	    	if ($globalDebug) {
617
+	    	    		echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
618
+	    	    	}
491 619
 	    	    	return false;
492 620
 	    	    }
493
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
494
-	    	    else unset($timediff);
495
-	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
496
-	    	    else unset($timediff_archive);
621
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) {
622
+	    	    	$timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
623
+	    	    } else {
624
+	    	    	unset($timediff);
625
+	    	    }
626
+	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) {
627
+	    	    	$timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
628
+	    	    } else {
629
+	    	    	unset($timediff_archive);
630
+	    	    }
497 631
 	    	    if ($this->tmd > 5
498 632
 	    	        || (isset($line['format_source']) 
499 633
 	    	    	    && $line['format_source'] == 'airwhere' 
@@ -529,16 +663,25 @@  discard block
 block discarded – undo
529 663
 				$this->all_flights[$id]['putinarchive'] = true;
530 664
 				$this->tmd = 0;
531 665
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
532
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
666
+				    if ($globalDebug) {
667
+				    	echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
668
+				    }
533 669
 				    $timeelapsed = microtime(true);
534 670
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
535 671
 					$Spotter = new Spotter($this->db);
536 672
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
537
-					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
538
-					else $this->all_flights[$id]['over_country'] = '';
673
+					if (!empty($all_country)) {
674
+						$this->all_flights[$id]['over_country'] = $all_country['iso2'];
675
+					} else {
676
+						$this->all_flights[$id]['over_country'] = '';
677
+					}
539 678
 					$Spotter->db = null;
540
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
541
-					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
679
+					if ($globalDebugTimeElapsed) {
680
+						echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
681
+					}
682
+					if ($globalDebug) {
683
+						echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
684
+					}
542 685
 				    }
543 686
 				}
544 687
 				$this->all_flights[$id]['time_last_archive_coord'] = time();
@@ -584,7 +727,9 @@  discard block
 block discarded – undo
584 727
 			    */
585 728
 			}
586 729
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
587
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
730
+			    if ($line['longitude'] > 180) {
731
+			    	$line['longitude'] = $line['longitude'] - 360;
732
+			    }
588 733
 			    //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) {
589 734
 				if (!isset($this->all_flights[$id]['archive_longitude'])) {
590 735
 					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
@@ -621,7 +766,9 @@  discard block
 block discarded – undo
621 766
 		    }
622 767
 		}
623 768
 		if (isset($line['last_update']) && $line['last_update'] != '') {
624
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
769
+		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) {
770
+		    	$dataFound = true;
771
+		    }
625 772
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
626 773
 		}
627 774
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
@@ -643,53 +790,79 @@  discard block
 block discarded – undo
643 790
 			// Here we force archive of flight because after ground it's a new one (or should be)
644 791
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
645 792
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
646
-			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')));
647
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
648
-			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']));
793
+			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')) {
794
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
795
+			} elseif (isset($line['id'])) {
796
+		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
797
+		        } elseif (isset($this->all_flights[$id]['ident'])) {
798
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
799
+			}
800
+		    }
801
+		    if ($line['ground'] != 1) {
802
+		    	$line['ground'] = 0;
649 803
 		    }
650
-		    if ($line['ground'] != 1) $line['ground'] = 0;
651 804
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
652 805
 		    //$dataFound = true;
653 806
 		}
654 807
 		if (isset($line['squawk']) && $line['squawk'] != '') {
655 808
 		    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'])) {
656
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
809
+			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) {
810
+			    	$this->all_flights[$id]['putinarchive'] = true;
811
+			    }
657 812
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
658 813
 			    $highlight = '';
659
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
660
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
661
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
814
+			    if ($this->all_flights[$id]['squawk'] == '7500') {
815
+			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
816
+			    }
817
+			    if ($this->all_flights[$id]['squawk'] == '7600') {
818
+			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
819
+			    }
820
+			    if ($this->all_flights[$id]['squawk'] == '7700') {
821
+			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
822
+			    }
662 823
 			    if ($highlight != '') {
663 824
 				$timeelapsed = microtime(true);
664 825
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
665 826
 				    $Spotter = new Spotter($this->db);
666 827
 				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
667 828
 				    $Spotter->db = null;
668
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
829
+				    if ($globalDebugTimeElapsed) {
830
+				    	echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
831
+				    }
669 832
 				}
670 833
 				//$putinarchive = true;
671 834
 				//$highlight = '';
672 835
 			    }
673 836
 			    
674
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
837
+		    } else {
838
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
839
+		    }
675 840
 		    //$dataFound = true;
676 841
 		}
677 842
 
678 843
 		if (isset($line['altitude']) && $line['altitude'] != '') {
679 844
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
680
-			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;
845
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) {
846
+				$this->all_flights[$id]['putinarchive'] = true;
847
+			}
681 848
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
682 849
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
683 850
 			//$dataFound = true;
684 851
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
685 852
 		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
686 853
 			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) {
687
-				if ($globalDebug) echo '--- Reset because of altitude'."\n";
854
+				if ($globalDebug) {
855
+					echo '--- Reset because of altitude'."\n";
856
+				}
688 857
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
689 858
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
690
-				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')));
691
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
692
-				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']));
859
+				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')) {
860
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
861
+				} elseif (isset($line['id'])) {
862
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
863
+				} elseif (isset($this->all_flights[$id]['ident'])) {
864
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
865
+				}
693 866
 			}
694 867
 		    }
695 868
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
@@ -700,22 +873,32 @@  discard block
 block discarded – undo
700 873
 		}
701 874
 		
702 875
 		if (isset($line['heading']) && $line['heading'] != '') {
703
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
876
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) {
877
+		    	$this->all_flights[$id]['putinarchive'] = true;
878
+		    }
704 879
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
705 880
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
706 881
 		    //$dataFound = true;
707 882
   		} 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']) {
708 883
   		    $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']);
709 884
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
710
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
711
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
885
+		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) {
886
+		    	$this->all_flights[$id]['putinarchive'] = true;
887
+		    }
888
+  		    if ($globalDebug) {
889
+  		    	echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
890
+  		    }
712 891
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
713 892
   		    // If not enough messages and ACARS set heading to 0
714 893
   		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
715 894
   		}
716
-		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
717
-		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
718
-		elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalMinupdate) $dataFound = false;
895
+		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) {
896
+			$dataFound = false;
897
+		} elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) {
898
+			$dataFound = false;
899
+		} elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalMinupdate) {
900
+			$dataFound = false;
901
+		}
719 902
 
720 903
 //		print_r($this->all_flights[$id]);
721 904
 		//gets the callsign from the last hour
@@ -732,23 +915,38 @@  discard block
 block discarded – undo
732 915
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
733 916
 			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
734 917
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
735
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
918
+				    if ($globalDebug) {
919
+				    	echo "Check if aircraft is already in DB...";
920
+				    }
736 921
 				    $timeelapsed = microtime(true);
737 922
 				    $SpotterLive = new SpotterLive($this->db);
738 923
 				    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')) {
739 924
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
740
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
925
+					if ($globalDebugTimeElapsed) {
926
+						echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
927
+					}
741 928
 				    } elseif (isset($line['id'])) {
742 929
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
743
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
930
+					if ($globalDebugTimeElapsed) {
931
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
932
+					}
744 933
 				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
745 934
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
746
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
747
-				    } else $recent_ident = '';
935
+					if ($globalDebugTimeElapsed) {
936
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
937
+					}
938
+				    } else {
939
+				    	$recent_ident = '';
940
+				    }
748 941
 				    $SpotterLive->db=null;
749
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
750
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
751
-				} else $recent_ident = '';
942
+				    if ($globalDebug && $recent_ident == '') {
943
+				    	echo " Not in DB.\n";
944
+				    } elseif ($globalDebug && $recent_ident != '') {
945
+				    	echo " Already in DB.\n";
946
+				    }
947
+				} else {
948
+					$recent_ident = '';
949
+				}
752 950
 			    } else {
753 951
 				$recent_ident = '';
754 952
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
@@ -756,7 +954,9 @@  discard block
 block discarded – undo
756 954
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
757 955
 			    if($recent_ident == "")
758 956
 			    {
759
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
957
+				if ($globalDebug) {
958
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
959
+				}
760 960
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
761 961
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
762 962
 				//adds the spotter data for the archive
@@ -800,31 +1000,49 @@  discard block
 block discarded – undo
800 1000
 				
801 1001
 				if (!$ignoreImport) {
802 1002
 				    $highlight = '';
803
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
804
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
805
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
806
-				    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')));
1003
+				    if ($this->all_flights[$id]['squawk'] == '7500') {
1004
+				    	$highlight = 'Squawk 7500 : Hijack';
1005
+				    }
1006
+				    if ($this->all_flights[$id]['squawk'] == '7600') {
1007
+				    	$highlight = 'Squawk 7600 : Lost Comm (radio failure)';
1008
+				    }
1009
+				    if ($this->all_flights[$id]['squawk'] == '7700') {
1010
+				    	$highlight = 'Squawk 7700 : Emergency';
1011
+				    }
1012
+				    if (!isset($this->all_flights[$id]['id'])) {
1013
+				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1014
+				    }
807 1015
 				    $timeelapsed = microtime(true);
808 1016
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
809 1017
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
810 1018
 					    $Spotter = new Spotter($this->db);
811 1019
 					    $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']);
812 1020
 					    $Spotter->db = null;
813
-					    if ($globalDebug && isset($result)) echo $result."\n";
1021
+					    if ($globalDebug && isset($result)) {
1022
+					    	echo $result."\n";
1023
+					    }
814 1024
 					}
815 1025
 				    }
816
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1026
+				    if ($globalDebugTimeElapsed) {
1027
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1028
+				    }
817 1029
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
818 1030
 
819 1031
 				    // Add source stat in DB
820 1032
 				    $Stats = new Stats($this->db);
821 1033
 				    if (!empty($this->stats)) {
822
-					if ($globalDebug) echo 'Add source stats : ';
1034
+					if ($globalDebug) {
1035
+						echo 'Add source stats : ';
1036
+					}
823 1037
 				        foreach($this->stats as $date => $data) {
824 1038
 					    foreach($data as $source => $sourced) {
825 1039
 					        //print_r($sourced);
826
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
827
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
1040
+				    	        if (isset($sourced['polar'])) {
1041
+				    	        	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
1042
+				    	        }
1043
+				    	        if (isset($sourced['hist'])) {
1044
+				    	        	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
1045
+				    	        }
828 1046
 				    		if (isset($sourced['msg'])) {
829 1047
 				    		    if (time() - $sourced['msg']['date'] > 10) {
830 1048
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -837,13 +1055,17 @@  discard block
 block discarded – undo
837 1055
 			    			unset($this->stats[$date]);
838 1056
 			    		    }
839 1057
 				    	}
840
-				    	if ($globalDebug) echo 'Done'."\n";
1058
+				    	if ($globalDebug) {
1059
+				    		echo 'Done'."\n";
1060
+				    	}
841 1061
 
842 1062
 				    }
843 1063
 				    $Stats->db = null;
844 1064
 				    }
845 1065
 				    $this->del();
846
-				} elseif ($globalDebug) echo 'Ignore data'."\n";
1066
+				} elseif ($globalDebug) {
1067
+					echo 'Ignore data'."\n";
1068
+				}
847 1069
 				//$ignoreImport = false;
848 1070
 				$this->all_flights[$id]['addedSpotter'] = 1;
849 1071
 				//print_r($this->all_flights[$id]);
@@ -860,7 +1082,9 @@  discard block
 block discarded – undo
860 1082
 			*/
861 1083
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
862 1084
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
863
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
1085
+				    if ($globalDebug) {
1086
+				    	echo "---- Deleting Live Spotter data older than 9 hours...";
1087
+				    }
864 1088
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
865 1089
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
866 1090
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -869,7 +1093,9 @@  discard block
 block discarded – undo
869 1093
 					    $SpotterLive->db=null;
870 1094
 					}
871 1095
 				    }
872
-				    if ($globalDebug) echo " Done\n";
1096
+				    if ($globalDebug) {
1097
+				    	echo " Done\n";
1098
+				    }
873 1099
 				    $this->last_delete = time();
874 1100
 				}
875 1101
 			    } else {
@@ -896,11 +1122,17 @@  discard block
 block discarded – undo
896 1122
 		    //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";
897 1123
 		    if ($globalDebug) {
898 1124
 			if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
899
-				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";
900
-				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";
1125
+				if (isset($this->all_flights[$id]['source_name'])) {
1126
+					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";
1127
+				} else {
1128
+					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";
1129
+				}
901 1130
 			} else {
902
-				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";
903
-				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";
1131
+				if (isset($this->all_flights[$id]['source_name'])) {
1132
+					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";
1133
+				} else {
1134
+					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";
1135
+				}
904 1136
 			}
905 1137
 		    }
906 1138
 		    $ignoreImport = false;
@@ -946,22 +1178,30 @@  discard block
 block discarded – undo
946 1178
 
947 1179
 		    if (!$ignoreImport) {
948 1180
 			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'])) {
949
-				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')));
1181
+				if (!isset($this->all_flights[$id]['id'])) {
1182
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1183
+				}
950 1184
 				$timeelapsed = microtime(true);
951 1185
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
952 1186
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
953
-					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1187
+					if ($globalDebug) {
1188
+						echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1189
+					}
954 1190
 					$SpotterLive = new SpotterLive($this->db);
955 1191
 					$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']);
956 1192
 					$SpotterLive->db = null;
957
-					if ($globalDebug) echo $result."\n";
1193
+					if ($globalDebug) {
1194
+						echo $result."\n";
1195
+					}
958 1196
 				    }
959 1197
 				}
960 1198
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
961 1199
 					$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']);
962 1200
 				}
963 1201
 				$this->all_flights[$id]['putinarchive'] = false;
964
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1202
+				if ($globalDebugTimeElapsed) {
1203
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1204
+				}
965 1205
 
966 1206
 				// Put statistics in $this->stats variable
967 1207
 				//if ($line['format_source'] != 'aprs') {
@@ -969,7 +1209,9 @@  discard block
 block discarded – undo
969 1209
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
970 1210
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
971 1211
 					$source = $this->all_flights[$id]['source_name'];
972
-					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1212
+					if ($source == '') {
1213
+						$source = $this->all_flights[$id]['format_source'];
1214
+					}
973 1215
 					if (!isset($this->source_location[$source])) {
974 1216
 						$Location = new Source();
975 1217
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -990,7 +1232,9 @@  discard block
 block discarded – undo
990 1232
 					$stats_heading = round($stats_heading/22.5);
991 1233
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
992 1234
 					$current_date = date('Y-m-d');
993
-					if ($stats_heading == 16) $stats_heading = 0;
1235
+					if ($stats_heading == 16) {
1236
+						$stats_heading = 0;
1237
+					}
994 1238
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
995 1239
 						for ($i=0;$i<=15;$i++) {
996 1240
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -1008,7 +1252,9 @@  discard block
 block discarded – undo
1008 1252
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1009 1253
 						    end($this->stats[$current_date][$source]['hist']);
1010 1254
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1011
-						} else $mini = 0;
1255
+						} else {
1256
+							$mini = 0;
1257
+						}
1012 1258
 						for ($i=$mini;$i<=$distance;$i+=10) {
1013 1259
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1014 1260
 						}
@@ -1020,19 +1266,27 @@  discard block
 block discarded – undo
1020 1266
 				}
1021 1267
 
1022 1268
 				$this->all_flights[$id]['lastupdate'] = time();
1023
-				if ($this->all_flights[$id]['putinarchive']) $send = true;
1269
+				if ($this->all_flights[$id]['putinarchive']) {
1270
+					$send = true;
1271
+				}
1024 1272
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1025
-			} 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";
1273
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
1274
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1275
+			}
1026 1276
 			//$this->del();
1027 1277
 			
1028 1278
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
1029 1279
 			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1030
-				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1280
+				if ($globalDebug) {
1281
+					echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1282
+				}
1031 1283
 				$SpotterLive = new SpotterLive($this->db);
1032 1284
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
1033 1285
 				$SpotterLive->db = null;
1034 1286
 				//SpotterLive->deleteLiveSpotterData();
1035
-				if ($globalDebug) echo " Done\n";
1287
+				if ($globalDebug) {
1288
+					echo " Done\n";
1289
+				}
1036 1290
 				$this->last_delete_hourly = time();
1037 1291
 			    } else {
1038 1292
 				$this->del();
@@ -1044,7 +1298,9 @@  discard block
 block discarded – undo
1044 1298
 		    //$ignoreImport = false;
1045 1299
 		}
1046 1300
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
1047
-		if ($send) return $this->all_flights[$id];
1301
+		if ($send) {
1302
+			return $this->all_flights[$id];
1303
+		}
1048 1304
 	    }
1049 1305
 	}
1050 1306
     }
Please login to merge, or discard this patch.