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