Completed
Push — master ( cc50d0...0f8c33 )
by Yannick
09:46
created
require/class.MarineImport.php 1 patch
Braces   +149 added lines, -51 removed lines patch added patch discarded remove patch
@@ -44,7 +44,9 @@  discard block
 block discarded – undo
44 44
 
45 45
     public function checkAll() {
46 46
 	global $globalDebug;
47
-	if ($globalDebug) echo "Update last seen tracked data...\n";
47
+	if ($globalDebug) {
48
+		echo "Update last seen tracked data...\n";
49
+	}
48 50
 	foreach ($this->all_tracked as $key => $flight) {
49 51
 	    if (isset($this->all_tracked[$key]['id'])) {
50 52
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
@@ -57,12 +59,16 @@  discard block
 block discarded – undo
57 59
     public function del() {
58 60
 	global $globalDebug;
59 61
 	// Delete old infos
60
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
62
+	if ($globalDebug) {
63
+		echo 'Delete old values and update latest data...'."\n";
64
+	}
61 65
 	foreach ($this->all_tracked as $key => $flight) {
62 66
     	    if (isset($flight['lastupdate'])) {
63 67
         	if ($flight['lastupdate'] < (time()-3000)) {
64 68
             	    if (isset($this->all_tracked[$key]['id'])) {
65
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
69
+            		if ($globalDebug) {
70
+            			echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
71
+            		}
66 72
 			/*
67 73
 			$MarineLive = new MarineLive();
68 74
             		$MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
@@ -72,7 +78,9 @@  discard block
 block discarded – undo
72 78
             		$Marine = new Marine($this->db);
73 79
             		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
74 80
 				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed']);
75
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
81
+				if ($globalDebug && $result != 'success') {
82
+					echo '!!! ERROR : '.$result."\n";
83
+				}
76 84
 			}
77 85
 			// Put in archive
78 86
 //			$Marine->db = null;
@@ -85,7 +93,9 @@  discard block
 block discarded – undo
85 93
 
86 94
     public function add($line) {
87 95
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked;
88
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
96
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
97
+		$globalCoordMinChange = '0.02';
98
+	}
89 99
 	date_default_timezone_set('UTC');
90 100
 	$dataFound = false;
91 101
 	$send = false;
@@ -109,8 +119,11 @@  discard block
 block discarded – undo
109 119
 		*/
110 120
 		
111 121
 		$Common = new Common();
112
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
113
-	        else $id = trim($line['id']);
122
+	        if (!isset($line['id'])) {
123
+	        	$id = trim($line['mmsi']);
124
+	        } else {
125
+	        	$id = trim($line['id']);
126
+	        }
114 127
 		
115 128
 		if (!isset($this->all_tracked[$id])) {
116 129
 		    $this->all_tracked[$id] = array();
@@ -118,10 +131,16 @@  discard block
 block discarded – undo
118 131
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','type' => '','status' => ''));
119 132
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
120 133
 		    if (!isset($line['id'])) {
121
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
134
+			if (!isset($globalDaemon)) {
135
+				$globalDaemon = TRUE;
136
+			}
122 137
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
123
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
124
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
138
+		     } else {
139
+		     	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
140
+		     }
141
+		    if ($globalAllTracked !== FALSE) {
142
+		    	$dataFound = true;
143
+		    }
125 144
 		}
126 145
 		
127 146
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
@@ -146,11 +165,17 @@  discard block
 block discarded – undo
146 165
             		$Marine = new Marine($this->db);
147 166
             		$fromsource = NULL;
148 167
             		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
149
-			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
168
+			if ($globalDebug && $result != 'success') {
169
+				echo '!!! ERROR : '.$result."\n";
170
+			}
150 171
 			$Marine->db = null;
151
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
172
+			if ($globalDebugTimeElapsed) {
173
+				echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
174
+			}
175
+		    }
176
+		    if (!isset($this->all_tracked[$id]['id'])) {
177
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
152 178
 		    }
153
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
154 179
 		}
155 180
 
156 181
 		if (isset($line['speed']) && $line['speed'] != '') {
@@ -161,14 +186,21 @@  discard block
 block discarded – undo
161 186
 		    if ($distance > 1000 && $distance < 10000) {
162 187
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
163 188
 			$speed = $speed*3.6;
164
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
165
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
189
+			if ($speed < 1000) {
190
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
191
+			}
192
+  			if ($globalDebug) {
193
+  				echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
194
+  			}
166 195
 		    }
167 196
 		}
168 197
 
169 198
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
170
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
171
-	    	    else unset($timediff);
199
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) {
200
+	    	    	$timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
201
+	    	    } else {
202
+	    	    	unset($timediff);
203
+	    	    }
172 204
 	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
173 205
 			if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) {
174 206
 			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
@@ -176,20 +208,30 @@  discard block
 block discarded – undo
176 208
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
177 209
 				$this->all_tracked[$id]['putinarchive'] = true;
178 210
 				
179
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
211
+				if ($globalDebug) {
212
+					echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
213
+				}
180 214
 				$timeelapsed = microtime(true);
181 215
 				$Marine = new Marine($this->db);
182 216
 				$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
183
-				if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
217
+				if (!empty($all_country)) {
218
+					$this->all_tracked[$id]['over_country'] = $all_country['iso2'];
219
+				}
184 220
 				$Marine->db = null;
185
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
221
+				if ($globalDebugTimeElapsed) {
222
+					echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
223
+				}
186 224
 				$this->tmd = 0;
187
-				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
225
+				if ($globalDebug) {
226
+					echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
227
+				}
188 228
 			    }
189 229
 			}
190 230
 
191 231
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
192
-				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
232
+				if (!isset($this->all_tracked[$id]['archive_latitude'])) {
233
+					$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
234
+				}
193 235
 				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
194 236
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
195 237
 				    $dataFound = true;
@@ -198,8 +240,12 @@  discard block
 block discarded – undo
198 240
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
199 241
 			}
200 242
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
201
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
202
-				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
243
+			    if ($line['longitude'] > 180) {
244
+			    	$line['longitude'] = $line['longitude'] - 360;
245
+			    }
246
+				if (!isset($this->all_tracked[$id]['archive_longitude'])) {
247
+					$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
248
+				}
203 249
 				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
204 250
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
205 251
 				    $dataFound = true;
@@ -217,7 +263,9 @@  discard block
 block discarded – undo
217 263
 		    }
218 264
 		}
219 265
 		if (isset($line['last_update']) && $line['last_update'] != '') {
220
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
266
+		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) {
267
+		    	$dataFound = true;
268
+		    }
221 269
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
222 270
 		}
223 271
 		if (isset($line['format_source']) && $line['format_source'] != '') {
@@ -235,15 +283,21 @@  discard block
 block discarded – undo
235 283
 		}
236 284
 		
237 285
 		if (isset($line['heading']) && $line['heading'] != '') {
238
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
286
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) {
287
+		    	$this->all_tracked[$id]['putinarchive'] = true;
288
+		    }
239 289
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
240 290
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
241 291
 		    //$dataFound = true;
242 292
   		} elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) {
243 293
   		    $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
244 294
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
245
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
246
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
295
+		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) {
296
+		    	$this->all_tracked[$id]['putinarchive'] = true;
297
+		    }
298
+  		    if ($globalDebug) {
299
+  		    	echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
300
+  		    }
247 301
   		}
248 302
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
249 303
 
@@ -251,8 +305,11 @@  discard block
 block discarded – undo
251 305
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
252 306
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
253 307
 		    } else {
254
-				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
255
-				elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
308
+				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
309
+					echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
310
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
311
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
312
+				}
256 313
 				return '';
257 314
 		    }
258 315
 		} else {
@@ -266,22 +323,35 @@  discard block
 block discarded – undo
266 323
 		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
267 324
 		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
268 325
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
269
-				if ($globalDebug) echo "Check if aircraft is already in DB...";
326
+				if ($globalDebug) {
327
+					echo "Check if aircraft is already in DB...";
328
+				}
270 329
 				$timeelapsed = microtime(true);
271 330
 				$MarineLive = new MarineLive($this->db);
272 331
 				if (isset($line['id'])) {
273 332
 				    $recent_ident = $MarineLive->checkIdRecent($line['id']);
274
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
333
+				    if ($globalDebugTimeElapsed) {
334
+				    	echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
335
+				    }
275 336
 				} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
276 337
 				    $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
277
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
338
+				    if ($globalDebugTimeElapsed) {
339
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
340
+				    }
278 341
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
279 342
 				    $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
280
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
281
-				} else $recent_ident = '';
343
+				    if ($globalDebugTimeElapsed) {
344
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
345
+				    }
346
+				} else {
347
+					$recent_ident = '';
348
+				}
282 349
 				$MarineLive->db=null;
283
-				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
284
-				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
350
+				if ($globalDebug && $recent_ident == '') {
351
+					echo " Not in DB.\n";
352
+				} elseif ($globalDebug && $recent_ident != '') {
353
+					echo " Already in DB.\n";
354
+				}
285 355
 			    } else {
286 356
 				$recent_ident = '';
287 357
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
@@ -289,16 +359,24 @@  discard block
 block discarded – undo
289 359
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
290 360
 			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
291 361
 			    {
292
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
362
+				if ($globalDebug) {
363
+					echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
364
+				}
293 365
 				//adds the spotter data for the archive
294 366
 				    $highlight = '';
295
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
367
+				    if (!isset($this->all_tracked[$id]['id'])) {
368
+				    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
369
+				    }
296 370
 				    $timeelapsed = microtime(true);
297 371
 				    $Marine = new Marine($this->db);
298 372
 				    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
299 373
 				    $Marine->db = null;
300
-				    if ($globalDebug && isset($result)) echo $result."\n";
301
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
374
+				    if ($globalDebug && isset($result)) {
375
+				    	echo $result."\n";
376
+				    }
377
+				    if ($globalDebugTimeElapsed) {
378
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
379
+				    }
302 380
 				    
303 381
 				    /*
304 382
 				    // Add source stat in DB
@@ -332,12 +410,16 @@  discard block
 block discarded – undo
332 410
 				$this->all_tracked[$id]['addedMarine'] = 1;
333 411
 				//print_r($this->all_tracked[$id]);
334 412
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
335
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
413
+				    if ($globalDebug) {
414
+				    	echo "---- Deleting Live Marine data older than 9 hours...";
415
+				    }
336 416
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
337 417
 				    $MarineLive = new MarineLive($this->db);
338 418
 				    $MarineLive->deleteLiveMarineData();
339 419
 				    $MarineLive->db=null;
340
-				    if ($globalDebug) echo " Done\n";
420
+				    if ($globalDebug) {
421
+				    	echo " Done\n";
422
+				    }
341 423
 				    $this->last_delete = time();
342 424
 				}
343 425
 			    } elseif ($recent_ident != '') {
@@ -360,13 +442,17 @@  discard block
 block discarded – undo
360 442
 
361 443
 		    if (!$ignoreImport) {
362 444
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
363
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
445
+				if ($globalDebug) {
446
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
447
+				}
364 448
 				$timeelapsed = microtime(true);
365 449
 				$MarineLive = new MarineLive($this->db);
366 450
 				$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
367 451
 				$MarineLive->db = null;
368 452
 				$this->all_tracked[$id]['putinarchive'] = false;
369
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
453
+				if ($globalDebugTimeElapsed) {
454
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
455
+				}
370 456
 
371 457
 				// Put statistics in $this->stats variable
372 458
 				/*
@@ -423,19 +509,29 @@  discard block
 block discarded – undo
423 509
 				*/
424 510
 
425 511
 				$this->all_tracked[$id]['lastupdate'] = time();
426
-				if ($this->all_tracked[$id]['putinarchive']) $send = true;
427
-				if ($globalDebug) echo $result."\n";
428
-			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
512
+				if ($this->all_tracked[$id]['putinarchive']) {
513
+					$send = true;
514
+				}
515
+				if ($globalDebug) {
516
+					echo $result."\n";
517
+				}
518
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
519
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
520
+			}
429 521
 			//$this->del();
430 522
 			
431 523
 			
432 524
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
433
-			    if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
525
+			    if ($globalDebug) {
526
+			    	echo "---- Deleting Live Marine data Not updated since 2 hour...";
527
+			    }
434 528
 			    $MarineLive = new MarineLive($this->db);
435 529
 			    $MarineLive->deleteLiveMarineDataNotUpdated();
436 530
 			    $MarineLive->db = null;
437 531
 			    //MarineLive->deleteLiveMarineData();
438
-			    if ($globalDebug) echo " Done\n";
532
+			    if ($globalDebug) {
533
+			    	echo " Done\n";
534
+			    }
439 535
 			    $this->last_delete_hourly = time();
440 536
 			}
441 537
 			
@@ -443,7 +539,9 @@  discard block
 block discarded – undo
443 539
 		    //$ignoreImport = false;
444 540
 		}
445 541
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
446
-		if ($send) return $this->all_tracked[$id];
542
+		if ($send) {
543
+			return $this->all_tracked[$id];
544
+		}
447 545
 	    }
448 546
 	}
449 547
     }
Please login to merge, or discard this patch.
require/class.Tracker.php 1 patch
Braces   +143 added lines, -51 removed lines patch added patch discarded remove patch
@@ -31,7 +31,9 @@  discard block
 block discarded – undo
31 31
 		if (isset($filter[0]['source'])) {
32 32
 			$filters = array_merge($filters,$filter);
33 33
 		}
34
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
34
+		if (is_array($globalFilter)) {
35
+			$filter = array_merge($filter,$globalFilter);
36
+		}
35 37
 		$filter_query_join = '';
36 38
 		$filter_query_where = '';
37 39
 		foreach($filters as $flt) {
@@ -70,8 +72,11 @@  discard block
 block discarded – undo
70 72
 				$filter_query_where .= " AND EXTRACT(DAY FROM tracker_output.date) = '".$filter['day']."'";
71 73
 			}
72 74
 		}
73
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
74
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
75
+		if ($filter_query_where == '' && $where) {
76
+			$filter_query_where = ' WHERE';
77
+		} elseif ($filter_query_where != '' && $and) {
78
+			$filter_query_where .= ' AND';
79
+		}
75 80
 		if ($filter_query_where != '') {
76 81
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
77 82
 		}
@@ -125,26 +130,43 @@  discard block
 block discarded – undo
125 130
 				$temp_array['spotter_id'] = $row['spotter_archive_id'];
126 131
 			} elseif (isset($row['spotter_archive_output_id'])) {
127 132
 				$temp_array['spotter_id'] = $row['spotter_archive_output_id'];
128
-			*/} 
129
-			elseif (isset($row['trackerid'])) {
133
+			*/} elseif (isset($row['trackerid'])) {
130 134
 				$temp_array['trackerid'] = $row['trackerid'];
131 135
 			} else {
132 136
 				$temp_array['trackerid'] = '';
133 137
 			}
134
-			if (isset($row['famtrackid'])) $temp_array['famtrackid'] = $row['famtrackid'];
135
-			if (isset($row['type'])) $temp_array['type'] = $row['type'];
136
-			if (isset($row['comment'])) $temp_array['comment'] = $row['comment'];
138
+			if (isset($row['famtrackid'])) {
139
+				$temp_array['famtrackid'] = $row['famtrackid'];
140
+			}
141
+			if (isset($row['type'])) {
142
+				$temp_array['type'] = $row['type'];
143
+			}
144
+			if (isset($row['comment'])) {
145
+				$temp_array['comment'] = $row['comment'];
146
+			}
137 147
 			$temp_array['ident'] = $row['ident'];
138
-			if (isset($row['latitude'])) $temp_array['latitude'] = $row['latitude'];
139
-			if (isset($row['longitude'])) $temp_array['longitude'] = $row['longitude'];
140
-			if (isset($row['format_source'])) $temp_array['format_source'] = $row['format_source'];
141
-			if (isset($row['altitude'])) $temp_array['altitude'] = $row['altitude'];
148
+			if (isset($row['latitude'])) {
149
+				$temp_array['latitude'] = $row['latitude'];
150
+			}
151
+			if (isset($row['longitude'])) {
152
+				$temp_array['longitude'] = $row['longitude'];
153
+			}
154
+			if (isset($row['format_source'])) {
155
+				$temp_array['format_source'] = $row['format_source'];
156
+			}
157
+			if (isset($row['altitude'])) {
158
+				$temp_array['altitude'] = $row['altitude'];
159
+			}
142 160
 			if (isset($row['heading'])) {
143 161
 				$temp_array['heading'] = $row['heading'];
144 162
 				$heading_direction = $this->parseDirection($row['heading']);
145
-				if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
163
+				if (isset($heading_direction[0]['direction_fullname'])) {
164
+					$temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
165
+				}
166
+			}
167
+			if (isset($row['ground_speed'])) {
168
+				$temp_array['ground_speed'] = $row['ground_speed'];
146 169
 			}
147
-			if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed'];
148 170
 			
149 171
 			if (isset($row['date'])) {
150 172
 				$dateArray = $this->parseDateString($row['date']);
@@ -187,13 +209,21 @@  discard block
 block discarded – undo
187 209
 			}
188 210
 			
189 211
 			$fromsource = NULL;
190
-			if (isset($row['source_name']) && $row['source_name'] != '') $temp_array['source_name'] = $row['source_name'];
191
-			if (isset($row['over_country']) && $row['over_country'] != '') $temp_array['over_country'] = $row['over_country'];
192
-			if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance'];
212
+			if (isset($row['source_name']) && $row['source_name'] != '') {
213
+				$temp_array['source_name'] = $row['source_name'];
214
+			}
215
+			if (isset($row['over_country']) && $row['over_country'] != '') {
216
+				$temp_array['over_country'] = $row['over_country'];
217
+			}
218
+			if (isset($row['distance']) && $row['distance'] != '') {
219
+				$temp_array['distance'] = $row['distance'];
220
+			}
193 221
 			$temp_array['query_number_rows'] = $num_rows;
194 222
 			$spotter_array[] = $temp_array;
195 223
 		}
196
-		if ($num_rows == 0) return array();
224
+		if ($num_rows == 0) {
225
+			return array();
226
+		}
197 227
 		$spotter_array[0]['query_number_rows'] = $num_rows;
198 228
 		return $spotter_array;
199 229
 	}	
@@ -224,8 +254,12 @@  discard block
 block discarded – undo
224 254
 			{
225 255
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
226 256
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
227
-			} else $limit_query = "";
228
-		} else $limit_query = "";
257
+			} else {
258
+				$limit_query = "";
259
+			}
260
+		} else {
261
+			$limit_query = "";
262
+		}
229 263
 		
230 264
 		if ($sort != "")
231 265
 		{
@@ -253,7 +287,9 @@  discard block
 block discarded – undo
253 287
 		global $global_query;
254 288
 		
255 289
 		date_default_timezone_set('UTC');
256
-		if ($id == '') return array();
290
+		if ($id == '') {
291
+			return array();
292
+		}
257 293
 		$additional_query = "tracker_output.famtrackid = :id";
258 294
 		$query_values = array(':id' => $id);
259 295
 		$query  = $global_query." WHERE ".$additional_query." ";
@@ -396,8 +432,11 @@  discard block
 block discarded – undo
396 432
 		$query .= " ORDER BY tracker_output.source_name ASC";
397 433
 
398 434
 		$sth = $this->db->prepare($query);
399
-		if (!empty($query_values)) $sth->execute($query_values);
400
-		else $sth->execute();
435
+		if (!empty($query_values)) {
436
+			$sth->execute($query_values);
437
+		} else {
438
+			$sth->execute();
439
+		}
401 440
 
402 441
 		$source_array = array();
403 442
 		$temp_array = array();
@@ -452,7 +491,9 @@  discard block
 block discarded – undo
452 491
 			date_default_timezone_set($globalTimezone);
453 492
 			$datetime = new DateTime();
454 493
 			$offset = $datetime->format('P');
455
-		} else $offset = '+00:00';
494
+		} else {
495
+			$offset = '+00:00';
496
+		}
456 497
 
457 498
 		if ($globalDBdriver == 'mysql') {
458 499
 			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(tracker_output.date,'+00:00', :offset)) as date
@@ -608,7 +649,9 @@  discard block
 block discarded – undo
608 649
 			{
609 650
 				return false;
610 651
 			}
611
-		} else $altitude = 0;
652
+		} else {
653
+			$altitude = 0;
654
+		}
612 655
 		
613 656
 		if ($heading != "")
614 657
 		{
@@ -647,8 +690,12 @@  discard block
 block discarded – undo
647 690
             		$latitude = 0;
648 691
             		$longitude = 0;
649 692
             	}
650
-                if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
651
-                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
693
+                if ($heading == '' || $Common->isInteger($heading) === false) {
694
+                	$heading = 0;
695
+                }
696
+                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) {
697
+                	$groundspeed = 0;
698
+                }
652 699
                 $query  = "INSERT INTO tracker_output (famtrackid, ident, latitude, longitude, altitude, heading, ground_speed, date, format_source, source_name, comment, type) 
653 700
                 VALUES (:famtrackid,:ident,:latitude,:longitude,:altitude,:heading,:speed,:date,:format_source, :source_name,:comment,:type)";
654 701
 
@@ -813,12 +860,18 @@  discard block
 block discarded – undo
813 860
 		$query  = "SELECT DISTINCT tracker_output.ident, COUNT(tracker_output.ident) AS callsign_icao_count 
814 861
                     FROM tracker_output".$filter_query." tracker_output.ident <> ''";
815 862
 		 if ($olderthanmonths > 0) {
816
-			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
817
-			else $query .= " AND tracker_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
863
+			if ($globalDBdriver == 'mysql') {
864
+				$query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
865
+			} else {
866
+				$query .= " AND tracker_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
867
+			}
818 868
 		}
819 869
 		if ($sincedate != '') {
820
-			if ($globalDBdriver == 'mysql') $query .= " AND tracker_output.date > '".$sincedate."'";
821
-			else $query .= " AND tracker_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
870
+			if ($globalDBdriver == 'mysql') {
871
+				$query .= " AND tracker_output.date > '".$sincedate."'";
872
+			} else {
873
+				$query .= " AND tracker_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
874
+			}
822 875
 		}
823 876
 		$query_values = array();
824 877
 		if ($year != '') {
@@ -849,7 +902,9 @@  discard block
 block discarded – undo
849 902
 			}
850 903
 		}
851 904
 		$query .= " GROUP BY tracker_output.ident ORDER BY callsign_icao_count DESC";
852
-		if ($limit) $query .= " LIMIT 10 OFFSET 0";
905
+		if ($limit) {
906
+			$query .= " LIMIT 10 OFFSET 0";
907
+		}
853 908
       		
854 909
 		$sth = $this->db->prepare($query);
855 910
 		$sth->execute($query_values);
@@ -884,7 +939,9 @@  discard block
 block discarded – undo
884 939
 			date_default_timezone_set($globalTimezone);
885 940
 			$datetime = new DateTime();
886 941
 			$offset = $datetime->format('P');
887
-		} else $offset = '+00:00';
942
+		} else {
943
+			$offset = '+00:00';
944
+		}
888 945
 
889 946
 		if ($globalDBdriver == 'mysql') {
890 947
 			$query  = "SELECT DATE(CONVERT_TZ(tracker_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -934,7 +991,9 @@  discard block
 block discarded – undo
934 991
 			date_default_timezone_set($globalTimezone);
935 992
 			$datetime = new DateTime();
936 993
 			$offset = $datetime->format('P');
937
-		} else $offset = '+00:00';
994
+		} else {
995
+			$offset = '+00:00';
996
+		}
938 997
 		$filter_query = $this->getFilter($filters,true,true);
939 998
 		if ($globalDBdriver == 'mysql') {
940 999
 			$query  = "SELECT DATE(CONVERT_TZ(tracker_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -980,7 +1039,9 @@  discard block
 block discarded – undo
980 1039
 			date_default_timezone_set($globalTimezone);
981 1040
 			$datetime = new DateTime();
982 1041
 			$offset = $datetime->format('P');
983
-		} else $offset = '+00:00';
1042
+		} else {
1043
+			$offset = '+00:00';
1044
+		}
984 1045
 		$filter_query = $this->getFilter($filters,true,true);
985 1046
 		if ($globalDBdriver == 'mysql') {
986 1047
 			$query  = "SELECT DATE(CONVERT_TZ(tracker_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -1028,7 +1089,9 @@  discard block
 block discarded – undo
1028 1089
 			date_default_timezone_set($globalTimezone);
1029 1090
 			$datetime = new DateTime();
1030 1091
 			$offset = $datetime->format('P');
1031
-		} else $offset = '+00:00';
1092
+		} else {
1093
+			$offset = '+00:00';
1094
+		}
1032 1095
 
1033 1096
 		if ($globalDBdriver == 'mysql') {
1034 1097
 			$query  = "SELECT YEAR(CONVERT_TZ(tracker_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(tracker_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count
@@ -1077,7 +1140,9 @@  discard block
 block discarded – undo
1077 1140
 			date_default_timezone_set($globalTimezone);
1078 1141
 			$datetime = new DateTime();
1079 1142
 			$offset = $datetime->format('P');
1080
-		} else $offset = '+00:00';
1143
+		} else {
1144
+			$offset = '+00:00';
1145
+		}
1081 1146
 		$filter_query = $this->getFilter($filters,true,true);
1082 1147
 		if ($globalDBdriver == 'mysql') {
1083 1148
 			$query  = "SELECT MONTH(CONVERT_TZ(tracker_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(tracker_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count
@@ -1126,7 +1191,9 @@  discard block
 block discarded – undo
1126 1191
 			date_default_timezone_set($globalTimezone);
1127 1192
 			$datetime = new DateTime();
1128 1193
 			$offset = $datetime->format('P');
1129
-		} else $offset = '+00:00';
1194
+		} else {
1195
+			$offset = '+00:00';
1196
+		}
1130 1197
 
1131 1198
 		$orderby_sql = '';
1132 1199
 		if ($orderby == "hour")
@@ -1195,7 +1262,9 @@  discard block
 block discarded – undo
1195 1262
 			date_default_timezone_set($globalTimezone);
1196 1263
 			$datetime = new DateTime($date);
1197 1264
 			$offset = $datetime->format('P');
1198
-		} else $offset = '+00:00';
1265
+		} else {
1266
+			$offset = '+00:00';
1267
+		}
1199 1268
 
1200 1269
 		if ($globalDBdriver == 'mysql') {
1201 1270
 			$query  = "SELECT HOUR(CONVERT_TZ(tracker_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1243,7 +1312,9 @@  discard block
 block discarded – undo
1243 1312
 			date_default_timezone_set($globalTimezone);
1244 1313
 			$datetime = new DateTime();
1245 1314
 			$offset = $datetime->format('P');
1246
-		} else $offset = '+00:00';
1315
+		} else {
1316
+			$offset = '+00:00';
1317
+		}
1247 1318
 
1248 1319
 		if ($globalDBdriver == 'mysql') {
1249 1320
 			$query  = "SELECT HOUR(CONVERT_TZ(tracker_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1307,8 +1378,11 @@  discard block
 block discarded – undo
1307 1378
 				$query_values = array_merge($query_values,array(':month' => $month));
1308 1379
 			}
1309 1380
 		}
1310
-		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1311
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1381
+		if (empty($query_values)) {
1382
+			$queryi .= $this->getFilter($filters);
1383
+		} else {
1384
+			$queryi .= $this->getFilter($filters,true,true).substr($query,4);
1385
+		}
1312 1386
 		
1313 1387
 		$sth = $this->db->prepare($queryi);
1314 1388
 		$sth->execute($query_values);
@@ -1330,7 +1404,9 @@  discard block
 block discarded – undo
1330 1404
 			date_default_timezone_set($globalTimezone);
1331 1405
 			$datetime = new DateTime();
1332 1406
 			$offset = $datetime->format('P');
1333
-		} else $offset = '+00:00';
1407
+		} else {
1408
+			$offset = '+00:00';
1409
+		}
1334 1410
 
1335 1411
 		if ($globalDBdriver == 'mysql') {
1336 1412
 			$query  = "SELECT HOUR(CONVERT_TZ(tracker_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1434,7 +1510,9 @@  discard block
 block discarded – undo
1434 1510
 	*/
1435 1511
 	public function parseDirection($direction = 0)
1436 1512
 	{
1437
-		if ($direction == '') $direction = 0;
1513
+		if ($direction == '') {
1514
+			$direction = 0;
1515
+		}
1438 1516
 		$direction_array = array();
1439 1517
 		$temp_array = array();
1440 1518
 
@@ -1523,7 +1601,9 @@  discard block
 block discarded – undo
1523 1601
 		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1524 1602
 	
1525 1603
 		$Connection = new Connection($this->db);
1526
-		if (!$Connection->tableExists('countries')) return '';
1604
+		if (!$Connection->tableExists('countries')) {
1605
+			return '';
1606
+		}
1527 1607
 	
1528 1608
 		try {
1529 1609
 			/*
@@ -1543,9 +1623,13 @@  discard block
 block discarded – undo
1543 1623
 			$sth->closeCursor();
1544 1624
 			if (count($row) > 0) {
1545 1625
 				return $row;
1546
-			} else return '';
1626
+			} else {
1627
+				return '';
1628
+			}
1547 1629
 		} catch (PDOException $e) {
1548
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
1630
+			if (isset($globalDebug) && $globalDebug) {
1631
+				echo 'Error : '.$e->getMessage()."\n";
1632
+			}
1549 1633
 			return '';
1550 1634
 		}
1551 1635
 	
@@ -1563,7 +1647,9 @@  discard block
 block discarded – undo
1563 1647
 		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
1564 1648
 	
1565 1649
 		$Connection = new Connection($this->db);
1566
-		if (!$Connection->tableExists('countries')) return '';
1650
+		if (!$Connection->tableExists('countries')) {
1651
+			return '';
1652
+		}
1567 1653
 	
1568 1654
 		try {
1569 1655
 			$query = "SELECT name,iso2,iso3 FROM countries WHERE iso2 = :iso2 LIMIT 1";
@@ -1575,9 +1661,13 @@  discard block
 block discarded – undo
1575 1661
 			$sth->closeCursor();
1576 1662
 			if (count($row) > 0) {
1577 1663
 				return $row;
1578
-			} else return '';
1664
+			} else {
1665
+				return '';
1666
+			}
1579 1667
 		} catch (PDOException $e) {
1580
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
1668
+			if (isset($globalDebug) && $globalDebug) {
1669
+				echo 'Error : '.$e->getMessage()."\n";
1670
+			}
1581 1671
 			return '';
1582 1672
 		}
1583 1673
 	
@@ -1595,7 +1685,9 @@  discard block
 block discarded – undo
1595 1685
 	{
1596 1686
 		global $globalBitlyAccessToken;
1597 1687
 		
1598
-		if ($globalBitlyAccessToken == '') return $url;
1688
+		if ($globalBitlyAccessToken == '') {
1689
+			return $url;
1690
+		}
1599 1691
         
1600 1692
 		$google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url;
1601 1693
 		
Please login to merge, or discard this patch.
require/class.SpotterImport.php 1 patch
Braces   +331 added lines, -117 removed lines patch added patch discarded remove patch
@@ -53,7 +53,9 @@  discard block
 block discarded – undo
53 53
 	$dbc = $this->db;
54 54
 	$this->all_flights[$id]['schedule_check'] = true;
55 55
 	if ($globalSchedulesFetch) {
56
-	if ($globalDebug) echo 'Getting schedule info...'."\n";
56
+	if ($globalDebug) {
57
+		echo 'Getting schedule info...'."\n";
58
+	}
57 59
 	$Spotter = new Spotter($dbc);
58 60
 	$Schedule = new Schedule($dbc);
59 61
 	$Translation = new Translation($dbc);
@@ -64,7 +66,9 @@  discard block
 block discarded – undo
64 66
 	    if ($Schedule->checkSchedule($operator) == 0) {
65 67
 		$schedule = $Schedule->fetchSchedule($operator);
66 68
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
67
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
69
+		    if ($globalDebug) {
70
+		    	echo "-> Schedule info for ".$operator." (".$ident.")\n";
71
+		    }
68 72
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
69 73
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
70 74
 		    // Should also check if route schedule = route from DB
@@ -73,7 +77,9 @@  discard block
 block discarded – undo
73 77
 			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
74 78
 			    if (trim($airport_icao) != '') {
75 79
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
76
-				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
80
+				if ($globalDebug) {
81
+					echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
82
+				}
77 83
 			    }
78 84
 			}
79 85
 		    }
@@ -82,17 +88,25 @@  discard block
 block discarded – undo
82 88
 			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
83 89
 			    if (trim($airport_icao) != '') {
84 90
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
85
-				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
91
+				if ($globalDebug) {
92
+					echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
93
+				}
86 94
 			    }
87 95
 			}
88 96
 		    }
89 97
 		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
90 98
 		}
91
-	    } else $scheduleexist = true;
92
-	} else $scheduleexist = true;
99
+	    } else {
100
+	    	$scheduleexist = true;
101
+	    }
102
+	} else {
103
+		$scheduleexist = true;
104
+	}
93 105
 	// close connection, at least one way will work ?
94 106
        if ($scheduleexist) {
95
-		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
107
+		if ($globalDebug) {
108
+			echo "-> get arrival/departure airport info for ".$ident."\n";
109
+		}
96 110
     		$sch = $Schedule->getSchedule($operator);
97 111
 		$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']));
98 112
        }
@@ -114,7 +128,9 @@  discard block
 block discarded – undo
114 128
 
115 129
     public function checkAll() {
116 130
 	global $globalDebug;
117
-	if ($globalDebug) echo "Update last seen flights data...\n";
131
+	if ($globalDebug) {
132
+		echo "Update last seen flights data...\n";
133
+	}
118 134
 	foreach ($this->all_flights as $key => $flight) {
119 135
 	    if (isset($this->all_flights[$key]['id'])) {
120 136
 		//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
@@ -127,24 +143,32 @@  discard block
 block discarded – undo
127 143
 
128 144
     public function arrival($key) {
129 145
 	global $globalClosestMinDist, $globalDebug;
130
-	if ($globalDebug) echo 'Update arrival...'."\n";
146
+	if ($globalDebug) {
147
+		echo 'Update arrival...'."\n";
148
+	}
131 149
 	$Spotter = new Spotter($this->db);
132 150
         $airport_icao = '';
133 151
         $airport_time = '';
134
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
152
+        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') {
153
+        	$globalClosestMinDist = 50;
154
+        }
135 155
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
136 156
 	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
137 157
     	    if (isset($closestAirports[0])) {
138 158
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
139 159
         	    $airport_icao = $closestAirports[0]['icao'];
140 160
         	    $airport_time = $this->all_flights[$key]['datetime'];
141
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
161
+        	    if ($globalDebug) {
162
+        	    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
163
+        	    }
142 164
         	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
143 165
         	    foreach ($closestAirports as $airport) {
144 166
         		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
145 167
         		    $airport_icao = $airport['icao'];
146 168
         		    $airport_time = $this->all_flights[$key]['datetime'];
147
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
169
+        		    if ($globalDebug) {
170
+        		    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
171
+        		    }
148 172
         		    break;
149 173
         		}
150 174
         	    }
@@ -152,14 +176,20 @@  discard block
 block discarded – undo
152 176
         		$airport_icao = $closestAirports[0]['icao'];
153 177
         		$airport_time = $this->all_flights[$key]['datetime'];
154 178
         	} else {
155
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
179
+        		if ($globalDebug) {
180
+        			echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
181
+        		}
156 182
         	}
157 183
     	    } else {
158
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
184
+    		    if ($globalDebug) {
185
+    		    	echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
186
+    		    }
159 187
     	    }
160 188
 
161 189
         } else {
162
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
190
+        	if ($globalDebug) {
191
+        		echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
192
+        	}
163 193
         }
164 194
         return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
165 195
     }
@@ -169,12 +199,16 @@  discard block
 block discarded – undo
169 199
     public function del() {
170 200
 	global $globalDebug;
171 201
 	// Delete old infos
172
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
202
+	if ($globalDebug) {
203
+		echo 'Delete old values and update latest data...'."\n";
204
+	}
173 205
 	foreach ($this->all_flights as $key => $flight) {
174 206
     	    if (isset($flight['lastupdate'])) {
175 207
         	if ($flight['lastupdate'] < (time()-3000)) {
176 208
             	    if (isset($this->all_flights[$key]['id'])) {
177
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
209
+            		if ($globalDebug) {
210
+            			echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
211
+            		}
178 212
 			/*
179 213
 			$SpotterLive = new SpotterLive();
180 214
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
@@ -184,7 +218,9 @@  discard block
 block discarded – undo
184 218
             		$Spotter = new Spotter($this->db);
185 219
             		if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
186 220
 				$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']);
187
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
221
+				if ($globalDebug && $result != 'success') {
222
+					echo '!!! ERROR : '.$result."\n";
223
+				}
188 224
 			}
189 225
 			// Put in archive
190 226
 //			$Spotter->db = null;
@@ -198,8 +234,10 @@  discard block
 block discarded – undo
198 234
     public function add($line) {
199 235
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights;
200 236
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
201
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
202
-/*
237
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
238
+		$globalCoordMinChange = '0.02';
239
+	}
240
+	/*
203 241
 	$Spotter = new Spotter();
204 242
 	$dbc = $Spotter->db;
205 243
 	$SpotterLive = new SpotterLive($dbc);
@@ -227,11 +265,15 @@  discard block
 block discarded – undo
227 265
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
228 266
 		    $current_date = date('Y-m-d');
229 267
 		    $source = $line['source_name'];
230
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
268
+		    if ($source == '' || $line['format_source'] == 'aprs') {
269
+		    	$source = $line['format_source'];
270
+		    }
231 271
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
232 272
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
233 273
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
234
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
274
+		    } else {
275
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
276
+		    }
235 277
 		}
236 278
 		
237 279
 		/*
@@ -247,8 +289,11 @@  discard block
 block discarded – undo
247 289
 		//$this->db = $dbc;
248 290
 
249 291
 		//$hex = trim($line['hex']);
250
-	        if (!isset($line['id'])) $id = trim($line['hex']);
251
-	        else $id = trim($line['id']);
292
+	        if (!isset($line['id'])) {
293
+	        	$id = trim($line['hex']);
294
+	        } else {
295
+	        	$id = trim($line['id']);
296
+	        }
252 297
 		
253 298
 		if (!isset($this->all_flights[$id])) {
254 299
 		    $this->all_flights[$id] = array();
@@ -256,13 +301,21 @@  discard block
 block discarded – undo
256 301
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
257 302
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
258 303
 		    if (!isset($line['id'])) {
259
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
260
-//			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')));
304
+			if (!isset($globalDaemon)) {
305
+				$globalDaemon = TRUE;
306
+			}
307
+			//			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')));
261 308
 //			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')));
262
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
309
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
310
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
311
+			}
263 312
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
264
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
265
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
313
+		     } else {
314
+		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
315
+		     }
316
+		    if ($globalAllFlights !== FALSE) {
317
+		    	$dataFound = true;
318
+		    }
266 319
 		}
267 320
 		if (isset($line['source_type']) && $line['source_type'] != '') {
268 321
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
@@ -283,11 +336,19 @@  discard block
 block discarded – undo
283 336
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
284 337
 			}
285 338
 			$Spotter->db = null;
286
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
287
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
339
+			if ($globalDebugTimeElapsed) {
340
+				echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
341
+			}
342
+			if ($aircraft_icao != '') {
343
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
344
+			}
345
+		    }
346
+		    if ($globalAllFlights !== FALSE) {
347
+		    	$dataFound = true;
348
+		    }
349
+		    if ($globalDebug) {
350
+		    	echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
288 351
 		    }
289
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
290
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
291 352
 		}
292 353
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
293 354
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
@@ -297,14 +358,23 @@  discard block
 block discarded – undo
297 358
 			$Spotter = new Spotter($this->db);
298 359
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
299 360
 			$Spotter->db = null;
300
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
361
+			if ($aircraft_icao != '') {
362
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
363
+			}
301 364
 		}
302 365
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
303
-			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
304
-			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
305
-			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
306
-			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
307
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
366
+			if ($line['aircraft_type'] == 'PARA_GLIDER') {
367
+				$aircraft_icao = 'GLID';
368
+			} elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') {
369
+				$aircraft_icao = 'UHEL';
370
+			} elseif ($line['aircraft_type'] == 'TOW_PLANE') {
371
+				$aircraft_icao = 'TOWPLANE';
372
+			} elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') {
373
+				$aircraft_icao = 'POWAIRC';
374
+			}
375
+			if (isset($aircraft_icao)) {
376
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
377
+			}
308 378
 		}
309 379
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
310 380
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
@@ -314,8 +384,11 @@  discard block
 block discarded – undo
314 384
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
315 385
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
316 386
 		    } else {
317
-				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";
318
-				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";
387
+				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
388
+					echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
389
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
390
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
391
+				}
319 392
 				/*
320 393
 				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
321 394
 				print_r($this->all_flights[$id]);
@@ -347,15 +420,25 @@  discard block
 block discarded – undo
347 420
 			$timeelapsed = microtime(true);
348 421
             		$Spotter = new Spotter($this->db);
349 422
             		$fromsource = NULL;
350
-            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
351
-            		elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
352
-			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
353
-			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
354
-			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
423
+            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') {
424
+            			$fromsource = $globalAirlinesSource;
425
+            		} elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') {
426
+            			$fromsource = 'vatsim';
427
+            		} elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') {
428
+				$fromsource = 'ivao';
429
+			} elseif (isset($globalVATSIM) && $globalVATSIM) {
430
+				$fromsource = 'vatsim';
431
+			} elseif (isset($globalIVAO) && $globalIVAO) {
432
+				$fromsource = 'ivao';
433
+			}
355 434
             		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
356
-			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
435
+			if ($globalDebug && $result != 'success') {
436
+				echo '!!! ERROR : '.$result."\n";
437
+			}
357 438
 			$Spotter->db = null;
358
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
439
+			if ($globalDebugTimeElapsed) {
440
+				echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
441
+			}
359 442
 		    }
360 443
 
361 444
 /*
@@ -366,7 +449,9 @@  discard block
 block discarded – undo
366 449
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
367 450
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
368 451
   */
369
-		    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']));
452
+		    if (!isset($this->all_flights[$id]['id'])) {
453
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
454
+		    }
370 455
 
371 456
 		    //$putinarchive = true;
372 457
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
@@ -383,7 +468,9 @@  discard block
 block discarded – undo
383 468
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
384 469
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
385 470
 		    		$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' => ''));
386
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
471
+				if ($globalDebugTimeElapsed) {
472
+					echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
473
+				}
387 474
 
388 475
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
389 476
 			$timeelapsed = microtime(true);
@@ -396,7 +483,9 @@  discard block
 block discarded – undo
396 483
 				$Translation->db = null;
397 484
 			}
398 485
 			$Spotter->db = null;
399
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
486
+			if ($globalDebugTimeElapsed) {
487
+				echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
488
+			}
400 489
 
401 490
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
402 491
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
@@ -405,9 +494,13 @@  discard block
 block discarded – undo
405 494
 		    		$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']));
406 495
 		    	    }
407 496
 			}
408
-			if (!isset($globalFork)) $globalFork = TRUE;
497
+			if (!isset($globalFork)) {
498
+				$globalFork = TRUE;
499
+			}
409 500
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
410
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
501
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) {
502
+					$this->get_Schedule($id,trim($line['ident']));
503
+				}
411 504
 			}
412 505
 		    }
413 506
 		}
@@ -423,16 +516,23 @@  discard block
 block discarded – undo
423 516
 		    // use datetime
424 517
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
425 518
 			$speed = $speed*3.6;
426
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
427
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
519
+			if ($speed < 1000) {
520
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
521
+			}
522
+  			if ($globalDebug) {
523
+  				echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
524
+  			}
428 525
 		    }
429 526
 		}
430 527
 
431 528
 
432 529
 
433 530
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
434
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
435
-	    	    else unset($timediff);
531
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) {
532
+	    	    	$timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
533
+	    	    } else {
534
+	    	    	unset($timediff);
535
+	    	    }
436 536
 	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
437 537
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
438 538
 			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
@@ -440,21 +540,31 @@  discard block
 block discarded – undo
440 540
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
441 541
 				$this->all_flights[$id]['putinarchive'] = true;
442 542
 				
443
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
543
+				if ($globalDebug) {
544
+					echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
545
+				}
444 546
 				$timeelapsed = microtime(true);
445 547
 				$Spotter = new Spotter($this->db);
446 548
 				$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
447
-				if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
549
+				if (!empty($all_country)) {
550
+					$this->all_flights[$id]['over_country'] = $all_country['iso2'];
551
+				}
448 552
 				$Spotter->db = null;
449
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
553
+				if ($globalDebugTimeElapsed) {
554
+					echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
555
+				}
450 556
 				$this->tmd = 0;
451
-				if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
557
+				if ($globalDebug) {
558
+					echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
559
+				}
452 560
 			    }
453 561
 			}
454 562
 
455 563
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
456 564
 			    //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) {
457
-				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
565
+				if (!isset($this->all_flights[$id]['archive_latitude'])) {
566
+					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
567
+				}
458 568
 				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') {
459 569
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
460 570
 				    $dataFound = true;
@@ -476,9 +586,13 @@  discard block
 block discarded – undo
476 586
 			    */
477 587
 			}
478 588
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
479
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
589
+			    if ($line['longitude'] > 180) {
590
+			    	$line['longitude'] = $line['longitude'] - 360;
591
+			    }
480 592
 			    //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) {
481
-				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
593
+				if (!isset($this->all_flights[$id]['archive_longitude'])) {
594
+					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
595
+				}
482 596
 				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') {
483 597
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
484 598
 				    $dataFound = true;
@@ -509,7 +623,9 @@  discard block
 block discarded – undo
509 623
 		    }
510 624
 		}
511 625
 		if (isset($line['last_update']) && $line['last_update'] != '') {
512
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
626
+		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) {
627
+		    	$dataFound = true;
628
+		    }
513 629
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
514 630
 		}
515 631
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
@@ -531,40 +647,60 @@  discard block
 block discarded – undo
531 647
 			// Here we force archive of flight because after ground it's a new one (or should be)
532 648
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
533 649
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
534
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
535
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
536
-			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']));
650
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) {
651
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
652
+			} elseif (isset($line['id'])) {
653
+		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
654
+		        } elseif (isset($this->all_flights[$id]['ident'])) {
655
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
656
+			}
657
+		    }
658
+		    if ($line['ground'] != 1) {
659
+		    	$line['ground'] = 0;
537 660
 		    }
538
-		    if ($line['ground'] != 1) $line['ground'] = 0;
539 661
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
540 662
 		    //$dataFound = true;
541 663
 		}
542 664
 		if (isset($line['squawk']) && $line['squawk'] != '') {
543 665
 		    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'])) {
544
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
666
+			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) {
667
+			    	$this->all_flights[$id]['putinarchive'] = true;
668
+			    }
545 669
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
546 670
 			    $highlight = '';
547
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
548
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
549
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
671
+			    if ($this->all_flights[$id]['squawk'] == '7500') {
672
+			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
673
+			    }
674
+			    if ($this->all_flights[$id]['squawk'] == '7600') {
675
+			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
676
+			    }
677
+			    if ($this->all_flights[$id]['squawk'] == '7700') {
678
+			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
679
+			    }
550 680
 			    if ($highlight != '') {
551 681
 				$timeelapsed = microtime(true);
552 682
 				$Spotter = new Spotter($this->db);
553 683
 				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
554 684
 				$Spotter->db = null;
555
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
685
+				if ($globalDebugTimeElapsed) {
686
+					echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
687
+				}
556 688
 
557 689
 				//$putinarchive = true;
558 690
 				//$highlight = '';
559 691
 			    }
560 692
 			    
561
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
693
+		    } else {
694
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
695
+		    }
562 696
 		    //$dataFound = true;
563 697
 		}
564 698
 
565 699
 		if (isset($line['altitude']) && $line['altitude'] != '') {
566 700
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
567
-			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;
701
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) {
702
+				$this->all_flights[$id]['putinarchive'] = true;
703
+			}
568 704
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
569 705
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
570 706
 			//$dataFound = true;
@@ -576,21 +712,30 @@  discard block
 block discarded – undo
576 712
 		}
577 713
 		
578 714
 		if (isset($line['heading']) && $line['heading'] != '') {
579
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
715
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) {
716
+		    	$this->all_flights[$id]['putinarchive'] = true;
717
+		    }
580 718
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
581 719
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
582 720
 		    //$dataFound = true;
583 721
   		} 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']) {
584 722
   		    $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']);
585 723
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
586
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
587
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
724
+		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) {
725
+		    	$this->all_flights[$id]['putinarchive'] = true;
726
+		    }
727
+  		    if ($globalDebug) {
728
+  		    	echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
729
+  		    }
588 730
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
589 731
   		    // If not enough messages and ACARS set heading to 0
590 732
   		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
591 733
   		}
592
-		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
593
-		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
734
+		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) {
735
+			$dataFound = false;
736
+		} elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) {
737
+			$dataFound = false;
738
+		}
594 739
 
595 740
 //		print_r($this->all_flights[$id]);
596 741
 		//gets the callsign from the last hour
@@ -605,23 +750,36 @@  discard block
 block discarded – undo
605 750
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
606 751
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
607 752
 			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
608
-				if ($globalDebug) echo "Check if aircraft is already in DB...";
753
+				if ($globalDebug) {
754
+					echo "Check if aircraft is already in DB...";
755
+				}
609 756
 				$timeelapsed = microtime(true);
610 757
 				$SpotterLive = new SpotterLive($this->db);
611 758
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
612 759
 				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
613
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
760
+				    if ($globalDebugTimeElapsed) {
761
+				    	echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
762
+				    }
614 763
 				} elseif (isset($line['id'])) {
615 764
 				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
616
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
765
+				    if ($globalDebugTimeElapsed) {
766
+				    	echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
767
+				    }
617 768
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
618 769
 				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
619
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
620
-				} else $recent_ident = '';
770
+				    if ($globalDebugTimeElapsed) {
771
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
772
+				    }
773
+				} else {
774
+					$recent_ident = '';
775
+				}
621 776
 				$SpotterLive->db=null;
622 777
 
623
-				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
624
-				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
778
+				if ($globalDebug && $recent_ident == '') {
779
+					echo " Not in DB.\n";
780
+				} elseif ($globalDebug && $recent_ident != '') {
781
+					echo " Already in DB.\n";
782
+				}
625 783
 			    } else {
626 784
 				$recent_ident = '';
627 785
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
@@ -629,7 +787,9 @@  discard block
 block discarded – undo
629 787
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
630 788
 			    if($recent_ident == "")
631 789
 			    {
632
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
790
+				if ($globalDebug) {
791
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
792
+				}
633 793
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
634 794
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
635 795
 				//adds the spotter data for the archive
@@ -673,26 +833,44 @@  discard block
 block discarded – undo
673 833
 				
674 834
 				if (!$ignoreImport) {
675 835
 				    $highlight = '';
676
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
677
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
678
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
679
-				    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')));
836
+				    if ($this->all_flights[$id]['squawk'] == '7500') {
837
+				    	$highlight = 'Squawk 7500 : Hijack';
838
+				    }
839
+				    if ($this->all_flights[$id]['squawk'] == '7600') {
840
+				    	$highlight = 'Squawk 7600 : Lost Comm (radio failure)';
841
+				    }
842
+				    if ($this->all_flights[$id]['squawk'] == '7700') {
843
+				    	$highlight = 'Squawk 7700 : Emergency';
844
+				    }
845
+				    if (!isset($this->all_flights[$id]['id'])) {
846
+				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
847
+				    }
680 848
 				    $timeelapsed = microtime(true);
681 849
 				    $Spotter = new Spotter($this->db);
682 850
 				    $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]['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']);
683 851
 				    $Spotter->db = null;
684
-				    if ($globalDebug && isset($result)) echo $result."\n";
685
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
852
+				    if ($globalDebug && isset($result)) {
853
+				    	echo $result."\n";
854
+				    }
855
+				    if ($globalDebugTimeElapsed) {
856
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
857
+				    }
686 858
 				    
687 859
 				    // Add source stat in DB
688 860
 				    $Stats = new Stats($this->db);
689 861
 				    if (!empty($this->stats)) {
690
-					if ($globalDebug) echo 'Add source stats : ';
862
+					if ($globalDebug) {
863
+						echo 'Add source stats : ';
864
+					}
691 865
 				        foreach($this->stats as $date => $data) {
692 866
 					    foreach($data as $source => $sourced) {
693 867
 					        //print_r($sourced);
694
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
695
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
868
+				    	        if (isset($sourced['polar'])) {
869
+				    	        	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
870
+				    	        }
871
+				    	        if (isset($sourced['hist'])) {
872
+				    	        	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
873
+				    	        }
696 874
 				    		if (isset($sourced['msg'])) {
697 875
 				    		    if (time() - $sourced['msg']['date'] > 10) {
698 876
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -705,13 +883,17 @@  discard block
 block discarded – undo
705 883
 			    			unset($this->stats[$date]);
706 884
 			    		    }
707 885
 				    	}
708
-				    	if ($globalDebug) echo 'Done'."\n";
886
+				    	if ($globalDebug) {
887
+				    		echo 'Done'."\n";
888
+				    	}
709 889
 
710 890
 				    }
711 891
 				    $Stats->db = null;
712 892
 				    
713 893
 				    $this->del();
714
-				} elseif ($globalDebug) echo 'Ignore data'."\n";
894
+				} elseif ($globalDebug) {
895
+					echo 'Ignore data'."\n";
896
+				}
715 897
 				//$ignoreImport = false;
716 898
 				$this->all_flights[$id]['addedSpotter'] = 1;
717 899
 				//print_r($this->all_flights[$id]);
@@ -728,12 +910,16 @@  discard block
 block discarded – undo
728 910
 			*/
729 911
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
730 912
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
731
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
913
+				    if ($globalDebug) {
914
+				    	echo "---- Deleting Live Spotter data older than 9 hours...";
915
+				    }
732 916
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
733 917
 				    $SpotterLive = new SpotterLive($this->db);
734 918
 				    $SpotterLive->deleteLiveSpotterData();
735 919
 				    $SpotterLive->db=null;
736
-				    if ($globalDebug) echo " Done\n";
920
+				    if ($globalDebug) {
921
+				    	echo " Done\n";
922
+				    }
737 923
 				    $this->last_delete = time();
738 924
 				}
739 925
 			    } else {
@@ -756,11 +942,17 @@  discard block
 block discarded – undo
756 942
 		    //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";
757 943
 		    if ($globalDebug) {
758 944
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
759
-				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";
760
-				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";
945
+				if (isset($this->all_flights[$id]['source_name'])) {
946
+					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";
947
+				} else {
948
+					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";
949
+				}
761 950
 			} else {
762
-				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";
763
-				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";
951
+				if (isset($this->all_flights[$id]['source_name'])) {
952
+					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";
953
+				} else {
954
+					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";
955
+				}
764 956
 			}
765 957
 		    }
766 958
 		    $ignoreImport = false;
@@ -806,20 +998,26 @@  discard block
 block discarded – undo
806 998
 
807 999
 		    if (!$ignoreImport) {
808 1000
 			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'])) {
809
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1001
+				if ($globalDebug) {
1002
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1003
+				}
810 1004
 				$timeelapsed = microtime(true);
811 1005
 				$SpotterLive = new SpotterLive($this->db);
812 1006
 				$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]['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']);
813 1007
 				$SpotterLive->db = null;
814 1008
 				$this->all_flights[$id]['putinarchive'] = false;
815
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1009
+				if ($globalDebugTimeElapsed) {
1010
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1011
+				}
816 1012
 
817 1013
 				// Put statistics in $this->stats variable
818 1014
 				//if ($line['format_source'] != 'aprs') {
819 1015
 				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
820 1016
 				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
821 1017
 					$source = $this->all_flights[$id]['source_name'];
822
-					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1018
+					if ($source == '') {
1019
+						$source = $this->all_flights[$id]['format_source'];
1020
+					}
823 1021
 					if (!isset($this->source_location[$source])) {
824 1022
 						$Location = new Source();
825 1023
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -840,7 +1038,9 @@  discard block
 block discarded – undo
840 1038
 					$stats_heading = round($stats_heading/22.5);
841 1039
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
842 1040
 					$current_date = date('Y-m-d');
843
-					if ($stats_heading == 16) $stats_heading = 0;
1041
+					if ($stats_heading == 16) {
1042
+						$stats_heading = 0;
1043
+					}
844 1044
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
845 1045
 						for ($i=0;$i<=15;$i++) {
846 1046
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -858,7 +1058,9 @@  discard block
 block discarded – undo
858 1058
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
859 1059
 						    end($this->stats[$current_date][$source]['hist']);
860 1060
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
861
-						} else $mini = 0;
1061
+						} else {
1062
+							$mini = 0;
1063
+						}
862 1064
 						for ($i=$mini;$i<=$distance;$i+=10) {
863 1065
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
864 1066
 						}
@@ -869,20 +1071,30 @@  discard block
 block discarded – undo
869 1071
 				}
870 1072
 
871 1073
 				$this->all_flights[$id]['lastupdate'] = time();
872
-				if ($this->all_flights[$id]['putinarchive']) $send = true;
1074
+				if ($this->all_flights[$id]['putinarchive']) {
1075
+					$send = true;
1076
+				}
873 1077
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
874
-				if ($globalDebug) echo $result."\n";
875
-			} 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";
1078
+				if ($globalDebug) {
1079
+					echo $result."\n";
1080
+				}
1081
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
1082
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1083
+			}
876 1084
 			//$this->del();
877 1085
 			
878 1086
 			
879 1087
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
880
-			    if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1088
+			    if ($globalDebug) {
1089
+			    	echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1090
+			    }
881 1091
 			    $SpotterLive = new SpotterLive($this->db);
882 1092
 			    $SpotterLive->deleteLiveSpotterDataNotUpdated();
883 1093
 			    $SpotterLive->db = null;
884 1094
 			    //SpotterLive->deleteLiveSpotterData();
885
-			    if ($globalDebug) echo " Done\n";
1095
+			    if ($globalDebug) {
1096
+			    	echo " Done\n";
1097
+			    }
886 1098
 			    $this->last_delete_hourly = time();
887 1099
 			}
888 1100
 			
@@ -890,7 +1102,9 @@  discard block
 block discarded – undo
890 1102
 		    //$ignoreImport = false;
891 1103
 		}
892 1104
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
893
-		if ($send) return $this->all_flights[$id];
1105
+		if ($send) {
1106
+			return $this->all_flights[$id];
1107
+		}
894 1108
 	    }
895 1109
 	}
896 1110
     }
Please login to merge, or discard this patch.
require/class.TrackerLive.php 1 patch
Braces   +59 added lines, -20 removed lines patch added patch discarded remove patch
@@ -29,7 +29,9 @@  discard block
 block discarded – undo
29 29
 		if (isset($filter[0]['source'])) {
30 30
 			$filters = array_merge($filters,$filter);
31 31
 		}
32
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
32
+		if (is_array($globalFilter)) {
33
+			$filter = array_merge($filter,$globalFilter);
34
+		}
33 35
 		$filter_query_join = '';
34 36
 		$filter_query_where = '';
35 37
 		foreach($filters as $flt) {
@@ -76,8 +78,11 @@  discard block
 block discarded – undo
76 78
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
77 79
 			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
78 80
 		}
79
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
80
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
81
+		if ($filter_query_where == '' && $where) {
82
+			$filter_query_where = ' WHERE';
83
+		} elseif ($filter_query_where != '' && $and) {
84
+			$filter_query_where .= ' AND';
85
+		}
81 86
 		if ($filter_query_where != '') {
82 87
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
83 88
 		}
@@ -119,7 +124,9 @@  discard block
 block discarded – undo
119 124
 			}
120 125
 		}
121 126
 
122
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
127
+		if (!isset($globalLiveInterval)) {
128
+			$globalLiveInterval = '200';
129
+		}
123 130
 		if ($globalDBdriver == 'mysql') {
124 131
 			//$query  = "SELECT tracker_live.* FROM tracker_live INNER JOIN (SELECT l.famtrackid, max(l.date) as maxdate FROM tracker_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.famtrackid) s on tracker_live.famtrackid = s.famtrackid AND tracker_live.date = s.maxdate";
125 132
 			$query  = 'SELECT tracker_live.* FROM tracker_live INNER JOIN (SELECT l.famtrackid, max(l.date) as maxdate FROM tracker_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.famtrackid) s on tracker_live.famtrackid = s.famtrackid AND tracker_live.date = s.maxdate'.$filter_query.$orderby_query;
@@ -144,7 +151,9 @@  discard block
 block discarded – undo
144 151
 
145 152
 		$filter_query = $this->getFilter($filter,true,true);
146 153
 
147
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
154
+		if (!isset($globalLiveInterval)) {
155
+			$globalLiveInterval = '200';
156
+		}
148 157
 		if ($globalDBdriver == 'mysql') {
149 158
 			$query  = 'SELECT tracker_live.ident, tracker_live.type,tracker_live.famtrackid, tracker_live.latitude, tracker_live.longitude, tracker_live.altitude, tracker_live.heading, tracker_live.ground_speed, tracker_live.date, tracker_live.format_source 
150 159
 			FROM tracker_live INNER JOIN (SELECT l.famtrackid, max(l.date) as maxdate FROM tracker_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.famtrackid) s on tracker_live.famtrackid = s.famtrackid AND tracker_live.date = s.maxdate'.$filter_query." tracker_live.latitude <> 0 AND tracker_live.longitude <> 0";
@@ -182,7 +191,9 @@  discard block
 block discarded – undo
182 191
 
183 192
 		$filter_query = $this->getFilter($filter,true,true);
184 193
 
185
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
194
+		if (!isset($globalLiveInterval)) {
195
+			$globalLiveInterval = '200';
196
+		}
186 197
 		if ($globalDBdriver == 'mysql') {
187 198
 			$query  = 'SELECT tracker_live.ident, tracker_live.famtrackid,tracker_live.type, tracker_live.latitude, tracker_live.longitude, tracker_live.altitude, tracker_live.heading, tracker_live.ground_speed, tracker_live.date, tracker_live.format_source 
188 199
 			FROM tracker_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= tracker_live.date AND tracker_live.latitude <> '0' AND tracker_live.longitude <> '0' 
@@ -215,7 +226,9 @@  discard block
 block discarded – undo
215 226
 		global $globalDBdriver, $globalLiveInterval;
216 227
 		$filter_query = $this->getFilter($filter,true,true);
217 228
 
218
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
229
+		if (!isset($globalLiveInterval)) {
230
+			$globalLiveInterval = '200';
231
+		}
219 232
 		if ($globalDBdriver == 'mysql') {
220 233
 			$query = 'SELECT COUNT(DISTINCT tracker_live.famtrackid) as nb FROM tracker_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
221 234
 		} else {
@@ -243,7 +256,9 @@  discard block
 block discarded – undo
243 256
 	{
244 257
 		global $globalDBdriver, $globalLiveInterval;
245 258
 		$Spotter = new Spotter($this->db);
246
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
259
+		if (!isset($globalLiveInterval)) {
260
+			$globalLiveInterval = '200';
261
+		}
247 262
 		$filter_query = $this->getFilter($filter);
248 263
 
249 264
 		if (is_array($coord)) {
@@ -251,7 +266,9 @@  discard block
 block discarded – undo
251 266
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
252 267
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
253 268
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
254
-		} else return array();
269
+		} else {
270
+			return array();
271
+		}
255 272
 		if ($globalDBdriver == 'mysql') {
256 273
 			$query  = 'SELECT tracker_live.* FROM tracker_live INNER JOIN (SELECT l.famtrackid, max(l.date) as maxdate FROM tracker_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.famtrackid) s on tracker_live.famtrackid = s.famtrackid AND tracker_live.date = s.maxdate AND tracker_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND tracker_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY tracker_live.famtrackid'.$filter_query;
257 274
 		} else {
@@ -441,11 +458,15 @@  discard block
 block discarded – undo
441 458
 		//$query  = self::$global_query.' WHERE tracker_live.famtrackid = :id ORDER BY date';
442 459
 		if ($globalDBdriver == 'mysql') {
443 460
 			$query = 'SELECT tracker_live.* FROM tracker_live WHERE tracker_live.famtrackid = :id';
444
-			if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
461
+			if ($liveinterval) {
462
+				$query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
463
+			}
445 464
 			$query .= ' ORDER BY date';
446 465
 		} else {
447 466
 			$query = 'SELECT tracker_live.* FROM tracker_live WHERE tracker_live.famtrackid = :id';
448
-			if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
467
+			if ($liveinterval) {
468
+				$query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
469
+			}
449 470
 			$query .= ' ORDER BY date';
450 471
 		}
451 472
 
@@ -540,7 +561,9 @@  discard block
 block discarded – undo
540 561
 				$i++;
541 562
 				$j++;
542 563
 				if ($j == 30) {
543
-					if ($globalDebug) echo ".";
564
+					if ($globalDebug) {
565
+						echo ".";
566
+					}
544 567
 				    	try {
545 568
 						
546 569
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
@@ -787,7 +810,9 @@  discard block
 block discarded – undo
787 810
 			{
788 811
 				return false;
789 812
 			}
790
-		} else return '';
813
+		} else {
814
+			return '';
815
+		}
791 816
 
792 817
 		if ($longitude != '')
793 818
 		{
@@ -795,7 +820,9 @@  discard block
 block discarded – undo
795 820
 			{
796 821
 				return false;
797 822
 			}
798
-		} else return '';
823
+		} else {
824
+			return '';
825
+		}
799 826
 
800 827
 		if ($altitude != '')
801 828
 		{
@@ -803,7 +830,9 @@  discard block
 block discarded – undo
803 830
 			{
804 831
 				return false;
805 832
 			}
806
-		} else $altitude = 0;
833
+		} else {
834
+			$altitude = 0;
835
+		}
807 836
 
808 837
 		if ($heading != '')
809 838
 		{
@@ -811,7 +840,9 @@  discard block
 block discarded – undo
811 840
 			{
812 841
 				return false;
813 842
 			}
814
-		} else $heading = 0;
843
+		} else {
844
+			$heading = 0;
845
+		}
815 846
 
816 847
 		if ($groundspeed != '')
817 848
 		{
@@ -819,9 +850,13 @@  discard block
 block discarded – undo
819 850
 			{
820 851
 				return false;
821 852
 			}
822
-		} else $groundspeed = 0;
853
+		} else {
854
+			$groundspeed = 0;
855
+		}
823 856
 		date_default_timezone_set('UTC');
824
-		if ($date == '') $date = date("Y-m-d H:i:s", time());
857
+		if ($date == '') {
858
+			$date = date("Y-m-d H:i:s", time());
859
+		}
825 860
 
826 861
         
827 862
 		$famtrackid = filter_var($famtrackid,FILTER_SANITIZE_STRING);
@@ -837,8 +872,12 @@  discard block
 block discarded – undo
837 872
 		$comment = filter_var($comment,FILTER_SANITIZE_STRING);
838 873
 		$type = filter_var($type,FILTER_SANITIZE_STRING);
839 874
 
840
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
841
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
875
+            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) {
876
+            		$groundspeed = 0;
877
+            	}
878
+            	if ($heading == '' || $Common->isInteger($heading) === false ) {
879
+            		$heading = 0;
880
+            	}
842 881
             	
843 882
 		$query  = 'INSERT INTO tracker_live (famtrackid, ident, latitude, longitude, altitude, heading, ground_speed, date, format_source, source_name, over_country, comment, type) 
844 883
 		VALUES (:famtrackid,:ident,:latitude,:longitude,:altitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:comment,:type)';
Please login to merge, or discard this patch.
require/class.MarineLive.php 1 patch
Braces   +56 added lines, -19 removed lines patch added patch discarded remove patch
@@ -29,7 +29,9 @@  discard block
 block discarded – undo
29 29
 		if (isset($filter[0]['source'])) {
30 30
 			$filters = array_merge($filters,$filter);
31 31
 		}
32
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
32
+		if (is_array($globalFilter)) {
33
+			$filter = array_merge($filter,$globalFilter);
34
+		}
33 35
 		$filter_query_join = '';
34 36
 		$filter_query_where = '';
35 37
 		foreach($filters as $flt) {
@@ -76,8 +78,11 @@  discard block
 block discarded – undo
76 78
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
77 79
 			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
78 80
 		}
79
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
80
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
81
+		if ($filter_query_where == '' && $where) {
82
+			$filter_query_where = ' WHERE';
83
+		} elseif ($filter_query_where != '' && $and) {
84
+			$filter_query_where .= ' AND';
85
+		}
81 86
 		if ($filter_query_where != '') {
82 87
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
83 88
 		}
@@ -119,7 +124,9 @@  discard block
 block discarded – undo
119 124
 			}
120 125
 		}
121 126
 
122
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
127
+		if (!isset($globalLiveInterval)) {
128
+			$globalLiveInterval = '200';
129
+		}
123 130
 		if ($globalDBdriver == 'mysql') {
124 131
 			//$query  = "SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate";
125 132
 			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate'.$filter_query.$orderby_query;
@@ -144,7 +151,9 @@  discard block
 block discarded – undo
144 151
 
145 152
 		$filter_query = $this->getFilter($filter,true,true);
146 153
 
147
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
154
+		if (!isset($globalLiveInterval)) {
155
+			$globalLiveInterval = '200';
156
+		}
148 157
 		if ($globalDBdriver == 'mysql') {
149 158
 			$query  = 'SELECT marine_live.mmsi, marine_live.ident, marine_live.type,marine_live.fammarine_id, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
150 159
 			FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate'.$filter_query." marine_live.latitude <> 0 AND marine_live.longitude <> 0";
@@ -178,7 +187,9 @@  discard block
 block discarded – undo
178 187
 
179 188
 		$filter_query = $this->getFilter($filter,true,true);
180 189
 
181
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
190
+		if (!isset($globalLiveInterval)) {
191
+			$globalLiveInterval = '200';
192
+		}
182 193
 		if ($globalDBdriver == 'mysql') {
183 194
 			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
184 195
 			FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
@@ -211,7 +222,9 @@  discard block
 block discarded – undo
211 222
 		global $globalDBdriver, $globalLiveInterval;
212 223
 		$filter_query = $this->getFilter($filter,true,true);
213 224
 
214
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
225
+		if (!isset($globalLiveInterval)) {
226
+			$globalLiveInterval = '200';
227
+		}
215 228
 		if ($globalDBdriver == 'mysql') {
216 229
 			$query = 'SELECT COUNT(DISTINCT marine_live.fammarine_id) as nb FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
217 230
 		} else {
@@ -239,7 +252,9 @@  discard block
 block discarded – undo
239 252
 	{
240 253
 		global $globalDBdriver, $globalLiveInterval;
241 254
 		$Spotter = new Spotter($this->db);
242
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
255
+		if (!isset($globalLiveInterval)) {
256
+			$globalLiveInterval = '200';
257
+		}
243 258
 		$filter_query = $this->getFilter($filter);
244 259
 
245 260
 		if (is_array($coord)) {
@@ -247,7 +262,9 @@  discard block
 block discarded – undo
247 262
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
248 263
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
249 264
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
250
-		} else return array();
265
+		} else {
266
+			return array();
267
+		}
251 268
 		if ($globalDBdriver == 'mysql') {
252 269
 			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND marine_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY marine_live.fammarine_id'.$filter_query;
253 270
 		} else {
@@ -411,11 +428,15 @@  discard block
 block discarded – undo
411 428
 		//$query  = self::$global_query.' WHERE marine_live.fammarine_id = :id ORDER BY date';
412 429
 		if ($globalDBdriver == 'mysql') {
413 430
 			$query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id';
414
-			if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
431
+			if ($liveinterval) {
432
+				$query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
433
+			}
415 434
 			$query .= ' ORDER BY date';
416 435
 		} else {
417 436
 			$query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id';
418
-			if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
437
+			if ($liveinterval) {
438
+				$query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
439
+			}
419 440
 			$query .= ' ORDER BY date';
420 441
 		}
421 442
 
@@ -510,7 +531,9 @@  discard block
 block discarded – undo
510 531
 				$i++;
511 532
 				$j++;
512 533
 				if ($j == 30) {
513
-					if ($globalDebug) echo ".";
534
+					if ($globalDebug) {
535
+						echo ".";
536
+					}
514 537
 				    	try {
515 538
 						
516 539
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
@@ -790,7 +813,9 @@  discard block
 block discarded – undo
790 813
 			{
791 814
 				return false;
792 815
 			}
793
-		} else return '';
816
+		} else {
817
+			return '';
818
+		}
794 819
 
795 820
 		if ($longitude != '')
796 821
 		{
@@ -798,7 +823,9 @@  discard block
 block discarded – undo
798 823
 			{
799 824
 				return false;
800 825
 			}
801
-		} else return '';
826
+		} else {
827
+			return '';
828
+		}
802 829
 
803 830
 
804 831
 		if ($heading != '')
@@ -807,7 +834,9 @@  discard block
 block discarded – undo
807 834
 			{
808 835
 				return false;
809 836
 			}
810
-		} else $heading = 0;
837
+		} else {
838
+			$heading = 0;
839
+		}
811 840
 
812 841
 		if ($groundspeed != '')
813 842
 		{
@@ -815,9 +844,13 @@  discard block
 block discarded – undo
815 844
 			{
816 845
 				return false;
817 846
 			}
818
-		} else $groundspeed = 0;
847
+		} else {
848
+			$groundspeed = 0;
849
+		}
819 850
 		date_default_timezone_set('UTC');
820
-		if ($date == '') $date = date("Y-m-d H:i:s", time());
851
+		if ($date == '') {
852
+			$date = date("Y-m-d H:i:s", time());
853
+		}
821 854
 
822 855
         
823 856
 		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
@@ -833,8 +866,12 @@  discard block
 block discarded – undo
833 866
 		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
834 867
 		$status = filter_var($status,FILTER_SANITIZE_STRING);
835 868
 
836
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
837
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
869
+            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) {
870
+            		$groundspeed = 0;
871
+            	}
872
+            	if ($heading == '' || $Common->isInteger($heading) === false ) {
873
+            		$heading = 0;
874
+            	}
838 875
             	
839 876
 		$query  = 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,status) 
840 877
 		VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:mmsi,:type,:status)';
Please login to merge, or discard this patch.
require/class.TrackerImport.php 1 patch
Braces   +149 added lines, -51 removed lines patch added patch discarded remove patch
@@ -44,7 +44,9 @@  discard block
 block discarded – undo
44 44
 
45 45
     public function checkAll() {
46 46
 	global $globalDebug;
47
-	if ($globalDebug) echo "Update last seen tracked data...\n";
47
+	if ($globalDebug) {
48
+		echo "Update last seen tracked data...\n";
49
+	}
48 50
 	foreach ($this->all_tracked as $key => $flight) {
49 51
 	    if (isset($this->all_tracked[$key]['id'])) {
50 52
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
@@ -57,12 +59,16 @@  discard block
 block discarded – undo
57 59
     public function del() {
58 60
 	global $globalDebug;
59 61
 	// Delete old infos
60
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
62
+	if ($globalDebug) {
63
+		echo 'Delete old values and update latest data...'."\n";
64
+	}
61 65
 	foreach ($this->all_tracked as $key => $flight) {
62 66
     	    if (isset($flight['lastupdate'])) {
63 67
         	if ($flight['lastupdate'] < (time()-3000)) {
64 68
             	    if (isset($this->all_tracked[$key]['id'])) {
65
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
69
+            		if ($globalDebug) {
70
+            			echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
71
+            		}
66 72
 			/*
67 73
 			$TrackerLive = new TrackerLive();
68 74
             		$TrackerLive->deleteLiveTrackerDataById($this->all_tracked[$key]['id']);
@@ -72,7 +78,9 @@  discard block
 block discarded – undo
72 78
             		$Tracker = new Tracker($this->db);
73 79
             		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
74 80
 				$result = $Tracker->updateLatestTrackerData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['altitude'],$this->all_tracked[$key]['speed']);
75
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
81
+				if ($globalDebug && $result != 'success') {
82
+					echo '!!! ERROR : '.$result."\n";
83
+				}
76 84
 			}
77 85
 			// Put in archive
78 86
 //			$Tracker->db = null;
@@ -85,7 +93,9 @@  discard block
 block discarded – undo
85 93
 
86 94
     public function add($line) {
87 95
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked;
88
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
96
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
97
+		$globalCoordMinChange = '0.02';
98
+	}
89 99
 	date_default_timezone_set('UTC');
90 100
 	$dataFound = false;
91 101
 	$send = false;
@@ -109,8 +119,11 @@  discard block
 block discarded – undo
109 119
 		*/
110 120
 		
111 121
 		$Common = new Common();
112
-	        if (!isset($line['id'])) $id = trim($line['ident']);
113
-	        else $id = trim($line['id']);
122
+	        if (!isset($line['id'])) {
123
+	        	$id = trim($line['ident']);
124
+	        } else {
125
+	        	$id = trim($line['id']);
126
+	        }
114 127
 		
115 128
 		if (!isset($this->all_tracked[$id])) {
116 129
 		    $this->all_tracked[$id] = array();
@@ -118,18 +131,27 @@  discard block
 block discarded – undo
118 131
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => ''));
119 132
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
120 133
 		    if (!isset($line['id'])) {
121
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
134
+			if (!isset($globalDaemon)) {
135
+				$globalDaemon = TRUE;
136
+			}
122 137
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
123
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
124
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
138
+		     } else {
139
+		     	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
140
+		     }
141
+		    if ($globalAllTracked !== FALSE) {
142
+		    	$dataFound = true;
143
+		    }
125 144
 		}
126 145
 		
127 146
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60) {
128 147
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_tracked[$id]['datetime'])) {
129 148
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
130 149
 		    } else {
131
-				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
132
-				elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
150
+				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
151
+					echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
152
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
153
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
154
+				}
133 155
 				return '';
134 156
 		    }
135 157
 		} else {
@@ -145,11 +167,17 @@  discard block
 block discarded – undo
145 167
             		$Tracker = new Tracker($this->db);
146 168
             		$fromsource = NULL;
147 169
             		$result = $Tracker->updateIdentTrackerData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
148
-			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
170
+			if ($globalDebug && $result != 'success') {
171
+				echo '!!! ERROR : '.$result."\n";
172
+			}
149 173
 			$Tracker->db = null;
150
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
174
+			if ($globalDebugTimeElapsed) {
175
+				echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
176
+			}
177
+		    }
178
+		    if (!isset($this->all_tracked[$id]['id'])) {
179
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
151 180
 		    }
152
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
153 181
 		}
154 182
 
155 183
 		if (isset($line['speed']) && $line['speed'] != '') {
@@ -160,14 +188,21 @@  discard block
 block discarded – undo
160 188
 		    if ($distance > 1000 && $distance < 10000) {
161 189
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
162 190
 			$speed = $speed*3.6;
163
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
164
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
191
+			if ($speed < 1000) {
192
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
193
+			}
194
+  			if ($globalDebug) {
195
+  				echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
196
+  			}
165 197
 		    }
166 198
 		}
167 199
 
168 200
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
169
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
170
-	    	    else unset($timediff);
201
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) {
202
+	    	    	$timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
203
+	    	    } else {
204
+	    	    	unset($timediff);
205
+	    	    }
171 206
 	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
172 207
 			if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) {
173 208
 			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
@@ -175,20 +210,30 @@  discard block
 block discarded – undo
175 210
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
176 211
 				$this->all_tracked[$id]['putinarchive'] = true;
177 212
 				
178
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
213
+				if ($globalDebug) {
214
+					echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
215
+				}
179 216
 				$timeelapsed = microtime(true);
180 217
 				$Tracker = new Tracker($this->db);
181 218
 				$all_country = $Tracker->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
182
-				if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
219
+				if (!empty($all_country)) {
220
+					$this->all_tracked[$id]['over_country'] = $all_country['iso2'];
221
+				}
183 222
 				$Tracker->db = null;
184
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
223
+				if ($globalDebugTimeElapsed) {
224
+					echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
225
+				}
185 226
 				$this->tmd = 0;
186
-				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
227
+				if ($globalDebug) {
228
+					echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
229
+				}
187 230
 			    }
188 231
 			}
189 232
 
190 233
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
191
-				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
234
+				if (!isset($this->all_tracked[$id]['archive_latitude'])) {
235
+					$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
236
+				}
192 237
 				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
193 238
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
194 239
 				    $dataFound = true;
@@ -197,8 +242,12 @@  discard block
 block discarded – undo
197 242
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
198 243
 			}
199 244
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
200
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
201
-				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
245
+			    if ($line['longitude'] > 180) {
246
+			    	$line['longitude'] = $line['longitude'] - 360;
247
+			    }
248
+				if (!isset($this->all_tracked[$id]['archive_longitude'])) {
249
+					$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
250
+				}
202 251
 				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
203 252
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
204 253
 				    $dataFound = true;
@@ -216,7 +265,9 @@  discard block
 block discarded – undo
216 265
 		    }
217 266
 		}
218 267
 		if (isset($line['last_update']) && $line['last_update'] != '') {
219
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
268
+		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) {
269
+		    	$dataFound = true;
270
+		    }
220 271
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
221 272
 		}
222 273
 		if (isset($line['format_source']) && $line['format_source'] != '') {
@@ -236,7 +287,9 @@  discard block
 block discarded – undo
236 287
 
237 288
 		if (isset($line['altitude']) && $line['altitude'] != '') {
238 289
 		    //if (!isset($this->all_tracked[$id]['altitude']) || $this->all_tracked[$id]['altitude'] == '' || ($this->all_tracked[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
239
-			if (is_int($this->all_tracked[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_tracked[$id]['altitude']) > 3) $this->all_tracked[$id]['putinarchive'] = true;
290
+			if (is_int($this->all_tracked[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_tracked[$id]['altitude']) > 3) {
291
+				$this->all_tracked[$id]['putinarchive'] = true;
292
+			}
240 293
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('altitude' => round($line['altitude']/100)));
241 294
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('altitude_real' => $line['altitude']));
242 295
 			//$dataFound = true;
@@ -248,15 +301,21 @@  discard block
 block discarded – undo
248 301
 		}
249 302
 		
250 303
 		if (isset($line['heading']) && $line['heading'] != '') {
251
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
304
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) {
305
+		    	$this->all_tracked[$id]['putinarchive'] = true;
306
+		    }
252 307
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
253 308
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
254 309
 		    //$dataFound = true;
255 310
   		} elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) {
256 311
   		    $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
257 312
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
258
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
259
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
313
+		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) {
314
+		    	$this->all_tracked[$id]['putinarchive'] = true;
315
+		    }
316
+  		    if ($globalDebug) {
317
+  		    	echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
318
+  		    }
260 319
   		}
261 320
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
262 321
 
@@ -265,20 +324,31 @@  discard block
 block discarded – undo
265 324
 		    if ($this->all_tracked[$id]['addedTracker'] == 0) {
266 325
 		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
267 326
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
268
-				if ($globalDebug) echo "Check if aircraft is already in DB...";
327
+				if ($globalDebug) {
328
+					echo "Check if aircraft is already in DB...";
329
+				}
269 330
 				$timeelapsed = microtime(true);
270 331
 				$TrackerLive = new TrackerLive($this->db);
271 332
 				if (isset($line['id'])) {
272 333
 				    $recent_ident = $TrackerLive->checkIdRecent($line['id']);
273
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
334
+				    if ($globalDebugTimeElapsed) {
335
+				    	echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
336
+				    }
274 337
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
275 338
 				    $recent_ident = $TrackerLive->checkIdentRecent($this->all_tracked[$id]['ident']);
276
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
277
-				} else $recent_ident = '';
339
+				    if ($globalDebugTimeElapsed) {
340
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
341
+				    }
342
+				} else {
343
+					$recent_ident = '';
344
+				}
278 345
 				$TrackerLive->db=null;
279 346
 
280
-				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
281
-				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
347
+				if ($globalDebug && $recent_ident == '') {
348
+					echo " Not in DB.\n";
349
+				} elseif ($globalDebug && $recent_ident != '') {
350
+					echo " Already in DB.\n";
351
+				}
282 352
 			    } else {
283 353
 				$recent_ident = '';
284 354
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
@@ -286,16 +356,24 @@  discard block
 block discarded – undo
286 356
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
287 357
 			    if($recent_ident == "")
288 358
 			    {
289
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : ";
359
+				if ($globalDebug) {
360
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : ";
361
+				}
290 362
 				//adds the spotter data for the archive
291 363
 				    $highlight = '';
292
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'].'-'.date('YmdHi')));
364
+				    if (!isset($this->all_tracked[$id]['id'])) {
365
+				    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'].'-'.date('YmdHi')));
366
+				    }
293 367
 				    $timeelapsed = microtime(true);
294 368
 				    $Tracker = new Tracker($this->db);
295 369
 				    $result = $Tracker->addTrackerData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['altitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['comment'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
296 370
 				    $Tracker->db = null;
297
-				    if ($globalDebug && isset($result)) echo $result."\n";
298
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
371
+				    if ($globalDebug && isset($result)) {
372
+				    	echo $result."\n";
373
+				    }
374
+				    if ($globalDebugTimeElapsed) {
375
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
376
+				    }
299 377
 				    
300 378
 				    /*
301 379
 				    // Add source stat in DB
@@ -329,12 +407,16 @@  discard block
 block discarded – undo
329 407
 				$this->all_tracked[$id]['addedTracker'] = 1;
330 408
 				//print_r($this->all_tracked[$id]);
331 409
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
332
-				    if ($globalDebug) echo "---- Deleting Live Tracker data older than 9 hours...";
410
+				    if ($globalDebug) {
411
+				    	echo "---- Deleting Live Tracker data older than 9 hours...";
412
+				    }
333 413
 				    //TrackerLive->deleteLiveTrackerDataNotUpdated();
334 414
 				    $TrackerLive = new TrackerLive($this->db);
335 415
 				    $TrackerLive->deleteLiveTrackerData();
336 416
 				    $TrackerLive->db=null;
337
-				    if ($globalDebug) echo " Done\n";
417
+				    if ($globalDebug) {
418
+				    	echo " Done\n";
419
+				    }
338 420
 				    $this->last_delete = time();
339 421
 				}
340 422
 			    } else {
@@ -357,13 +439,17 @@  discard block
 block discarded – undo
357 439
 
358 440
 		    if (!$ignoreImport) {
359 441
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
360
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
442
+				if ($globalDebug) {
443
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
444
+				}
361 445
 				$timeelapsed = microtime(true);
362 446
 				$TrackerLive = new TrackerLive($this->db);
363 447
 				$result = $TrackerLive->addLiveTrackerData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['altitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['comment'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
364 448
 				$TrackerLive->db = null;
365 449
 				$this->all_tracked[$id]['putinarchive'] = false;
366
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
450
+				if ($globalDebugTimeElapsed) {
451
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
452
+				}
367 453
 
368 454
 				// Put statistics in $this->stats variable
369 455
 				/*
@@ -420,19 +506,29 @@  discard block
 block discarded – undo
420 506
 				*/
421 507
 
422 508
 				$this->all_tracked[$id]['lastupdate'] = time();
423
-				if ($this->all_tracked[$id]['putinarchive']) $send = true;
424
-				if ($globalDebug) echo $result."\n";
425
-			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
509
+				if ($this->all_tracked[$id]['putinarchive']) {
510
+					$send = true;
511
+				}
512
+				if ($globalDebug) {
513
+					echo $result."\n";
514
+				}
515
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
516
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
517
+			}
426 518
 			//$this->del();
427 519
 			
428 520
 			
429 521
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
430
-			    if ($globalDebug) echo "---- Deleting Live Tracker data Not updated since 2 hour...";
522
+			    if ($globalDebug) {
523
+			    	echo "---- Deleting Live Tracker data Not updated since 2 hour...";
524
+			    }
431 525
 			    $TrackerLive = new TrackerLive($this->db);
432 526
 			    $TrackerLive->deleteLiveTrackerDataNotUpdated();
433 527
 			    $TrackerLive->db = null;
434 528
 			    //TrackerLive->deleteLiveTrackerData();
435
-			    if ($globalDebug) echo " Done\n";
529
+			    if ($globalDebug) {
530
+			    	echo " Done\n";
531
+			    }
436 532
 			    $this->last_delete_hourly = time();
437 533
 			}
438 534
 			
@@ -440,7 +536,9 @@  discard block
 block discarded – undo
440 536
 		    //$ignoreImport = false;
441 537
 		}
442 538
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
443
-		if ($send) return $this->all_tracked[$id];
539
+		if ($send) {
540
+			return $this->all_tracked[$id];
541
+		}
444 542
 	    }
445 543
 	}
446 544
     }
Please login to merge, or discard this patch.
tracker-data.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,9 @@
 block discarded – undo
63 63
 {
64 64
 	if ($spotter_item['image_source'] == 'flickr' || $spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart') {
65 65
 		$image = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
66
-	} else $image = $spotter_item['image_thumbnail'];
66
+	} else {
67
+		$image = $spotter_item['image_thumbnail'];
68
+	}
67 69
 
68 70
 }
69 71
 /* else {
Please login to merge, or discard this patch.