Completed
Push — master ( 804bdc...b40ad5 )
by Yannick
26:28
created
require/class.SpotterImport.php 3 patches
Indentation   +423 added lines, -423 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,43 +78,43 @@  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
 		if ($this->all_flights[$id]['addedSpotter'] == 1) $Spotter->updateLatestScheduleSpotterData($this->all_flights[$id]['id'],$sch['departure_airport_icao'],$sch['departure_airport_time'],$sch['arrival_airport_icao'],$sch['arrival_airport_time']);
117
-       }
117
+	   }
118 118
 	$Spotter->db = null;
119 119
 	$Schedule->db = null;
120 120
 	$Translation->db = null;
@@ -129,78 +129,78 @@  discard block
 block discarded – undo
129 129
 	}
130 130
 	  */
131 131
 	}
132
-    }
132
+	}
133 133
 
134
-    public function checkAll() {
134
+	public function checkAll() {
135 135
 	global $globalDebug, $globalNoImport;
136 136
 	if ($globalDebug) echo "Update last seen flights data...\n";
137 137
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
138
-	    foreach ($this->all_flights as $key => $flight) {
138
+		foreach ($this->all_flights as $key => $flight) {
139 139
 		if (isset($this->all_flights[$key]['id'])) {
140
-		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
141
-    		    $Spotter = new Spotter($this->db);
142
-        	    $real_arrival = $this->arrival($key);
143
-        	    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']);
144
-        	}
145
-	    }
140
+			//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
141
+				$Spotter = new Spotter($this->db);
142
+				$real_arrival = $this->arrival($key);
143
+				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']);
144
+			}
145
+		}
146
+	}
146 147
 	}
147
-    }
148 148
 
149
-    public function arrival($key) {
149
+	public function arrival($key) {
150 150
 	global $globalClosestMinDist, $globalDebug;
151 151
 	if ($globalDebug) echo 'Update arrival...'."\n";
152 152
 	$Spotter = new Spotter($this->db);
153
-        $airport_icao = '';
154
-        $airport_time = '';
155
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
153
+		$airport_icao = '';
154
+		$airport_time = '';
155
+		if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
156 156
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
157
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
158
-    	    if (isset($closestAirports[0])) {
159
-        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
160
-        	    $airport_icao = $closestAirports[0]['icao'];
161
-        	    $airport_time = $this->all_flights[$key]['datetime'];
162
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
163
-        	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
164
-        	    foreach ($closestAirports as $airport) {
165
-        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
166
-        		    $airport_icao = $airport['icao'];
167
-        		    $airport_time = $this->all_flights[$key]['datetime'];
168
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
169
-        		    break;
170
-        		}
171
-        	    }
172
-        	} 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))) {
173
-        		$airport_icao = $closestAirports[0]['icao'];
174
-        		$airport_time = $this->all_flights[$key]['datetime'];
175
-        	} else {
176
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
177
-        	}
178
-    	    } else {
179
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
180
-    	    }
157
+		$closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
158
+			if (isset($closestAirports[0])) {
159
+			if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
160
+				$airport_icao = $closestAirports[0]['icao'];
161
+				$airport_time = $this->all_flights[$key]['datetime'];
162
+				if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
163
+			} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
164
+				foreach ($closestAirports as $airport) {
165
+				if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
166
+					$airport_icao = $airport['icao'];
167
+					$airport_time = $this->all_flights[$key]['datetime'];
168
+					if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
169
+					break;
170
+				}
171
+				}
172
+			} 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))) {
173
+				$airport_icao = $closestAirports[0]['icao'];
174
+				$airport_time = $this->all_flights[$key]['datetime'];
175
+			} else {
176
+				if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
177
+			}
178
+			} else {
179
+				if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
180
+			}
181 181
 
182
-        } else {
183
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
184
-        }
185
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
186
-    }
182
+		} else {
183
+			if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
184
+		}
185
+		return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
186
+	}
187 187
 
188 188
 
189 189
 
190
-    public function del() {
190
+	public function del() {
191 191
 	global $globalDebug, $globalNoImport, $globalNoDB;
192 192
 	// Delete old infos
193 193
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
194 194
 	foreach ($this->all_flights as $key => $flight) {
195
-	    if (isset($flight['lastupdate'])) {
195
+		if (isset($flight['lastupdate'])) {
196 196
 		if ($flight['lastupdate'] < (time()-1800)) {
197
-		    $this->delKey($key);
197
+			$this->delKey($key);
198 198
 		}
199
-	    }
199
+		}
200
+	}
200 201
 	}
201
-    }
202 202
 
203
-    public function delKey($key) {
203
+	public function delKey($key) {
204 204
 	global $globalDebug, $globalNoImport, $globalNoDB;
205 205
 	// Delete old infos
206 206
 	if (isset($this->all_flights[$key]['id'])) {
@@ -215,9 +215,9 @@  discard block
 block discarded – undo
215 215
 		}
216 216
 	}
217 217
 	unset($this->all_flights[$key]);
218
-    }
218
+	}
219 219
 
220
-    public function add($line) {
220
+	public function add($line) {
221 221
 	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, $globalArchive;
222 222
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
223 223
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.01';
@@ -243,20 +243,20 @@  discard block
 block discarded – undo
243 243
 	
244 244
 	// SBS format is CSV format
245 245
 	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
246
-	    //print_r($line);
247
-	    if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
248
-  	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && substr($line['hex'],0,1) != '~' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
246
+		//print_r($line);
247
+		if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
248
+  		if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && substr($line['hex'],0,1) != '~' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
249 249
 
250 250
 		// Increment message number
251 251
 		if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) {
252
-		    $current_date = date('Y-m-d');
253
-		    if (isset($line['source_name'])) $source = $line['source_name'];
254
-		    else $source = '';
255
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
256
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
257
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
258
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
259
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
252
+			$current_date = date('Y-m-d');
253
+			if (isset($line['source_name'])) $source = $line['source_name'];
254
+			else $source = '';
255
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
256
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
257
+				$this->stats[$current_date][$source]['msg']['date'] = time();
258
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
259
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
260 260
 		}
261 261
 		
262 262
 		/*
@@ -272,54 +272,54 @@  discard block
 block discarded – undo
272 272
 		//$this->db = $dbc;
273 273
 
274 274
 		//$hex = trim($line['hex']);
275
-	        if (!isset($line['id'])) $id = trim($line['hex']);
276
-	        else $id = trim($line['id']);
275
+			if (!isset($line['id'])) $id = trim($line['hex']);
276
+			else $id = trim($line['id']);
277 277
 		
278 278
 		if (!isset($this->all_flights[$id])) {
279
-		    if ($globalDebug) echo 'New flight...'."\n";
280
-		    $this->all_flights[$id] = array();
281
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
282
-		    $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' => ''));
283
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
284
-		    if (!isset($line['id'])) {
279
+			if ($globalDebug) echo 'New flight...'."\n";
280
+			$this->all_flights[$id] = array();
281
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
282
+			$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' => ''));
283
+			if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
284
+			if (!isset($line['id'])) {
285 285
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
286 286
 //			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')));
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') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
288 288
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')));
289
-		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
290
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
291
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
289
+				//else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
290
+			 } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
291
+			if ($globalAllFlights !== FALSE) $dataFound = true;
292 292
 		}
293 293
 		if (isset($line['source_type']) && $line['source_type'] != '') {
294
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
294
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
295 295
 		}
296 296
 		
297 297
 		//print_r($this->all_flights);
298 298
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
299
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
300
-		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
299
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
300
+			//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
301 301
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
302
-		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
303
-		    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') {
302
+			//} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
303
+			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') {
304 304
 			$timeelapsed = microtime(true);
305 305
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
306
-			    $Spotter = new Spotter($this->db);
307
-			    if (isset($this->all_flights[$id]['source_type'])) {
306
+				$Spotter = new Spotter($this->db);
307
+				if (isset($this->all_flights[$id]['source_type'])) {
308 308
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
309
-			    } else {
309
+				} else {
310 310
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
311
-			    }
312
-			    $Spotter->db = null;
313
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
314
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
311
+				}
312
+				$Spotter->db = null;
313
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
314
+				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
315 315
 			}
316
-		    }
317
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
318
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
316
+			}
317
+			if ($globalAllFlights !== FALSE) $dataFound = true;
318
+			if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
319 319
 		}
320
-	        if (isset($line['id']) && !isset($line['hex'])) {
321
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
322
-	        }
320
+			if (isset($line['id']) && !isset($line['hex'])) {
321
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
322
+			}
323 323
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
324 324
 			$icao = $line['aircraft_icao'];
325 325
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -349,9 +349,9 @@  discard block
 block discarded – undo
349 349
 		}
350 350
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
351 351
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) {
352
-		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
352
+			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
353 353
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
354
-		    } else {
354
+			} else {
355 355
 				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";
356 356
 				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";
357 357
 				/*
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 				print_r($line);
361 361
 				*/
362 362
 				return '';
363
-		    }
363
+			}
364 364
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
365 365
 			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
366 366
 			return '';
@@ -376,21 +376,21 @@  discard block
 block discarded – undo
376 376
 		}
377 377
 
378 378
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG' && $line['registration'] != 'NA') {
379
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
379
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
380 380
 		}
381 381
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
382
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
382
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
383 383
 		}
384 384
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
385
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
385
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
386 386
 		}
387 387
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
388
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
388
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
389 389
 		}
390 390
  
391 391
 		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'])) {
392 392
 
393
-		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
393
+			if ($this->all_flights[$id]['addedSpotter'] == 1) {
394 394
 			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
395 395
 				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
396 396
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
@@ -399,23 +399,23 @@  discard block
 block discarded – undo
399 399
 				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
400 400
 				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']));
401 401
 			} else {
402
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
403
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
402
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
403
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
404 404
 				$timeelapsed = microtime(true);
405
-            			$Spotter = new Spotter($this->db);
406
-            			$fromsource = NULL;
407
-            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
408
-            			elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
405
+						$Spotter = new Spotter($this->db);
406
+						$fromsource = NULL;
407
+						if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
408
+						elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
409 409
 				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
410 410
 				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
411 411
 				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
412
-            			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
412
+						$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
413 413
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
414 414
 				$Spotter->db = null;
415 415
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
416
-			    }
416
+				}
417 417
 			}
418
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
418
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
419 419
 		    
420 420
 /*
421 421
 		    if (!isset($line['id'])) {
@@ -425,63 +425,63 @@  discard block
 block discarded – undo
425 425
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
426 426
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
427 427
   */
428
-		    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']));
428
+			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']));
429 429
 
430
-		    //$putinarchive = true;
431
-		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
430
+			//$putinarchive = true;
431
+			if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
432 432
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
433
-		    }
434
-		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
433
+			}
434
+			if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
435 435
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
436
-		    }
437
-		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
438
-		    		$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' => ''));
439
-		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
436
+			}
437
+			if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
438
+					$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' => ''));
439
+			} elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
440 440
 			$timeelapsed = microtime(true);
441 441
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
442 442
 				$Spotter = new Spotter($this->db);
443 443
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
444 444
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
445
-		    		$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' => ''));
445
+					$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' => ''));
446 446
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
447
-                        }
448
-		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
447
+						}
448
+			} elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
449 449
 			$timeelapsed = microtime(true);
450 450
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
451
-			    $Spotter = new Spotter($this->db);
452
-			    $route = $Spotter->getRouteInfo(trim($line['ident']));
453
-			    if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) {
451
+				$Spotter = new Spotter($this->db);
452
+				$route = $Spotter->getRouteInfo(trim($line['ident']));
453
+				if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) {
454 454
 				$Translation = new Translation($this->db);
455 455
 				$ident = $Translation->checkTranslation(trim($line['ident']));
456 456
 				$route = $Spotter->getRouteInfo($ident);
457 457
 				$Translation->db = null;
458
-			    }
459
-			    $Spotter->db = null;
460
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
461
-                    	}
458
+				}
459
+				$Spotter->db = null;
460
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
461
+						}
462 462
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
463
-			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
464
-			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
463
+				//if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
464
+				if ($route['fromairport_icao'] != $route['toairport_icao']) {
465 465
 				//    $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']));
466
-		    		$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']));
467
-		    	    }
466
+					$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']));
467
+					}
468 468
 			}
469 469
 			if (!isset($globalFork)) $globalFork = TRUE;
470 470
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
471 471
 				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
472 472
 			}
473
-		    }
473
+			}
474 474
 		}
475 475
 
476 476
 		if (isset($line['speed']) && $line['speed'] != '' && $line['speed'] != 0) {
477 477
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
478
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
479
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
480
-		    //$dataFound = true;
478
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
479
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
480
+			//$dataFound = true;
481 481
 		} 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'])) {
482
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
483
-		    if ($distance > 1000 && $distance < 10000) {
484
-		    // use datetime
482
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
483
+			if ($distance > 1000 && $distance < 10000) {
484
+			// use datetime
485 485
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
486 486
 			$speed = $speed*3.6;
487 487
 			if ($speed < 1000) {
@@ -490,49 +490,49 @@  discard block
 block discarded – undo
490 490
 	  		} else {
491 491
 	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
492 492
 	  		}
493
-		    }
493
+			}
494 494
 		}
495 495
 
496 496
 
497 497
 
498
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
499
-	    	    if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
500
-	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
501
-	    	    	return false;
502
-	    	    }
503
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
504
-	    	    else unset($timediff);
505
-	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
506
-	    	    else unset($timediff_archive);
507
-	    	    if ($this->tmd > 5
508
-	    	        || (isset($line['format_source']) 
509
-	    	    	    && $line['format_source'] == 'airwhere' 
510
-	    	    	    && ((!isset($this->all_flights[$id]['latitude']) 
511
-	    	    		|| !isset($this->all_flights[$id]['longitude'])) 
512
-	    	    		|| (isset($this->all_flights[$id]['latitude']) 
513
-	    	    		    && isset($this->all_flights[$id]['longitude']) 
514
-	    	    		    && $this->all_flights[$id]['latitude'] != $line['latitude'] 
515
-	    	    		    && $this->all_flights[$id]['longitude'] != $line['longitude']
516
-	    	    		)
517
-	    	    	    )
518
-	    	    	)
519
-	    		|| (isset($globalVA) && $globalVA) 
520
-	    	    	|| (isset($globalIVAO) && $globalIVAO)
521
-	    	    	|| (isset($globalVATSIM) && $globalVATSIM)
522
-	    	    	|| (isset($globalphpVMS) && $globalphpVMS)
523
-	    	    	|| (isset($globalVAM) && $globalVAM)
524
-	    	    	|| !isset($timediff)
525
-	    	    	|| $timediff > $globalLiveInterval
526
-	    	    	|| $globalArchive
527
-	    	    	|| ($timediff > 30 
528
-	    	    	    && isset($this->all_flights[$id]['latitude']) 
529
-	    	    	    && isset($this->all_flights[$id]['longitude']) 
530
-	    	    	    && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
531
-	    	    	    )
532
-	    	    	) {
498
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
499
+				if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
500
+					if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
501
+					return false;
502
+				}
503
+				if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
504
+				else unset($timediff);
505
+				if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
506
+				else unset($timediff_archive);
507
+				if ($this->tmd > 5
508
+					|| (isset($line['format_source']) 
509
+						&& $line['format_source'] == 'airwhere' 
510
+						&& ((!isset($this->all_flights[$id]['latitude']) 
511
+						|| !isset($this->all_flights[$id]['longitude'])) 
512
+						|| (isset($this->all_flights[$id]['latitude']) 
513
+							&& isset($this->all_flights[$id]['longitude']) 
514
+							&& $this->all_flights[$id]['latitude'] != $line['latitude'] 
515
+							&& $this->all_flights[$id]['longitude'] != $line['longitude']
516
+						)
517
+						)
518
+					)
519
+				|| (isset($globalVA) && $globalVA) 
520
+					|| (isset($globalIVAO) && $globalIVAO)
521
+					|| (isset($globalVATSIM) && $globalVATSIM)
522
+					|| (isset($globalphpVMS) && $globalphpVMS)
523
+					|| (isset($globalVAM) && $globalVAM)
524
+					|| !isset($timediff)
525
+					|| $timediff > $globalLiveInterval
526
+					|| $globalArchive
527
+					|| ($timediff > 30 
528
+						&& isset($this->all_flights[$id]['latitude']) 
529
+						&& isset($this->all_flights[$id]['longitude']) 
530
+						&& $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
531
+						)
532
+					) {
533 533
 
534 534
 			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']))) {
535
-			    if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
535
+				if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
536 536
 				|| (isset($line['format_source']) && $line['format_source'] == 'airwhere') 
537 537
 				|| !$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'])) {
538 538
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -540,9 +540,9 @@  discard block
 block discarded – undo
540 540
 				$this->all_flights[$id]['putinarchive'] = true;
541 541
 				$this->tmd = 0;
542 542
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
543
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
544
-				    $timeelapsed = microtime(true);
545
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
543
+					if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
544
+					$timeelapsed = microtime(true);
545
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
546 546
 					$Spotter = new Spotter($this->db);
547 547
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
548 548
 					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
@@ -550,11 +550,11 @@  discard block
 block discarded – undo
550 550
 					$Spotter->db = null;
551 551
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
552 552
 					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
553
-				    }
553
+					}
554 554
 				}
555 555
 				$this->all_flights[$id]['time_last_archive_coord'] = time();
556
-			    } 
557
-			    /*
556
+				} 
557
+				/*
558 558
 			    else {
559 559
 				if (!isset($timediff)) echo 'NO TIMEDIFF';
560 560
 				else {
@@ -568,16 +568,16 @@  discard block
 block discarded – undo
568 568
 			}
569 569
 
570 570
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
571
-			    //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) {
571
+				//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) {
572 572
 				if (!isset($this->all_flights[$id]['archive_latitude'])) {
573 573
 					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
574 574
 					$this->all_flights[$id]['time_last_coord'] = time();
575 575
 				}
576 576
 				//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)) {
577 577
 				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)) {
578
-				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
579
-				    $dataFound = true;
580
-				    $this->all_flights[$id]['time_last_coord'] = time();
578
+					$this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
579
+					$dataFound = true;
580
+					$this->all_flights[$id]['time_last_coord'] = time();
581 581
 				}
582 582
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
583 583
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
@@ -588,24 +588,24 @@  discard block
 block discarded – undo
588 588
 				    //$putinarchive = true;
589 589
 				}
590 590
 				*/
591
-			    /*
591
+				/*
592 592
 			    } elseif (isset($this->all_flights[$id]['latitude'])) {
593 593
 				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";
594 594
 			    }
595 595
 			    */
596 596
 			}
597 597
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
598
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
599
-			    //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) {
598
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
599
+				//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) {
600 600
 				if (!isset($this->all_flights[$id]['archive_longitude'])) {
601 601
 					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
602 602
 					$this->all_flights[$id]['time_last_coord'] = time();
603 603
 				}
604 604
 				//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)) {
605 605
 				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)) {
606
-				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
607
-				    $dataFound = true;
608
-				    $this->all_flights[$id]['time_last_coord'] = time();
606
+					$this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
607
+					$dataFound = true;
608
+					$this->all_flights[$id]['time_last_coord'] = time();
609 609
 				}
610 610
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
611 611
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
@@ -623,67 +623,67 @@  discard block
 block discarded – undo
623 623
 			    */
624 624
 			}
625 625
 
626
-		    } else if ($globalDebug && $timediff > 30) {
626
+			} else if ($globalDebug && $timediff > 30) {
627 627
 			$this->tmd = $this->tmd + 1;
628 628
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
629 629
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
630 630
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
631 631
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
632
-		    }
632
+			}
633 633
 		}
634 634
 		if (isset($line['last_update']) && $line['last_update'] != '') {
635
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
636
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
635
+			if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
636
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
637 637
 		}
638 638
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
639
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
640
-		    //$dataFound = true;
639
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
640
+			//$dataFound = true;
641 641
 		}
642 642
 		if (isset($line['format_source']) && $line['format_source'] != '') {
643
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
643
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
644 644
 		}
645 645
 		if (isset($line['source_name']) && $line['source_name'] != '') {
646
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
646
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
647 647
 		}
648 648
 		if (isset($line['emergency']) && $line['emergency'] != '') {
649
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
650
-		    //$dataFound = true;
649
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
650
+			//$dataFound = true;
651 651
 		}
652 652
 		if (isset($line['ground']) && $line['ground'] != '') {
653
-		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
653
+			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
654 654
 			// Here we force archive of flight because after ground it's a new one (or should be)
655 655
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
656 656
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
657 657
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')));
658
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
658
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
659 659
 			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']));
660
-		    }
661
-		    if ($line['ground'] != 1) $line['ground'] = 0;
662
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
663
-		    //$dataFound = true;
660
+			}
661
+			if ($line['ground'] != 1) $line['ground'] = 0;
662
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
663
+			//$dataFound = true;
664 664
 		}
665 665
 		if (isset($line['squawk']) && $line['squawk'] != '') {
666
-		    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'])) {
667
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
668
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
669
-			    $highlight = '';
670
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
671
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
672
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
673
-			    if ($highlight != '') {
666
+			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'])) {
667
+				if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
668
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
669
+				$highlight = '';
670
+				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
671
+				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
672
+				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
673
+				if ($highlight != '') {
674 674
 				$timeelapsed = microtime(true);
675 675
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
676
-				    $Spotter = new Spotter($this->db);
677
-				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
678
-				    $Spotter->db = null;
679
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
676
+					$Spotter = new Spotter($this->db);
677
+					$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
678
+					$Spotter->db = null;
679
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
680 680
 				}
681 681
 				//$putinarchive = true;
682 682
 				//$highlight = '';
683
-			    }
683
+				}
684 684
 			    
685
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
686
-		    //$dataFound = true;
685
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
686
+			//$dataFound = true;
687 687
 		}
688 688
 
689 689
 		if (isset($line['altitude']) && $line['altitude'] != '') {
@@ -694,13 +694,13 @@  discard block
 block discarded – undo
694 694
 					$line['altitude'] = $line['altitude'] - $geoid;
695 695
 				}
696 696
 			}
697
-		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
697
+			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
698 698
 			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;
699 699
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
700 700
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
701 701
 			//$dataFound = true;
702
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
703
-		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
702
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
703
+			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
704 704
 			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) {
705 705
 				if ($globalDebug) echo '--- Reset because of altitude'."\n";
706 706
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
@@ -709,27 +709,27 @@  discard block
 block discarded – undo
709 709
 				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
710 710
 				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']));
711 711
 			}
712
-		    }
713
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
712
+			}
713
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
714 714
 		}
715 715
 
716 716
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
717
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
717
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
718 718
 		}
719 719
 		
720 720
 		if (isset($line['heading']) && $line['heading'] != '') {
721
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
722
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
723
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
724
-		    //$dataFound = true;
721
+			if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
722
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
723
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
724
+			//$dataFound = true;
725 725
   		} 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']) {
726
-  		    $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']);
727
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
728
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
729
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
726
+  			$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']);
727
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
728
+			if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
729
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
730 730
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
731
-  		    // If not enough messages and ACARS set heading to 0
732
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
731
+  			// If not enough messages and ACARS set heading to 0
732
+  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
733 733
   		}
734 734
 		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
735 735
 		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
@@ -742,125 +742,125 @@  discard block
 block discarded – undo
742 742
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
743 743
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
744 744
 		if ($dataFound === true && isset($this->all_flights[$id]['id'])) {
745
-		    $this->all_flights[$id]['lastupdate'] = time();
746
-		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
747
-		        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'])) {
748
-			    //print_r($this->all_flights);
749
-			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
750
-			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
751
-			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
745
+			$this->all_flights[$id]['lastupdate'] = time();
746
+			if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
747
+				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'])) {
748
+				//print_r($this->all_flights);
749
+				//echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
750
+				//$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
751
+				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
752 752
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
753
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
754
-				    $timeelapsed = microtime(true);
755
-				    $SpotterLive = new SpotterLive($this->db);
756
-				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')) {
753
+					if ($globalDebug) echo "Check if aircraft is already in DB...";
754
+					$timeelapsed = microtime(true);
755
+					$SpotterLive = new SpotterLive($this->db);
756
+					if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')) {
757 757
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
758 758
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
759
-				    } elseif (isset($line['id'])) {
759
+					} elseif (isset($line['id'])) {
760 760
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
761 761
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
762
-				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
762
+					} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
763 763
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
764 764
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
765
-				    } else $recent_ident = '';
766
-				    $SpotterLive->db=null;
767
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
768
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
765
+					} else $recent_ident = '';
766
+					$SpotterLive->db=null;
767
+					if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
768
+					elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
769 769
 				} else $recent_ident = '';
770
-			    } else {
770
+				} else {
771 771
 				$recent_ident = '';
772 772
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
773
-			    }
774
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
775
-			    if($recent_ident == "")
776
-			    {
773
+				}
774
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
775
+				if($recent_ident == "")
776
+				{
777 777
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
778 778
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
779 779
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
780 780
 				//adds the spotter data for the archive
781 781
 				$ignoreImport = false;
782 782
 				foreach($globalAirportIgnore as $airportIgnore) {
783
-				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
783
+					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
784 784
 					$ignoreImport = true;
785
-				    }
785
+					}
786 786
 				}
787 787
 				if (count($globalAirportAccept) > 0) {
788
-				    $ignoreImport = true;
789
-				    foreach($globalAirportIgnore as $airportIgnore) {
788
+					$ignoreImport = true;
789
+					foreach($globalAirportIgnore as $airportIgnore) {
790 790
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
791
-					    $ignoreImport = false;
791
+						$ignoreImport = false;
792
+					}
792 793
 					}
793
-				    }
794 794
 				}
795 795
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
796
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
796
+					foreach($globalAirlineIgnore as $airlineIgnore) {
797 797
 					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)) {
798
-					    $ignoreImport = true;
798
+						$ignoreImport = true;
799
+					}
799 800
 					}
800
-				    }
801 801
 				}
802 802
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
803
-				    $ignoreImport = true;
804
-				    foreach($globalAirlineAccept as $airlineAccept) {
803
+					$ignoreImport = true;
804
+					foreach($globalAirlineAccept as $airlineAccept) {
805 805
 					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)) {
806
-					    $ignoreImport = false;
806
+						$ignoreImport = false;
807
+					}
807 808
 					}
808
-				    }
809 809
 				}
810 810
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
811
-				    $ignoreImport = true;
812
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
811
+					$ignoreImport = true;
812
+					foreach($globalPilotIdAccept as $pilotIdAccept) {
813 813
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
814
-					    $ignoreImport = false;
814
+						$ignoreImport = false;
815
+					}
815 816
 					}
816
-				    }
817 817
 				}
818 818
 				
819 819
 				if (!$ignoreImport) {
820
-				    $highlight = '';
821
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
822
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
823
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
824
-				    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')));
825
-				    $timeelapsed = microtime(true);
826
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
820
+					$highlight = '';
821
+					if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
822
+					if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
823
+					if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
824
+					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')));
825
+					$timeelapsed = microtime(true);
826
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
827 827
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
828
-					    $Spotter = new Spotter($this->db);
829
-					    $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']);
830
-					    $Spotter->db = null;
831
-					    if ($globalDebug && isset($result)) echo $result."\n";
828
+						$Spotter = new Spotter($this->db);
829
+						$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']);
830
+						$Spotter->db = null;
831
+						if ($globalDebug && isset($result)) echo $result."\n";
832 832
 					}
833
-				    }
834
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
835
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
833
+					}
834
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
835
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
836 836
 
837
-				    // Add source stat in DB
838
-				    $Stats = new Stats($this->db);
839
-				    if (!empty($this->stats)) {
837
+					// Add source stat in DB
838
+					$Stats = new Stats($this->db);
839
+					if (!empty($this->stats)) {
840 840
 					if ($globalDebug) echo 'Add source stats : ';
841
-				        foreach($this->stats as $date => $data) {
842
-					    foreach($data as $source => $sourced) {
843
-					        //print_r($sourced);
844
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
845
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
846
-				    		if (isset($sourced['msg'])) {
847
-				    		    if (time() - $sourced['msg']['date'] > 10) {
848
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
849
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
850
-			    			        unset($this->stats[$date][$source]['msg']);
851
-			    			    }
852
-			    			}
853
-			    		    }
854
-			    		    if ($date != date('Y-m-d')) {
855
-			    			unset($this->stats[$date]);
856
-			    		    }
857
-				    	}
858
-				    	if ($globalDebug) echo 'Done'."\n";
841
+						foreach($this->stats as $date => $data) {
842
+						foreach($data as $source => $sourced) {
843
+							//print_r($sourced);
844
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
845
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
846
+							if (isset($sourced['msg'])) {
847
+								if (time() - $sourced['msg']['date'] > 10) {
848
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
849
+									echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
850
+									unset($this->stats[$date][$source]['msg']);
851
+								}
852
+							}
853
+							}
854
+							if ($date != date('Y-m-d')) {
855
+							unset($this->stats[$date]);
856
+							}
857
+						}
858
+						if ($globalDebug) echo 'Done'."\n";
859 859
 
860
-				    }
861
-				    $Stats->db = null;
862
-				    }
863
-				    $this->del();
860
+					}
861
+					$Stats->db = null;
862
+					}
863
+					$this->del();
864 864
 				} elseif ($globalDebug) echo 'Ignore data'."\n";
865 865
 				//$ignoreImport = false;
866 866
 				$this->all_flights[$id]['addedSpotter'] = 1;
@@ -878,41 +878,41 @@  discard block
 block discarded – undo
878 878
 			*/
879 879
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
880 880
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
881
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
882
-				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
883
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
881
+					if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
882
+					//SpotterLive->deleteLiveSpotterDataNotUpdated();
883
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
884 884
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
885
-					    $SpotterLive = new SpotterLive($this->db);
886
-					    $SpotterLive->deleteLiveSpotterData();
887
-					    $SpotterLive->db=null;
885
+						$SpotterLive = new SpotterLive($this->db);
886
+						$SpotterLive->deleteLiveSpotterData();
887
+						$SpotterLive->db=null;
888 888
 					}
889
-				    }
890
-				    if ($globalDebug) echo " Done\n";
891
-				    $this->last_delete = time();
889
+					}
890
+					if ($globalDebug) echo " Done\n";
891
+					$this->last_delete = time();
892 892
 				}
893
-			    } else {
893
+				} else {
894 894
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')) {
895
-				    $this->all_flights[$id]['id'] = $recent_ident;
896
-				    $this->all_flights[$id]['addedSpotter'] = 1;
895
+					$this->all_flights[$id]['id'] = $recent_ident;
896
+					$this->all_flights[$id]['addedSpotter'] = 1;
897 897
 				}
898 898
 				if (isset($globalDaemon) && !$globalDaemon) {
899
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
899
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
900 900
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
901
-					    $Spotter = new Spotter($this->db);
902
-					    $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']);
903
-					    $Spotter->db = null;
901
+						$Spotter = new Spotter($this->db);
902
+						$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']);
903
+						$Spotter->db = null;
904
+					}
904 905
 					}
905
-				    }
906 906
 				}
907 907
 				
908
-			    }
908
+				}
909 909
 			}
910
-		    }
911
-		    //adds the spotter LIVE data
912
-		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
913
-		    //echo "\nAdd in Live !! \n";
914
-		    //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";
915
-		    if ($globalDebug) {
910
+			}
911
+			//adds the spotter LIVE data
912
+			//SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
913
+			//echo "\nAdd in Live !! \n";
914
+			//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";
915
+			if ($globalDebug) {
916 916
 			if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
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'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - 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'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
@@ -920,60 +920,60 @@  discard block
 block discarded – undo
920 920
 				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";
921 921
 				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";
922 922
 			}
923
-		    }
924
-		    $ignoreImport = false;
925
-		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
926
-		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
923
+			}
924
+			$ignoreImport = false;
925
+			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
926
+			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
927 927
 
928
-		    foreach($globalAirportIgnore as $airportIgnore) {
929
-		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
930
-			    $ignoreImport = true;
928
+			foreach($globalAirportIgnore as $airportIgnore) {
929
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
930
+				$ignoreImport = true;
931
+			}
931 932
 			}
932
-		    }
933
-		    if (count($globalAirportAccept) > 0) {
934
-		        $ignoreImport = true;
935
-		        foreach($globalAirportIgnore as $airportIgnore) {
936
-			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
933
+			if (count($globalAirportAccept) > 0) {
934
+				$ignoreImport = true;
935
+				foreach($globalAirportIgnore as $airportIgnore) {
936
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
937 937
 				$ignoreImport = false;
938
-			    }
938
+				}
939 939
 			}
940
-		    }
941
-		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
940
+			}
941
+			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
942 942
 			foreach($globalAirlineIgnore as $airlineIgnore) {
943
-			    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)) {
943
+				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)) {
944 944
 				$ignoreImport = true;
945
-			    }
945
+				}
946 946
 			}
947
-		    }
948
-		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
947
+			}
948
+			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
949 949
 			$ignoreImport = true;
950 950
 			foreach($globalAirlineAccept as $airlineAccept) {
951
-			    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)) {
951
+				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)) {
952 952
 				$ignoreImport = false;
953
-			    }
953
+				}
954
+			}
954 955
 			}
955
-		    }
956
-		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
956
+			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
957 957
 			$ignoreImport = true;
958 958
 			foreach($globalPilotIdAccept as $pilotIdAccept) {
959
-			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
960
-			        $ignoreImport = false;
961
-			    }
959
+				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
960
+					$ignoreImport = false;
961
+				}
962
+			}
962 963
 			}
963
-		    }
964 964
 
965
-		    if (!$ignoreImport) {
965
+			if (!$ignoreImport) {
966 966
 			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'])) {
967 967
 				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')));
968 968
 				$timeelapsed = microtime(true);
969 969
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
970
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
970
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
971 971
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
972 972
 					$SpotterLive = new SpotterLive($this->db);
973 973
 					$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']);
974 974
 					$SpotterLive->db = null;
975 975
 					if ($globalDebug) echo $result."\n";
976
-				    }
976
+					}
977 977
 				}
978 978
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
979 979
 					$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']);
@@ -985,7 +985,7 @@  discard block
 block discarded – undo
985 985
 				//if ($line['format_source'] != 'aprs') {
986 986
 				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
987 987
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
988
-				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
988
+					if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
989 989
 					$source = $this->all_flights[$id]['source_name'];
990 990
 					if ($source == '') $source = $this->all_flights[$id]['format_source'];
991 991
 					if (!isset($this->source_location[$source])) {
@@ -1011,7 +1011,7 @@  discard block
 block discarded – undo
1011 1011
 					if ($stats_heading == 16) $stats_heading = 0;
1012 1012
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
1013 1013
 						for ($i=0;$i<=15;$i++) {
1014
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
1014
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
1015 1015
 						}
1016 1016
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
1017 1017
 					} else {
@@ -1024,17 +1024,17 @@  discard block
 block discarded – undo
1024 1024
 					//var_dump($this->stats);
1025 1025
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
1026 1026
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1027
-						    end($this->stats[$current_date][$source]['hist']);
1028
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1027
+							end($this->stats[$current_date][$source]['hist']);
1028
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
1029 1029
 						} else $mini = 0;
1030 1030
 						for ($i=$mini;$i<=$distance;$i+=10) {
1031
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1031
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
1032 1032
 						}
1033 1033
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
1034 1034
 					} else {
1035 1035
 						$this->stats[$current_date][$source]['hist'][$distance] += 1;
1036 1036
 					}
1037
-				    }
1037
+					}
1038 1038
 				}
1039 1039
 
1040 1040
 				$this->all_flights[$id]['lastupdate'] = time();
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
 			//$this->del();
1045 1045
 			
1046 1046
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
1047
-			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1047
+				if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1048 1048
 				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1049 1049
 				$SpotterLive = new SpotterLive($this->db);
1050 1050
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
@@ -1052,19 +1052,19 @@  discard block
 block discarded – undo
1052 1052
 				//SpotterLive->deleteLiveSpotterData();
1053 1053
 				if ($globalDebug) echo " Done\n";
1054 1054
 				$this->last_delete_hourly = time();
1055
-			    } else {
1055
+				} else {
1056 1056
 				$this->del();
1057 1057
 				$this->last_delete_hourly = time();
1058
-			    }
1058
+				}
1059 1059
 			}
1060 1060
 			
1061
-		    }
1062
-		    //$ignoreImport = false;
1061
+			}
1062
+			//$ignoreImport = false;
1063 1063
 		}
1064 1064
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
1065 1065
 		if ($send) return $this->all_flights[$id];
1066
-	    }
1066
+		}
1067
+	}
1067 1068
 	}
1068
-    }
1069 1069
 }
1070 1070
 ?>
Please login to merge, or discard this patch.
Spacing   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -34,12 +34,12 @@  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) {
37
+		    foreach ($sourcestat as $srcst) {
38 38
 		    	$type = $srcst['stats_type'];
39 39
 			if ($type == 'polar' || $type == 'hist') {
40 40
 			    $source = $srcst['source_name'];
41 41
 			    $data = $srcst['source_data'];
42
-			    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
42
+			    $this->stats[$currentdate][$source][$type] = json_decode($data, true);
43 43
 	    		}
44 44
 		    }
45 45
 		}
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
 	if (isset($globalGeoid) && $globalGeoid) {
52 52
 		try {
53 53
 			$GeoidClass = new GeoidHeight();
54
-		} catch(Exception $e) {
54
+		} catch (Exception $e) {
55 55
 			if ($globalDebug) echo "Can't calculate geoid, check that you downloaded it via update_db.php (".$e.")\n";
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
 	
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
 		$schedule = $Schedule->fetchSchedule($operator);
84 84
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
85 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']));
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 88
 		    // Should also check if route schedule = route from DB
89 89
 		    if ($schedule['DepartureAirportIATA'] != '') {
90 90
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 			    }
105 105
 			}
106 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']);
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 109
 	    } else $scheduleexist = true;
110 110
 	} else $scheduleexist = true;
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
        if ($scheduleexist) {
113 113
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
114 114
     		$sch = $Schedule->getSchedule($operator);
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
-		if ($this->all_flights[$id]['addedSpotter'] == 1) $Spotter->updateLatestScheduleSpotterData($this->all_flights[$id]['id'],$sch['departure_airport_icao'],$sch['departure_airport_time'],$sch['arrival_airport_icao'],$sch['arrival_airport_time']);
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
+		if ($this->all_flights[$id]['addedSpotter'] == 1) $Spotter->updateLatestScheduleSpotterData($this->all_flights[$id]['id'], $sch['departure_airport_icao'], $sch['departure_airport_time'], $sch['arrival_airport_icao'], $sch['arrival_airport_time']);
117 117
        }
118 118
 	$Spotter->db = null;
119 119
 	$Schedule->db = null;
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
141 141
     		    $Spotter = new Spotter($this->db);
142 142
         	    $real_arrival = $this->arrival($key);
143
-        	    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
+        	    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']);
144 144
         	}
145 145
 	    }
146 146
 	}
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
         $airport_time = '';
155 155
         if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
156 156
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
157
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
157
+	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $globalClosestMinDist);
158 158
     	    if (isset($closestAirports[0])) {
159 159
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
160 160
         	    $airport_icao = $closestAirports[0]['icao'];
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         		    break;
170 170
         		}
171 171
         	    }
172
-        	} 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
+        	} 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))) {
173 173
         		$airport_icao = $closestAirports[0]['icao'];
174 174
         		$airport_time = $this->all_flights[$key]['datetime'];
175 175
         	} else {
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
         } else {
183 183
         	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
184 184
         }
185
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
185
+        return array('airport_icao' => $airport_icao, 'airport_time' => $airport_time);
186 186
     }
187 187
 
188 188
 
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
194 194
 	foreach ($this->all_flights as $key => $flight) {
195 195
 	    if (isset($flight['lastupdate'])) {
196
-		if ($flight['lastupdate'] < (time()-1800)) {
196
+		if ($flight['lastupdate'] < (time() - 1800)) {
197 197
 		    $this->delKey($key);
198 198
 		}
199 199
 	    }
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 			$real_arrival = $this->arrival($key);
210 210
 			$Spotter = new Spotter($this->db);
211 211
 			if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
212
-				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
212
+				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $real_arrival['airport_icao'], $real_arrival['airport_time']);
213 213
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
214 214
 			}
215 215
 		}
@@ -242,10 +242,10 @@  discard block
 block discarded – undo
242 242
 	$send = false;
243 243
 	
244 244
 	// SBS format is CSV format
245
-	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
245
+	if (is_array($line) && (isset($line['hex']) || isset($line['id']))) {
246 246
 	    //print_r($line);
247 247
 	    if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
248
-  	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && substr($line['hex'],0,1) != '~' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
248
+  	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && substr($line['hex'], 0, 1) != '~' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
249 249
 
250 250
 		// Increment message number
251 251
 		if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) {
@@ -278,25 +278,25 @@  discard block
 block discarded – undo
278 278
 		if (!isset($this->all_flights[$id])) {
279 279
 		    if ($globalDebug) echo 'New flight...'."\n";
280 280
 		    $this->all_flights[$id] = array();
281
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
282
-		    $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' => ''));
283
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
281
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
282
+		    $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' => ''));
283
+		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('lastupdate' => time()));
284 284
 		    if (!isset($line['id'])) {
285 285
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
286 286
 //			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')));
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') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
288
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')));
289 289
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
290
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
290
+		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
291 291
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
292 292
 		}
293 293
 		if (isset($line['source_type']) && $line['source_type'] != '') {
294
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
294
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_type' => $line['source_type']));
295 295
 		}
296 296
 		
297 297
 		//print_r($this->all_flights);
298 298
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
299
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
299
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('hex' => trim($line['hex'])));
300 300
 		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
301 301
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
302 302
 		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -305,20 +305,20 @@  discard block
 block discarded – undo
305 305
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
306 306
 			    $Spotter = new Spotter($this->db);
307 307
 			    if (isset($this->all_flights[$id]['source_type'])) {
308
-				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
308
+				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']), $this->all_flights[$id]['source_type']);
309 309
 			    } else {
310 310
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
311 311
 			    }
312 312
 			    $Spotter->db = null;
313
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
314
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
313
+			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
314
+			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
315 315
 			}
316 316
 		    }
317 317
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
318 318
 		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
319 319
 		}
320 320
 	        if (isset($line['id']) && !isset($line['hex'])) {
321
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
321
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('hex' => ''));
322 322
 	        }
323 323
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
324 324
 			$icao = $line['aircraft_icao'];
@@ -327,14 +327,14 @@  discard block
 block discarded – undo
327 327
 				if (isset($Spotter->aircraft_correct_icaotype[$icao])) $icao = $Spotter->aircraft_correct_icaotype[$icao];
328 328
 				$Spotter->db = null;
329 329
 			}
330
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $icao));
330
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $icao));
331 331
 		} elseif (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_name'])) {
332 332
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
333 333
 				// Get aircraft ICAO from aircraft name
334 334
 				$Spotter = new Spotter($this->db);
335 335
 				$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
336 336
 				$Spotter->db = null;
337
-				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
337
+				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
338 338
 			}
339 339
 		}
340 340
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
@@ -342,15 +342,15 @@  discard block
 block discarded – undo
342 342
 			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
343 343
 			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
344 344
 			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
345
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
345
+			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
346 346
 		}
347 347
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
348
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
348
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => 'NA'));
349 349
 		}
350 350
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
351
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) {
351
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 20*60 && strtotime($line['datetime']) < time() + 20*60) {
352 352
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
353
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
353
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => $line['datetime']));
354 354
 		    } else {
355 355
 				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";
356 356
 				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";
@@ -361,31 +361,31 @@  discard block
 block discarded – undo
361 361
 				*/
362 362
 				return '';
363 363
 		    }
364
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
364
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time() - 20*60) {
365 365
 			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
366 366
 			return '';
367
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) {
367
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time() + 20*60) {
368 368
 			if ($globalDebug) echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
369 369
 			return '';
370 370
 		} elseif (!isset($line['datetime'])) {
371 371
 			date_default_timezone_set('UTC');
372
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
372
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => date('Y-m-d H:i:s')));
373 373
 		} else {
374 374
 			if ($globalDebug) echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
375 375
 			return '';
376 376
 		}
377 377
 
378 378
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG' && $line['registration'] != 'NA') {
379
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
379
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('registration' => $line['registration']));
380 380
 		}
381 381
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
382
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
382
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('waypoints' => $line['waypoints']));
383 383
 		}
384 384
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
385
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
385
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_id' => trim($line['pilot_id'])));
386 386
 		}
387 387
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
388
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
388
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_name' => trim($line['pilot_name'])));
389 389
 		}
390 390
  
391 391
 		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'])) {
@@ -393,13 +393,13 @@  discard block
 block discarded – undo
393 393
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
394 394
 			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
395 395
 				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
396
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
397
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
398
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')));
399
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
400
-				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']));
396
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
397
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
398
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')));
399
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
400
+				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']));
401 401
 			} else {
402
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
402
+			    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident'])));
403 403
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
404 404
 				$timeelapsed = microtime(true);
405 405
             			$Spotter = new Spotter($this->db);
@@ -409,13 +409,13 @@  discard block
 block discarded – undo
409 409
 				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
410 410
 				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
411 411
 				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
412
-            			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
412
+            			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $fromsource);
413 413
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
414 414
 				$Spotter->db = null;
415
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
415
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
416 416
 			    }
417 417
 			}
418
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
418
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident'])));
419 419
 		    
420 420
 /*
421 421
 		    if (!isset($line['id'])) {
@@ -425,25 +425,25 @@  discard block
 block discarded – undo
425 425
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
426 426
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
427 427
   */
428
-		    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']));
428
+		    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']));
429 429
 
430 430
 		    //$putinarchive = true;
431 431
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
432
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
432
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $line['departure_airport_time']));
433 433
 		    }
434 434
 		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
435
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
435
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $line['arrival_airport_time']));
436 436
 		    }
437 437
 		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
438
-		    		$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' => ''));
438
+		    		$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' => ''));
439 439
 		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
440 440
 			$timeelapsed = microtime(true);
441 441
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
442 442
 				$Spotter = new Spotter($this->db);
443 443
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
444 444
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
445
-		    		$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' => ''));
446
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
445
+		    		$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' => ''));
446
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
447 447
                         }
448 448
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
449 449
 			$timeelapsed = microtime(true);
@@ -457,35 +457,35 @@  discard block
 block discarded – undo
457 457
 				$Translation->db = null;
458 458
 			    }
459 459
 			    $Spotter->db = null;
460
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
460
+			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
461 461
                     	}
462 462
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
463 463
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
464 464
 			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
465 465
 				//    $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']));
466
-		    		$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']));
466
+		    		$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']));
467 467
 		    	    }
468 468
 			}
469 469
 			if (!isset($globalFork)) $globalFork = TRUE;
470 470
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
471
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
471
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id, trim($line['ident']));
472 472
 			}
473 473
 		    }
474 474
 		}
475 475
 
476 476
 		if (isset($line['speed']) && $line['speed'] != '' && $line['speed'] != 0) {
477 477
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
478
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
479
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
478
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($line['speed'])));
479
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed_fromsrc' => true));
480 480
 		    //$dataFound = true;
481 481
 		} 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'])) {
482
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
482
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm');
483 483
 		    if ($distance > 1000 && $distance < 10000) {
484 484
 		    // use datetime
485 485
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
486 486
 			$speed = $speed*3.6;
487 487
 			if ($speed < 1000) {
488
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
488
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($speed)));
489 489
 	  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
490 490
 	  		} else {
491 491
 	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
@@ -500,9 +500,9 @@  discard block
 block discarded – undo
500 500
 	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
501 501
 	    	    	return false;
502 502
 	    	    }
503
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
503
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time() - $this->all_flights[$id]['time_last_coord']);
504 504
 	    	    else unset($timediff);
505
-	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
505
+	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time() - $this->all_flights[$id]['time_last_archive_coord']);
506 506
 	    	    else unset($timediff_archive);
507 507
 	    	    if ($this->tmd > 5
508 508
 	    	        || (isset($line['format_source']) 
@@ -527,14 +527,14 @@  discard block
 block discarded – undo
527 527
 	    	    	|| ($timediff > 30 
528 528
 	    	    	    && isset($this->all_flights[$id]['latitude']) 
529 529
 	    	    	    && isset($this->all_flights[$id]['longitude']) 
530
-	    	    	    && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
530
+	    	    	    && $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm'))
531 531
 	    	    	    )
532 532
 	    	    	) {
533 533
 
534 534
 			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']))) {
535 535
 			    if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
536 536
 				|| (isset($line['format_source']) && $line['format_source'] == 'airwhere') 
537
-				|| !$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'])) {
537
+				|| !$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'])) {
538 538
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
539 539
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
540 540
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -544,11 +544,11 @@  discard block
 block discarded – undo
544 544
 				    $timeelapsed = microtime(true);
545 545
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
546 546
 					$Spotter = new Spotter($this->db);
547
-					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
547
+					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
548 548
 					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
549 549
 					else $this->all_flights[$id]['over_country'] = '';
550 550
 					$Spotter->db = null;
551
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
551
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
552 552
 					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
553 553
 				    }
554 554
 				}
@@ -574,13 +574,13 @@  discard block
 block discarded – undo
574 574
 					$this->all_flights[$id]['time_last_coord'] = time();
575 575
 				}
576 576
 				//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)) {
577
-				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)) {
577
+				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)) {
578 578
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
579 579
 				    $dataFound = true;
580 580
 				    $this->all_flights[$id]['time_last_coord'] = time();
581 581
 				}
582 582
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
583
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
583
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('latitude' => $line['latitude']));
584 584
 				/*
585 585
 				if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) {
586 586
 				    $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -602,13 +602,13 @@  discard block
 block discarded – undo
602 602
 					$this->all_flights[$id]['time_last_coord'] = time();
603 603
 				}
604 604
 				//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)) {
605
-				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)) {
605
+				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)) {
606 606
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
607 607
 				    $dataFound = true;
608 608
 				    $this->all_flights[$id]['time_last_coord'] = time();
609 609
 				}
610 610
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
611
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
611
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('longitude' => $line['longitude']));
612 612
 				/*
613 613
 				if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) {
614 614
 				    $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
@@ -626,46 +626,46 @@  discard block
 block discarded – undo
626 626
 		    } else if ($globalDebug && $timediff > 30) {
627 627
 			$this->tmd = $this->tmd + 1;
628 628
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
629
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
630
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
629
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')."m -";
630
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
631 631
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
632 632
 		    }
633 633
 		}
634 634
 		if (isset($line['last_update']) && $line['last_update'] != '') {
635 635
 		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
636
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
636
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('last_update' => $line['last_update']));
637 637
 		}
638 638
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
639
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
639
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('verticalrate' => $line['verticalrate']));
640 640
 		    //$dataFound = true;
641 641
 		}
642 642
 		if (isset($line['format_source']) && $line['format_source'] != '') {
643
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
643
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('format_source' => $line['format_source']));
644 644
 		}
645 645
 		if (isset($line['source_name']) && $line['source_name'] != '') {
646
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
646
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_name' => $line['source_name']));
647 647
 		}
648 648
 		if (isset($line['emergency']) && $line['emergency'] != '') {
649
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
649
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('emergency' => $line['emergency']));
650 650
 		    //$dataFound = true;
651 651
 		}
652 652
 		if (isset($line['ground']) && $line['ground'] != '') {
653 653
 		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
654 654
 			// Here we force archive of flight because after ground it's a new one (or should be)
655
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
656
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
657
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')));
658
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
659
-			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']));
655
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
656
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
657
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')));
658
+		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
659
+			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']));
660 660
 		    }
661 661
 		    if ($line['ground'] != 1) $line['ground'] = 0;
662
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
662
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ground' => $line['ground']));
663 663
 		    //$dataFound = true;
664 664
 		}
665 665
 		if (isset($line['squawk']) && $line['squawk'] != '') {
666 666
 		    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'])) {
667 667
 			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
668
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
668
+			    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
669 669
 			    $highlight = '';
670 670
 			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
671 671
 			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
@@ -674,66 +674,66 @@  discard block
 block discarded – undo
674 674
 				$timeelapsed = microtime(true);
675 675
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
676 676
 				    $Spotter = new Spotter($this->db);
677
-				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
677
+				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'], $highlight);
678 678
 				    $Spotter->db = null;
679
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
679
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
680 680
 				}
681 681
 				//$putinarchive = true;
682 682
 				//$highlight = '';
683 683
 			    }
684 684
 			    
685
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
685
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
686 686
 		    //$dataFound = true;
687 687
 		}
688 688
 
689 689
 		if (isset($line['altitude']) && $line['altitude'] != '') {
690 690
 			if (isset($line['altitude_relative']) && isset($GeoidClass) && is_object($GeoidClass)) {
691 691
 				if ($line['altitude_relative'] == 'AMSL' || $line['altitude_relative'] == 'MSL') {
692
-					$geoid = round($GeoidClass->get($this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'])*3.28084,2);
692
+					$geoid = round($GeoidClass->get($this->all_flights[$id]['livedb_latitude'], $this->all_flights[$id]['livedb_longitude'])*3.28084, 2);
693 693
 					//if ($globalDebug) echo '=> Set altitude to WGS84 Ellipsoid, add '.$geoid.' to '.$line['altitude']."\n";
694 694
 					$line['altitude'] = $line['altitude'] - $geoid;
695 695
 				}
696 696
 			}
697 697
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
698
-			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;
699
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
700
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
698
+			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;
699
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude' => round($line['altitude']/100)));
700
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_real' => $line['altitude']));
701 701
 			//$dataFound = true;
702 702
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
703 703
 		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
704 704
 			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) {
705 705
 				if ($globalDebug) echo '--- Reset because of altitude'."\n";
706
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
707
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
708
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')));
709
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
710
-				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']));
706
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
707
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
708
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')));
709
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
710
+				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']));
711 711
 			}
712 712
 		    }
713
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
713
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_previous' => $line['altitude']));
714 714
 		}
715 715
 
716 716
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
717
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
717
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('noarchive' => true));
718 718
 		}
719 719
 		
720 720
 		if (isset($line['heading']) && $line['heading'] != '') {
721
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
722
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
723
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
721
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading'] - round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
722
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($line['heading'])));
723
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading_fromsrc' => true));
724 724
 		    //$dataFound = true;
725 725
   		} 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']) {
726
-  		    $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']);
727
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
728
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
726
+  		    $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']);
727
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($heading)));
728
+		    if (abs($this->all_flights[$id]['heading'] - round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
729 729
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
730 730
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
731 731
   		    // If not enough messages and ACARS set heading to 0
732
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
732
+  		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => 0));
733 733
   		}
734
-		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
735
-		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
736
-		elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalAircraftMinupdate) $dataFound = false;
734
+		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
735
+		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
736
+		elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalAircraftMinupdate) $dataFound = false;
737 737
 
738 738
 //		print_r($this->all_flights[$id]);
739 739
 		//gets the callsign from the last hour
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 		if ($dataFound === true && isset($this->all_flights[$id]['id'])) {
745 745
 		    $this->all_flights[$id]['lastupdate'] = time();
746 746
 		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
747
-		        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'])) {
747
+		        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'])) {
748 748
 			    //print_r($this->all_flights);
749 749
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
750 750
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
@@ -755,61 +755,61 @@  discard block
 block discarded – undo
755 755
 				    $SpotterLive = new SpotterLive($this->db);
756 756
 				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')) {
757 757
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
758
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
758
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
759 759
 				    } elseif (isset($line['id'])) {
760 760
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
761
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
761
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
762 762
 				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
763 763
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
764
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
764
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
765 765
 				    } else $recent_ident = '';
766
-				    $SpotterLive->db=null;
766
+				    $SpotterLive->db = null;
767 767
 				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
768 768
 				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
769 769
 				} else $recent_ident = '';
770 770
 			    } else {
771 771
 				$recent_ident = '';
772
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
772
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 0));
773 773
 			    }
774 774
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
775
-			    if($recent_ident == "")
775
+			    if ($recent_ident == "")
776 776
 			    {
777 777
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
778 778
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
779 779
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
780 780
 				//adds the spotter data for the archive
781 781
 				$ignoreImport = false;
782
-				foreach($globalAirportIgnore as $airportIgnore) {
782
+				foreach ($globalAirportIgnore as $airportIgnore) {
783 783
 				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
784 784
 					$ignoreImport = true;
785 785
 				    }
786 786
 				}
787 787
 				if (count($globalAirportAccept) > 0) {
788 788
 				    $ignoreImport = true;
789
-				    foreach($globalAirportIgnore as $airportIgnore) {
789
+				    foreach ($globalAirportIgnore as $airportIgnore) {
790 790
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
791 791
 					    $ignoreImport = false;
792 792
 					}
793 793
 				    }
794 794
 				}
795 795
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
796
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
797
-					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)) {
796
+				    foreach ($globalAirlineIgnore as $airlineIgnore) {
797
+					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)) {
798 798
 					    $ignoreImport = true;
799 799
 					}
800 800
 				    }
801 801
 				}
802 802
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
803 803
 				    $ignoreImport = true;
804
-				    foreach($globalAirlineAccept as $airlineAccept) {
805
-					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)) {
804
+				    foreach ($globalAirlineAccept as $airlineAccept) {
805
+					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)) {
806 806
 					    $ignoreImport = false;
807 807
 					}
808 808
 				    }
809 809
 				}
810 810
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
811 811
 				    $ignoreImport = true;
812
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
812
+				    foreach ($globalPilotIdAccept as $pilotIdAccept) {
813 813
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
814 814
 					    $ignoreImport = false;
815 815
 					}
@@ -821,32 +821,32 @@  discard block
 block discarded – undo
821 821
 				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
822 822
 				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
823 823
 				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
824
-				    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')));
824
+				    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')));
825 825
 				    $timeelapsed = microtime(true);
826 826
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
827 827
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
828 828
 					    $Spotter = new Spotter($this->db);
829
-					    $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']);
829
+					    $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']);
830 830
 					    $Spotter->db = null;
831 831
 					    if ($globalDebug && isset($result)) echo $result."\n";
832 832
 					}
833 833
 				    }
834
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
834
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
835 835
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
836 836
 
837 837
 				    // Add source stat in DB
838 838
 				    $Stats = new Stats($this->db);
839 839
 				    if (!empty($this->stats)) {
840 840
 					if ($globalDebug) echo 'Add source stats : ';
841
-				        foreach($this->stats as $date => $data) {
842
-					    foreach($data as $source => $sourced) {
841
+				        foreach ($this->stats as $date => $data) {
842
+					    foreach ($data as $source => $sourced) {
843 843
 					        //print_r($sourced);
844
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
845
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
844
+				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar', $date);
845
+				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist', $date);
846 846
 				    		if (isset($sourced['msg'])) {
847 847
 				    		    if (time() - $sourced['msg']['date'] > 10) {
848 848
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
849
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
849
+				    		        echo $Stats->addStatSource($nbmsg, $source, 'msg', $date);
850 850
 			    			        unset($this->stats[$date][$source]['msg']);
851 851
 			    			    }
852 852
 			    			}
@@ -884,14 +884,14 @@  discard block
 block discarded – undo
884 884
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
885 885
 					    $SpotterLive = new SpotterLive($this->db);
886 886
 					    $SpotterLive->deleteLiveSpotterData();
887
-					    $SpotterLive->db=null;
887
+					    $SpotterLive->db = null;
888 888
 					}
889 889
 				    }
890 890
 				    if ($globalDebug) echo " Done\n";
891 891
 				    $this->last_delete = time();
892 892
 				}
893 893
 			    } else {
894
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')) {
894
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')) {
895 895
 				    $this->all_flights[$id]['id'] = $recent_ident;
896 896
 				    $this->all_flights[$id]['addedSpotter'] = 1;
897 897
 				}
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
900 900
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
901 901
 					    $Spotter = new Spotter($this->db);
902
-					    $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']);
902
+					    $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']);
903 903
 					    $Spotter->db = null;
904 904
 					}
905 905
 				    }
@@ -925,37 +925,37 @@  discard block
 block discarded – undo
925 925
 		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
926 926
 		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
927 927
 
928
-		    foreach($globalAirportIgnore as $airportIgnore) {
928
+		    foreach ($globalAirportIgnore as $airportIgnore) {
929 929
 		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
930 930
 			    $ignoreImport = true;
931 931
 			}
932 932
 		    }
933 933
 		    if (count($globalAirportAccept) > 0) {
934 934
 		        $ignoreImport = true;
935
-		        foreach($globalAirportIgnore as $airportIgnore) {
935
+		        foreach ($globalAirportIgnore as $airportIgnore) {
936 936
 			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
937 937
 				$ignoreImport = false;
938 938
 			    }
939 939
 			}
940 940
 		    }
941 941
 		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
942
-			foreach($globalAirlineIgnore as $airlineIgnore) {
943
-			    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)) {
942
+			foreach ($globalAirlineIgnore as $airlineIgnore) {
943
+			    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)) {
944 944
 				$ignoreImport = true;
945 945
 			    }
946 946
 			}
947 947
 		    }
948 948
 		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
949 949
 			$ignoreImport = true;
950
-			foreach($globalAirlineAccept as $airlineAccept) {
951
-			    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)) {
950
+			foreach ($globalAirlineAccept as $airlineAccept) {
951
+			    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)) {
952 952
 				$ignoreImport = false;
953 953
 			    }
954 954
 			}
955 955
 		    }
956 956
 		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
957 957
 			$ignoreImport = true;
958
-			foreach($globalPilotIdAccept as $pilotIdAccept) {
958
+			foreach ($globalPilotIdAccept as $pilotIdAccept) {
959 959
 			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
960 960
 			        $ignoreImport = false;
961 961
 			    }
@@ -963,23 +963,23 @@  discard block
 block discarded – undo
963 963
 		    }
964 964
 
965 965
 		    if (!$ignoreImport) {
966
-			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'])) {
967
-				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')));
966
+			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'])) {
967
+				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')));
968 968
 				$timeelapsed = microtime(true);
969 969
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
970 970
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
971 971
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
972 972
 					$SpotterLive = new SpotterLive($this->db);
973
-					$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']);
973
+					$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']);
974 974
 					$SpotterLive->db = null;
975 975
 					if ($globalDebug) echo $result."\n";
976 976
 				    }
977 977
 				}
978 978
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
979
-					$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']);
979
+					$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']);
980 980
 				}
981 981
 				$this->all_flights[$id]['putinarchive'] = false;
982
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
982
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
983 983
 
984 984
 				// Put statistics in $this->stats variable
985 985
 				//if ($line['format_source'] != 'aprs') {
@@ -998,19 +998,19 @@  discard block
 block discarded – undo
998 998
 							$latitude = $globalCenterLatitude;
999 999
 							$longitude = $globalCenterLongitude;
1000 1000
 						}
1001
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
1001
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
1002 1002
 					} else {
1003 1003
 						$latitude = $this->source_location[$source]['latitude'];
1004 1004
 						$longitude = $this->source_location[$source]['longitude'];
1005 1005
 					}
1006
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
1006
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
1007 1007
 					//$stats_heading = $stats_heading%22.5;
1008 1008
 					$stats_heading = round($stats_heading/22.5);
1009
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
1009
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
1010 1010
 					$current_date = date('Y-m-d');
1011 1011
 					if ($stats_heading == 16) $stats_heading = 0;
1012 1012
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
1013
-						for ($i=0;$i<=15;$i++) {
1013
+						for ($i = 0; $i <= 15; $i++) {
1014 1014
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
1015 1015
 						}
1016 1016
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -1025,9 +1025,9 @@  discard block
 block discarded – undo
1025 1025
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
1026 1026
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1027 1027
 						    end($this->stats[$current_date][$source]['hist']);
1028
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1028
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
1029 1029
 						} else $mini = 0;
1030
-						for ($i=$mini;$i<=$distance;$i+=10) {
1030
+						for ($i = $mini; $i <= $distance; $i += 10) {
1031 1031
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1032 1032
 						}
1033 1033
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -1040,7 +1040,7 @@  discard block
 block discarded – undo
1040 1040
 				$this->all_flights[$id]['lastupdate'] = time();
1041 1041
 				if ($this->all_flights[$id]['putinarchive']) $send = true;
1042 1042
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1043
-			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1043
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n";
1044 1044
 			//$this->del();
1045 1045
 			
1046 1046
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
Please login to merge, or discard this patch.
Braces   +404 added lines, -144 removed lines patch added patch discarded remove patch
@@ -52,7 +52,9 @@  discard block
 block discarded – undo
52 52
 		try {
53 53
 			$GeoidClass = new GeoidHeight();
54 54
 		} catch(Exception $e) {
55
-			if ($globalDebug) echo "Can't calculate geoid, check that you downloaded it via update_db.php (".$e.")\n";
55
+			if ($globalDebug) {
56
+				echo "Can't calculate geoid, check that you downloaded it via update_db.php (".$e.")\n";
57
+			}
56 58
 			$GeoidClass = FALSE;
57 59
 		}
58 60
 	}
@@ -71,7 +73,9 @@  discard block
 block discarded – undo
71 73
 	$dbc = $this->db;
72 74
 	$this->all_flights[$id]['schedule_check'] = true;
73 75
 	if ($globalSchedulesFetch) {
74
-	if ($globalDebug) echo 'Getting schedule info...'."\n";
76
+	if ($globalDebug) {
77
+		echo 'Getting schedule info...'."\n";
78
+	}
75 79
 	$Spotter = new Spotter($dbc);
76 80
 	$Schedule = new Schedule($dbc);
77 81
 	$Translation = new Translation($dbc);
@@ -82,7 +86,9 @@  discard block
 block discarded – undo
82 86
 	    if ($Schedule->checkSchedule($operator) == 0) {
83 87
 		$schedule = $Schedule->fetchSchedule($operator);
84 88
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
85
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
89
+		    if ($globalDebug) {
90
+		    	echo "-> Schedule info for ".$operator." (".$ident.")\n";
91
+		    }
86 92
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
87 93
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
88 94
 		    // Should also check if route schedule = route from DB
@@ -91,7 +97,9 @@  discard block
 block discarded – undo
91 97
 			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
92 98
 			    if (trim($airport_icao) != '') {
93 99
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
94
-				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
100
+				if ($globalDebug) {
101
+					echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
102
+				}
95 103
 			    }
96 104
 			}
97 105
 		    }
@@ -100,20 +108,30 @@  discard block
 block discarded – undo
100 108
 			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
101 109
 			    if (trim($airport_icao) != '') {
102 110
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
103
-				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
111
+				if ($globalDebug) {
112
+					echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
113
+				}
104 114
 			    }
105 115
 			}
106 116
 		    }
107 117
 		    $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 118
 		}
109
-	    } else $scheduleexist = true;
110
-	} else $scheduleexist = true;
119
+	    } else {
120
+	    	$scheduleexist = true;
121
+	    }
122
+	} else {
123
+		$scheduleexist = true;
124
+	}
111 125
 	// close connection, at least one way will work ?
112 126
        if ($scheduleexist) {
113
-		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
127
+		if ($globalDebug) {
128
+			echo "-> get arrival/departure airport info for ".$ident."\n";
129
+		}
114 130
     		$sch = $Schedule->getSchedule($operator);
115 131
 		$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
-		if ($this->all_flights[$id]['addedSpotter'] == 1) $Spotter->updateLatestScheduleSpotterData($this->all_flights[$id]['id'],$sch['departure_airport_icao'],$sch['departure_airport_time'],$sch['arrival_airport_icao'],$sch['arrival_airport_time']);
132
+		if ($this->all_flights[$id]['addedSpotter'] == 1) {
133
+			$Spotter->updateLatestScheduleSpotterData($this->all_flights[$id]['id'],$sch['departure_airport_icao'],$sch['departure_airport_time'],$sch['arrival_airport_icao'],$sch['arrival_airport_time']);
134
+		}
117 135
        }
118 136
 	$Spotter->db = null;
119 137
 	$Schedule->db = null;
@@ -133,14 +151,18 @@  discard block
 block discarded – undo
133 151
 
134 152
     public function checkAll() {
135 153
 	global $globalDebug, $globalNoImport;
136
-	if ($globalDebug) echo "Update last seen flights data...\n";
154
+	if ($globalDebug) {
155
+		echo "Update last seen flights data...\n";
156
+	}
137 157
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
138 158
 	    foreach ($this->all_flights as $key => $flight) {
139 159
 		if (isset($this->all_flights[$key]['id'])) {
140 160
 		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
141 161
     		    $Spotter = new Spotter($this->db);
142 162
         	    $real_arrival = $this->arrival($key);
143
-        	    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']);
163
+        	    if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) {
164
+        	    	$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']);
165
+        	    }
144 166
         	}
145 167
 	    }
146 168
 	}
@@ -148,24 +170,32 @@  discard block
 block discarded – undo
148 170
 
149 171
     public function arrival($key) {
150 172
 	global $globalClosestMinDist, $globalDebug;
151
-	if ($globalDebug) echo 'Update arrival...'."\n";
173
+	if ($globalDebug) {
174
+		echo 'Update arrival...'."\n";
175
+	}
152 176
 	$Spotter = new Spotter($this->db);
153 177
         $airport_icao = '';
154 178
         $airport_time = '';
155
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
179
+        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') {
180
+        	$globalClosestMinDist = 50;
181
+        }
156 182
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
157 183
 	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
158 184
     	    if (isset($closestAirports[0])) {
159 185
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
160 186
         	    $airport_icao = $closestAirports[0]['icao'];
161 187
         	    $airport_time = $this->all_flights[$key]['datetime'];
162
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
188
+        	    if ($globalDebug) {
189
+        	    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
190
+        	    }
163 191
         	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
164 192
         	    foreach ($closestAirports as $airport) {
165 193
         		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
166 194
         		    $airport_icao = $airport['icao'];
167 195
         		    $airport_time = $this->all_flights[$key]['datetime'];
168
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
196
+        		    if ($globalDebug) {
197
+        		    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
198
+        		    }
169 199
         		    break;
170 200
         		}
171 201
         	    }
@@ -173,14 +203,20 @@  discard block
 block discarded – undo
173 203
         		$airport_icao = $closestAirports[0]['icao'];
174 204
         		$airport_time = $this->all_flights[$key]['datetime'];
175 205
         	} else {
176
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
206
+        		if ($globalDebug) {
207
+        			echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
208
+        		}
177 209
         	}
178 210
     	    } else {
179
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
211
+    		    if ($globalDebug) {
212
+    		    	echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
213
+    		    }
180 214
     	    }
181 215
 
182 216
         } else {
183
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
217
+        	if ($globalDebug) {
218
+        		echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
219
+        	}
184 220
         }
185 221
         return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
186 222
     }
@@ -190,7 +226,9 @@  discard block
 block discarded – undo
190 226
     public function del() {
191 227
 	global $globalDebug, $globalNoImport, $globalNoDB;
192 228
 	// Delete old infos
193
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
229
+	if ($globalDebug) {
230
+		echo 'Delete old values and update latest data...'."\n";
231
+	}
194 232
 	foreach ($this->all_flights as $key => $flight) {
195 233
 	    if (isset($flight['lastupdate'])) {
196 234
 		if ($flight['lastupdate'] < (time()-1800)) {
@@ -204,13 +242,17 @@  discard block
 block discarded – undo
204 242
 	global $globalDebug, $globalNoImport, $globalNoDB;
205 243
 	// Delete old infos
206 244
 	if (isset($this->all_flights[$key]['id'])) {
207
-		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
245
+		if ($globalDebug) {
246
+			echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
247
+		}
208 248
 		if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
209 249
 			$real_arrival = $this->arrival($key);
210 250
 			$Spotter = new Spotter($this->db);
211 251
 			if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
212 252
 				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
213
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
253
+				if ($globalDebug && $result != 'success') {
254
+					echo '!!! ERROR : '.$result."\n";
255
+				}
214 256
 			}
215 257
 		}
216 258
 	}
@@ -220,9 +262,13 @@  discard block
 block discarded – undo
220 262
     public function add($line) {
221 263
 	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, $globalArchive;
222 264
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
223
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.01';
224
-	if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') $globalAircraftMaxUpdate = 3000;
225
-/*
265
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
266
+		$globalCoordMinChange = '0.01';
267
+	}
268
+	if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') {
269
+		$globalAircraftMaxUpdate = 3000;
270
+	}
271
+	/*
226 272
 	$Spotter = new Spotter();
227 273
 	$dbc = $Spotter->db;
228 274
 	$SpotterLive = new SpotterLive($dbc);
@@ -244,19 +290,28 @@  discard block
 block discarded – undo
244 290
 	// SBS format is CSV format
245 291
 	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
246 292
 	    //print_r($line);
247
-	    if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
293
+	    if (isset($line['hex'])) {
294
+	    	$line['hex'] = strtoupper($line['hex']);
295
+	    }
248 296
   	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && substr($line['hex'],0,1) != '~' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
249 297
 
250 298
 		// Increment message number
251 299
 		if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) {
252 300
 		    $current_date = date('Y-m-d');
253
-		    if (isset($line['source_name'])) $source = $line['source_name'];
254
-		    else $source = '';
255
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
301
+		    if (isset($line['source_name'])) {
302
+		    	$source = $line['source_name'];
303
+		    } else {
304
+		    	$source = '';
305
+		    }
306
+		    if ($source == '' || $line['format_source'] == 'aprs') {
307
+		    	$source = $line['format_source'];
308
+		    }
256 309
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
257 310
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
258 311
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
259
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
312
+		    } else {
313
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
314
+		    }
260 315
 		}
261 316
 		
262 317
 		/*
@@ -272,23 +327,38 @@  discard block
 block discarded – undo
272 327
 		//$this->db = $dbc;
273 328
 
274 329
 		//$hex = trim($line['hex']);
275
-	        if (!isset($line['id'])) $id = trim($line['hex']);
276
-	        else $id = trim($line['id']);
330
+	        if (!isset($line['id'])) {
331
+	        	$id = trim($line['hex']);
332
+	        } else {
333
+	        	$id = trim($line['id']);
334
+	        }
277 335
 		
278 336
 		if (!isset($this->all_flights[$id])) {
279
-		    if ($globalDebug) echo 'New flight...'."\n";
337
+		    if ($globalDebug) {
338
+		    	echo 'New flight...'."\n";
339
+		    }
280 340
 		    $this->all_flights[$id] = array();
281 341
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
282 342
 		    $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' => ''));
283
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
343
+		    if (isset($globalDaemon) && $globalDaemon === FALSE) {
344
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
345
+		    }
284 346
 		    if (!isset($line['id'])) {
285
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
286
-//			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')));
347
+			if (!isset($globalDaemon)) {
348
+				$globalDaemon = TRUE;
349
+			}
350
+			//			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')));
287 351
 //			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')));
288
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')));
352
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')) {
353
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
354
+			}
289 355
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
290
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
291
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
356
+		     } else {
357
+		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
358
+		     }
359
+		    if ($globalAllFlights !== FALSE) {
360
+		    	$dataFound = true;
361
+		    }
292 362
 		}
293 363
 		if (isset($line['source_type']) && $line['source_type'] != '') {
294 364
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
@@ -310,12 +380,20 @@  discard block
 block discarded – undo
310 380
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
311 381
 			    }
312 382
 			    $Spotter->db = null;
313
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
314
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
383
+			    if ($globalDebugTimeElapsed) {
384
+			    	echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
385
+			    }
386
+			    if ($aircraft_icao != '') {
387
+			    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
388
+			    }
315 389
 			}
316 390
 		    }
317
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
318
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
391
+		    if ($globalAllFlights !== FALSE) {
392
+		    	$dataFound = true;
393
+		    }
394
+		    if ($globalDebug) {
395
+		    	echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
396
+		    }
319 397
 		}
320 398
 	        if (isset($line['id']) && !isset($line['hex'])) {
321 399
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
@@ -324,7 +402,9 @@  discard block
 block discarded – undo
324 402
 			$icao = $line['aircraft_icao'];
325 403
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
326 404
 				$Spotter = new Spotter($this->db);
327
-				if (isset($Spotter->aircraft_correct_icaotype[$icao])) $icao = $Spotter->aircraft_correct_icaotype[$icao];
405
+				if (isset($Spotter->aircraft_correct_icaotype[$icao])) {
406
+					$icao = $Spotter->aircraft_correct_icaotype[$icao];
407
+				}
328 408
 				$Spotter->db = null;
329 409
 			}
330 410
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $icao));
@@ -334,15 +414,24 @@  discard block
 block discarded – undo
334 414
 				$Spotter = new Spotter($this->db);
335 415
 				$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
336 416
 				$Spotter->db = null;
337
-				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
417
+				if ($aircraft_icao != '') {
418
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
419
+				}
338 420
 			}
339 421
 		}
340 422
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
341
-			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
342
-			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
343
-			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
344
-			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
345
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
423
+			if ($line['aircraft_type'] == 'PARA_GLIDER') {
424
+				$aircraft_icao = 'GLID';
425
+			} elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') {
426
+				$aircraft_icao = 'UHEL';
427
+			} elseif ($line['aircraft_type'] == 'TOW_PLANE') {
428
+				$aircraft_icao = 'TOWPLANE';
429
+			} elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') {
430
+				$aircraft_icao = 'POWAIRC';
431
+			}
432
+			if (isset($aircraft_icao)) {
433
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
434
+			}
346 435
 		}
347 436
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
348 437
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
@@ -352,8 +441,11 @@  discard block
 block discarded – undo
352 441
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
353 442
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
354 443
 		    } else {
355
-				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";
356
-				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";
444
+				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
445
+					echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
446
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
447
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
448
+				}
357 449
 				/*
358 450
 				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
359 451
 				print_r($this->all_flights[$id]);
@@ -362,16 +454,22 @@  discard block
 block discarded – undo
362 454
 				return '';
363 455
 		    }
364 456
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
365
-			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
457
+			if ($globalDebug) {
458
+				echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
459
+			}
366 460
 			return '';
367 461
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) {
368
-			if ($globalDebug) echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
462
+			if ($globalDebug) {
463
+				echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
464
+			}
369 465
 			return '';
370 466
 		} elseif (!isset($line['datetime'])) {
371 467
 			date_default_timezone_set('UTC');
372 468
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
373 469
 		} else {
374
-			if ($globalDebug) echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
470
+			if ($globalDebug) {
471
+				echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
472
+			}
375 473
 			return '';
376 474
 		}
377 475
 
@@ -392,30 +490,48 @@  discard block
 block discarded – undo
392 490
 
393 491
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
394 492
 			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
395
-				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
493
+				if ($globalDebug) {
494
+					echo '---!!!! New ident, reset aircraft data...'."\n";
495
+				}
396 496
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
397 497
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
398
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')));
399
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
400
-				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']));
498
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')) {
499
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
500
+				} elseif (isset($line['id'])) {
501
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
502
+				} elseif (isset($this->all_flights[$id]['ident'])) {
503
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
504
+				}
401 505
 			} else {
402 506
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
403 507
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
404 508
 				$timeelapsed = microtime(true);
405 509
             			$Spotter = new Spotter($this->db);
406 510
             			$fromsource = NULL;
407
-            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
408
-            			elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
409
-				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
410
-				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
411
-				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
511
+            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') {
512
+            				$fromsource = $globalAirlinesSource;
513
+            			} elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') {
514
+            				$fromsource = 'vatsim';
515
+            			} elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') {
516
+					$fromsource = 'ivao';
517
+				} elseif (isset($globalVATSIM) && $globalVATSIM) {
518
+					$fromsource = 'vatsim';
519
+				} elseif (isset($globalIVAO) && $globalIVAO) {
520
+					$fromsource = 'ivao';
521
+				}
412 522
             			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
413
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
523
+				if ($globalDebug && $result != 'success') {
524
+					echo '!!! ERROR : '.$result."\n";
525
+				}
414 526
 				$Spotter->db = null;
415
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
527
+				if ($globalDebugTimeElapsed) {
528
+					echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
529
+				}
416 530
 			    }
417 531
 			}
418
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
532
+		    } else {
533
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
534
+		    }
419 535
 		    
420 536
 /*
421 537
 		    if (!isset($line['id'])) {
@@ -425,7 +541,9 @@  discard block
 block discarded – undo
425 541
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
426 542
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
427 543
   */
428
-		    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']));
544
+		    if (!isset($this->all_flights[$id]['id'])) {
545
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
546
+		    }
429 547
 
430 548
 		    //$putinarchive = true;
431 549
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
@@ -443,7 +561,9 @@  discard block
 block discarded – undo
443 561
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
444 562
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
445 563
 		    		$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' => ''));
446
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
564
+				if ($globalDebugTimeElapsed) {
565
+					echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
566
+				}
447 567
                         }
448 568
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
449 569
 			$timeelapsed = microtime(true);
@@ -457,7 +577,9 @@  discard block
 block discarded – undo
457 577
 				$Translation->db = null;
458 578
 			    }
459 579
 			    $Spotter->db = null;
460
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
580
+			    if ($globalDebugTimeElapsed) {
581
+			    	echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
582
+			    }
461 583
                     	}
462 584
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
463 585
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
@@ -466,9 +588,13 @@  discard block
 block discarded – undo
466 588
 		    		$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']));
467 589
 		    	    }
468 590
 			}
469
-			if (!isset($globalFork)) $globalFork = TRUE;
591
+			if (!isset($globalFork)) {
592
+				$globalFork = TRUE;
593
+			}
470 594
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
471
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
595
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) {
596
+					$this->get_Schedule($id,trim($line['ident']));
597
+				}
472 598
 			}
473 599
 		    }
474 600
 		}
@@ -486,9 +612,13 @@  discard block
 block discarded – undo
486 612
 			$speed = $speed*3.6;
487 613
 			if ($speed < 1000) {
488 614
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
489
-	  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
615
+	  			if ($globalDebug) {
616
+	  				echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
617
+	  			}
490 618
 	  		} else {
491
-	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
619
+	  			if ($globalDebug) {
620
+	  				echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
621
+	  			}
492 622
 	  		}
493 623
 		    }
494 624
 		}
@@ -497,13 +627,21 @@  discard block
 block discarded – undo
497 627
 
498 628
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
499 629
 	    	    if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
500
-	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
630
+	    	    	if ($globalDebug) {
631
+	    	    		echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
632
+	    	    	}
501 633
 	    	    	return false;
502 634
 	    	    }
503
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
504
-	    	    else unset($timediff);
505
-	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
506
-	    	    else unset($timediff_archive);
635
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) {
636
+	    	    	$timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
637
+	    	    } else {
638
+	    	    	unset($timediff);
639
+	    	    }
640
+	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) {
641
+	    	    	$timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
642
+	    	    } else {
643
+	    	    	unset($timediff_archive);
644
+	    	    }
507 645
 	    	    if ($this->tmd > 5
508 646
 	    	        || (isset($line['format_source']) 
509 647
 	    	    	    && $line['format_source'] == 'airwhere' 
@@ -540,16 +678,25 @@  discard block
 block discarded – undo
540 678
 				$this->all_flights[$id]['putinarchive'] = true;
541 679
 				$this->tmd = 0;
542 680
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
543
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
681
+				    if ($globalDebug) {
682
+				    	echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
683
+				    }
544 684
 				    $timeelapsed = microtime(true);
545 685
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
546 686
 					$Spotter = new Spotter($this->db);
547 687
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
548
-					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
549
-					else $this->all_flights[$id]['over_country'] = '';
688
+					if (!empty($all_country)) {
689
+						$this->all_flights[$id]['over_country'] = $all_country['iso2'];
690
+					} else {
691
+						$this->all_flights[$id]['over_country'] = '';
692
+					}
550 693
 					$Spotter->db = null;
551
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
552
-					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
694
+					if ($globalDebugTimeElapsed) {
695
+						echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
696
+					}
697
+					if ($globalDebug) {
698
+						echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
699
+					}
553 700
 				    }
554 701
 				}
555 702
 				$this->all_flights[$id]['time_last_archive_coord'] = time();
@@ -595,7 +742,9 @@  discard block
 block discarded – undo
595 742
 			    */
596 743
 			}
597 744
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
598
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
745
+			    if ($line['longitude'] > 180) {
746
+			    	$line['longitude'] = $line['longitude'] - 360;
747
+			    }
599 748
 			    //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) {
600 749
 				if (!isset($this->all_flights[$id]['archive_longitude'])) {
601 750
 					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
@@ -632,7 +781,9 @@  discard block
 block discarded – undo
632 781
 		    }
633 782
 		}
634 783
 		if (isset($line['last_update']) && $line['last_update'] != '') {
635
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
784
+		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) {
785
+		    	$dataFound = true;
786
+		    }
636 787
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
637 788
 		}
638 789
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
@@ -654,35 +805,53 @@  discard block
 block discarded – undo
654 805
 			// Here we force archive of flight because after ground it's a new one (or should be)
655 806
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
656 807
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
657
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')));
658
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
659
-			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']));
808
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')) {
809
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
810
+			} elseif (isset($line['id'])) {
811
+		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
812
+		        } elseif (isset($this->all_flights[$id]['ident'])) {
813
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
814
+			}
815
+		    }
816
+		    if ($line['ground'] != 1) {
817
+		    	$line['ground'] = 0;
660 818
 		    }
661
-		    if ($line['ground'] != 1) $line['ground'] = 0;
662 819
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
663 820
 		    //$dataFound = true;
664 821
 		}
665 822
 		if (isset($line['squawk']) && $line['squawk'] != '') {
666 823
 		    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'])) {
667
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
824
+			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) {
825
+			    	$this->all_flights[$id]['putinarchive'] = true;
826
+			    }
668 827
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
669 828
 			    $highlight = '';
670
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
671
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
672
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
829
+			    if ($this->all_flights[$id]['squawk'] == '7500') {
830
+			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
831
+			    }
832
+			    if ($this->all_flights[$id]['squawk'] == '7600') {
833
+			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
834
+			    }
835
+			    if ($this->all_flights[$id]['squawk'] == '7700') {
836
+			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
837
+			    }
673 838
 			    if ($highlight != '') {
674 839
 				$timeelapsed = microtime(true);
675 840
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
676 841
 				    $Spotter = new Spotter($this->db);
677 842
 				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
678 843
 				    $Spotter->db = null;
679
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
844
+				    if ($globalDebugTimeElapsed) {
845
+				    	echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
846
+				    }
680 847
 				}
681 848
 				//$putinarchive = true;
682 849
 				//$highlight = '';
683 850
 			    }
684 851
 			    
685
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
852
+		    } else {
853
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
854
+		    }
686 855
 		    //$dataFound = true;
687 856
 		}
688 857
 
@@ -695,19 +864,27 @@  discard block
 block discarded – undo
695 864
 				}
696 865
 			}
697 866
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
698
-			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;
867
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) {
868
+				$this->all_flights[$id]['putinarchive'] = true;
869
+			}
699 870
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
700 871
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
701 872
 			//$dataFound = true;
702 873
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
703 874
 		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
704 875
 			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) {
705
-				if ($globalDebug) echo '--- Reset because of altitude'."\n";
876
+				if ($globalDebug) {
877
+					echo '--- Reset because of altitude'."\n";
878
+				}
706 879
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
707 880
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
708
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')));
709
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
710
-				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']));
881
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')) {
882
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
883
+				} elseif (isset($line['id'])) {
884
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
885
+				} elseif (isset($this->all_flights[$id]['ident'])) {
886
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
887
+				}
711 888
 			}
712 889
 		    }
713 890
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
@@ -718,22 +895,32 @@  discard block
 block discarded – undo
718 895
 		}
719 896
 		
720 897
 		if (isset($line['heading']) && $line['heading'] != '') {
721
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
898
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) {
899
+		    	$this->all_flights[$id]['putinarchive'] = true;
900
+		    }
722 901
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
723 902
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
724 903
 		    //$dataFound = true;
725 904
   		} 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']) {
726 905
   		    $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']);
727 906
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
728
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
729
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
907
+		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) {
908
+		    	$this->all_flights[$id]['putinarchive'] = true;
909
+		    }
910
+  		    if ($globalDebug) {
911
+  		    	echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
912
+  		    }
730 913
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
731 914
   		    // If not enough messages and ACARS set heading to 0
732 915
   		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
733 916
   		}
734
-		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
735
-		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
736
-		elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalAircraftMinupdate) $dataFound = false;
917
+		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) {
918
+			$dataFound = false;
919
+		} elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) {
920
+			$dataFound = false;
921
+		} elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalAircraftMinupdate) {
922
+			$dataFound = false;
923
+		}
737 924
 
738 925
 //		print_r($this->all_flights[$id]);
739 926
 		//gets the callsign from the last hour
@@ -750,23 +937,38 @@  discard block
 block discarded – undo
750 937
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
751 938
 			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
752 939
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
753
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
940
+				    if ($globalDebug) {
941
+				    	echo "Check if aircraft is already in DB...";
942
+				    }
754 943
 				    $timeelapsed = microtime(true);
755 944
 				    $SpotterLive = new SpotterLive($this->db);
756 945
 				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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')) {
757 946
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
758
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
947
+					if ($globalDebugTimeElapsed) {
948
+						echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
949
+					}
759 950
 				    } elseif (isset($line['id'])) {
760 951
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
761
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
952
+					if ($globalDebugTimeElapsed) {
953
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
954
+					}
762 955
 				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
763 956
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
764
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
765
-				    } else $recent_ident = '';
957
+					if ($globalDebugTimeElapsed) {
958
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
959
+					}
960
+				    } else {
961
+				    	$recent_ident = '';
962
+				    }
766 963
 				    $SpotterLive->db=null;
767
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
768
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
769
-				} else $recent_ident = '';
964
+				    if ($globalDebug && $recent_ident == '') {
965
+				    	echo " Not in DB.\n";
966
+				    } elseif ($globalDebug && $recent_ident != '') {
967
+				    	echo " Already in DB.\n";
968
+				    }
969
+				} else {
970
+					$recent_ident = '';
971
+				}
770 972
 			    } else {
771 973
 				$recent_ident = '';
772 974
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
@@ -774,7 +976,9 @@  discard block
 block discarded – undo
774 976
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
775 977
 			    if($recent_ident == "")
776 978
 			    {
777
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
979
+				if ($globalDebug) {
980
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
981
+				}
778 982
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
779 983
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
780 984
 				//adds the spotter data for the archive
@@ -818,31 +1022,49 @@  discard block
 block discarded – undo
818 1022
 				
819 1023
 				if (!$ignoreImport) {
820 1024
 				    $highlight = '';
821
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
822
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
823
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
824
-				    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')));
1025
+				    if ($this->all_flights[$id]['squawk'] == '7500') {
1026
+				    	$highlight = 'Squawk 7500 : Hijack';
1027
+				    }
1028
+				    if ($this->all_flights[$id]['squawk'] == '7600') {
1029
+				    	$highlight = 'Squawk 7600 : Lost Comm (radio failure)';
1030
+				    }
1031
+				    if ($this->all_flights[$id]['squawk'] == '7700') {
1032
+				    	$highlight = 'Squawk 7700 : Emergency';
1033
+				    }
1034
+				    if (!isset($this->all_flights[$id]['id'])) {
1035
+				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1036
+				    }
825 1037
 				    $timeelapsed = microtime(true);
826 1038
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
827 1039
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
828 1040
 					    $Spotter = new Spotter($this->db);
829 1041
 					    $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']);
830 1042
 					    $Spotter->db = null;
831
-					    if ($globalDebug && isset($result)) echo $result."\n";
1043
+					    if ($globalDebug && isset($result)) {
1044
+					    	echo $result."\n";
1045
+					    }
832 1046
 					}
833 1047
 				    }
834
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1048
+				    if ($globalDebugTimeElapsed) {
1049
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1050
+				    }
835 1051
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
836 1052
 
837 1053
 				    // Add source stat in DB
838 1054
 				    $Stats = new Stats($this->db);
839 1055
 				    if (!empty($this->stats)) {
840
-					if ($globalDebug) echo 'Add source stats : ';
1056
+					if ($globalDebug) {
1057
+						echo 'Add source stats : ';
1058
+					}
841 1059
 				        foreach($this->stats as $date => $data) {
842 1060
 					    foreach($data as $source => $sourced) {
843 1061
 					        //print_r($sourced);
844
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
845
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
1062
+				    	        if (isset($sourced['polar'])) {
1063
+				    	        	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
1064
+				    	        }
1065
+				    	        if (isset($sourced['hist'])) {
1066
+				    	        	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
1067
+				    	        }
846 1068
 				    		if (isset($sourced['msg'])) {
847 1069
 				    		    if (time() - $sourced['msg']['date'] > 10) {
848 1070
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -855,13 +1077,17 @@  discard block
 block discarded – undo
855 1077
 			    			unset($this->stats[$date]);
856 1078
 			    		    }
857 1079
 				    	}
858
-				    	if ($globalDebug) echo 'Done'."\n";
1080
+				    	if ($globalDebug) {
1081
+				    		echo 'Done'."\n";
1082
+				    	}
859 1083
 
860 1084
 				    }
861 1085
 				    $Stats->db = null;
862 1086
 				    }
863 1087
 				    $this->del();
864
-				} elseif ($globalDebug) echo 'Ignore data'."\n";
1088
+				} elseif ($globalDebug) {
1089
+					echo 'Ignore data'."\n";
1090
+				}
865 1091
 				//$ignoreImport = false;
866 1092
 				$this->all_flights[$id]['addedSpotter'] = 1;
867 1093
 				//print_r($this->all_flights[$id]);
@@ -878,7 +1104,9 @@  discard block
 block discarded – undo
878 1104
 			*/
879 1105
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
880 1106
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
881
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
1107
+				    if ($globalDebug) {
1108
+				    	echo "---- Deleting Live Spotter data older than 9 hours...";
1109
+				    }
882 1110
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
883 1111
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
884 1112
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -887,7 +1115,9 @@  discard block
 block discarded – undo
887 1115
 					    $SpotterLive->db=null;
888 1116
 					}
889 1117
 				    }
890
-				    if ($globalDebug) echo " Done\n";
1118
+				    if ($globalDebug) {
1119
+				    	echo " Done\n";
1120
+				    }
891 1121
 				    $this->last_delete = time();
892 1122
 				}
893 1123
 			    } else {
@@ -914,11 +1144,17 @@  discard block
 block discarded – undo
914 1144
 		    //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";
915 1145
 		    if ($globalDebug) {
916 1146
 			if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
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'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
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'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
1147
+				if (isset($this->all_flights[$id]['source_name'])) {
1148
+					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";
1149
+				} else {
1150
+					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";
1151
+				}
919 1152
 			} else {
920
-				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";
921
-				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";
1153
+				if (isset($this->all_flights[$id]['source_name'])) {
1154
+					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";
1155
+				} else {
1156
+					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";
1157
+				}
922 1158
 			}
923 1159
 		    }
924 1160
 		    $ignoreImport = false;
@@ -964,22 +1200,30 @@  discard block
 block discarded – undo
964 1200
 
965 1201
 		    if (!$ignoreImport) {
966 1202
 			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'])) {
967
-				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')));
1203
+				if (!isset($this->all_flights[$id]['id'])) {
1204
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1205
+				}
968 1206
 				$timeelapsed = microtime(true);
969 1207
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
970 1208
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
971
-					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1209
+					if ($globalDebug) {
1210
+						echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1211
+					}
972 1212
 					$SpotterLive = new SpotterLive($this->db);
973 1213
 					$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']);
974 1214
 					$SpotterLive->db = null;
975
-					if ($globalDebug) echo $result."\n";
1215
+					if ($globalDebug) {
1216
+						echo $result."\n";
1217
+					}
976 1218
 				    }
977 1219
 				}
978 1220
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
979 1221
 					$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']);
980 1222
 				}
981 1223
 				$this->all_flights[$id]['putinarchive'] = false;
982
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1224
+				if ($globalDebugTimeElapsed) {
1225
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1226
+				}
983 1227
 
984 1228
 				// Put statistics in $this->stats variable
985 1229
 				//if ($line['format_source'] != 'aprs') {
@@ -987,7 +1231,9 @@  discard block
 block discarded – undo
987 1231
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
988 1232
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
989 1233
 					$source = $this->all_flights[$id]['source_name'];
990
-					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1234
+					if ($source == '') {
1235
+						$source = $this->all_flights[$id]['format_source'];
1236
+					}
991 1237
 					if (!isset($this->source_location[$source])) {
992 1238
 						$Location = new Source($this->db);
993 1239
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -1008,7 +1254,9 @@  discard block
 block discarded – undo
1008 1254
 					$stats_heading = round($stats_heading/22.5);
1009 1255
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
1010 1256
 					$current_date = date('Y-m-d');
1011
-					if ($stats_heading == 16) $stats_heading = 0;
1257
+					if ($stats_heading == 16) {
1258
+						$stats_heading = 0;
1259
+					}
1012 1260
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
1013 1261
 						for ($i=0;$i<=15;$i++) {
1014 1262
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -1026,7 +1274,9 @@  discard block
 block discarded – undo
1026 1274
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1027 1275
 						    end($this->stats[$current_date][$source]['hist']);
1028 1276
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1029
-						} else $mini = 0;
1277
+						} else {
1278
+							$mini = 0;
1279
+						}
1030 1280
 						for ($i=$mini;$i<=$distance;$i+=10) {
1031 1281
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1032 1282
 						}
@@ -1038,19 +1288,27 @@  discard block
 block discarded – undo
1038 1288
 				}
1039 1289
 
1040 1290
 				$this->all_flights[$id]['lastupdate'] = time();
1041
-				if ($this->all_flights[$id]['putinarchive']) $send = true;
1291
+				if ($this->all_flights[$id]['putinarchive']) {
1292
+					$send = true;
1293
+				}
1042 1294
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1043
-			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1295
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
1296
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1297
+			}
1044 1298
 			//$this->del();
1045 1299
 			
1046 1300
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
1047 1301
 			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1048
-				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1302
+				if ($globalDebug) {
1303
+					echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1304
+				}
1049 1305
 				$SpotterLive = new SpotterLive($this->db);
1050 1306
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
1051 1307
 				$SpotterLive->db = null;
1052 1308
 				//SpotterLive->deleteLiveSpotterData();
1053
-				if ($globalDebug) echo " Done\n";
1309
+				if ($globalDebug) {
1310
+					echo " Done\n";
1311
+				}
1054 1312
 				$this->last_delete_hourly = time();
1055 1313
 			    } else {
1056 1314
 				$this->del();
@@ -1062,7 +1320,9 @@  discard block
 block discarded – undo
1062 1320
 		    //$ignoreImport = false;
1063 1321
 		}
1064 1322
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
1065
-		if ($send) return $this->all_flights[$id];
1323
+		if ($send) {
1324
+			return $this->all_flights[$id];
1325
+		}
1066 1326
 	    }
1067 1327
 	}
1068 1328
     }
Please login to merge, or discard this patch.
require/class.Scheduler.php 2 patches
Spacing   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 	* @param String $arrival_airport_time arrival airport time
37 37
 	/ @param String $source source of data
38 38
 	*/
39
-	public function addSchedule($ident,$departure_airport_icao,$departure_airport_time,$arrival_airport_icao,$arrival_airport_time,$source = 'website') {
39
+	public function addSchedule($ident, $departure_airport_icao, $departure_airport_time, $arrival_airport_icao, $arrival_airport_time, $source = 'website') {
40 40
 		date_default_timezone_set('UTC');
41
-		$date = date("Y-m-d H:i:s",time());
41
+		$date = date("Y-m-d H:i:s", time());
42 42
 		//if ($departure_airport_time == '' && $arrival_airport_time == '') exit;
43 43
 		//$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident";
44 44
 		$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident";
@@ -46,69 +46,69 @@  discard block
 block discarded – undo
46 46
 		 try {
47 47
 			$sth = $this->db->prepare($query);
48 48
 			$sth->execute($query_values);
49
-		} catch(PDOException $e) {
49
+		} catch (PDOException $e) {
50 50
 			return "error : ".$e->getMessage();
51 51
 		}
52 52
 		if ($sth->fetchColumn() > 0) {
53 53
 			if ($departure_airport_time == '' && $arrival_airport_time == '') {
54 54
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao";
55
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao);
55
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao);
56 56
 			} elseif ($arrival_airport_time == '') {
57 57
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao";
58
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao);
58
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao);
59 59
 			} elseif ($departure_airport_time == '') {
60 60
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
61
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
61
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time);
62 62
 			} else {
63 63
 			    //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time";
64 64
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
65
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
65
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time);
66 66
 			}
67 67
 			try {
68 68
 				$sth = $this->db->prepare($query);
69 69
 				$sth->execute($query_values);
70
-			} catch(PDOException $e) {
70
+			} catch (PDOException $e) {
71 71
 				return "error : ".$e->getMessage();
72 72
 			}
73 73
 			if ($sth->fetchColumn() == 0) {
74 74
 				//$query = 'UPDATE schedule SET departure_airport_icao = :departure_airport_icao, departure_airport_time = :departure_airport_time, arrival_airport_icao = :arrival_airport_icao, arrival_airport_time = :arrival_airport_time, date_modified = :date, source = :source WHERE ident = :ident';
75 75
 				if ($departure_airport_time == '' && $arrival_airport_time == '') {
76 76
 					$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
77
-					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
77
+					$query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
78 78
 				} elseif ($arrival_airport_time == '') {
79 79
 					$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
80
-					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
80
+					$query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
81 81
 				} elseif ($departure_airport_time == '') {
82 82
 					$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
83
-					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
83
+					$query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
84 84
 				} else {
85 85
 					$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
86
-					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
86
+					$query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
87 87
 				}
88 88
 				try {
89 89
 					$sth = $this->db->prepare($query);
90 90
 					$sth->execute($query_values);
91
-				} catch(PDOException $e) {
91
+				} catch (PDOException $e) {
92 92
 					return "error : ".$e->getMessage();
93 93
 				}
94 94
 			} else {
95 95
 				//$query = 'UPDATE schedule SET date_lastseen = :date WHERE ident = :ident';
96 96
 				$query = 'UPDATE routes SET date_lastseen = :date WHERE CallSign = :ident';
97
-				$query_values = array(':ident' => $ident,':date' => $date);
97
+				$query_values = array(':ident' => $ident, ':date' => $date);
98 98
 				try {
99 99
 					$sth = $this->db->prepare($query);
100 100
 					$sth->execute($query_values);
101
-				} catch(PDOException $e) {
101
+				} catch (PDOException $e) {
102 102
 					return "error : ".$e->getMessage();
103 103
 				}
104 104
 			}
105 105
 		} else {
106 106
 			$query = 'INSERT INTO  routes (CallSign,FromAirport_ICAO, FromAirport_Time, ToAirport_ICAO, ToAirport_Time,date_added,source)  VALUES (:ident,:departure_airport_icao,:departure_airport_time,:arrival_airport_icao,:arrival_airport_time,:date,:source)';
107
-			$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
107
+			$query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
108 108
 			 try {
109 109
 				$sth = $this->db->prepare($query);
110 110
 				$sth->execute($query_values);
111
-			} catch(PDOException $e) {
111
+			} catch (PDOException $e) {
112 112
 				return "error : ".$e->getMessage();
113 113
 			}
114 114
 		}
@@ -121,10 +121,10 @@  discard block
 block discarded – undo
121 121
 	*/
122 122
 	public function getSchedule($ident) {
123 123
 		$Translation = new Translation($this->db);
124
-		$operator = $Translation->checkTranslation($ident,false);
124
+		$operator = $Translation->checkTranslation($ident, false);
125 125
 		if ($ident != $operator) {
126 126
 			$query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :operator OR CallSign = :ident LIMIT 1";
127
-			$query_values = array(':ident' => $ident,'operator' => $operator);
127
+			$query_values = array(':ident' => $ident, 'operator' => $operator);
128 128
 		} else {
129 129
 			$query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :ident LIMIT 1";
130 130
 			$query_values = array(':ident' => $ident);
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 		 try {
133 133
 			$sth = $this->db->prepare($query);
134 134
 			$sth->execute($query_values);
135
-		} catch(PDOException $e) {
135
+		} catch (PDOException $e) {
136 136
 			return "error : ".$e->getMessage();
137 137
 		}
138 138
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 		 try {
162 162
 			$sth = $this->db->prepare($query);
163 163
 			$sth->execute($query_values);
164
-		} catch(PDOException $e) {
164
+		} catch (PDOException $e) {
165 165
 			return "error : ".$e->getMessage();
166 166
 		}
167 167
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -176,16 +176,16 @@  discard block
 block discarded – undo
176 176
 	* @param String $carrier IATA code
177 177
 	* @return Flight departure and arrival airports and time
178 178
 	*/
179
-	public function getAirFrance($callsign, $date = 'NOW',$carrier = 'AF') {
179
+	public function getAirFrance($callsign, $date = 'NOW', $carrier = 'AF') {
180 180
 		$Common = new Common();
181 181
 		$check_date = new Datetime($date);
182
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
183
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
182
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
183
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
184 184
 		$url = "http://www.airfrance.fr/cgi-bin/AF/FR/fr/local/resainfovol/infovols/detailsVolJson.do?codeCompagnie[0]=".$carrier."&numeroVol[0]=".$numvol."&dayFlightDate=".$check_date->format('d')."&yearMonthFlightDate=".$check_date->format('Ym');
185 185
 		$json = $Common->getData($url);
186 186
 		var_dump($json);
187 187
 		$parsed_json = json_decode($json);
188
-		if (property_exists($parsed_json,'errors') === false) {
188
+		if (property_exists($parsed_json, 'errors') === false) {
189 189
 			//$originLong = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originLong'};
190 190
 			$originShort = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originShort'};
191 191
 			//$departureDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'departureDateMedium'};
@@ -195,9 +195,9 @@  discard block
 block discarded – undo
195 195
 			//$arrivalDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalDateMedium'};
196 196
 			$arrivalTime = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalTime'};
197 197
 
198
-			preg_match('/\((.*?)\)/',$originShort,$originiata);
198
+			preg_match('/\((.*?)\)/', $originShort, $originiata);
199 199
 			$DepartureAirportIata = $originiata[1];
200
-			preg_match('/\((.*?)\)/',$destinationShort,$destinationiata);
200
+			preg_match('/\((.*?)\)/', $destinationShort, $destinationiata);
201 201
 			$ArrivalAirportIata = $destinationiata[1];
202 202
 
203 203
 			/*
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 			$arrivalTime = gmdate('H:i',strtotime($arrivalTime));
207 207
 			*/
208 208
 		
209
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airfrance');
209
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_airfrance');
210 210
 		} else return array();
211 211
 	}
212 212
 
@@ -221,8 +221,8 @@  discard block
 block discarded – undo
221 221
 		$Common = new Common();
222 222
 		date_default_timezone_set($globalTimezone);
223 223
 		$check_date = new Datetime($date);
224
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
225
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
224
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
225
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
226 226
 		$url = "http://www.easyjet.com/ft/api/flights?date=".$check_date->format('Y-m-d')."&fn=".$callsign;
227 227
 		$json = $Common->getData($url);
228 228
 		$parsed_json = json_decode($json);
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 			$departureTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fstd'};
235 235
 			$arrivalTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fsta'};
236 236
 
237
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_easyjet');
237
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_easyjet');
238 238
 		} else return array();
239 239
 	}
240 240
 
@@ -245,12 +245,12 @@  discard block
 block discarded – undo
245 245
 	*/
246 246
 	private function getRyanair($callsign) {
247 247
 		$Common = new Common();
248
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
249
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
248
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
249
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
250 250
 		$url = "http://www.ryanair.com/fr/api/2/flight-info/0/50/";
251 251
 		$post = '{"flight":"'.$numvol.'","minDepartureTime":"00:00","maxDepartureTime":"23:59"}';
252
-		$headers = array('Content-Type: application/json','Content-Length: ' . strlen($post));
253
-		$json = $Common->getData($url,'post',$post,$headers);
252
+		$headers = array('Content-Type: application/json', 'Content-Length: '.strlen($post));
253
+		$json = $Common->getData($url, 'post', $post, $headers);
254 254
 		$parsed_json = json_decode($json);
255 255
 		if (isset($parsed_json->{'flightInfo'})) {
256 256
 			$flights = $parsed_json->{'flightInfo'};
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 				$ArrivalAirportIata = $parsed_json->{'flightInfo'}[0]->{'arrivalAirport'}->{'iata'}; //name
260 260
 				$departureTime = $parsed_json->{'flightInfo'}[0]->{'departureTime'};
261 261
 				$arrivalTime = $parsed_json->{'flightInfo'}[0]->{'arrivalTime'};
262
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair');
262
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair');
263 263
 			} else return array();
264 264
 		} else return array();
265 265
 	}
@@ -271,8 +271,8 @@  discard block
 block discarded – undo
271 271
 	*/
272 272
 	private function getSwiss($callsign) {
273 273
 		$Common = new Common();
274
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
275
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
274
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
275
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
276 276
 		$url = "http://www.world-of-swiss.com/fr/routenetwork.json";
277 277
 		$json = $Common->getData($url);
278 278
 		$parsed_json = json_decode($json);
@@ -286,12 +286,12 @@  discard block
 block discarded – undo
286 286
 				if ($flight->{'no'} == "Vol LX ".$numvol) {
287 287
 					$DepartureAirportIata = $flight->{'from'}->{'code'}; //city
288 288
 					$ArrivalAirportIata = $flight->{'to'}->{'code'}; //city
289
-					$departureTime = substr($flight->{'from'}->{'hour'},0,5);
290
-					$arrivalTime = substr($flight->{'to'}->{'hour'},0,5);
289
+					$departureTime = substr($flight->{'from'}->{'hour'},0, 5);
290
+					$arrivalTime = substr($flight->{'to'}->{'hour'},0, 5);
291 291
 				}
292 292
 			}
293 293
 			if (isset($DepartureAirportIata) && isset($ArrivalAirportIata)) {
294
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_swiss');
294
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_swiss');
295 295
 			} else return array();
296 296
 		} else return array();
297 297
 	}
@@ -306,21 +306,21 @@  discard block
 block discarded – undo
306 306
 		global $globalBritishAirwaysKey;
307 307
 		$Common = new Common();
308 308
 		$check_date = new Datetime($date);
309
-		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
310
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
309
+		$numvol = sprintf('%04d', preg_replace('/^[A-Z]*/', '', $callsign));
310
+		if (!filter_var(preg_replace('/^[A-Z]*/', '', $callsign), FILTER_VALIDATE_INT)) return array();
311 311
 		if ($globalBritishAirwaysKey == '') return array();
312 312
 		$url = "https://api.ba.com/rest-v1/v1/flights;flightNumber=".$numvol.";scheduledDepartureDate=".$check_date->format('Y-m-d').".json";
313 313
 		$headers = array('Client-Key: '.$globalBritishAirwaysKey);
314
-		$json = $Common->getData($url,'get','',$headers);
314
+		$json = $Common->getData($url, 'get', '', $headers);
315 315
 		if ($json == '') return array();
316 316
 		$parsed_json = json_decode($json);
317 317
 		$flights = $parsed_json->{'FlightsResponse'};
318 318
 		if (count($flights) > 0) {
319 319
 			$DepartureAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'DepartureAirport'};
320 320
 			$ArrivalAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ArrivalAirport'};
321
-			$departureTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'}));
322
-			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'}));
323
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_britishairways');
321
+			$departureTime = date('H:i', strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'}));
322
+			$arrivalTime = date('H:i', strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'}));
323
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_britishairways');
324 324
 		} else return array();
325 325
 	}
326 326
 
@@ -334,27 +334,27 @@  discard block
 block discarded – undo
334 334
 		global $globalLufthansaKey;
335 335
 		$Common = new Common();
336 336
 		$check_date = new Datetime($date);
337
-		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
338
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
337
+		$numvol = sprintf('%04d', preg_replace('/^[A-Z]*/', '', $callsign));
338
+		if (!filter_var(preg_replace('/^[A-Z]*/', '', $callsign), FILTER_VALIDATE_INT)) return array();
339 339
 		if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') return array();
340 340
 		$url = "https://api.lufthansa.com/v1/oauth/token";
341
-		$post = array('client_id' => $globalLufthansaKey['key'],'client_secret' => $globalLufthansaKey['secret'],'grant_type' => 'client_credentials');
342
-		$data = $Common->getData($url,'post',$post);
341
+		$post = array('client_id' => $globalLufthansaKey['key'], 'client_secret' => $globalLufthansaKey['secret'], 'grant_type' => 'client_credentials');
342
+		$data = $Common->getData($url, 'post', $post);
343 343
 		$parsed_data = json_decode($data);
344 344
 		if (!isset($parsed_data->{'access_token'})) return array();
345 345
 		$token = $parsed_data->{'access_token'};
346 346
 		
347 347
 		$url = "https://api.lufthansa.com/v1/operations/flightstatus/LH".$numvol."/".$check_date->format('Y-m-d');
348
-		$headers = array('Authorization: Bearer '.$token,'Accept: application/json');
349
-		$json = $Common->getData($url,'get','',$headers);
348
+		$headers = array('Authorization: Bearer '.$token, 'Accept: application/json');
349
+		$json = $Common->getData($url, 'get', '', $headers);
350 350
 		if ($json == '') return array();
351 351
 		$parsed_json = json_decode($json);
352 352
 		if (isset($parsed_json->{'FlightStatusResource'}) && count($parsed_json->{'FlightStatusResource'}) > 0) {
353 353
 			$DepartureAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'AirportCode'};
354
-			$departureTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'ScheduledTimeLocal'}->{'DateTime'}));
354
+			$departureTime = date('H:i', strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'ScheduledTimeLocal'}->{'DateTime'}));
355 355
 			$ArrivalAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'AirportCode'};
356
-			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'}));
357
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa');
356
+			$arrivalTime = date('H:i', strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'}));
357
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_lufthansa');
358 358
 		} else return array();
359 359
 	}
360 360
 
@@ -368,23 +368,23 @@  discard block
 block discarded – undo
368 368
 		global $globalTransaviaKey;
369 369
 		$Common = new Common();
370 370
 		$check_date = new Datetime($date);
371
-		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
372
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
371
+		$numvol = sprintf('%04d', preg_replace('/^[A-Z]*/', '', $callsign));
372
+		if (!filter_var(preg_replace('/^[A-Z]*/', '', $callsign), FILTER_VALIDATE_INT)) return array();
373 373
 		if ($globalTransaviaKey == '') return array();
374 374
 		$url = "https://tst.api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
375 375
 		//$url = "https://api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
376 376
 		$headers = array('apikey: '.$globalTransaviaKey);
377
-		$json = $Common->getData($url,'get','',$headers);
377
+		$json = $Common->getData($url, 'get', '', $headers);
378 378
 		//echo 'result : '.$json;
379 379
 		if ($json == '') return array();
380 380
 		$parsed_json = json_decode($json);
381 381
 		
382 382
 		if (isset($parsed_json->{'data'}[0])) {
383 383
 			$DepartureAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'departureAirport'}->{'locationCode'};
384
-			$departureTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'departureDateTime'}));
384
+			$departureTime = date('H:i', strtotime($parsed_json->{'data'}[0]->{'flight'}->{'departureDateTime'}));
385 385
 			$ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'};
386
-			$arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'}));
387
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia');
386
+			$arrivalTime = date('H:i', strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'}));
387
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_transavia');
388 388
 		} else return array();
389 389
 	}
390 390
 
@@ -395,14 +395,14 @@  discard block
 block discarded – undo
395 395
 	*/
396 396
 	public function getTunisair($callsign) {
397 397
 		$Common = new Common();
398
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
399
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
398
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
399
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
400 400
 		$url = "http://www.tunisair.com/site/publish/module/Volj/fr/Flight_List.asp";
401 401
 		$data = $Common->getData($url);
402 402
 		$table = $Common->table2array($data);
403 403
 		foreach ($table as $flight) {
404
-			if (isset($flight[1]) && $flight[1] == "TU ".sprintf('%04d',$numvol)) {
405
-				return array('DepartureAirportIATA' => $flight[2],'DepartureTime' => str_replace('.',':',$flight[5]),'ArrivalAirportIATA' => $flight[3],'ArrivalTime' => str_replace('.',':',$flight[6]),'Source' => 'website_tunisair');
404
+			if (isset($flight[1]) && $flight[1] == "TU ".sprintf('%04d', $numvol)) {
405
+				return array('DepartureAirportIATA' => $flight[2], 'DepartureTime' => str_replace('.', ':', $flight[5]), 'ArrivalAirportIATA' => $flight[3], 'ArrivalTime' => str_replace('.', ':', $flight[6]), 'Source' => 'website_tunisair');
406 406
 			}
407 407
 		}
408 408
 		return array();
@@ -413,21 +413,21 @@  discard block
 block discarded – undo
413 413
 	* @param String $callsign The callsign
414 414
 	* @return Flight departure and arrival airports and time
415 415
 	*/
416
-	public function getVueling($callsign,$date = 'NOW') {
416
+	public function getVueling($callsign, $date = 'NOW') {
417 417
 		$Common = new Common();
418 418
 		$check_date = new Datetime($date);
419
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
420
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
421
-		$final_date = str_replace('/','%2F',$check_date->format('d/m/Y'));
419
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
420
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
421
+		$final_date = str_replace('/', '%2F', $check_date->format('d/m/Y'));
422 422
 		$url = "http://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=FlightStatusResult&searchBy=bycode&date=".$final_date."&flightNumber=".$numvol."&idioma=en-GB";
423 423
 		$data = $Common->getData($url);
424
-		$data=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$data));
424
+		$data = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $data));
425 425
 		if ($data != '') {
426
-			preg_match('/flightOri=[A-Z]{3}/',$data,$result);
427
-			$DepartureAirportIata = str_replace('flightOri=','',$result[0]);
428
-			preg_match('/flightDest=[A-Z]{3}/',$data,$result);
429
-			$ArrivalAirportIata = str_replace('flightDest=','',$result[0]);
430
-			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling');
426
+			preg_match('/flightOri=[A-Z]{3}/', $data, $result);
427
+			$DepartureAirportIata = str_replace('flightOri=', '', $result[0]);
428
+			preg_match('/flightDest=[A-Z]{3}/', $data, $result);
429
+			$ArrivalAirportIata = str_replace('flightDest=', '', $result[0]);
430
+			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'Source' => 'website_vueling');
431 431
 			else return array();
432 432
 		}
433 433
 		return array();
@@ -441,27 +441,27 @@  discard block
 block discarded – undo
441 441
 	*/
442 442
 	public function getIberia($callsign, $date = 'NOW') {
443 443
 		$Common = new Common();
444
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
444
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
445 445
 		$check_date = new Datetime($date);
446
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
446
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
447 447
 		$url = "https://www.iberia.com/web/flightDetail.do";
448
-		$post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB');
449
-		$data = $Common->getData($url,'post',$post);
448
+		$post = array('numvuelo' => $numvol, 'fecha' => $check_date->format('Ymd'), 'airlineID' => 'IB');
449
+		$data = $Common->getData($url, 'post', $post);
450 450
 		if ($data != '') {
451 451
 			$table = $Common->table2array($data);
452 452
 			//print_r($table);
453 453
 			if (count($table) > 0) {
454 454
 				$flight = $table;
455
-				preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch);
456
-				preg_match('/([A-Z]{3})/',$flight[5][0],$ArrivalAirportIataMatch);
455
+				preg_match('/([A-Z]{3})/', $flight[3][0], $DepartureAirportIataMatch);
456
+				preg_match('/([A-Z]{3})/', $flight[5][0], $ArrivalAirportIataMatch);
457 457
 				$DepartureAirportIata = $DepartureAirportIataMatch[0];
458 458
 				$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
459
-				$departureTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[3][2]))),0,5);
460
-				$arrivalTime = trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][1])));
459
+				$departureTime = substr(trim(str_replace(' lunes', '', str_replace('&nbsp;', '', $flight[3][2]))), 0, 5);
460
+				$arrivalTime = trim(str_replace(' lunes', '', str_replace('&nbsp;', '', $flight[5][1])));
461 461
 				if ($arrivalTime == 'Hora estimada de llegada') {
462
-					$arrivalTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][2]))),0,5);
463
-				} else $arrivalTime = substr($arrivalTime,0,5);
464
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia');
462
+					$arrivalTime = substr(trim(str_replace(' lunes', '', str_replace('&nbsp;', '', $flight[5][2]))), 0, 5);
463
+				} else $arrivalTime = substr($arrivalTime, 0, 5);
464
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_iberia');
465 465
 			}
466 466
 		}
467 467
 		return array();
@@ -474,11 +474,11 @@  discard block
 block discarded – undo
474 474
 	* @return Flight departure and arrival airports and time
475 475
 	*/
476 476
 
477
-	private function getStarAlliance($callsign, $date = 'NOW',$carrier = '') {
477
+	private function getStarAlliance($callsign, $date = 'NOW', $carrier = '') {
478 478
 		$Common = new Common();
479
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
479
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
480 480
 		$check_date = new Datetime($date);
481
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
481
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
482 482
 		$url = "http://www.staralliance.com/flifoQueryAction.do?myAirline=&airlineCode=".$carrier."&flightNo=".$numvol."&day=".$check_date->format('d')."&month=".$check_date->format('m')."&year=".$check_date->format('Y')."&departuredate=".$check_date->format('d-M-Y');
483 483
 		$data = $Common->getData($url);
484 484
 		if ($data != '') {
@@ -487,13 +487,13 @@  discard block
 block discarded – undo
487 487
 				$flight = $table;
488 488
 				//print_r($table);
489 489
 				if (isset($flight[25]) && isset($flight[29])) {
490
-					preg_match('/([A-Z]{3})/',$flight[25][1],$DepartureAirportIataMatch);
491
-					preg_match('/([A-Z]{3})/',$flight[25][3],$ArrivalAirportIataMatch);
490
+					preg_match('/([A-Z]{3})/', $flight[25][1], $DepartureAirportIataMatch);
491
+					preg_match('/([A-Z]{3})/', $flight[25][3], $ArrivalAirportIataMatch);
492 492
 					$DepartureAirportIata = $DepartureAirportIataMatch[0];
493 493
 					$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
494
-					$departureTime = substr(trim(str_replace('Scheduled: ','',$flight[29][0])),0,5);
495
-					$arrivalTime = substr(trim(str_replace('Scheduled: ','',$flight[29][1])),0,5);
496
-					return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_staralliance');
494
+					$departureTime = substr(trim(str_replace('Scheduled: ', '', $flight[29][0])), 0, 5);
495
+					$arrivalTime = substr(trim(str_replace('Scheduled: ', '', $flight[29][1])), 0, 5);
496
+					return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_staralliance');
497 497
 				} else return array();
498 498
 			}
499 499
 			
@@ -511,10 +511,10 @@  discard block
 block discarded – undo
511 511
 	*/
512 512
 	private function getAlitalia($callsign, $date = 'NOW') {
513 513
 		$Common = new Common();
514
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
514
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
515 515
 		$check_date = new Datetime($date);
516
-		$url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y');
517
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
516
+		$url = "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y');
517
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
518 518
 		$data = $Common->getData($url);
519 519
 		if ($data != '') {
520 520
 			$table = $Common->text2array($data);
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
 			$ArrivalAirportIata = '';
523 523
 			$departureTime = $table[4];
524 524
 			$arrivalTime = $table[5];
525
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_alitalia');
525
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_alitalia');
526 526
 		}
527 527
 	}
528 528
 
@@ -534,21 +534,21 @@  discard block
 block discarded – undo
534 534
 	*/
535 535
 	private function getBrussels($callsign, $date = 'NOW') {
536 536
 		$Common = new Common();
537
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
537
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
538 538
 		$check_date = new Datetime($date);
539
-		$url= "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302";
539
+		$url = "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302";
540 540
 		//http://www.brusselsairlines.com/fr-fr/informations-pratiques/statut-de-votre-vol/resultat.aspx?flightnumber=".$numvol."&date=".$check_date->format('d/m/Y')."&lookup=flightnumber";
541
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
541
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
542 542
 		$data = $Common->getData($url);
543 543
 		if ($data != '') {
544 544
 		    //echo $data;
545
-		    $parsed_json = json_decode($data,true);
545
+		    $parsed_json = json_decode($data, true);
546 546
 		    if (isset($parsed_json[0]['FromAirportCode'])) {
547 547
 			$DepartureAirportIata = $parsed_json[0]['FromAirportCode'];
548 548
 			$ArrivalAirportIata = $parsed_json[0]['ToAirportCode'];
549
-			$departureTime = date('H:i',strtotime($parsed_json[0]['ScheduledDepatureDate']));
550
-			$arrivalTime = date('H:i',strtotime($parsed_json[0]['ScheduledArrivalDate']));
551
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_brussels');
549
+			$departureTime = date('H:i', strtotime($parsed_json[0]['ScheduledDepatureDate']));
550
+			$arrivalTime = date('H:i', strtotime($parsed_json[0]['ScheduledArrivalDate']));
551
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_brussels');
552 552
 		    }
553 553
 		}
554 554
 	}
@@ -625,21 +625,21 @@  discard block
 block discarded – undo
625 625
 	*/
626 626
 	private function getFlyTap($callsign) {
627 627
 		$Common = new Common();
628
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
629
-		$url= "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees";
628
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
629
+		$url = "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees";
630 630
 		//$check_date = new Datetime($date);
631
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
632
-		$post = array('arrivalsdepartures_content' => 'number','arrivalsdepartures_tp' => $numvol,'arrivalsdepartures_trk' => 'ARR','arrivalsdepartures_date_trk' => '1','aptCode' => '','arrivalsdepartures' => 'DEP','arrivalsdepartures_date' => '1','aptCodeFrom' => '','aptCodeTo' => '','arrivalsdepartures2' => 'DEP','arrivalsdepartures_date2' => '1');
633
-		$data = $Common->getData($url,'post',$post);
631
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
632
+		$post = array('arrivalsdepartures_content' => 'number', 'arrivalsdepartures_tp' => $numvol, 'arrivalsdepartures_trk' => 'ARR', 'arrivalsdepartures_date_trk' => '1', 'aptCode' => '', 'arrivalsdepartures' => 'DEP', 'arrivalsdepartures_date' => '1', 'aptCodeFrom' => '', 'aptCodeTo' => '', 'arrivalsdepartures2' => 'DEP', 'arrivalsdepartures_date2' => '1');
633
+		$data = $Common->getData($url, 'post', $post);
634 634
 		if ($data != '') {
635 635
 			$table = $Common->table2array($data);
636
-			$departureTime = trim(substr($table[15][0],0,5));
637
-			$arrivalTime = trim(substr($table[35][0],0,5));
638
-			preg_match('/([A-Z]{3})/',$table[11][0],$DepartureAirportIataMatch);
639
-			preg_match('/([A-Z]{3})/',$table[31][0],$ArrivalAirportIataMatch);
636
+			$departureTime = trim(substr($table[15][0], 0, 5));
637
+			$arrivalTime = trim(substr($table[35][0], 0, 5));
638
+			preg_match('/([A-Z]{3})/', $table[11][0], $DepartureAirportIataMatch);
639
+			preg_match('/([A-Z]{3})/', $table[31][0], $ArrivalAirportIataMatch);
640 640
 			$DepartureAirportIata = $DepartureAirportIataMatch[0];
641 641
 			$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
642
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flytap');
642
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_flytap');
643 643
 		}
644 644
 		return array();
645 645
 	}
@@ -661,10 +661,10 @@  discard block
 block discarded – undo
661 661
 			} 
662 662
 		}
663 663
 		if ($airline_icao == '') return array();
664
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
665
-		$url= "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol;
664
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
665
+		$url = "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol;
666 666
 		//$check_date = new Datetime($date);
667
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
667
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
668 668
 		$data = $Common->getData($url);
669 669
 		if ($data != '') {
670 670
 			$table = $Common->table2array($data);
@@ -674,13 +674,13 @@  discard block
 block discarded – undo
674 674
 				$darr = '';
675 675
 				$ahour = '';
676 676
 				$aarr = '';
677
-				$n = sscanf($sched,'%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])',$dhour,$darr,$ahour,$aarr);
677
+				$n = sscanf($sched, '%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])', $dhour, $darr, $ahour, $aarr);
678 678
 				if ($n == 7) {
679 679
 				    $departureTime = $dhour;
680 680
 				    $arrivalTime = $ahour;
681
-				    $DepartureAirportIata = str_replace(array('(',')'),'',$darr);
682
-				    $ArrivalAirportIata = str_replace(array('(',')'),'',$aarr);
683
-				    return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper');
681
+				    $DepartureAirportIata = str_replace(array('(', ')'), '', $darr);
682
+				    $ArrivalAirportIata = str_replace(array('(', ')'), '', $aarr);
683
+				    return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_flightmapper');
684 684
 				}
685 685
 			}
686 686
 		}
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
 			$url = 'http://'.$globalFlightAwareUsername.':'.$globalFlightAwarePassword.'@flightxml.flightaware.com/json/FlightXML3/FlightInfoStatus?ident='.$callsign;
713 713
 			$data = $Common->getData($url);
714 714
 			if ($data != '') {
715
-				$result = json_decode($data,true);
715
+				$result = json_decode($data, true);
716 716
 				$flight = $result['FlightInfoStatusResult']['flights'][0];
717 717
 				if (isset($flight['origin'])) {
718 718
 					return array(
@@ -725,18 +725,18 @@  discard block
 block discarded – undo
725 725
 			}
726 726
 		}
727 727
 		
728
-		$url= "http://flightaware.com/live/flight/".$callsign;
728
+		$url = "http://flightaware.com/live/flight/".$callsign;
729 729
 		$data = $Common->getData($url);
730 730
 		if ($data != '') {
731
-			preg_match(':<script>var trackpollBootstrap = (.*?);</script>:',$data,$result);
732
-			$flights = json_decode($result[1],true);
731
+			preg_match(':<script>var trackpollBootstrap = (.*?);</script>:', $data, $result);
732
+			$flights = json_decode($result[1], true);
733 733
 			$flight = reset($flights['flights']);
734 734
 			if (isset($flight['activityLog']['flights'][0]['origin'])) {
735 735
 				return array(
736 736
 				    'DepartureAirportIATA' => $flight['activityLog']['flights'][0]['origin']['iata'],
737
-				    'DepartureTime' => date('H:i',$flight['activityLog']['flights'][0]['takeoffTimes']['scheduled']),
737
+				    'DepartureTime' => date('H:i', $flight['activityLog']['flights'][0]['takeoffTimes']['scheduled']),
738 738
 				    'ArrivalAirportIATA' => $flight['activityLog']['flights'][0]['destination']['iata'],
739
-				    'ArrivalTime' => date('H:i',$flight['activityLog']['flights'][0]['landingTimes']['scheduled']),
739
+				    'ArrivalTime' => date('H:i', $flight['activityLog']['flights'][0]['landingTimes']['scheduled']),
740 740
 				    'Source' => 'website_flightaware');
741 741
 			}
742 742
 		}
@@ -750,20 +750,20 @@  discard block
 block discarded – undo
750 750
 	*/
751 751
 	public function getCostToTravel($callsign) {
752 752
 		$Common = new Common();
753
-		$url= "http://www.costtotravel.com/flight-number/".$callsign;
753
+		$url = "http://www.costtotravel.com/flight-number/".$callsign;
754 754
 		//$check_date = new Datetime($date);
755 755
 		//if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
756 756
 		$data = $Common->getData($url);
757 757
 		if ($data != '') {
758 758
 			$table = $Common->table2array($data);
759 759
 			if (isset($table[11][1])) {
760
-				if (is_numeric(substr($table[11][1],0,1))) $departureTime = substr($table[11][1],0,5);
760
+				if (is_numeric(substr($table[11][1], 0, 1))) $departureTime = substr($table[11][1], 0, 5);
761 761
 				else $departureTime = '';
762
-				if (is_numeric(substr($table[17][1],0,1))) $arrivalTime = substr($table[17][1],0,5);
762
+				if (is_numeric(substr($table[17][1], 0, 1))) $arrivalTime = substr($table[17][1], 0, 5);
763 763
 				else $arrivalTime = '';
764
-				$DepartureAirportIata = substr($table[13][1],0,3);
765
-				$ArrivalAirportIata = substr($table[15][1],0,3);
766
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_costtotravel');
764
+				$DepartureAirportIata = substr($table[13][1], 0, 3);
765
+				$ArrivalAirportIata = substr($table[15][1], 0, 3);
766
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_costtotravel');
767 767
 			}
768 768
 		}
769 769
 		return array();
@@ -775,14 +775,14 @@  discard block
 block discarded – undo
775 775
 	* @param String $date date we want flight number info
776 776
 	* @return Flight departure and arrival airports and time
777 777
 	*/
778
-	private function getAirCanada($callsign,$date = 'NOW') {
778
+	private function getAirCanada($callsign, $date = 'NOW') {
779 779
 		$Common = new Common();
780 780
 		if (class_exists("DomDocument") === FALSE) return array();
781 781
 		date_default_timezone_set('UTC');
782 782
 		$check_date = new Datetime($date);
783
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
784
-		$url= "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249";
785
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
783
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
784
+		$url = "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249";
785
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
786 786
 		$data = $Common->getData($url);
787 787
 		$dom = new DomDocument();
788 788
 		$dom->loadXML($data);
@@ -790,11 +790,11 @@  discard block
 block discarded – undo
790 790
 		$departure = $dom->getElementsByTagName('DepartureStationInfo')->item(0);
791 791
 		if (isset($departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue)) {
792 792
 			$DepartureAirportIata = $departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
793
-			$departureTime = date('H:i',strtotime($departure->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
793
+			$departureTime = date('H:i', strtotime($departure->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
794 794
 			$arrival = $dom->getElementsByTagName('ArrivalStationInfo')->item(0);
795 795
 			$ArrivalAirportIata = $arrival->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
796
-			$arrivalTime = date('H:i',strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
797
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_aircanada');
796
+			$arrivalTime = date('H:i', strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
797
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_aircanada');
798 798
 		} else return array();
799 799
 	}
800 800
 
@@ -806,21 +806,21 @@  discard block
 block discarded – undo
806 806
 	*/
807 807
 	private function getVietnamAirlines($callsign, $date = 'NOW') {
808 808
 		$Common = new Common();
809
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
809
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
810 810
 		$check_date = new Datetime($date);
811
-		$url= "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&";
812
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
811
+		$url = "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&";
812
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
813 813
 		$data = $Common->getData($url);
814 814
 		if ($data != '') {
815 815
 			$table = $Common->table2array($data);
816 816
 			$flight = $table;
817
-			preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch);
818
-			preg_match('/([A-Z]{3})/',$flight[21][0],$ArrivalAirportIataMatch);
817
+			preg_match('/([A-Z]{3})/', $flight[3][0], $DepartureAirportIataMatch);
818
+			preg_match('/([A-Z]{3})/', $flight[21][0], $ArrivalAirportIataMatch);
819 819
 			$DepartureAirportIata = $DepartureAirportIataMatch[0];
820 820
 			$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
821 821
 			$departureTime = $flight[5][1];
822 822
 			$arrivalTime = $flight[23][1];
823
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_vietnamairlines');
823
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_vietnamairlines');
824 824
 		}
825 825
 	}
826 826
 
@@ -831,16 +831,16 @@  discard block
 block discarded – undo
831 831
 	* @param String $carrier airline code
832 832
 	* @return Flight departure and arrival airports and time
833 833
 	*/
834
-	private function getAirBerlin($callsign, $date = 'NOW',$carrier = 'AB') {
834
+	private function getAirBerlin($callsign, $date = 'NOW', $carrier = 'AB') {
835 835
 		$Common = new Common();
836 836
 		date_default_timezone_set('UTC');
837 837
 		//AB = airberlin, HG/NLY = NIKI, 4T/BHP = Belair 
838
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
838
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
839 839
 		$check_date = new Datetime($date);
840
-		$url= "http://www.airberlin.com/en-US/site/aims.php";
841
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
842
-		$post = array('type' => 'departure','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => $carrier);
843
-		$data = $Common->getData($url,'post',$post);
840
+		$url = "http://www.airberlin.com/en-US/site/aims.php";
841
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
842
+		$post = array('type' => 'departure', 'searchFlightNo' => '1', 'requestsent' => 'true', 'flightno' => $numvol, 'date' => $check_date->format('Y-m-d'), 'carrier' => $carrier);
843
+		$data = $Common->getData($url, 'post', $post);
844 844
 		//echo $data;
845 845
 		$DepartureAirportIata = '';
846 846
 		$ArrivalAirportIata = '';
@@ -853,8 +853,8 @@  discard block
 block discarded – undo
853 853
 			if (isset($flight[5][2])) $departureAirport = $flight[5][2];
854 854
 			else $departureAirport = '';
855 855
 		} else return array();
856
-		$post = array('type' => 'arrival','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB');
857
-		$data = $Common->getData($url,'post',$post);
856
+		$post = array('type' => 'arrival', 'searchFlightNo' => '1', 'requestsent' => 'true', 'flightno' => $numvol, 'date' => $check_date->format('Y-m-d'), 'carrier' => 'AB');
857
+		$data = $Common->getData($url, 'post', $post);
858 858
 		if ($data != '') {
859 859
 			$table = $Common->table2array($data);
860 860
 			$flight = $table;
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
 			}
883 883
 		}
884 884
 		if (isset($DepartureAirportIata)) {
885
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airberlin');
885
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_airberlin');
886 886
 		} else return array();
887 887
 	}
888 888
 
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
 	 * @param String $date Date
893 893
 	 * @return Array Schedules info
894 894
 	*/
895
-	public function fetchSchedule($ident,$date = 'NOW') {
895
+	public function fetchSchedule($ident, $date = 'NOW') {
896 896
 		global $globalSchedulesSources, $globalSchedulesFetch, $globalOffline, $globalFlightAwareUsername;
897 897
 		//$Common = new Common();
898 898
 		if ($globalSchedulesFetch === FALSE || (isset($globalOffline) && $globalOffline === TRUE)) return array();
@@ -962,7 +962,7 @@  discard block
 block discarded – undo
962 962
 				// Brussels Airlines
963 963
 				case "BEL":
964 964
 				case "SN":
965
-					return $this->getBrussels($ident,$date);
965
+					return $this->getBrussels($ident, $date);
966 966
 /*
967 967
 				// Copa Airlines
968 968
 				case "CMP":
@@ -1061,7 +1061,7 @@  discard block
 block discarded – undo
1061 1061
 				case "DS":
1062 1062
 				case "EZY":
1063 1063
 				case "EZS":
1064
-					return $this->getEasyJet($ident,$date);
1064
+					return $this->getEasyJet($ident, $date);
1065 1065
 				// Ryanair
1066 1066
 				case "FR":
1067 1067
 				case "RYR":
@@ -1113,19 +1113,19 @@  discard block
 block discarded – undo
1113 1113
 					return $this->getIberia($ident);
1114 1114
 				// Vietnam Airlines
1115 1115
 				case "HVN":
1116
-					return $this->getVietnamAirlines($ident,$date);
1116
+					return $this->getVietnamAirlines($ident, $date);
1117 1117
 				// Air Berlin
1118 1118
 				case "AB":
1119 1119
 				case "BER":
1120
-					return $this->getAirBerlin($ident,$date,'AB');
1120
+					return $this->getAirBerlin($ident, $date, 'AB');
1121 1121
 				// NIKI
1122 1122
 				case "HG":
1123 1123
 				case "NLY":
1124
-					return $this->getAirBerlin($ident,$date,'HG');
1124
+					return $this->getAirBerlin($ident, $date, 'HG');
1125 1125
 				// BelAir
1126 1126
 				case "4T":
1127 1127
 				case "BHP":
1128
-					return $this->getAirBerlin($ident,$date,'4T');
1128
+					return $this->getAirBerlin($ident, $date, '4T');
1129 1129
 				default:
1130 1130
 					if (strlen($airline_icao) == 3) {
1131 1131
 						$Spotter = new Spotter($this->db);
@@ -1134,9 +1134,9 @@  discard block
 block discarded – undo
1134 1134
 					}
1135 1135
 					// Randomly use a generic function to get hours
1136 1136
 					if (strlen($airline_icao) == 2) {
1137
-						if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper','costtotravel','flightaware');
1137
+						if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper', 'costtotravel', 'flightaware');
1138 1138
 						if (count($globalSchedulesSources) > 0) {
1139
-							$rand = mt_rand(0,count($globalSchedulesSources)-1);
1139
+							$rand = mt_rand(0, count($globalSchedulesSources) - 1);
1140 1140
 							$source = $globalSchedulesSources[$rand];
1141 1141
 							if ($source == 'flightmapper') return $this->getFlightMapper($ident);
1142 1142
 							elseif ($source == 'costtotravel') return $this->getCostToTravel($ident);
Please login to merge, or discard this patch.
Braces   +180 added lines, -62 removed lines patch added patch discarded remove patch
@@ -24,7 +24,9 @@  discard block
 block discarded – undo
24 24
 	public function __construct($dbc = null) {
25 25
 		$Connection = new Connection($dbc);
26 26
 		$this->db = $Connection->db();
27
-		if ($this->db === null) die('Error: No DB connection.');
27
+		if ($this->db === null) {
28
+			die('Error: No DB connection.');
29
+		}
28 30
 	}
29 31
 
30 32
 	/**
@@ -139,7 +141,9 @@  discard block
 block discarded – undo
139 141
 		$sth->closeCursor();
140 142
 		if (count($row) > 0) {
141 143
 			return $row;
142
-		} else return array();
144
+		} else {
145
+			return array();
146
+		}
143 147
 	}
144 148
 
145 149
 	/*
@@ -180,7 +184,9 @@  discard block
 block discarded – undo
180 184
 		$Common = new Common();
181 185
 		$check_date = new Datetime($date);
182 186
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
183
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
187
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
188
+			return array();
189
+		}
184 190
 		$url = "http://www.airfrance.fr/cgi-bin/AF/FR/fr/local/resainfovol/infovols/detailsVolJson.do?codeCompagnie[0]=".$carrier."&numeroVol[0]=".$numvol."&dayFlightDate=".$check_date->format('d')."&yearMonthFlightDate=".$check_date->format('Ym');
185 191
 		$json = $Common->getData($url);
186 192
 		var_dump($json);
@@ -207,7 +213,9 @@  discard block
 block discarded – undo
207 213
 			*/
208 214
 		
209 215
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airfrance');
210
-		} else return array();
216
+		} else {
217
+			return array();
218
+		}
211 219
 	}
212 220
 
213 221
 	/**
@@ -222,7 +230,9 @@  discard block
 block discarded – undo
222 230
 		date_default_timezone_set($globalTimezone);
223 231
 		$check_date = new Datetime($date);
224 232
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
225
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
233
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
234
+			return array();
235
+		}
226 236
 		$url = "http://www.easyjet.com/ft/api/flights?date=".$check_date->format('Y-m-d')."&fn=".$callsign;
227 237
 		$json = $Common->getData($url);
228 238
 		$parsed_json = json_decode($json);
@@ -235,7 +245,9 @@  discard block
 block discarded – undo
235 245
 			$arrivalTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fsta'};
236 246
 
237 247
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_easyjet');
238
-		} else return array();
248
+		} else {
249
+			return array();
250
+		}
239 251
 	}
240 252
 
241 253
 	/**
@@ -246,7 +258,9 @@  discard block
 block discarded – undo
246 258
 	private function getRyanair($callsign) {
247 259
 		$Common = new Common();
248 260
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
249
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
261
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
262
+			return array();
263
+		}
250 264
 		$url = "http://www.ryanair.com/fr/api/2/flight-info/0/50/";
251 265
 		$post = '{"flight":"'.$numvol.'","minDepartureTime":"00:00","maxDepartureTime":"23:59"}';
252 266
 		$headers = array('Content-Type: application/json','Content-Length: ' . strlen($post));
@@ -260,8 +274,12 @@  discard block
 block discarded – undo
260 274
 				$departureTime = $parsed_json->{'flightInfo'}[0]->{'departureTime'};
261 275
 				$arrivalTime = $parsed_json->{'flightInfo'}[0]->{'arrivalTime'};
262 276
 				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair');
263
-			} else return array();
264
-		} else return array();
277
+			} else {
278
+				return array();
279
+			}
280
+		} else {
281
+			return array();
282
+		}
265 283
 	}
266 284
 
267 285
 	/**
@@ -272,7 +290,9 @@  discard block
 block discarded – undo
272 290
 	private function getSwiss($callsign) {
273 291
 		$Common = new Common();
274 292
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
275
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
293
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
294
+			return array();
295
+		}
276 296
 		$url = "http://www.world-of-swiss.com/fr/routenetwork.json";
277 297
 		$json = $Common->getData($url);
278 298
 		$parsed_json = json_decode($json);
@@ -292,8 +312,12 @@  discard block
 block discarded – undo
292 312
 			}
293 313
 			if (isset($DepartureAirportIata) && isset($ArrivalAirportIata)) {
294 314
 				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_swiss');
295
-			} else return array();
296
-		} else return array();
315
+			} else {
316
+				return array();
317
+			}
318
+		} else {
319
+			return array();
320
+		}
297 321
 	}
298 322
 	
299 323
 	/**
@@ -307,12 +331,18 @@  discard block
 block discarded – undo
307 331
 		$Common = new Common();
308 332
 		$check_date = new Datetime($date);
309 333
 		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
310
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
311
-		if ($globalBritishAirwaysKey == '') return array();
334
+		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) {
335
+			return array();
336
+		}
337
+		if ($globalBritishAirwaysKey == '') {
338
+			return array();
339
+		}
312 340
 		$url = "https://api.ba.com/rest-v1/v1/flights;flightNumber=".$numvol.";scheduledDepartureDate=".$check_date->format('Y-m-d').".json";
313 341
 		$headers = array('Client-Key: '.$globalBritishAirwaysKey);
314 342
 		$json = $Common->getData($url,'get','',$headers);
315
-		if ($json == '') return array();
343
+		if ($json == '') {
344
+			return array();
345
+		}
316 346
 		$parsed_json = json_decode($json);
317 347
 		$flights = $parsed_json->{'FlightsResponse'};
318 348
 		if (count($flights) > 0) {
@@ -321,7 +351,9 @@  discard block
 block discarded – undo
321 351
 			$departureTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'}));
322 352
 			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'}));
323 353
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_britishairways');
324
-		} else return array();
354
+		} else {
355
+			return array();
356
+		}
325 357
 	}
326 358
 
327 359
 	/**
@@ -335,19 +367,27 @@  discard block
 block discarded – undo
335 367
 		$Common = new Common();
336 368
 		$check_date = new Datetime($date);
337 369
 		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
338
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
339
-		if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') return array();
370
+		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) {
371
+			return array();
372
+		}
373
+		if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') {
374
+			return array();
375
+		}
340 376
 		$url = "https://api.lufthansa.com/v1/oauth/token";
341 377
 		$post = array('client_id' => $globalLufthansaKey['key'],'client_secret' => $globalLufthansaKey['secret'],'grant_type' => 'client_credentials');
342 378
 		$data = $Common->getData($url,'post',$post);
343 379
 		$parsed_data = json_decode($data);
344
-		if (!isset($parsed_data->{'access_token'})) return array();
380
+		if (!isset($parsed_data->{'access_token'})) {
381
+			return array();
382
+		}
345 383
 		$token = $parsed_data->{'access_token'};
346 384
 		
347 385
 		$url = "https://api.lufthansa.com/v1/operations/flightstatus/LH".$numvol."/".$check_date->format('Y-m-d');
348 386
 		$headers = array('Authorization: Bearer '.$token,'Accept: application/json');
349 387
 		$json = $Common->getData($url,'get','',$headers);
350
-		if ($json == '') return array();
388
+		if ($json == '') {
389
+			return array();
390
+		}
351 391
 		$parsed_json = json_decode($json);
352 392
 		if (isset($parsed_json->{'FlightStatusResource'}) && count($parsed_json->{'FlightStatusResource'}) > 0) {
353 393
 			$DepartureAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'AirportCode'};
@@ -355,7 +395,9 @@  discard block
 block discarded – undo
355 395
 			$ArrivalAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'AirportCode'};
356 396
 			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'}));
357 397
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa');
358
-		} else return array();
398
+		} else {
399
+			return array();
400
+		}
359 401
 	}
360 402
 
361 403
 	/**
@@ -369,14 +411,20 @@  discard block
 block discarded – undo
369 411
 		$Common = new Common();
370 412
 		$check_date = new Datetime($date);
371 413
 		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
372
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
373
-		if ($globalTransaviaKey == '') return array();
414
+		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) {
415
+			return array();
416
+		}
417
+		if ($globalTransaviaKey == '') {
418
+			return array();
419
+		}
374 420
 		$url = "https://tst.api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
375 421
 		//$url = "https://api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
376 422
 		$headers = array('apikey: '.$globalTransaviaKey);
377 423
 		$json = $Common->getData($url,'get','',$headers);
378 424
 		//echo 'result : '.$json;
379
-		if ($json == '') return array();
425
+		if ($json == '') {
426
+			return array();
427
+		}
380 428
 		$parsed_json = json_decode($json);
381 429
 		
382 430
 		if (isset($parsed_json->{'data'}[0])) {
@@ -385,7 +433,9 @@  discard block
 block discarded – undo
385 433
 			$ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'};
386 434
 			$arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'}));
387 435
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia');
388
-		} else return array();
436
+		} else {
437
+			return array();
438
+		}
389 439
 	}
390 440
 
391 441
 	/**
@@ -396,7 +446,9 @@  discard block
 block discarded – undo
396 446
 	public function getTunisair($callsign) {
397 447
 		$Common = new Common();
398 448
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
399
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
449
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
450
+			return array();
451
+		}
400 452
 		$url = "http://www.tunisair.com/site/publish/module/Volj/fr/Flight_List.asp";
401 453
 		$data = $Common->getData($url);
402 454
 		$table = $Common->table2array($data);
@@ -417,7 +469,9 @@  discard block
 block discarded – undo
417 469
 		$Common = new Common();
418 470
 		$check_date = new Datetime($date);
419 471
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
420
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
472
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
473
+			return array();
474
+		}
421 475
 		$final_date = str_replace('/','%2F',$check_date->format('d/m/Y'));
422 476
 		$url = "http://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=FlightStatusResult&searchBy=bycode&date=".$final_date."&flightNumber=".$numvol."&idioma=en-GB";
423 477
 		$data = $Common->getData($url);
@@ -427,8 +481,11 @@  discard block
 block discarded – undo
427 481
 			$DepartureAirportIata = str_replace('flightOri=','',$result[0]);
428 482
 			preg_match('/flightDest=[A-Z]{3}/',$data,$result);
429 483
 			$ArrivalAirportIata = str_replace('flightDest=','',$result[0]);
430
-			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling');
431
-			else return array();
484
+			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') {
485
+				return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling');
486
+			} else {
487
+				return array();
488
+			}
432 489
 		}
433 490
 		return array();
434 491
 	}
@@ -443,7 +500,9 @@  discard block
 block discarded – undo
443 500
 		$Common = new Common();
444 501
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
445 502
 		$check_date = new Datetime($date);
446
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
503
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
504
+			return array();
505
+		}
447 506
 		$url = "https://www.iberia.com/web/flightDetail.do";
448 507
 		$post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB');
449 508
 		$data = $Common->getData($url,'post',$post);
@@ -460,7 +519,9 @@  discard block
 block discarded – undo
460 519
 				$arrivalTime = trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][1])));
461 520
 				if ($arrivalTime == 'Hora estimada de llegada') {
462 521
 					$arrivalTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][2]))),0,5);
463
-				} else $arrivalTime = substr($arrivalTime,0,5);
522
+				} else {
523
+					$arrivalTime = substr($arrivalTime,0,5);
524
+				}
464 525
 				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia');
465 526
 			}
466 527
 		}
@@ -478,7 +539,9 @@  discard block
 block discarded – undo
478 539
 		$Common = new Common();
479 540
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
480 541
 		$check_date = new Datetime($date);
481
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
542
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
543
+			return array();
544
+		}
482 545
 		$url = "http://www.staralliance.com/flifoQueryAction.do?myAirline=&airlineCode=".$carrier."&flightNo=".$numvol."&day=".$check_date->format('d')."&month=".$check_date->format('m')."&year=".$check_date->format('Y')."&departuredate=".$check_date->format('d-M-Y');
483 546
 		$data = $Common->getData($url);
484 547
 		if ($data != '') {
@@ -494,7 +557,9 @@  discard block
 block discarded – undo
494 557
 					$departureTime = substr(trim(str_replace('Scheduled: ','',$flight[29][0])),0,5);
495 558
 					$arrivalTime = substr(trim(str_replace('Scheduled: ','',$flight[29][1])),0,5);
496 559
 					return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_staralliance');
497
-				} else return array();
560
+				} else {
561
+					return array();
562
+				}
498 563
 			}
499 564
 			
500 565
 
@@ -514,7 +579,9 @@  discard block
 block discarded – undo
514 579
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
515 580
 		$check_date = new Datetime($date);
516 581
 		$url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y');
517
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
582
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
583
+			return array();
584
+		}
518 585
 		$data = $Common->getData($url);
519 586
 		if ($data != '') {
520 587
 			$table = $Common->text2array($data);
@@ -538,7 +605,9 @@  discard block
 block discarded – undo
538 605
 		$check_date = new Datetime($date);
539 606
 		$url= "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302";
540 607
 		//http://www.brusselsairlines.com/fr-fr/informations-pratiques/statut-de-votre-vol/resultat.aspx?flightnumber=".$numvol."&date=".$check_date->format('d/m/Y')."&lookup=flightnumber";
541
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
608
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
609
+			return array();
610
+		}
542 611
 		$data = $Common->getData($url);
543 612
 		if ($data != '') {
544 613
 		    //echo $data;
@@ -628,7 +697,9 @@  discard block
 block discarded – undo
628 697
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
629 698
 		$url= "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees";
630 699
 		//$check_date = new Datetime($date);
631
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
700
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
701
+			return array();
702
+		}
632 703
 		$post = array('arrivalsdepartures_content' => 'number','arrivalsdepartures_tp' => $numvol,'arrivalsdepartures_trk' => 'ARR','arrivalsdepartures_date_trk' => '1','aptCode' => '','arrivalsdepartures' => 'DEP','arrivalsdepartures_date' => '1','aptCodeFrom' => '','aptCodeTo' => '','arrivalsdepartures2' => 'DEP','arrivalsdepartures_date2' => '1');
633 704
 		$data = $Common->getData($url,'post',$post);
634 705
 		if ($data != '') {
@@ -660,11 +731,15 @@  discard block
 block discarded – undo
660 731
 				$airline_icao = substr($callsign, 0, 3);
661 732
 			} 
662 733
 		}
663
-		if ($airline_icao == '') return array();
734
+		if ($airline_icao == '') {
735
+			return array();
736
+		}
664 737
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
665 738
 		$url= "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol;
666 739
 		//$check_date = new Datetime($date);
667
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
740
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
741
+			return array();
742
+		}
668 743
 		$data = $Common->getData($url);
669 744
 		if ($data != '') {
670 745
 			$table = $Common->table2array($data);
@@ -757,10 +832,16 @@  discard block
 block discarded – undo
757 832
 		if ($data != '') {
758 833
 			$table = $Common->table2array($data);
759 834
 			if (isset($table[11][1])) {
760
-				if (is_numeric(substr($table[11][1],0,1))) $departureTime = substr($table[11][1],0,5);
761
-				else $departureTime = '';
762
-				if (is_numeric(substr($table[17][1],0,1))) $arrivalTime = substr($table[17][1],0,5);
763
-				else $arrivalTime = '';
835
+				if (is_numeric(substr($table[11][1],0,1))) {
836
+					$departureTime = substr($table[11][1],0,5);
837
+				} else {
838
+					$departureTime = '';
839
+				}
840
+				if (is_numeric(substr($table[17][1],0,1))) {
841
+					$arrivalTime = substr($table[17][1],0,5);
842
+				} else {
843
+					$arrivalTime = '';
844
+				}
764 845
 				$DepartureAirportIata = substr($table[13][1],0,3);
765 846
 				$ArrivalAirportIata = substr($table[15][1],0,3);
766 847
 				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_costtotravel');
@@ -777,16 +858,22 @@  discard block
 block discarded – undo
777 858
 	*/
778 859
 	private function getAirCanada($callsign,$date = 'NOW') {
779 860
 		$Common = new Common();
780
-		if (class_exists("DomDocument") === FALSE) return array();
861
+		if (class_exists("DomDocument") === FALSE) {
862
+			return array();
863
+		}
781 864
 		date_default_timezone_set('UTC');
782 865
 		$check_date = new Datetime($date);
783 866
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
784 867
 		$url= "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249";
785
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
868
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
869
+			return array();
870
+		}
786 871
 		$data = $Common->getData($url);
787 872
 		$dom = new DomDocument();
788 873
 		$dom->loadXML($data);
789
-		if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) return array();
874
+		if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) {
875
+			return array();
876
+		}
790 877
 		$departure = $dom->getElementsByTagName('DepartureStationInfo')->item(0);
791 878
 		if (isset($departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue)) {
792 879
 			$DepartureAirportIata = $departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
@@ -795,7 +882,9 @@  discard block
 block discarded – undo
795 882
 			$ArrivalAirportIata = $arrival->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
796 883
 			$arrivalTime = date('H:i',strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
797 884
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_aircanada');
798
-		} else return array();
885
+		} else {
886
+			return array();
887
+		}
799 888
 	}
800 889
 
801 890
 	/**
@@ -809,7 +898,9 @@  discard block
 block discarded – undo
809 898
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
810 899
 		$check_date = new Datetime($date);
811 900
 		$url= "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&";
812
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
901
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
902
+			return array();
903
+		}
813 904
 		$data = $Common->getData($url);
814 905
 		if ($data != '') {
815 906
 			$table = $Common->table2array($data);
@@ -838,7 +929,9 @@  discard block
 block discarded – undo
838 929
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
839 930
 		$check_date = new Datetime($date);
840 931
 		$url= "http://www.airberlin.com/en-US/site/aims.php";
841
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
932
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
933
+			return array();
934
+		}
842 935
 		$post = array('type' => 'departure','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => $carrier);
843 936
 		$data = $Common->getData($url,'post',$post);
844 937
 		//echo $data;
@@ -848,11 +941,19 @@  discard block
 block discarded – undo
848 941
 		if ($data != '') {
849 942
 			$table = $Common->table2array($data);
850 943
 			$flight = $table;
851
-			if (isset($flight[5][4])) $departureTime = $flight[5][4];
852
-			else $departureTime = '';
853
-			if (isset($flight[5][2])) $departureAirport = $flight[5][2];
854
-			else $departureAirport = '';
855
-		} else return array();
944
+			if (isset($flight[5][4])) {
945
+				$departureTime = $flight[5][4];
946
+			} else {
947
+				$departureTime = '';
948
+			}
949
+			if (isset($flight[5][2])) {
950
+				$departureAirport = $flight[5][2];
951
+			} else {
952
+				$departureAirport = '';
953
+			}
954
+		} else {
955
+			return array();
956
+		}
856 957
 		$post = array('type' => 'arrival','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB');
857 958
 		$data = $Common->getData($url,'post',$post);
858 959
 		if ($data != '') {
@@ -865,10 +966,14 @@  discard block
 block discarded – undo
865 966
 			    $arrivalTime = '';
866 967
 			    $arrivalAirport = '';
867 968
 			}
868
-		} else return array();
969
+		} else {
970
+			return array();
971
+		}
869 972
 		$url = 'http://www.airberlin.com/en-US/site/json/suggestAirport.php?searchfor=departures&searchflightid=0&departures%5B%5D=&suggestsource%5B0%5D=activeairports&withcountries=0&withoutroutings=0&promotion%5Bid%5D=&promotion%5Btype%5D=&routesource%5B0%5D=airberlin&routesource%5B1%5D=partner';
870 973
 		$json = $Common->getData($url);
871
-		if ($json == '') return array();
974
+		if ($json == '') {
975
+			return array();
976
+		}
872 977
 		$parsed_json = json_decode($json);
873 978
 		$airports = $parsed_json->{'suggestList'};
874 979
 		if (count($airports) > 0) {
@@ -883,7 +988,9 @@  discard block
 block discarded – undo
883 988
 		}
884 989
 		if (isset($DepartureAirportIata)) {
885 990
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airberlin');
886
-		} else return array();
991
+		} else {
992
+			return array();
993
+		}
887 994
 	}
888 995
 
889 996
 	/*
@@ -895,7 +1002,9 @@  discard block
 block discarded – undo
895 1002
 	public function fetchSchedule($ident,$date = 'NOW') {
896 1003
 		global $globalSchedulesSources, $globalSchedulesFetch, $globalOffline, $globalFlightAwareUsername;
897 1004
 		//$Common = new Common();
898
-		if ($globalSchedulesFetch === FALSE || (isset($globalOffline) && $globalOffline === TRUE)) return array();
1005
+		if ($globalSchedulesFetch === FALSE || (isset($globalOffline) && $globalOffline === TRUE)) {
1006
+			return array();
1007
+		}
899 1008
 		$airline_icao = '';
900 1009
 		if (!is_numeric(substr($ident, 0, 3)))
901 1010
 		{
@@ -1130,18 +1239,27 @@  discard block
 block discarded – undo
1130 1239
 					if (strlen($airline_icao) == 3) {
1131 1240
 						$Spotter = new Spotter($this->db);
1132 1241
 						$airline_info = $Spotter->getAllAirlineInfo($airline_icao);
1133
-						if (isset($airline_info[0]['iata'])) $airline_icao = $airline_info[0]['iata'];
1242
+						if (isset($airline_info[0]['iata'])) {
1243
+							$airline_icao = $airline_info[0]['iata'];
1244
+						}
1134 1245
 					}
1135 1246
 					// Randomly use a generic function to get hours
1136 1247
 					if (strlen($airline_icao) == 2) {
1137
-						if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper','costtotravel','flightaware');
1248
+						if (!isset($globalSchedulesSources)) {
1249
+							$globalSchedulesSources = array('flightmapper','costtotravel','flightaware');
1250
+						}
1138 1251
 						if (count($globalSchedulesSources) > 0) {
1139 1252
 							$rand = mt_rand(0,count($globalSchedulesSources)-1);
1140 1253
 							$source = $globalSchedulesSources[$rand];
1141
-							if ($source == 'flightmapper') return $this->getFlightMapper($ident);
1142
-							elseif ($source == 'costtotravel') return $this->getCostToTravel($ident);
1254
+							if ($source == 'flightmapper') {
1255
+								return $this->getFlightMapper($ident);
1256
+							} elseif ($source == 'costtotravel') {
1257
+								return $this->getCostToTravel($ident);
1258
+							}
1143 1259
 							//elseif ($source == 'flightradar24') return $this->getFlightRadar24($ident,$date);
1144
-							elseif ($source == 'flightaware' && $globalFlightAwareUsername != '') return $this->getFlightAware($ident);
1260
+							elseif ($source == 'flightaware' && $globalFlightAwareUsername != '') {
1261
+								return $this->getFlightAware($ident);
1262
+							}
1145 1263
 						}
1146 1264
 					}
1147 1265
 			}
Please login to merge, or discard this patch.