Completed
Push — master ( 3f35c5...0c6dd7 )
by Yannick
88:47 queued 56:59
created
require/class.MarineImport.php 1 patch
Braces   +202 added lines, -69 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;
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' => ''));
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']) {
@@ -189,7 +215,9 @@  discard block
 block discarded – undo
189 215
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
190 216
 		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
191 217
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
192
-			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
218
+			if ($globalDebug) {
219
+				echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
220
+			}
193 221
 			if ($this->all_tracked[$id]['addedMarine'] != 0) {
194 222
 			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
195 223
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -202,7 +230,9 @@  discard block
 block discarded – undo
202 230
 			}
203 231
 		    } elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) {
204 232
 			$this->all_tracked[$id]['arrival_code'] = $line['arrival_code'];
205
-			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
233
+			if ($globalDebug) {
234
+				echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
235
+			}
206 236
 			if (!isset($line['id'])) {
207 237
 				$this->all_tracked[$id]['id'] = $id.'-'.date('YmdHi');
208 238
 				$this->all_tracked[$id]['forcenew'] = 1;
@@ -211,7 +241,9 @@  discard block
 block discarded – undo
211 241
 		    }
212 242
 		}
213 243
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
214
-		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
244
+		    if (strtotime($line['arrival_date']) > time()) {
245
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
246
+		    }
215 247
 		}
216 248
 
217 249
 		//if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) {
@@ -224,35 +256,50 @@  discard block
 block discarded – undo
224 256
 				$Marine = new Marine($this->db);
225 257
 				$fromsource = NULL;
226 258
 				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
227
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
259
+				if ($globalDebug && $result != 'success') {
260
+					echo '!!! ERROR : '.$result."\n";
261
+				}
228 262
 				$Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']);
229 263
 				$Marine->db = null;
230
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
264
+				if ($globalDebugTimeElapsed) {
265
+					echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
266
+				}
231 267
 			    }
232 268
 			}
233 269
 		    }
234
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
270
+		    if (!isset($this->all_tracked[$id]['id'])) {
271
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
272
+		    }
235 273
 		}
236 274
 
237 275
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
238 276
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
239 277
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
240 278
 		    } else {
241
-				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";
242
-				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";
279
+				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
280
+					echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
281
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
282
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
283
+				}
243 284
 				return '';
244 285
 		    }
245 286
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
246
-			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
287
+			if ($globalDebug) {
288
+				echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
289
+			}
247 290
 			return '';
248 291
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
249
-			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
292
+			if ($globalDebug) {
293
+				echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
294
+			}
250 295
 			return '';
251 296
 		} elseif (!isset($line['datetime'])) {
252 297
 			date_default_timezone_set('UTC');
253 298
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
254 299
 		} else {
255
-			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
300
+			if ($globalDebug) {
301
+				echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
302
+			}
256 303
 			return '';
257 304
 		}
258 305
 
@@ -265,14 +312,21 @@  discard block
 block discarded – undo
265 312
 		    if ($distance > 1000 && $distance < 10000) {
266 313
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
267 314
 			$speed = $speed*3.6;
268
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
269
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
315
+			if ($speed < 1000) {
316
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
317
+			}
318
+  			if ($globalDebug) {
319
+  				echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
320
+  			}
270 321
 		    }
271 322
 		}
272 323
 
273 324
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
274
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
275
-	    	    else unset($timediff);
325
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) {
326
+	    	    	$timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
327
+	    	    } else {
328
+	    	    	unset($timediff);
329
+	    	    }
276 330
 	    	    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')))) {
277 331
 			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'])) {
278 332
 			    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'])) {
@@ -280,22 +334,32 @@  discard block
 block discarded – undo
280 334
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
281 335
 				$this->all_tracked[$id]['putinarchive'] = true;
282 336
 				
283
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
337
+				if ($globalDebug) {
338
+					echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
339
+				}
284 340
 				$timeelapsed = microtime(true);
285 341
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
286 342
 				    $Marine = new Marine($this->db);
287 343
 				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
288
-				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
344
+				    if (!empty($all_country)) {
345
+				    	$this->all_tracked[$id]['over_country'] = $all_country['iso2'];
346
+				    }
289 347
 				    $Marine->db = null;
290
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
348
+				    if ($globalDebugTimeElapsed) {
349
+				    	echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
350
+				    }
291 351
 				}
292 352
 				$this->tmd = 0;
293
-				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
353
+				if ($globalDebug) {
354
+					echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
355
+				}
294 356
 			    }
295 357
 			}
296 358
 
297 359
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
298
-				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
360
+				if (!isset($this->all_tracked[$id]['archive_latitude'])) {
361
+					$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
362
+				}
299 363
 				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') {
300 364
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
301 365
 				    $dataFound = true;
@@ -304,8 +368,12 @@  discard block
 block discarded – undo
304 368
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
305 369
 			}
306 370
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
307
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
308
-				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
371
+			    if ($line['longitude'] > 180) {
372
+			    	$line['longitude'] = $line['longitude'] - 360;
373
+			    }
374
+				if (!isset($this->all_tracked[$id]['archive_longitude'])) {
375
+					$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
376
+				}
309 377
 				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') {
310 378
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
311 379
 				    $dataFound = true;
@@ -323,7 +391,9 @@  discard block
 block discarded – undo
323 391
 		    }
324 392
 		}
325 393
 		if (isset($line['last_update']) && $line['last_update'] != '') {
326
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
394
+		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) {
395
+		    	$dataFound = true;
396
+		    }
327 397
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
328 398
 		}
329 399
 		if (isset($line['format_source']) && $line['format_source'] != '') {
@@ -337,15 +407,21 @@  discard block
 block discarded – undo
337 407
 		}
338 408
 		
339 409
 		if (isset($line['heading']) && $line['heading'] != '') {
340
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
410
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) {
411
+		    	$this->all_tracked[$id]['putinarchive'] = true;
412
+		    }
341 413
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
342 414
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
343 415
 		    //$dataFound = true;
344 416
   		} 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']) {
345 417
   		    $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']);
346 418
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
347
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
348
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
419
+		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) {
420
+		    	$this->all_tracked[$id]['putinarchive'] = true;
421
+		    }
422
+  		    if ($globalDebug) {
423
+  		    	echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
424
+  		    }
349 425
   		}
350 426
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
351 427
 
@@ -357,23 +433,38 @@  discard block
 block discarded – undo
357 433
 		        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'])) {
358 434
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
359 435
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
360
-				    if ($globalDebug) echo "Check if vessel is already in DB...";
436
+				    if ($globalDebug) {
437
+				    	echo "Check if vessel is already in DB...";
438
+				    }
361 439
 				    $timeelapsed = microtime(true);
362 440
 				    $MarineLive = new MarineLive($this->db);
363 441
 				    if (isset($line['id'])) {
364 442
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
365
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
443
+					if ($globalDebugTimeElapsed) {
444
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
445
+					}
366 446
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
367 447
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
368
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
448
+					if ($globalDebugTimeElapsed) {
449
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
450
+					}
369 451
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
370 452
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
371
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
372
-				    } else $recent_ident = '';
453
+					if ($globalDebugTimeElapsed) {
454
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
455
+					}
456
+				    } else {
457
+				    	$recent_ident = '';
458
+				    }
373 459
 				    $MarineLive->db=null;
374
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
375
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
376
-				} else $recent_ident = '';
460
+				    if ($globalDebug && $recent_ident == '') {
461
+				    	echo " Not in DB.\n";
462
+				    } elseif ($globalDebug && $recent_ident != '') {
463
+				    	echo " Already in DB.\n";
464
+				    }
465
+				} else {
466
+					$recent_ident = '';
467
+				}
377 468
 			    } else {
378 469
 				$recent_ident = '';
379 470
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
@@ -381,30 +472,44 @@  discard block
 block discarded – undo
381 472
 			    //if there was no vessel with the same callsign within the last hour and go post it into the archive
382 473
 			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
383 474
 			    {
384
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
475
+				if ($globalDebug) {
476
+					echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
477
+				}
385 478
 				//adds the spotter data for the archive
386 479
 				    $highlight = '';
387
-				    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')));
480
+				    if (!isset($this->all_tracked[$id]['id'])) {
481
+				    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
482
+				    }
388 483
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
389 484
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
390 485
 					    $timeelapsed = microtime(true);
391 486
 					    $Marine = new Marine($this->db);
392 487
 					    $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']);
393 488
 					    $Marine->db = null;
394
-					    if ($globalDebug && isset($result)) echo $result."\n";
395
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
489
+					    if ($globalDebug && isset($result)) {
490
+					    	echo $result."\n";
491
+					    }
492
+					    if ($globalDebugTimeElapsed) {
493
+					    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
494
+					    }
396 495
 					}
397 496
 				    }
398 497
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
399 498
 					// Add source stat in DB
400 499
 					$Stats = new Stats($this->db);
401 500
 					if (!empty($this->stats)) {
402
-					    if ($globalDebug) echo 'Add source stats : ';
501
+					    if ($globalDebug) {
502
+					    	echo 'Add source stats : ';
503
+					    }
403 504
 				    	    foreach($this->stats as $date => $data) {
404 505
 						foreach($data as $source => $sourced) {
405 506
 					    	    //print_r($sourced);
406
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
407
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
507
+				    	    	    if (isset($sourced['polar'])) {
508
+				    	    	    	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
509
+				    	    	    }
510
+				    	    	    if (isset($sourced['hist'])) {
511
+				    	    	    	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
512
+				    	    	    }
408 513
 				    		    if (isset($sourced['msg'])) {
409 514
 				    			if (time() - $sourced['msg']['date'] > 10) {
410 515
 				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -417,7 +522,9 @@  discard block
 block discarded – undo
417 522
 			    			    unset($this->stats[$date]);
418 523
 			    			}
419 524
 				    	    }
420
-				    	    if ($globalDebug) echo 'Done'."\n";
525
+				    	    if ($globalDebug) {
526
+				    	    	echo 'Done'."\n";
527
+				    	    }
421 528
 					}
422 529
 					$Stats->db = null;
423 530
 				    }
@@ -427,13 +534,17 @@  discard block
 block discarded – undo
427 534
 				$this->all_tracked[$id]['addedMarine'] = 1;
428 535
 				//print_r($this->all_tracked[$id]);
429 536
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
430
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
537
+				    if ($globalDebug) {
538
+				    	echo "---- Deleting Live Marine data older than 9 hours...";
539
+				    }
431 540
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
432 541
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
433 542
 					$MarineLive = new MarineLive($this->db);
434 543
 					$MarineLive->deleteLiveMarineData();
435 544
 					$MarineLive->db=null;
436
-					if ($globalDebug) echo " Done\n";
545
+					if ($globalDebug) {
546
+						echo " Done\n";
547
+					}
437 548
 				    }
438 549
 				    $this->last_delete = time();
439 550
 				}
@@ -459,15 +570,21 @@  discard block
 block discarded – undo
459 570
 
460 571
 		    if (!$ignoreImport) {
461 572
 			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'])) {
462
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
573
+				if ($globalDebug) {
574
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
575
+				}
463 576
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
464 577
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
465 578
 					$timeelapsed = microtime(true);
466 579
 					$MarineLive = new MarineLive($this->db);
467 580
 					$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']);
468 581
 					$MarineLive->db = null;
469
-					if ($globalDebug) echo $result."\n";
470
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
582
+					if ($globalDebug) {
583
+						echo $result."\n";
584
+					}
585
+					if ($globalDebugTimeElapsed) {
586
+						echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
587
+					}
471 588
 				    }
472 589
 				}
473 590
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
@@ -479,7 +596,9 @@  discard block
 block discarded – undo
479 596
 				
480 597
 				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
481 598
 					$source = $this->all_tracked[$id]['source_name'];
482
-					if ($source == '') $source = $this->all_tracked[$id]['format_source'];
599
+					if ($source == '') {
600
+						$source = $this->all_tracked[$id]['format_source'];
601
+					}
483 602
 					if (!isset($this->source_location[$source])) {
484 603
 						$Location = new Source($this->db);
485 604
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -500,7 +619,9 @@  discard block
 block discarded – undo
500 619
 					$stats_heading = round($stats_heading/22.5);
501 620
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
502 621
 					$current_date = date('Y-m-d');
503
-					if ($stats_heading == 16) $stats_heading = 0;
622
+					if ($stats_heading == 16) {
623
+						$stats_heading = 0;
624
+					}
504 625
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
505 626
 						for ($i=0;$i<=15;$i++) {
506 627
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -518,7 +639,9 @@  discard block
 block discarded – undo
518 639
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
519 640
 						    end($this->stats[$current_date][$source]['hist']);
520 641
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
521
-						} else $mini = 0;
642
+						} else {
643
+							$mini = 0;
644
+						}
522 645
 						for ($i=$mini;$i<=$distance;$i+=10) {
523 646
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
524 647
 						}
@@ -530,19 +653,27 @@  discard block
 block discarded – undo
530 653
 				
531 654
 
532 655
 				$this->all_tracked[$id]['lastupdate'] = time();
533
-				if ($this->all_tracked[$id]['putinarchive']) $send = true;
534
-			} 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";
656
+				if ($this->all_tracked[$id]['putinarchive']) {
657
+					$send = true;
658
+				}
659
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
660
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
661
+			}
535 662
 			//$this->del();
536 663
 			
537 664
 			
538 665
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
539 666
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
540
-				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
667
+				if ($globalDebug) {
668
+					echo "---- Deleting Live Marine data Not updated since 2 hour...";
669
+				}
541 670
 				$MarineLive = new MarineLive($this->db);
542 671
 				$MarineLive->deleteLiveMarineDataNotUpdated();
543 672
 				$MarineLive->db = null;
544 673
 				//MarineLive->deleteLiveMarineData();
545
-				if ($globalDebug) echo " Done\n";
674
+				if ($globalDebug) {
675
+					echo " Done\n";
676
+				}
546 677
 			    }
547 678
 			    $this->last_delete_hourly = time();
548 679
 			}
@@ -551,7 +682,9 @@  discard block
 block discarded – undo
551 682
 		    //$ignoreImport = false;
552 683
 		}
553 684
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
554
-		if ($send) return $this->all_tracked[$id];
685
+		if ($send) {
686
+			return $this->all_tracked[$id];
687
+		}
555 688
 	    }
556 689
 	}
557 690
     }
Please login to merge, or discard this patch.