Completed
Push — master ( 57ec45...7a0770 )
by Yannick
33:58
created
require/class.SpotterImport.php 1 patch
Indentation   +422 added lines, -422 removed lines patch added patch discarded remove patch
@@ -9,20 +9,20 @@  discard block
 block discarded – undo
9 9
 require_once(dirname(__FILE__).'/class.Source.php');
10 10
 require_once(dirname(__FILE__).'/class.GeoidHeight.php');
11 11
 if (isset($globalServerAPRS) && $globalServerAPRS) {
12
-    require_once(dirname(__FILE__).'/class.APRS.php');
12
+	require_once(dirname(__FILE__).'/class.APRS.php');
13 13
 }
14 14
 
15 15
 class SpotterImport {
16
-    private $all_flights = array();
17
-    private $last_delete_hourly = 0;
18
-    private $last_delete = 0;
19
-    private $stats = array();
20
-    private $tmd = 0;
21
-    private $source_location = array();
22
-    public $db = null;
23
-    public $nb = 0;
16
+	private $all_flights = array();
17
+	private $last_delete_hourly = 0;
18
+	private $last_delete = 0;
19
+	private $stats = array();
20
+	private $tmd = 0;
21
+	private $source_location = array();
22
+	public $db = null;
23
+	public $nb = 0;
24 24
 
25
-    public function __construct($dbc = null) {
25
+	public function __construct($dbc = null) {
26 26
 	global $globalBeta, $globalServerAPRS, $APRSSpotter, $globalNoDB, $GeoidClass, $globalDebug, $globalGeoid;
27 27
 	if (!(isset($globalNoDB) && $globalNoDB)) {
28 28
 		$Connection = new Connection($dbc);
@@ -34,14 +34,14 @@  discard block
 block discarded – undo
34 34
 		$currentdate = date('Y-m-d');
35 35
 		$sourcestat = $Stats->getStatsSource($currentdate);
36 36
 		if (!empty($sourcestat)) {
37
-		    foreach($sourcestat as $srcst) {
38
-		    	$type = $srcst['stats_type'];
37
+			foreach($sourcestat as $srcst) {
38
+				$type = $srcst['stats_type'];
39 39
 			if ($type == 'polar' || $type == 'hist') {
40
-			    $source = $srcst['source_name'];
41
-			    $data = $srcst['source_data'];
42
-			    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
43
-	    		}
44
-		    }
40
+				$source = $srcst['source_name'];
41
+				$data = $srcst['source_data'];
42
+				$this->stats[$currentdate][$source][$type] = json_decode($data,true);
43
+				}
44
+			}
45 45
 		}
46 46
 	}
47 47
 	if (isset($globalServerAPRS) && $globalServerAPRS) {
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 			$GeoidClass = FALSE;
57 57
 		}
58 58
 	}
59
-    }
59
+	}
60 60
 
61
-    public function get_Schedule($id,$ident) {
61
+	public function get_Schedule($id,$ident) {
62 62
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
63 63
 	// Get schedule here, so it's done only one time
64 64
 	
@@ -78,42 +78,42 @@  discard block
 block discarded – undo
78 78
 	$operator = $Spotter->getOperator($ident);
79 79
 	$scheduleexist = false;
80 80
 	if ($Schedule->checkSchedule($operator) == 0) {
81
-	    $operator = $Translation->checkTranslation($ident);
82
-	    if ($Schedule->checkSchedule($operator) == 0) {
81
+		$operator = $Translation->checkTranslation($ident);
82
+		if ($Schedule->checkSchedule($operator) == 0) {
83 83
 		$schedule = $Schedule->fetchSchedule($operator);
84 84
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
85
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
86
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
87
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
88
-		    // Should also check if route schedule = route from DB
89
-		    if ($schedule['DepartureAirportIATA'] != '') {
85
+			if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
86
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
87
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
88
+			// Should also check if route schedule = route from DB
89
+			if ($schedule['DepartureAirportIATA'] != '') {
90 90
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
91
-			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
92
-			    if (trim($airport_icao) != '') {
91
+				$airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
92
+				if (trim($airport_icao) != '') {
93 93
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
94 94
 				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
95
-			    }
95
+				}
96
+			}
96 97
 			}
97
-		    }
98
-		    if ($schedule['ArrivalAirportIATA'] != '') {
98
+			if ($schedule['ArrivalAirportIATA'] != '') {
99 99
 			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) {
100
-			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
101
-			    if (trim($airport_icao) != '') {
100
+				$airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
101
+				if (trim($airport_icao) != '') {
102 102
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
103 103
 				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
104
-			    }
104
+				}
105 105
 			}
106
-		    }
107
-		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
106
+			}
107
+			$Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
108 108
 		}
109
-	    } else $scheduleexist = true;
109
+		} else $scheduleexist = true;
110 110
 	} else $scheduleexist = true;
111 111
 	// close connection, at least one way will work ?
112
-       if ($scheduleexist) {
112
+	   if ($scheduleexist) {
113 113
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
114
-    		$sch = $Schedule->getSchedule($operator);
114
+			$sch = $Schedule->getSchedule($operator);
115 115
 		$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']));
116
-       }
116
+	   }
117 117
 	$Spotter->db = null;
118 118
 	$Schedule->db = null;
119 119
 	$Translation->db = null;
@@ -128,78 +128,78 @@  discard block
 block discarded – undo
128 128
 	}
129 129
 	  */
130 130
 	}
131
-    }
131
+	}
132 132
 
133
-    public function checkAll() {
133
+	public function checkAll() {
134 134
 	global $globalDebug, $globalNoImport;
135 135
 	if ($globalDebug) echo "Update last seen flights data...\n";
136 136
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
137
-	    foreach ($this->all_flights as $key => $flight) {
137
+		foreach ($this->all_flights as $key => $flight) {
138 138
 		if (isset($this->all_flights[$key]['id'])) {
139
-		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
140
-    		    $Spotter = new Spotter($this->db);
141
-        	    $real_arrival = $this->arrival($key);
142
-        	    if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
143
-        	}
144
-	    }
139
+			//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
140
+				$Spotter = new Spotter($this->db);
141
+				$real_arrival = $this->arrival($key);
142
+				if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
143
+			}
144
+		}
145
+	}
145 146
 	}
146
-    }
147 147
 
148
-    public function arrival($key) {
148
+	public function arrival($key) {
149 149
 	global $globalClosestMinDist, $globalDebug;
150 150
 	if ($globalDebug) echo 'Update arrival...'."\n";
151 151
 	$Spotter = new Spotter($this->db);
152
-        $airport_icao = '';
153
-        $airport_time = '';
154
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
152
+		$airport_icao = '';
153
+		$airport_time = '';
154
+		if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
155 155
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
156
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
157
-    	    if (isset($closestAirports[0])) {
158
-        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
159
-        	    $airport_icao = $closestAirports[0]['icao'];
160
-        	    $airport_time = $this->all_flights[$key]['datetime'];
161
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
162
-        	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
163
-        	    foreach ($closestAirports as $airport) {
164
-        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
165
-        		    $airport_icao = $airport['icao'];
166
-        		    $airport_time = $this->all_flights[$key]['datetime'];
167
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
168
-        		    break;
169
-        		}
170
-        	    }
171
-        	} 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))) {
172
-        		$airport_icao = $closestAirports[0]['icao'];
173
-        		$airport_time = $this->all_flights[$key]['datetime'];
174
-        	} else {
175
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
176
-        	}
177
-    	    } else {
178
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
179
-    	    }
156
+		$closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
157
+			if (isset($closestAirports[0])) {
158
+			if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
159
+				$airport_icao = $closestAirports[0]['icao'];
160
+				$airport_time = $this->all_flights[$key]['datetime'];
161
+				if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
162
+			} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
163
+				foreach ($closestAirports as $airport) {
164
+				if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
165
+					$airport_icao = $airport['icao'];
166
+					$airport_time = $this->all_flights[$key]['datetime'];
167
+					if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
168
+					break;
169
+				}
170
+				}
171
+			} 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))) {
172
+				$airport_icao = $closestAirports[0]['icao'];
173
+				$airport_time = $this->all_flights[$key]['datetime'];
174
+			} else {
175
+				if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
176
+			}
177
+			} else {
178
+				if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
179
+			}
180 180
 
181
-        } else {
182
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
183
-        }
184
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
185
-    }
181
+		} else {
182
+			if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
183
+		}
184
+		return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
185
+	}
186 186
 
187 187
 
188 188
 
189
-    public function del() {
189
+	public function del() {
190 190
 	global $globalDebug, $globalNoImport, $globalNoDB;
191 191
 	// Delete old infos
192 192
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
193 193
 	foreach ($this->all_flights as $key => $flight) {
194
-	    if (isset($flight['lastupdate'])) {
194
+		if (isset($flight['lastupdate'])) {
195 195
 		if ($flight['lastupdate'] < (time()-5900)) {
196
-		    $this->delKey($key);
196
+			$this->delKey($key);
197 197
 		}
198
-	    }
198
+		}
199
+	}
199 200
 	}
200
-    }
201 201
 
202
-    public function delKey($key) {
202
+	public function delKey($key) {
203 203
 	global $globalDebug, $globalNoImport, $globalNoDB;
204 204
 	// Delete old infos
205 205
 	if (isset($this->all_flights[$key]['id'])) {
@@ -214,9 +214,9 @@  discard block
 block discarded – undo
214 214
 		}
215 215
 	}
216 216
 	unset($this->all_flights[$key]);
217
-    }
217
+	}
218 218
 
219
-    public function add($line) {
219
+	public function add($line) {
220 220
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport, $globalNoDB, $globalVA, $globalAircraftMaxUpdate, $globalAircraftMinUpdate, $globalLiveInterval, $GeoidClass;
221 221
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
222 222
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.01';
@@ -242,20 +242,20 @@  discard block
 block discarded – undo
242 242
 	
243 243
 	// SBS format is CSV format
244 244
 	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
245
-	    //print_r($line);
246
-	    if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
247
-  	    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)) {
245
+		//print_r($line);
246
+		if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
247
+  		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)) {
248 248
 
249 249
 		// Increment message number
250 250
 		if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) {
251
-		    $current_date = date('Y-m-d');
252
-		    if (isset($line['source_name'])) $source = $line['source_name'];
253
-		    else $source = '';
254
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
255
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
256
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
257
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
258
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
251
+			$current_date = date('Y-m-d');
252
+			if (isset($line['source_name'])) $source = $line['source_name'];
253
+			else $source = '';
254
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
255
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
256
+				$this->stats[$current_date][$source]['msg']['date'] = time();
257
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
258
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
259 259
 		}
260 260
 		
261 261
 		/*
@@ -271,54 +271,54 @@  discard block
 block discarded – undo
271 271
 		//$this->db = $dbc;
272 272
 
273 273
 		//$hex = trim($line['hex']);
274
-	        if (!isset($line['id'])) $id = trim($line['hex']);
275
-	        else $id = trim($line['id']);
274
+			if (!isset($line['id'])) $id = trim($line['hex']);
275
+			else $id = trim($line['id']);
276 276
 		
277 277
 		if (!isset($this->all_flights[$id])) {
278
-		    if ($globalDebug) echo 'New flight...'."\n";
279
-		    $this->all_flights[$id] = array();
280
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
281
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
282
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
283
-		    if (!isset($line['id'])) {
278
+			if ($globalDebug) echo 'New flight...'."\n";
279
+			$this->all_flights[$id] = array();
280
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
281
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
282
+			if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
283
+			if (!isset($line['id'])) {
284 284
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
285 285
 //			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')));
286 286
 //			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')));
287 287
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
288
-		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
289
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
290
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
288
+				//else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
289
+			 } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
290
+			if ($globalAllFlights !== FALSE) $dataFound = true;
291 291
 		}
292 292
 		if (isset($line['source_type']) && $line['source_type'] != '') {
293
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
293
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
294 294
 		}
295 295
 		
296 296
 		//print_r($this->all_flights);
297 297
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
298
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
299
-		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
298
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
299
+			//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
300 300
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
301
-		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
302
-		    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') {
301
+			//} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
302
+			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') {
303 303
 			$timeelapsed = microtime(true);
304 304
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
305
-			    $Spotter = new Spotter($this->db);
306
-			    if (isset($this->all_flights[$id]['source_type'])) {
305
+				$Spotter = new Spotter($this->db);
306
+				if (isset($this->all_flights[$id]['source_type'])) {
307 307
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
308
-			    } else {
308
+				} else {
309 309
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
310
-			    }
311
-			    $Spotter->db = null;
312
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
313
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
310
+				}
311
+				$Spotter->db = null;
312
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
313
+				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
314 314
 			}
315
-		    }
316
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
317
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
315
+			}
316
+			if ($globalAllFlights !== FALSE) $dataFound = true;
317
+			if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
318 318
 		}
319
-	        if (isset($line['id']) && !isset($line['hex'])) {
320
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
321
-	        }
319
+			if (isset($line['id']) && !isset($line['hex'])) {
320
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
321
+			}
322 322
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
323 323
 			$icao = $line['aircraft_icao'];
324 324
 			$Spotter = new Spotter($this->db);
@@ -347,9 +347,9 @@  discard block
 block discarded – undo
347 347
 		}
348 348
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
349 349
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) {
350
-		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
350
+			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
351 351
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
352
-		    } else {
352
+			} else {
353 353
 				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";
354 354
 				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";
355 355
 				/*
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 				print_r($line);
359 359
 				*/
360 360
 				return '';
361
-		    }
361
+			}
362 362
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
363 363
 			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
364 364
 			return '';
@@ -374,21 +374,21 @@  discard block
 block discarded – undo
374 374
 		}
375 375
 
376 376
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
377
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
377
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
378 378
 		}
379 379
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
380
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
380
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
381 381
 		}
382 382
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
383
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
383
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
384 384
 		}
385 385
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
386
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
386
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
387 387
 		}
388 388
  
389 389
 		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'])) {
390 390
 
391
-		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
391
+			if ($this->all_flights[$id]['addedSpotter'] == 1) {
392 392
 			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
393 393
 				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
394 394
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
@@ -397,23 +397,23 @@  discard block
 block discarded – undo
397 397
 				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
398 398
 				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']));
399 399
 			} else {
400
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
401
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
400
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
401
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
402 402
 				$timeelapsed = microtime(true);
403
-            			$Spotter = new Spotter($this->db);
404
-            			$fromsource = NULL;
405
-            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
406
-            			elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
403
+						$Spotter = new Spotter($this->db);
404
+						$fromsource = NULL;
405
+						if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
406
+						elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
407 407
 				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
408 408
 				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
409 409
 				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
410
-            			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
410
+						$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
411 411
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
412 412
 				$Spotter->db = null;
413 413
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
414
-			    }
414
+				}
415 415
 			}
416
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
416
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
417 417
 		    
418 418
 /*
419 419
 		    if (!isset($line['id'])) {
@@ -423,63 +423,63 @@  discard block
 block discarded – undo
423 423
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
424 424
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
425 425
   */
426
-		    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']));
426
+			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']));
427 427
 
428
-		    //$putinarchive = true;
429
-		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
428
+			//$putinarchive = true;
429
+			if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
430 430
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
431
-		    }
432
-		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
431
+			}
432
+			if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
433 433
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
434
-		    }
435
-		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
436
-		    		$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' => ''));
437
-		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
434
+			}
435
+			if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
436
+					$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' => ''));
437
+			} elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
438 438
 			$timeelapsed = microtime(true);
439 439
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
440 440
 				$Spotter = new Spotter($this->db);
441 441
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
442 442
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
443
-		    		$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' => ''));
443
+					$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' => ''));
444 444
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
445
-                        }
446
-		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
445
+						}
446
+			} elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
447 447
 			$timeelapsed = microtime(true);
448 448
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
449
-			    $Spotter = new Spotter($this->db);
450
-			    $route = $Spotter->getRouteInfo(trim($line['ident']));
451
-			    if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) {
449
+				$Spotter = new Spotter($this->db);
450
+				$route = $Spotter->getRouteInfo(trim($line['ident']));
451
+				if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) {
452 452
 				$Translation = new Translation($this->db);
453 453
 				$ident = $Translation->checkTranslation(trim($line['ident']));
454 454
 				$route = $Spotter->getRouteInfo($ident);
455 455
 				$Translation->db = null;
456
-			    }
457
-			    $Spotter->db = null;
458
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
459
-                    	}
456
+				}
457
+				$Spotter->db = null;
458
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
459
+						}
460 460
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
461
-			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
462
-			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
461
+				//if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
462
+				if ($route['fromairport_icao'] != $route['toairport_icao']) {
463 463
 				//    $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']));
464
-		    		$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']));
465
-		    	    }
464
+					$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']));
465
+					}
466 466
 			}
467 467
 			if (!isset($globalFork)) $globalFork = TRUE;
468 468
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
469 469
 				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
470 470
 			}
471
-		    }
471
+			}
472 472
 		}
473 473
 
474 474
 		if (isset($line['speed']) && $line['speed'] != '' && $line['speed'] != 0) {
475 475
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
476
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
477
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
478
-		    //$dataFound = true;
476
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
477
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
478
+			//$dataFound = true;
479 479
 		} 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'])) {
480
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
481
-		    if ($distance > 1000 && $distance < 10000) {
482
-		    // use datetime
480
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
481
+			if ($distance > 1000 && $distance < 10000) {
482
+			// use datetime
483 483
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
484 484
 			$speed = $speed*3.6;
485 485
 			if ($speed < 1000) {
@@ -488,48 +488,48 @@  discard block
 block discarded – undo
488 488
 	  		} else {
489 489
 	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
490 490
 	  		}
491
-		    }
491
+			}
492 492
 		}
493 493
 
494 494
 
495 495
 
496
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
497
-	    	    if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
498
-	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
499
-	    	    	return false;
500
-	    	    }
501
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
502
-	    	    else unset($timediff);
503
-	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
504
-	    	    else unset($timediff_archive);
505
-	    	    if ($this->tmd > 5
506
-	    	        || (isset($line['format_source']) 
507
-	    	    	    && $line['format_source'] == 'airwhere' 
508
-	    	    	    && ((!isset($this->all_flights[$id]['latitude']) 
509
-	    	    		|| !isset($this->all_flights[$id]['longitude'])) 
510
-	    	    		|| (isset($this->all_flights[$id]['latitude']) 
511
-	    	    		    && isset($this->all_flights[$id]['longitude']) 
512
-	    	    		    && $this->all_flights[$id]['latitude'] != $line['latitude'] 
513
-	    	    		    && $this->all_flights[$id]['longitude'] != $line['longitude']
514
-	    	    		)
515
-	    	    	    )
516
-	    	    	)
517
-	    		|| (isset($globalVA) && $globalVA) 
518
-	    	    	|| (isset($globalIVAO) && $globalIVAO)
519
-	    	    	|| (isset($globalVATSIM) && $globalVATSIM)
520
-	    	    	|| (isset($globalphpVMS) && $globalphpVMS)
521
-	    	    	|| (isset($globalVAM) && $globalVAM)
522
-	    	    	|| !isset($timediff)
523
-	    	    	|| $timediff > $globalLiveInterval
524
-	    	    	|| ($timediff > 30 
525
-	    	    	    && isset($this->all_flights[$id]['latitude']) 
526
-	    	    	    && isset($this->all_flights[$id]['longitude']) 
527
-	    	    	    && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
528
-	    	    	    )
529
-	    	    	) {
496
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
497
+				if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
498
+					if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
499
+					return false;
500
+				}
501
+				if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
502
+				else unset($timediff);
503
+				if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
504
+				else unset($timediff_archive);
505
+				if ($this->tmd > 5
506
+					|| (isset($line['format_source']) 
507
+						&& $line['format_source'] == 'airwhere' 
508
+						&& ((!isset($this->all_flights[$id]['latitude']) 
509
+						|| !isset($this->all_flights[$id]['longitude'])) 
510
+						|| (isset($this->all_flights[$id]['latitude']) 
511
+							&& isset($this->all_flights[$id]['longitude']) 
512
+							&& $this->all_flights[$id]['latitude'] != $line['latitude'] 
513
+							&& $this->all_flights[$id]['longitude'] != $line['longitude']
514
+						)
515
+						)
516
+					)
517
+				|| (isset($globalVA) && $globalVA) 
518
+					|| (isset($globalIVAO) && $globalIVAO)
519
+					|| (isset($globalVATSIM) && $globalVATSIM)
520
+					|| (isset($globalphpVMS) && $globalphpVMS)
521
+					|| (isset($globalVAM) && $globalVAM)
522
+					|| !isset($timediff)
523
+					|| $timediff > $globalLiveInterval
524
+					|| ($timediff > 30 
525
+						&& isset($this->all_flights[$id]['latitude']) 
526
+						&& isset($this->all_flights[$id]['longitude']) 
527
+						&& $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
528
+						)
529
+					) {
530 530
 
531 531
 			if ((isset($timediff) && !isset($timediff_archive)) || (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude']))) {
532
-			    if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
532
+				if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
533 533
 				|| (isset($line['format_source']) && $line['format_source'] == 'airwhere') 
534 534
 				|| !$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'])) {
535 535
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -537,9 +537,9 @@  discard block
 block discarded – undo
537 537
 				$this->all_flights[$id]['putinarchive'] = true;
538 538
 				$this->tmd = 0;
539 539
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
540
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
541
-				    $timeelapsed = microtime(true);
542
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
540
+					if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
541
+					$timeelapsed = microtime(true);
542
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
543 543
 					$Spotter = new Spotter($this->db);
544 544
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
545 545
 					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
@@ -547,11 +547,11 @@  discard block
 block discarded – undo
547 547
 					$Spotter->db = null;
548 548
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
549 549
 					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
550
-				    }
550
+					}
551 551
 				}
552 552
 				$this->all_flights[$id]['time_last_archive_coord'] = time();
553
-			    } 
554
-			    /*
553
+				} 
554
+				/*
555 555
 			    else {
556 556
 				if (!isset($timediff)) echo 'NO TIMEDIFF';
557 557
 				else {
@@ -565,16 +565,16 @@  discard block
 block discarded – undo
565 565
 			}
566 566
 
567 567
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
568
-			    //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) {
568
+				//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) {
569 569
 				if (!isset($this->all_flights[$id]['archive_latitude'])) {
570 570
 					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
571 571
 					$this->all_flights[$id]['time_last_coord'] = time();
572 572
 				}
573 573
 				//if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
574 574
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
575
-				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
576
-				    $dataFound = true;
577
-				    $this->all_flights[$id]['time_last_coord'] = time();
575
+					$this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
576
+					$dataFound = true;
577
+					$this->all_flights[$id]['time_last_coord'] = time();
578 578
 				}
579 579
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
580 580
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
@@ -585,24 +585,24 @@  discard block
 block discarded – undo
585 585
 				    //$putinarchive = true;
586 586
 				}
587 587
 				*/
588
-			    /*
588
+				/*
589 589
 			    } elseif (isset($this->all_flights[$id]['latitude'])) {
590 590
 				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";
591 591
 			    }
592 592
 			    */
593 593
 			}
594 594
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
595
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
596
-			    //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) {
595
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
596
+				//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) {
597 597
 				if (!isset($this->all_flights[$id]['archive_longitude'])) {
598 598
 					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
599 599
 					$this->all_flights[$id]['time_last_coord'] = time();
600 600
 				}
601 601
 				//if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
602 602
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
603
-				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
604
-				    $dataFound = true;
605
-				    $this->all_flights[$id]['time_last_coord'] = time();
603
+					$this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
604
+					$dataFound = true;
605
+					$this->all_flights[$id]['time_last_coord'] = time();
606 606
 				}
607 607
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
608 608
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
@@ -620,67 +620,67 @@  discard block
 block discarded – undo
620 620
 			    */
621 621
 			}
622 622
 
623
-		    } else if ($globalDebug && $timediff > 30) {
623
+			} else if ($globalDebug && $timediff > 30) {
624 624
 			$this->tmd = $this->tmd + 1;
625 625
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
626 626
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
627 627
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
628 628
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
629
-		    }
629
+			}
630 630
 		}
631 631
 		if (isset($line['last_update']) && $line['last_update'] != '') {
632
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
633
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
632
+			if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
633
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
634 634
 		}
635 635
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
636
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
637
-		    //$dataFound = true;
636
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
637
+			//$dataFound = true;
638 638
 		}
639 639
 		if (isset($line['format_source']) && $line['format_source'] != '') {
640
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
640
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
641 641
 		}
642 642
 		if (isset($line['source_name']) && $line['source_name'] != '') {
643
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
643
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
644 644
 		}
645 645
 		if (isset($line['emergency']) && $line['emergency'] != '') {
646
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
647
-		    //$dataFound = true;
646
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
647
+			//$dataFound = true;
648 648
 		}
649 649
 		if (isset($line['ground']) && $line['ground'] != '') {
650
-		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
650
+			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
651 651
 			// Here we force archive of flight because after ground it's a new one (or should be)
652 652
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
653 653
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
654 654
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
655
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
655
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
656 656
 			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']));
657
-		    }
658
-		    if ($line['ground'] != 1) $line['ground'] = 0;
659
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
660
-		    //$dataFound = true;
657
+			}
658
+			if ($line['ground'] != 1) $line['ground'] = 0;
659
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
660
+			//$dataFound = true;
661 661
 		}
662 662
 		if (isset($line['squawk']) && $line['squawk'] != '') {
663
-		    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'])) {
664
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
665
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
666
-			    $highlight = '';
667
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
668
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
669
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
670
-			    if ($highlight != '') {
663
+			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'])) {
664
+				if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
665
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
666
+				$highlight = '';
667
+				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
668
+				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
669
+				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
670
+				if ($highlight != '') {
671 671
 				$timeelapsed = microtime(true);
672 672
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
673
-				    $Spotter = new Spotter($this->db);
674
-				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
675
-				    $Spotter->db = null;
676
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
673
+					$Spotter = new Spotter($this->db);
674
+					$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
675
+					$Spotter->db = null;
676
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
677 677
 				}
678 678
 				//$putinarchive = true;
679 679
 				//$highlight = '';
680
-			    }
680
+				}
681 681
 			    
682
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
683
-		    //$dataFound = true;
682
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
683
+			//$dataFound = true;
684 684
 		}
685 685
 
686 686
 		if (isset($line['altitude']) && $line['altitude'] != '') {
@@ -691,13 +691,13 @@  discard block
 block discarded – undo
691 691
 					$line['altitude'] = $line['altitude'] - $geoid;
692 692
 				}
693 693
 			}
694
-		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
694
+			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
695 695
 			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;
696 696
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
697 697
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
698 698
 			//$dataFound = true;
699
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
700
-		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
699
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
700
+			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
701 701
 			if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
702 702
 				if ($globalDebug) echo '--- Reset because of altitude'."\n";
703 703
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
@@ -706,27 +706,27 @@  discard block
 block discarded – undo
706 706
 				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
707 707
 				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']));
708 708
 			}
709
-		    }
710
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
709
+			}
710
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
711 711
 		}
712 712
 
713 713
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
714
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
714
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
715 715
 		}
716 716
 		
717 717
 		if (isset($line['heading']) && $line['heading'] != '') {
718
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
719
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
720
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
721
-		    //$dataFound = true;
718
+			if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
719
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
720
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
721
+			//$dataFound = true;
722 722
   		} 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']) {
723
-  		    $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']);
724
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
725
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
726
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
723
+  			$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']);
724
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
725
+			if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
726
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
727 727
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
728
-  		    // If not enough messages and ACARS set heading to 0
729
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
728
+  			// If not enough messages and ACARS set heading to 0
729
+  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
730 730
   		}
731 731
 		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
732 732
 		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
@@ -739,125 +739,125 @@  discard block
 block discarded – undo
739 739
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
740 740
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
741 741
 		if ($dataFound === true && isset($this->all_flights[$id]['id'])) {
742
-		    $this->all_flights[$id]['lastupdate'] = time();
743
-		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
744
-		        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'])) {
745
-			    //print_r($this->all_flights);
746
-			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
747
-			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
748
-			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
742
+			$this->all_flights[$id]['lastupdate'] = time();
743
+			if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
744
+				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'])) {
745
+				//print_r($this->all_flights);
746
+				//echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
747
+				//$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
748
+				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
749 749
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
750
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
751
-				    $timeelapsed = microtime(true);
752
-				    $SpotterLive = new SpotterLive($this->db);
753
-				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
750
+					if ($globalDebug) echo "Check if aircraft is already in DB...";
751
+					$timeelapsed = microtime(true);
752
+					$SpotterLive = new SpotterLive($this->db);
753
+					if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
754 754
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
755 755
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
756
-				    } elseif (isset($line['id'])) {
756
+					} elseif (isset($line['id'])) {
757 757
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
758 758
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
759
-				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
759
+					} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
760 760
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
761 761
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
762
-				    } else $recent_ident = '';
763
-				    $SpotterLive->db=null;
764
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
765
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
762
+					} else $recent_ident = '';
763
+					$SpotterLive->db=null;
764
+					if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
765
+					elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
766 766
 				} else $recent_ident = '';
767
-			    } else {
767
+				} else {
768 768
 				$recent_ident = '';
769 769
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
770
-			    }
771
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
772
-			    if($recent_ident == "")
773
-			    {
770
+				}
771
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
772
+				if($recent_ident == "")
773
+				{
774 774
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
775 775
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
776 776
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
777 777
 				//adds the spotter data for the archive
778 778
 				$ignoreImport = false;
779 779
 				foreach($globalAirportIgnore as $airportIgnore) {
780
-				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
780
+					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
781 781
 					$ignoreImport = true;
782
-				    }
782
+					}
783 783
 				}
784 784
 				if (count($globalAirportAccept) > 0) {
785
-				    $ignoreImport = true;
786
-				    foreach($globalAirportIgnore as $airportIgnore) {
785
+					$ignoreImport = true;
786
+					foreach($globalAirportIgnore as $airportIgnore) {
787 787
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
788
-					    $ignoreImport = false;
788
+						$ignoreImport = false;
789
+					}
789 790
 					}
790
-				    }
791 791
 				}
792 792
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
793
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
793
+					foreach($globalAirlineIgnore as $airlineIgnore) {
794 794
 					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)) {
795
-					    $ignoreImport = true;
795
+						$ignoreImport = true;
796
+					}
796 797
 					}
797
-				    }
798 798
 				}
799 799
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
800
-				    $ignoreImport = true;
801
-				    foreach($globalAirlineAccept as $airlineAccept) {
800
+					$ignoreImport = true;
801
+					foreach($globalAirlineAccept as $airlineAccept) {
802 802
 					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)) {
803
-					    $ignoreImport = false;
803
+						$ignoreImport = false;
804
+					}
804 805
 					}
805
-				    }
806 806
 				}
807 807
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
808
-				    $ignoreImport = true;
809
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
808
+					$ignoreImport = true;
809
+					foreach($globalPilotIdAccept as $pilotIdAccept) {
810 810
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
811
-					    $ignoreImport = false;
811
+						$ignoreImport = false;
812
+					}
812 813
 					}
813
-				    }
814 814
 				}
815 815
 				
816 816
 				if (!$ignoreImport) {
817
-				    $highlight = '';
818
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
819
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
820
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
821
-				    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')));
822
-				    $timeelapsed = microtime(true);
823
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
817
+					$highlight = '';
818
+					if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
819
+					if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
820
+					if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
821
+					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')));
822
+					$timeelapsed = microtime(true);
823
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
824 824
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
825
-					    $Spotter = new Spotter($this->db);
826
-					    $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']);
827
-					    $Spotter->db = null;
828
-					    if ($globalDebug && isset($result)) echo $result."\n";
825
+						$Spotter = new Spotter($this->db);
826
+						$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']);
827
+						$Spotter->db = null;
828
+						if ($globalDebug && isset($result)) echo $result."\n";
829 829
 					}
830
-				    }
831
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
832
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
830
+					}
831
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
832
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
833 833
 
834
-				    // Add source stat in DB
835
-				    $Stats = new Stats($this->db);
836
-				    if (!empty($this->stats)) {
834
+					// Add source stat in DB
835
+					$Stats = new Stats($this->db);
836
+					if (!empty($this->stats)) {
837 837
 					if ($globalDebug) echo 'Add source stats : ';
838
-				        foreach($this->stats as $date => $data) {
839
-					    foreach($data as $source => $sourced) {
840
-					        //print_r($sourced);
841
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
842
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
843
-				    		if (isset($sourced['msg'])) {
844
-				    		    if (time() - $sourced['msg']['date'] > 10) {
845
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
846
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
847
-			    			        unset($this->stats[$date][$source]['msg']);
848
-			    			    }
849
-			    			}
850
-			    		    }
851
-			    		    if ($date != date('Y-m-d')) {
852
-			    			unset($this->stats[$date]);
853
-			    		    }
854
-				    	}
855
-				    	if ($globalDebug) echo 'Done'."\n";
838
+						foreach($this->stats as $date => $data) {
839
+						foreach($data as $source => $sourced) {
840
+							//print_r($sourced);
841
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
842
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
843
+							if (isset($sourced['msg'])) {
844
+								if (time() - $sourced['msg']['date'] > 10) {
845
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
846
+									echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
847
+									unset($this->stats[$date][$source]['msg']);
848
+								}
849
+							}
850
+							}
851
+							if ($date != date('Y-m-d')) {
852
+							unset($this->stats[$date]);
853
+							}
854
+						}
855
+						if ($globalDebug) echo 'Done'."\n";
856 856
 
857
-				    }
858
-				    $Stats->db = null;
859
-				    }
860
-				    $this->del();
857
+					}
858
+					$Stats->db = null;
859
+					}
860
+					$this->del();
861 861
 				} elseif ($globalDebug) echo 'Ignore data'."\n";
862 862
 				//$ignoreImport = false;
863 863
 				$this->all_flights[$id]['addedSpotter'] = 1;
@@ -875,41 +875,41 @@  discard block
 block discarded – undo
875 875
 			*/
876 876
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
877 877
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
878
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
879
-				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
880
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
878
+					if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
879
+					//SpotterLive->deleteLiveSpotterDataNotUpdated();
880
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
881 881
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
882
-					    $SpotterLive = new SpotterLive($this->db);
883
-					    $SpotterLive->deleteLiveSpotterData();
884
-					    $SpotterLive->db=null;
882
+						$SpotterLive = new SpotterLive($this->db);
883
+						$SpotterLive->deleteLiveSpotterData();
884
+						$SpotterLive->db=null;
885 885
 					}
886
-				    }
887
-				    if ($globalDebug) echo " Done\n";
888
-				    $this->last_delete = time();
886
+					}
887
+					if ($globalDebug) echo " Done\n";
888
+					$this->last_delete = time();
889 889
 				}
890
-			    } else {
890
+				} else {
891 891
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'famaprs' || $line['format_source'] === 'airwhere')) {
892
-				    $this->all_flights[$id]['id'] = $recent_ident;
893
-				    $this->all_flights[$id]['addedSpotter'] = 1;
892
+					$this->all_flights[$id]['id'] = $recent_ident;
893
+					$this->all_flights[$id]['addedSpotter'] = 1;
894 894
 				}
895 895
 				if (isset($globalDaemon) && !$globalDaemon) {
896
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
896
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
897 897
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
898
-					    $Spotter = new Spotter($this->db);
899
-					    $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']);
900
-					    $Spotter->db = null;
898
+						$Spotter = new Spotter($this->db);
899
+						$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']);
900
+						$Spotter->db = null;
901
+					}
901 902
 					}
902
-				    }
903 903
 				}
904 904
 				
905
-			    }
905
+				}
906 906
 			}
907
-		    }
908
-		    //adds the spotter LIVE data
909
-		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
910
-		    //echo "\nAdd in Live !! \n";
911
-		    //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";
912
-		    if ($globalDebug) {
907
+			}
908
+			//adds the spotter LIVE data
909
+			//SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
910
+			//echo "\nAdd in Live !! \n";
911
+			//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";
912
+			if ($globalDebug) {
913 913
 			if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
914 914
 				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";
915 915
 				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";
@@ -917,60 +917,60 @@  discard block
 block discarded – undo
917 917
 				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";
918 918
 				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";
919 919
 			}
920
-		    }
921
-		    $ignoreImport = false;
922
-		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
923
-		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
920
+			}
921
+			$ignoreImport = false;
922
+			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
923
+			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
924 924
 
925
-		    foreach($globalAirportIgnore as $airportIgnore) {
926
-		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
927
-			    $ignoreImport = true;
925
+			foreach($globalAirportIgnore as $airportIgnore) {
926
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
927
+				$ignoreImport = true;
928
+			}
928 929
 			}
929
-		    }
930
-		    if (count($globalAirportAccept) > 0) {
931
-		        $ignoreImport = true;
932
-		        foreach($globalAirportIgnore as $airportIgnore) {
933
-			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
930
+			if (count($globalAirportAccept) > 0) {
931
+				$ignoreImport = true;
932
+				foreach($globalAirportIgnore as $airportIgnore) {
933
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
934 934
 				$ignoreImport = false;
935
-			    }
935
+				}
936 936
 			}
937
-		    }
938
-		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
937
+			}
938
+			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
939 939
 			foreach($globalAirlineIgnore as $airlineIgnore) {
940
-			    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)) {
940
+				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)) {
941 941
 				$ignoreImport = true;
942
-			    }
942
+				}
943 943
 			}
944
-		    }
945
-		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
944
+			}
945
+			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
946 946
 			$ignoreImport = true;
947 947
 			foreach($globalAirlineAccept as $airlineAccept) {
948
-			    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)) {
948
+				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)) {
949 949
 				$ignoreImport = false;
950
-			    }
950
+				}
951
+			}
951 952
 			}
952
-		    }
953
-		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
953
+			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
954 954
 			$ignoreImport = true;
955 955
 			foreach($globalPilotIdAccept as $pilotIdAccept) {
956
-			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
957
-			        $ignoreImport = false;
958
-			    }
956
+				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
957
+					$ignoreImport = false;
958
+				}
959
+			}
959 960
 			}
960
-		    }
961 961
 
962
-		    if (!$ignoreImport) {
962
+			if (!$ignoreImport) {
963 963
 			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'])) {
964 964
 				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')));
965 965
 				$timeelapsed = microtime(true);
966 966
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
967
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
967
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
968 968
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
969 969
 					$SpotterLive = new SpotterLive($this->db);
970 970
 					$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']);
971 971
 					$SpotterLive->db = null;
972 972
 					if ($globalDebug) echo $result."\n";
973
-				    }
973
+					}
974 974
 				}
975 975
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
976 976
 					$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']);
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
 				//if ($line['format_source'] != 'aprs') {
983 983
 				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
984 984
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
985
-				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
985
+					if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
986 986
 					$source = $this->all_flights[$id]['source_name'];
987 987
 					if ($source == '') $source = $this->all_flights[$id]['format_source'];
988 988
 					if (!isset($this->source_location[$source])) {
@@ -1008,7 +1008,7 @@  discard block
 block discarded – undo
1008 1008
 					if ($stats_heading == 16) $stats_heading = 0;
1009 1009
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
1010 1010
 						for ($i=0;$i<=15;$i++) {
1011
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
1011
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
1012 1012
 						}
1013 1013
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
1014 1014
 					} else {
@@ -1021,17 +1021,17 @@  discard block
 block discarded – undo
1021 1021
 					//var_dump($this->stats);
1022 1022
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
1023 1023
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1024
-						    end($this->stats[$current_date][$source]['hist']);
1025
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1024
+							end($this->stats[$current_date][$source]['hist']);
1025
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
1026 1026
 						} else $mini = 0;
1027 1027
 						for ($i=$mini;$i<=$distance;$i+=10) {
1028
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1028
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
1029 1029
 						}
1030 1030
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
1031 1031
 					} else {
1032 1032
 						$this->stats[$current_date][$source]['hist'][$distance] += 1;
1033 1033
 					}
1034
-				    }
1034
+					}
1035 1035
 				}
1036 1036
 
1037 1037
 				$this->all_flights[$id]['lastupdate'] = time();
@@ -1041,7 +1041,7 @@  discard block
 block discarded – undo
1041 1041
 			//$this->del();
1042 1042
 			
1043 1043
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
1044
-			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1044
+				if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1045 1045
 				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1046 1046
 				$SpotterLive = new SpotterLive($this->db);
1047 1047
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
@@ -1049,19 +1049,19 @@  discard block
 block discarded – undo
1049 1049
 				//SpotterLive->deleteLiveSpotterData();
1050 1050
 				if ($globalDebug) echo " Done\n";
1051 1051
 				$this->last_delete_hourly = time();
1052
-			    } else {
1052
+				} else {
1053 1053
 				$this->del();
1054 1054
 				$this->last_delete_hourly = time();
1055
-			    }
1055
+				}
1056 1056
 			}
1057 1057
 			
1058
-		    }
1059
-		    //$ignoreImport = false;
1058
+			}
1059
+			//$ignoreImport = false;
1060 1060
 		}
1061 1061
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
1062 1062
 		if ($send) return $this->all_flights[$id];
1063
-	    }
1063
+		}
1064
+	}
1064 1065
 	}
1065
-    }
1066 1066
 }
1067 1067
 ?>
Please login to merge, or discard this patch.
require/class.Common.php 1 patch
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -14,12 +14,12 @@  discard block
 block discarded – undo
14 14
 	* @param Array $headers header to submit with the form
15 15
 	* @return String the result
16 16
 	*/
17
-	public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '') {
17
+	public function getData($url, $type = 'get', $data = '', $headers = '', $cookie = '', $referer = '', $timeout = '', $useragent = '') {
18 18
 		global $globalProxy, $globalForceIPv4;
19 19
 		$ch = curl_init();
20 20
 		curl_setopt($ch, CURLOPT_URL, $url);
21 21
 		if (isset($globalForceIPv4) && $globalForceIPv4) {
22
-			if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
22
+			if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) {
23 23
 				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
24 24
 			}
25 25
 		}
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
30 30
 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
31 31
 		curl_setopt($ch, CURLINFO_HEADER_OUT, true); 
32
-		curl_setopt($ch,CURLOPT_ENCODING , "gzip");
32
+		curl_setopt($ch, CURLOPT_ENCODING, "gzip");
33 33
 		//curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
34 34
 //		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0');
35 35
 		if ($useragent == '') {
@@ -39,13 +39,13 @@  discard block
 block discarded – undo
39 39
 		}
40 40
 		if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
41 41
 		else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 
42
-		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback"));
42
+		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common', "curlResponseHeaderCallback"));
43 43
 		if ($type == 'post') {
44 44
 			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
45 45
 			if (is_array($data)) {
46 46
 				curl_setopt($ch, CURLOPT_POST, count($data));
47 47
 				$data_string = '';
48
-				foreach($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; }
48
+				foreach ($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; }
49 49
 				rtrim($data_string, '&');
50 50
 				curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
51 51
 			} else {
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		}
58 58
 		if ($cookie != '') {
59 59
 			if (is_array($cookie)) {
60
-				curl_setopt($ch, CURLOPT_COOKIE, implode($cookie,';'));
60
+				curl_setopt($ch, CURLOPT_COOKIE, implode($cookie, ';'));
61 61
 			} else {
62 62
 				curl_setopt($ch, CURLOPT_COOKIE, $cookie);
63 63
 			}
@@ -69,13 +69,13 @@  discard block
 block discarded – undo
69 69
 		$info = curl_getinfo($ch);
70 70
 		//var_dump($info);
71 71
 		curl_close($ch);
72
-		if ($info['http_code'] == '503' && strstr($result,'DDoS protection by CloudFlare')) {
72
+		if ($info['http_code'] == '503' && strstr($result, 'DDoS protection by CloudFlare')) {
73 73
 			echo "Cloudflare Detected\n";
74 74
 			require_once(dirname(__FILE__).'/libs/cloudflare-bypass/libraries/cloudflareClass.php');
75 75
 			$useragent = UAgent::random();
76 76
 			cloudflare::useUserAgent($useragent);
77 77
 			if ($clearanceCookie = cloudflare::bypass($url)) {
78
-				return $this->getData($url,'get',$data,$headers,$clearanceCookie,$referer,$timeout,$useragent);
78
+				return $this->getData($url, 'get', $data, $headers, $clearanceCookie, $referer, $timeout, $useragent);
79 79
 			}
80 80
 		} else {
81 81
 			return $result;
@@ -106,20 +106,20 @@  discard block
 block discarded – undo
106 106
 		fclose($fp);
107 107
 	}
108 108
 
109
-	public static function gunzip($in_file,$out_file_name = '') {
109
+	public static function gunzip($in_file, $out_file_name = '') {
110 110
 		//echo $in_file.' -> '.$out_file_name."\n";
111 111
 		$buffer_size = 4096; // read 4kb at a time
112 112
 		if ($out_file_name == '') $out_file_name = str_replace('.gz', '', $in_file); 
113 113
 		if ($in_file != '' && file_exists($in_file)) {
114 114
 			// PHP version of Ubuntu use gzopen64 instead of gzopen
115
-			if (function_exists('gzopen')) $file = gzopen($in_file,'rb');
116
-			elseif (function_exists('gzopen64')) $file = gzopen64($in_file,'rb');
115
+			if (function_exists('gzopen')) $file = gzopen($in_file, 'rb');
116
+			elseif (function_exists('gzopen64')) $file = gzopen64($in_file, 'rb');
117 117
 			else {
118 118
 				echo 'gzopen not available';
119 119
 				die;
120 120
 			}
121 121
 			$out_file = fopen($out_file_name, 'wb'); 
122
-			while(!gzeof($file)) {
122
+			while (!gzeof($file)) {
123 123
 				fwrite($out_file, gzread($file, $buffer_size));
124 124
 			}  
125 125
 			fclose($out_file);
@@ -127,19 +127,19 @@  discard block
 block discarded – undo
127 127
 		}
128 128
 	}
129 129
 
130
-	public static function bunzip2($in_file,$out_file_name = '') {
130
+	public static function bunzip2($in_file, $out_file_name = '') {
131 131
 		//echo $in_file.' -> '.$out_file_name."\n";
132 132
 		$buffer_size = 4096; // read 4kb at a time
133 133
 		if ($out_file_name == '') $out_file_name = str_replace('.bz2', '', $in_file); 
134 134
 		if ($in_file != '' && file_exists($in_file)) {
135 135
 			// PHP version of Ubuntu use gzopen64 instead of gzopen
136
-			if (function_exists('bzopen')) $file = bzopen($in_file,'rb');
136
+			if (function_exists('bzopen')) $file = bzopen($in_file, 'rb');
137 137
 			else {
138 138
 				echo 'bzopen not available';
139 139
 				die;
140 140
 			}
141 141
 			$out_file = fopen($out_file_name, 'wb'); 
142
-			while(!feof($file)) {
142
+			while (!feof($file)) {
143 143
 				fwrite($out_file, bzread($file, $buffer_size));
144 144
 			}  
145 145
 			fclose($out_file);
@@ -157,27 +157,27 @@  discard block
 block discarded – undo
157 157
 		if ($data == '') return array();
158 158
 		$html = str_get_html($data);
159 159
 		if ($html === false) return array();
160
-		$tabledata=array();
161
-		foreach($html->find('tr') as $element)
160
+		$tabledata = array();
161
+		foreach ($html->find('tr') as $element)
162 162
 		{
163 163
 			$td = array();
164
-			foreach( $element->find('th') as $row)
164
+			foreach ($element->find('th') as $row)
165 165
 			{
166 166
 				$td [] = trim($row->plaintext);
167 167
 			}
168
-			$td=array_filter($td);
168
+			$td = array_filter($td);
169 169
 			$tabledata[] = $td;
170 170
 
171 171
 			$td = array();
172 172
 			$tdi = array();
173
-			foreach( $element->find('td') as $row)
173
+			foreach ($element->find('td') as $row)
174 174
 			{
175 175
 				$td [] = trim($row->plaintext);
176 176
 				$tdi [] = trim($row->innertext);
177 177
 			}
178
-			$td=array_filter($td);
179
-			$tdi=array_filter($tdi);
180
-			$tabledata[]=array_merge($td,$tdi);
178
+			$td = array_filter($td);
179
+			$tdi = array_filter($tdi);
180
+			$tabledata[] = array_merge($td, $tdi);
181 181
 		}
182 182
 		$html->clear();
183 183
 		unset($html);
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
 	public function text2array($data) {
193 193
 		$html = str_get_html($data);
194 194
 		if ($html === false) return array();
195
-		$tabledata=array();
196
-		foreach($html->find('p') as $element)
195
+		$tabledata = array();
196
+		foreach ($html->find('p') as $element)
197 197
 		{
198 198
 			$tabledata [] = trim($element->plaintext);
199 199
 		}
@@ -213,11 +213,11 @@  discard block
 block discarded – undo
213 213
 	*/
214 214
 	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
215 215
 		if ($lat == $latc && $lon == $lonc) return 0;
216
-		$dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515;
216
+		$dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc))) + cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon) - floatval($lonc)))))*60*1.1515;
217 217
 		if ($unit == "km") {
218
-			return round($dist * 1.609344);
218
+			return round($dist*1.609344);
219 219
 		} elseif ($unit == "m") {
220
-			return round($dist * 1.609344 * 1000);
220
+			return round($dist*1.609344*1000);
221 221
 		} elseif ($unit == "mile" || $unit == "mi") {
222 222
 			return round($dist);
223 223
 		} elseif ($unit == "nm") {
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 	* @param float $distance distance covered
234 234
 	* @return whether distance is realistic
235 235
 	*/
236
-	public function withinThreshold ($timeDifference, $distance) {
236
+	public function withinThreshold($timeDifference, $distance) {
237 237
 		$x = abs($timeDifference);
238 238
 		$d = abs($distance);
239 239
 		if ($x == 0 || $d == 0) return true;
@@ -249,12 +249,12 @@  discard block
 block discarded – undo
249 249
 		return ($array !== array_values($array));
250 250
 	}
251 251
 
252
-	public function isInteger($input){
252
+	public function isInteger($input) {
253 253
 	    return(ctype_digit(strval($input)));
254 254
 	}
255 255
 
256 256
 
257
-	public function convertDec($dms,$latlong) {
257
+	public function convertDec($dms, $latlong) {
258 258
 		if ($latlong == 'latitude') {
259 259
 			$deg = substr($dms, 0, 2);
260 260
 			$min = substr($dms, 2, 4);
@@ -262,10 +262,10 @@  discard block
 block discarded – undo
262 262
 			$deg = substr($dms, 0, 3);
263 263
 			$min = substr($dms, 3, 5);
264 264
 		}
265
-		return $deg+(($min*60)/3600);
265
+		return $deg + (($min*60)/3600);
266 266
 	}
267 267
 	
268
-	public function convertDM($coord,$latlong) {
268
+	public function convertDM($coord, $latlong) {
269 269
 		if ($latlong == 'latitude') {
270 270
 			if ($coord < 0) $NSEW = 'S';
271 271
 			else $NSEW = 'N';
@@ -275,9 +275,9 @@  discard block
 block discarded – undo
275 275
 		}
276 276
 		$coord = abs($coord);
277 277
 		$deg = floor($coord);
278
-		$coord = ($coord-$deg)*60;
278
+		$coord = ($coord - $deg)*60;
279 279
 		$min = $coord;
280
-		return array('deg' => $deg,'min' => $min,'NSEW' => $NSEW);
280
+		return array('deg' => $deg, 'min' => $min, 'NSEW' => $NSEW);
281 281
 	}
282 282
 	
283 283
 	/**
@@ -289,8 +289,8 @@  discard block
 block discarded – undo
289 289
 	public function xcopy($source, $dest)
290 290
 	{
291 291
 		$files = glob($source.'*.*');
292
-		foreach($files as $file){
293
-			$file_to_go = str_replace($source,$dest,$file);
292
+		foreach ($files as $file) {
293
+			$file_to_go = str_replace($source, $dest, $file);
294 294
 			copy($file, $file_to_go);
295 295
 		}
296 296
 		return true;
@@ -301,9 +301,9 @@  discard block
 block discarded – undo
301 301
 	* @param	String $url url to check
302 302
 	* @return	bool Return true on succes false on failure
303 303
 	*/
304
-	public function urlexist($url){
305
-		$headers=get_headers($url);
306
-		return stripos($headers[0],"200 OK")?true:false;
304
+	public function urlexist($url) {
305
+		$headers = get_headers($url);
306
+		return stripos($headers[0], "200 OK") ? true : false;
307 307
 	}
308 308
 	
309 309
 	/**
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	public function hex2str($hex) {
315 315
 		$str = '';
316 316
 		$hexln = strlen($hex);
317
-		for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
317
+		for ($i = 0; $i < $hexln; $i += 2) $str .= chr(hexdec(substr($hex, $i, 2)));
318 318
 		return $str;
319 319
 	}
320 320
 	
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 	* @return	String Return result
325 325
 	*/
326 326
 	public function hex2rgb($hex) {
327
-		$hex = str_replace('#','',$hex);
327
+		$hex = str_replace('#', '', $hex);
328 328
 		return sscanf($hex, "%02x%02x%02x"); 
329 329
 	}
330 330
 	
@@ -332,33 +332,33 @@  discard block
 block discarded – undo
332 332
 		//difference in longitudinal coordinates
333 333
 		$dLon = deg2rad($lon2) - deg2rad($lon1);
334 334
 		//difference in the phi of latitudinal coordinates
335
-		$dPhi = log(tan(deg2rad($lat2) / 2 + pi() / 4) / tan(deg2rad($lat1) / 2 + pi() / 4));
335
+		$dPhi = log(tan(deg2rad($lat2)/2 + pi()/4)/tan(deg2rad($lat1)/2 + pi()/4));
336 336
 		//we need to recalculate $dLon if it is greater than pi
337
-		if(abs($dLon) > pi()) {
338
-			if($dLon > 0) {
339
-				$dLon = (2 * pi() - $dLon) * -1;
337
+		if (abs($dLon) > pi()) {
338
+			if ($dLon > 0) {
339
+				$dLon = (2*pi() - $dLon)*-1;
340 340
 			} else {
341
-				$dLon = 2 * pi() + $dLon;
341
+				$dLon = 2*pi() + $dLon;
342 342
 			}
343 343
 		}
344 344
 		//return the angle, normalized
345
-		return (rad2deg(atan2($dLon, $dPhi)) + 360) % 360;
345
+		return (rad2deg(atan2($dLon, $dPhi)) + 360)%360;
346 346
 	}
347 347
 	
348
-	public function checkLine($lat1,$lon1,$lat2,$lon2,$lat3,$lon3,$approx = 0.15) {
348
+	public function checkLine($lat1, $lon1, $lat2, $lon2, $lat3, $lon3, $approx = 0.15) {
349 349
 		//$a = ($lon2-$lon1)*$lat3+($lat2-$lat1)*$lon3+($lat1*$lon2+$lat2*$lon1);
350
-		$a = -($lon2-$lon1);
350
+		$a = -($lon2 - $lon1);
351 351
 		$b = $lat2 - $lat1;
352
-		$c = -($a*$lat1+$b*$lon1);
353
-		$d = $a*$lat3+$b*$lon3+$c;
352
+		$c = -($a*$lat1 + $b*$lon1);
353
+		$d = $a*$lat3 + $b*$lon3 + $c;
354 354
 		if ($d > -$approx && $d < $approx) return true;
355 355
 		else return false;
356 356
 	}
357 357
 	
358 358
 	public function array_merge_noappend() {
359 359
 		$output = array();
360
-		foreach(func_get_args() as $array) {
361
-			foreach($array as $key => $value) {
360
+		foreach (func_get_args() as $array) {
361
+			foreach ($array as $key => $value) {
362 362
 				$output[$key] = isset($output[$key]) ?
363 363
 				array_merge($output[$key], $value) : $value;
364 364
 			}
@@ -422,34 +422,34 @@  discard block
 block discarded – undo
422 422
 		return $result;
423 423
 	}
424 424
 
425
-	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1){
425
+	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1) {
426 426
 		global $globalMapRefresh;
427 427
 		$distance = ($speed*0.514444*$globalMapRefresh*$archivespeed)/1000;
428 428
 		$r = 6378;
429 429
 		$latitude = deg2rad($latitude);
430 430
 		$longitude = deg2rad($longitude);
431 431
 		$bearing = deg2rad($heading); 
432
-		$latitude2 =  asin( (sin($latitude) * cos($distance/$r)) + (cos($latitude) * sin($distance/$r) * cos($bearing)) );
433
-		$longitude2 = $longitude + atan2( sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r)-(sin($latitude)*sin($latitude2)) );
434
-		return array('latitude' => number_format(rad2deg($latitude2),5,'.',''),'longitude' => number_format(rad2deg($longitude2),5,'.',''));
432
+		$latitude2 = asin((sin($latitude)*cos($distance/$r)) + (cos($latitude)*sin($distance/$r)*cos($bearing)));
433
+		$longitude2 = $longitude + atan2(sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r) - (sin($latitude)*sin($latitude2)));
434
+		return array('latitude' => number_format(rad2deg($latitude2), 5, '.', ''), 'longitude' => number_format(rad2deg($longitude2), 5, '.', ''));
435 435
 	}
436 436
 	
437
-	public function getCoordfromDistanceBearing($latitude,$longitude,$bearing,$distance) {
437
+	public function getCoordfromDistanceBearing($latitude, $longitude, $bearing, $distance) {
438 438
 		// distance in meter
439 439
 		$R = 6378.14;
440
-		$latitude1 = $latitude * (M_PI/180);
441
-		$longitude1 = $longitude * (M_PI/180);
442
-		$brng = $bearing * (M_PI/180);
440
+		$latitude1 = $latitude*(M_PI/180);
441
+		$longitude1 = $longitude*(M_PI/180);
442
+		$brng = $bearing*(M_PI/180);
443 443
 		$d = $distance;
444 444
 
445 445
 		$latitude2 = asin(sin($latitude1)*cos($d/$R) + cos($latitude1)*sin($d/$R)*cos($brng));
446
-		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1),cos($d/$R)-sin($latitude1)*sin($latitude2));
446
+		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1), cos($d/$R) - sin($latitude1)*sin($latitude2));
447 447
 
448
-		$latitude2 = $latitude2 * (180/M_PI);
449
-		$longitude2 = $longitude2 * (180/M_PI);
448
+		$latitude2 = $latitude2*(180/M_PI);
449
+		$longitude2 = $longitude2*(180/M_PI);
450 450
 
451
-		$flat = round ($latitude2,6);
452
-		$flong = round ($longitude2,6);
451
+		$flat = round($latitude2, 6);
452
+		$flong = round($longitude2, 6);
453 453
 /*
454 454
 		$dx = $distance*cos($bearing);
455 455
 		$dy = $distance*sin($bearing);
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 		$flong = $longitude + $dlong;
459 459
 		$flat = $latitude + $dlat;
460 460
 */
461
-		return array('latitude' => $flat,'longitude' => $flong);
461
+		return array('latitude' => $flat, 'longitude' => $flong);
462 462
 	}
463 463
 
464 464
 	/**
@@ -472,14 +472,14 @@  discard block
 block discarded – undo
472 472
 	 * @param integer $level GZIP compression level (default: 9)
473 473
 	 * @return string New filename (with .gz appended) if success, or false if operation fails
474 474
 	 */
475
-	public function gzCompressFile($source, $level = 9){ 
476
-		$dest = $source . '.gz'; 
477
-		$mode = 'wb' . $level; 
475
+	public function gzCompressFile($source, $level = 9) { 
476
+		$dest = $source.'.gz'; 
477
+		$mode = 'wb'.$level; 
478 478
 		$error = false; 
479 479
 		if ($fp_out = gzopen($dest, $mode)) { 
480
-			if ($fp_in = fopen($source,'rb')) { 
480
+			if ($fp_in = fopen($source, 'rb')) { 
481 481
 				while (!feof($fp_in)) 
482
-					gzwrite($fp_out, fread($fp_in, 1024 * 512)); 
482
+					gzwrite($fp_out, fread($fp_in, 1024*512)); 
483 483
 				fclose($fp_in); 
484 484
 			} else {
485 485
 				$error = true; 
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 	} 
496 496
 	
497 497
 	public function remove_accents($string) {
498
-		if ( !preg_match('/[\x80-\xff]/', $string) ) return $string;
498
+		if (!preg_match('/[\x80-\xff]/', $string)) return $string;
499 499
 		$chars = array(
500 500
 		    // Decompositions for Latin-1 Supplement
501 501
 		    chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
 		    chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
553 553
 		    chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
554 554
 		    chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
555
-		    chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
555
+		    chr(196).chr(178) => 'IJ', chr(196).chr(179) => 'ij',
556 556
 		    chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
557 557
 		    chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
558 558
 		    chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
@@ -568,13 +568,13 @@  discard block
 block discarded – undo
568 568
 		    chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
569 569
 		    chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
570 570
 		    chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
571
-		    chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
572
-		    chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
573
-		    chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
574
-		    chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
575
-		    chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
576
-		    chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
577
-		    chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
571
+		    chr(197).chr(146) => 'OE', chr(197).chr(147) => 'oe',
572
+		    chr(197).chr(148) => 'R', chr(197).chr(149) => 'r',
573
+		    chr(197).chr(150) => 'R', chr(197).chr(151) => 'r',
574
+		    chr(197).chr(152) => 'R', chr(197).chr(153) => 'r',
575
+		    chr(197).chr(154) => 'S', chr(197).chr(155) => 's',
576
+		    chr(197).chr(156) => 'S', chr(197).chr(157) => 's',
577
+		    chr(197).chr(158) => 'S', chr(197).chr(159) => 's',
578 578
 		    chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
579 579
 		    chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
580 580
 		    chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
 		for ($i = 0, $int = '', $concat_flag = true; $i < $length; $i++) {
609 609
 			if (is_numeric($string[$i]) && $concat_flag) {
610 610
 				$int .= $string[$i];
611
-			} elseif(!$concat && $concat_flag && strlen($int) > 0) {
611
+			} elseif (!$concat && $concat_flag && strlen($int) > 0) {
612 612
 				$concat_flag = false;
613 613
 			}
614 614
 		}
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 			$slice = array_slice($arr, $offset + 1, $length);
655 655
 			return implode("", $slice);
656 656
 		} else {
657
-			return mb_substr($string,$offset,$length,'UTF-8');
657
+			return mb_substr($string, $offset, $length, 'UTF-8');
658 658
 		}
659 659
 	}
660 660
 
@@ -664,14 +664,14 @@  discard block
 block discarded – undo
664 664
 		//NOTE: use a trailing slash for folders!!!
665 665
 		//see http://bugs.php.net/bug.php?id=27609
666 666
 		//see http://bugs.php.net/bug.php?id=30931
667
-		if ($path{strlen($path)-1}=='/') // recursively return a temporary file path
667
+		if ($path{strlen($path) - 1} == '/') // recursively return a temporary file path
668 668
 			return $this->is__writable($path.uniqid(mt_rand()).'.tmp');
669 669
 		else if (is_dir($path))
670 670
 			return $this->is__writable($path.'/'.uniqid(mt_rand()).'.tmp');
671 671
 		// check tmp file for read/write capabilities
672 672
 		$rm = file_exists($path);
673 673
 		$f = @fopen($path, 'a');
674
-		if ($f===false)
674
+		if ($f === false)
675 675
 			return false;
676 676
 		fclose($f);
677 677
 		if (!$rm)
Please login to merge, or discard this patch.