Completed
Push — master ( f113eb...90b969 )
by Yannick
27:15
created
require/class.MarineImport.php 1 patch
Braces   +204 added lines, -70 removed lines patch added patch discarded remove patch
@@ -54,7 +54,9 @@  discard block
 block discarded – undo
54 54
     public function checkAll() {
55 55
 	global $globalDebug, $globalNoDB;
56 56
 	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
57
-	    if ($globalDebug) echo "Update last seen tracked data...\n";
57
+	    if ($globalDebug) {
58
+	    	echo "Update last seen tracked data...\n";
59
+	    }
58 60
 	    foreach ($this->all_tracked as $key => $flight) {
59 61
 		if (isset($this->all_tracked[$key]['id'])) {
60 62
 		    //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
@@ -68,13 +70,17 @@  discard block
 block discarded – undo
68 70
     public function del() {
69 71
 	global $globalDebug, $globalNoDB, $globalNoImport;
70 72
 	// Delete old infos
71
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
73
+	if ($globalDebug) {
74
+		echo 'Delete old values and update latest data...'."\n";
75
+	}
72 76
 	foreach ($this->all_tracked as $key => $flight) {
73 77
     	    if (isset($flight['lastupdate'])) {
74 78
         	if ($flight['lastupdate'] < (time()-3000)) {
75 79
             	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
76 80
             		if (isset($this->all_tracked[$key]['id'])) {
77
-            		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
81
+            		    if ($globalDebug) {
82
+            		    	echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
83
+            		    }
78 84
 			    /*
79 85
 			    $MarineLive = new MarineLive();
80 86
             		    $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
@@ -84,7 +90,9 @@  discard block
 block discarded – undo
84 90
             		    $Marine = new Marine($this->db);
85 91
             		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
86 92
 				$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'],$this->all_tracked[$key]['datetime']);
87
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
93
+				if ($globalDebug && $result != 'success') {
94
+					echo '!!! ERROR : '.$result."\n";
95
+				}
88 96
 			    }
89 97
 			    // Put in archive
90 98
 //				$Marine->db = null;
@@ -98,7 +106,9 @@  discard block
 block discarded – undo
98 106
 
99 107
     public function add($line) {
100 108
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine, $globalLiveInterval;
101
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
109
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
110
+		$globalCoordMinChange = '0.02';
111
+	}
102 112
 	date_default_timezone_set('UTC');
103 113
 	$dataFound = false;
104 114
 	$send = false;
@@ -112,20 +122,30 @@  discard block
 block discarded – undo
112 122
 		// Increment message number
113 123
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
114 124
 		    $current_date = date('Y-m-d');
115
-		    if (isset($line['source_name'])) $source = $line['source_name'];
116
-		    else $source = '';
117
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
125
+		    if (isset($line['source_name'])) {
126
+		    	$source = $line['source_name'];
127
+		    } else {
128
+		    	$source = '';
129
+		    }
130
+		    if ($source == '' || $line['format_source'] == 'aprs') {
131
+		    	$source = $line['format_source'];
132
+		    }
118 133
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
119 134
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
120 135
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
121
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
136
+		    } else {
137
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
138
+		    }
122 139
 		}
123 140
 		
124 141
 		
125 142
 		$Common = new Common();
126 143
 		$AIS = new AIS();
127
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
128
-	        else $id = trim($line['id']);
144
+	        if (!isset($line['id'])) {
145
+	        	$id = trim($line['mmsi']);
146
+	        } else {
147
+	        	$id = trim($line['id']);
148
+	        }
129 149
 		
130 150
 		if (!isset($this->all_tracked[$id])) {
131 151
 		    $this->all_tracked[$id] = array();
@@ -133,10 +153,16 @@  discard block
 block discarded – undo
133 153
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '','captain_id' => '','captain_name' => '','race_id' => '','race_name' => ''));
134 154
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
135 155
 		    if (!isset($line['id'])) {
136
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
156
+			if (!isset($globalDaemon)) {
157
+				$globalDaemon = TRUE;
158
+			}
137 159
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
138
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
139
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
160
+		     } else {
161
+		     	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
162
+		     }
163
+		    if ($globalAllTracked !== FALSE) {
164
+		    	$dataFound = true;
165
+		    }
140 166
 		}
141 167
 		
142 168
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
@@ -191,7 +217,9 @@  discard block
 block discarded – undo
191 217
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
192 218
 		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
193 219
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
194
-			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
220
+			if ($globalDebug) {
221
+				echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
222
+			}
195 223
 			if ($this->all_tracked[$id]['addedMarine'] != 0) {
196 224
 			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
197 225
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -204,7 +232,9 @@  discard block
 block discarded – undo
204 232
 			}
205 233
 		    } elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) {
206 234
 			$this->all_tracked[$id]['arrival_code'] = $line['arrival_code'];
207
-			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
235
+			if ($globalDebug) {
236
+				echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
237
+			}
208 238
 			if (!isset($line['id'])) {
209 239
 				$this->all_tracked[$id]['id'] = $id.'-'.date('YmdHi');
210 240
 				$this->all_tracked[$id]['forcenew'] = 1;
@@ -213,7 +243,9 @@  discard block
 block discarded – undo
213 243
 		    }
214 244
 		}
215 245
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
216
-		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
246
+		    if (strtotime($line['arrival_date']) > time()) {
247
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
248
+		    }
217 249
 		}
218 250
 		if (isset($line['captain_id']) && $line['captain_id'] != '') {
219 251
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_id' => $line['captain_id']));
@@ -246,34 +278,49 @@  discard block
 block discarded – undo
246 278
 				$Marine = new Marine($this->db);
247 279
 				$fromsource = NULL;
248 280
 				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
249
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
281
+				if ($globalDebug && $result != 'success') {
282
+					echo '!!! ERROR : '.$result."\n";
283
+				}
250 284
 				$Marine->db = null;
251
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
285
+				if ($globalDebugTimeElapsed) {
286
+					echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
287
+				}
252 288
 			    }
253 289
 			}
254 290
 		    }
255
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
291
+		    if (!isset($this->all_tracked[$id]['id'])) {
292
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
293
+		    }
256 294
 		}
257 295
 
258 296
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
259 297
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
260 298
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
261 299
 		    } else {
262
-				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";
263
-				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";
300
+				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
301
+					echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
302
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
303
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
304
+				}
264 305
 				return '';
265 306
 		    }
266 307
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
267
-			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
308
+			if ($globalDebug) {
309
+				echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
310
+			}
268 311
 			return '';
269 312
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
270
-			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
313
+			if ($globalDebug) {
314
+				echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
315
+			}
271 316
 			return '';
272 317
 		} elseif (!isset($line['datetime'])) {
273 318
 			date_default_timezone_set('UTC');
274 319
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
275 320
 		} else {
276
-			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
321
+			if ($globalDebug) {
322
+				echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
323
+			}
277 324
 			return '';
278 325
 		}
279 326
 
@@ -286,14 +333,21 @@  discard block
 block discarded – undo
286 333
 		    if ($distance > 1000 && $distance < 10000) {
287 334
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
288 335
 			$speed = $speed*3.6;
289
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed,2)));
290
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
336
+			if ($speed < 1000) {
337
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed,2)));
338
+			}
339
+  			if ($globalDebug) {
340
+  				echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
341
+  			}
291 342
 		    }
292 343
 		}
293 344
 
294 345
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
295
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
296
-	    	    else unset($timediff);
346
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) {
347
+	    	    	$timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
348
+	    	    } else {
349
+	    	    	unset($timediff);
350
+	    	    }
297 351
 	    	    if ($this->tmd > 5 ||
298 352
 	    		!isset($timediff) ||
299 353
 	    		$timediff > $globalLiveInterval ||
@@ -310,22 +364,32 @@  discard block
 block discarded – undo
310 364
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
311 365
 				$this->all_tracked[$id]['putinarchive'] = true;
312 366
 				
313
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
367
+				if ($globalDebug) {
368
+					echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
369
+				}
314 370
 				$timeelapsed = microtime(true);
315 371
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
316 372
 				    $Marine = new Marine($this->db);
317 373
 				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
318
-				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
374
+				    if (!empty($all_country)) {
375
+				    	$this->all_tracked[$id]['over_country'] = $all_country['iso2'];
376
+				    }
319 377
 				    $Marine->db = null;
320
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
378
+				    if ($globalDebugTimeElapsed) {
379
+				    	echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
380
+				    }
321 381
 				}
322 382
 				$this->tmd = 0;
323
-				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
383
+				if ($globalDebug) {
384
+					echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
385
+				}
324 386
 			    }
325 387
 			}
326 388
 
327 389
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
328
-				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
390
+				if (!isset($this->all_tracked[$id]['archive_latitude'])) {
391
+					$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
392
+				}
329 393
 				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') {
330 394
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
331 395
 				    $dataFound = true;
@@ -334,8 +398,12 @@  discard block
 block discarded – undo
334 398
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
335 399
 			}
336 400
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
337
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
338
-				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
401
+			    if ($line['longitude'] > 180) {
402
+			    	$line['longitude'] = $line['longitude'] - 360;
403
+			    }
404
+				if (!isset($this->all_tracked[$id]['archive_longitude'])) {
405
+					$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
406
+				}
339 407
 				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') {
340 408
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
341 409
 				    $dataFound = true;
@@ -353,7 +421,9 @@  discard block
 block discarded – undo
353 421
 		    }
354 422
 		}
355 423
 		if (isset($line['last_update']) && $line['last_update'] != '') {
356
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
424
+		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) {
425
+		    	$dataFound = true;
426
+		    }
357 427
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
358 428
 		}
359 429
 		if (isset($line['format_source']) && $line['format_source'] != '') {
@@ -367,15 +437,21 @@  discard block
 block discarded – undo
367 437
 		}
368 438
 		
369 439
 		if (isset($line['heading']) && $line['heading'] != '') {
370
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
440
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) {
441
+		    	$this->all_tracked[$id]['putinarchive'] = true;
442
+		    }
371 443
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
372 444
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
373 445
 		    //$dataFound = true;
374 446
   		} 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']) {
375 447
   		    $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']);
376 448
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
377
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
378
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
449
+		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) {
450
+		    	$this->all_tracked[$id]['putinarchive'] = true;
451
+		    }
452
+  		    if ($globalDebug) {
453
+  		    	echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
454
+  		    }
379 455
   		}
380 456
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
381 457
 
@@ -387,23 +463,38 @@  discard block
 block discarded – undo
387 463
 		        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'])) {
388 464
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
389 465
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
390
-				    if ($globalDebug) echo "Check if vessel is already in DB...";
466
+				    if ($globalDebug) {
467
+				    	echo "Check if vessel is already in DB...";
468
+				    }
391 469
 				    $timeelapsed = microtime(true);
392 470
 				    $MarineLive = new MarineLive($this->db);
393 471
 				    if (isset($line['id'])) {
394 472
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
395
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
473
+					if ($globalDebugTimeElapsed) {
474
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
475
+					}
396 476
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
397 477
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
398
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
478
+					if ($globalDebugTimeElapsed) {
479
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
480
+					}
399 481
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
400 482
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
401
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
402
-				    } else $recent_ident = '';
483
+					if ($globalDebugTimeElapsed) {
484
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
485
+					}
486
+				    } else {
487
+				    	$recent_ident = '';
488
+				    }
403 489
 				    $MarineLive->db=null;
404
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
405
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
406
-				} else $recent_ident = '';
490
+				    if ($globalDebug && $recent_ident == '') {
491
+				    	echo " Not in DB.\n";
492
+				    } elseif ($globalDebug && $recent_ident != '') {
493
+				    	echo " Already in DB.\n";
494
+				    }
495
+				} else {
496
+					$recent_ident = '';
497
+				}
407 498
 			    } else {
408 499
 				$recent_ident = '';
409 500
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
@@ -412,32 +503,47 @@  discard block
 block discarded – undo
412 503
 			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
413 504
 			    {
414 505
 				if ($globalDebug) {
415
-					if ($this->all_tracked[$id]['mmsi'] == '') echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
416
-					else echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : ";
506
+					if ($this->all_tracked[$id]['mmsi'] == '') {
507
+						echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
508
+					} else {
509
+						echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : ";
510
+					}
417 511
 				}
418 512
 				//adds the spotter data for the archive
419 513
 				    $highlight = '';
420
-				    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')));
514
+				    if (!isset($this->all_tracked[$id]['id'])) {
515
+				    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
516
+				    }
421 517
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
422 518
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
423 519
 					    $timeelapsed = microtime(true);
424 520
 					    $Marine = new Marine($this->db);
425 521
 					    $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]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name']);
426 522
 					    $Marine->db = null;
427
-					    if ($globalDebug && isset($result)) echo $result."\n";
428
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
523
+					    if ($globalDebug && isset($result)) {
524
+					    	echo $result."\n";
525
+					    }
526
+					    if ($globalDebugTimeElapsed) {
527
+					    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
528
+					    }
429 529
 					}
430 530
 				    }
431 531
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
432 532
 					// Add source stat in DB
433 533
 					$Stats = new Stats($this->db);
434 534
 					if (!empty($this->stats)) {
435
-					    if ($globalDebug) echo 'Add source stats : ';
535
+					    if ($globalDebug) {
536
+					    	echo 'Add source stats : ';
537
+					    }
436 538
 				    	    foreach($this->stats as $date => $data) {
437 539
 						foreach($data as $source => $sourced) {
438 540
 					    	    //print_r($sourced);
439
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
440
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
541
+				    	    	    if (isset($sourced['polar'])) {
542
+				    	    	    	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
543
+				    	    	    }
544
+				    	    	    if (isset($sourced['hist'])) {
545
+				    	    	    	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
546
+				    	    	    }
441 547
 				    		    if (isset($sourced['msg'])) {
442 548
 				    			if (time() - $sourced['msg']['date'] > 10) {
443 549
 				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -450,7 +556,9 @@  discard block
 block discarded – undo
450 556
 			    			    unset($this->stats[$date]);
451 557
 			    			}
452 558
 				    	    }
453
-				    	    if ($globalDebug) echo 'Done'."\n";
559
+				    	    if ($globalDebug) {
560
+				    	    	echo 'Done'."\n";
561
+				    	    }
454 562
 					}
455 563
 					$Stats->db = null;
456 564
 				    }
@@ -460,13 +568,17 @@  discard block
 block discarded – undo
460 568
 				$this->all_tracked[$id]['addedMarine'] = 1;
461 569
 				//print_r($this->all_tracked[$id]);
462 570
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
463
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
571
+				    if ($globalDebug) {
572
+				    	echo "---- Deleting Live Marine data older than 9 hours...";
573
+				    }
464 574
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
465 575
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
466 576
 					$MarineLive = new MarineLive($this->db);
467 577
 					$MarineLive->deleteLiveMarineData();
468 578
 					$MarineLive->db=null;
469
-					if ($globalDebug) echo " Done\n";
579
+					if ($globalDebug) {
580
+						echo " Done\n";
581
+					}
470 582
 				    }
471 583
 				    $this->last_delete = time();
472 584
 				}
@@ -492,15 +604,21 @@  discard block
 block discarded – undo
492 604
 
493 605
 		    if (!$ignoreImport) {
494 606
 			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'])) {
495
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
607
+				if ($globalDebug) {
608
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
609
+				}
496 610
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
497 611
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
498 612
 					$timeelapsed = microtime(true);
499 613
 					$MarineLive = new MarineLive($this->db);
500 614
 					$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]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name']);
501 615
 					$MarineLive->db = null;
502
-					if ($globalDebug) echo $result."\n";
503
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
616
+					if ($globalDebug) {
617
+						echo $result."\n";
618
+					}
619
+					if ($globalDebugTimeElapsed) {
620
+						echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
621
+					}
504 622
 				    }
505 623
 				}
506 624
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
@@ -512,7 +630,9 @@  discard block
 block discarded – undo
512 630
 				
513 631
 				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
514 632
 					$source = $this->all_tracked[$id]['source_name'];
515
-					if ($source == '') $source = $this->all_tracked[$id]['format_source'];
633
+					if ($source == '') {
634
+						$source = $this->all_tracked[$id]['format_source'];
635
+					}
516 636
 					if (!isset($this->source_location[$source])) {
517 637
 						$Location = new Source($this->db);
518 638
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -533,7 +653,9 @@  discard block
 block discarded – undo
533 653
 					$stats_heading = round($stats_heading/22.5);
534 654
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
535 655
 					$current_date = date('Y-m-d');
536
-					if ($stats_heading == 16) $stats_heading = 0;
656
+					if ($stats_heading == 16) {
657
+						$stats_heading = 0;
658
+					}
537 659
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
538 660
 						for ($i=0;$i<=15;$i++) {
539 661
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -551,7 +673,9 @@  discard block
 block discarded – undo
551 673
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
552 674
 						    end($this->stats[$current_date][$source]['hist']);
553 675
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
554
-						} else $mini = 0;
676
+						} else {
677
+							$mini = 0;
678
+						}
555 679
 						for ($i=$mini;$i<=$distance;$i+=10) {
556 680
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
557 681
 						}
@@ -563,19 +687,27 @@  discard block
 block discarded – undo
563 687
 				
564 688
 
565 689
 				$this->all_tracked[$id]['lastupdate'] = time();
566
-				if ($this->all_tracked[$id]['putinarchive']) $send = true;
567
-			} 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";
690
+				if ($this->all_tracked[$id]['putinarchive']) {
691
+					$send = true;
692
+				}
693
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
694
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
695
+			}
568 696
 			//$this->del();
569 697
 			
570 698
 			
571 699
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
572 700
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
573
-				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
701
+				if ($globalDebug) {
702
+					echo "---- Deleting Live Marine data Not updated since 2 hour...";
703
+				}
574 704
 				$MarineLive = new MarineLive($this->db);
575 705
 				$MarineLive->deleteLiveMarineDataNotUpdated();
576 706
 				$MarineLive->db = null;
577 707
 				//MarineLive->deleteLiveMarineData();
578
-				if ($globalDebug) echo " Done\n";
708
+				if ($globalDebug) {
709
+					echo " Done\n";
710
+				}
579 711
 			    }
580 712
 			    $this->last_delete_hourly = time();
581 713
 			}
@@ -584,7 +716,9 @@  discard block
 block discarded – undo
584 716
 		    //$ignoreImport = false;
585 717
 		}
586 718
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
587
-		if ($send) return $this->all_tracked[$id];
719
+		if ($send) {
720
+			return $this->all_tracked[$id];
721
+		}
588 722
 	    }
589 723
 	}
590 724
     }
Please login to merge, or discard this patch.