Completed
Push — master ( d02653...48f01d )
by Yannick
09:33
created
require/class.MarineImport.php 3 patches
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -9,25 +9,25 @@  discard block
 block discarded – undo
9 9
 require_once(dirname(__FILE__).'/class.Stats.php');
10 10
 require_once(dirname(__FILE__).'/class.Source.php');
11 11
 if (isset($globalServerAPRS) && $globalServerAPRS) {
12
-    require_once(dirname(__FILE__).'/class.APRS.php');
12
+	require_once(dirname(__FILE__).'/class.APRS.php');
13 13
 }
14 14
 
15 15
 class MarineImport {
16
-    private $all_tracked = array();
17
-    private $last_delete_hourly = 0;
18
-    private $last_delete = 0;
19
-    private $stats = array();
20
-    private $tmd = 0;
21
-    private $source_location = array();
22
-    public $db = null;
23
-    public $nb = 0;
16
+	private $all_tracked = array();
17
+	private $last_delete_hourly = 0;
18
+	private $last_delete = 0;
19
+	private $stats = array();
20
+	private $tmd = 0;
21
+	private $source_location = array();
22
+	public $db = null;
23
+	public $nb = 0;
24 24
 
25
-    public function __construct($dbc = null) {
25
+	public function __construct($dbc = null) {
26 26
 	global $globalBeta, $globalServerAPRS, $APRSMarine, $globalNoDB;
27 27
 	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
28
-	    $Connection = new Connection($dbc);
29
-	    $this->db = $Connection->db();
30
-	    date_default_timezone_set('UTC');
28
+		$Connection = new Connection($dbc);
29
+		$this->db = $Connection->db();
30
+		date_default_timezone_set('UTC');
31 31
 	}
32 32
 	// Get previous source stats
33 33
 	/*
@@ -46,55 +46,55 @@  discard block
 block discarded – undo
46 46
 	}
47 47
 	*/
48 48
 	if (isset($globalServerAPRS) && $globalServerAPRS) {
49
-	    $APRSMarine = new APRSMarine();
50
-	    //$APRSSpotter->connect();
49
+		$APRSMarine = new APRSMarine();
50
+		//$APRSSpotter->connect();
51
+	}
51 52
 	}
52
-    }
53 53
 
54
-    public function checkAll() {
54
+	public function checkAll() {
55 55
 	global $globalDebug;
56 56
 	if ($globalDebug) echo "Update last seen tracked data...\n";
57 57
 	foreach ($this->all_tracked as $key => $flight) {
58
-	    if (isset($this->all_tracked[$key]['id'])) {
58
+		if (isset($this->all_tracked[$key]['id'])) {
59 59
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
60
-    		$Marine = new Marine($this->db);
61
-        	$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']);
62
-            }
60
+			$Marine = new Marine($this->db);
61
+			$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']);
62
+			}
63
+	}
63 64
 	}
64
-    }
65 65
 
66
-    public function del() {
66
+	public function del() {
67 67
 	global $globalDebug, $globalNoDB;
68 68
 	// Delete old infos
69 69
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
70 70
 	foreach ($this->all_tracked as $key => $flight) {
71
-    	    if (isset($flight['lastupdate'])) {
72
-        	if ($flight['lastupdate'] < (time()-3000)) {
73
-            	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
74
-            		if (isset($this->all_tracked[$key]['id'])) {
75
-            		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
76
-			    /*
71
+			if (isset($flight['lastupdate'])) {
72
+			if ($flight['lastupdate'] < (time()-3000)) {
73
+					if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
74
+					if (isset($this->all_tracked[$key]['id'])) {
75
+						if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
76
+				/*
77 77
 			    $MarineLive = new MarineLive();
78 78
             		    $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
79 79
 			    $MarineLive->db = null;
80 80
 			    */
81
-            		    //$real_arrival = $this->arrival($key);
82
-            		    $Marine = new Marine($this->db);
83
-            		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
81
+						//$real_arrival = $this->arrival($key);
82
+						$Marine = new Marine($this->db);
83
+						if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
84 84
 				$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']);
85 85
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
86
-			    }
87
-			    // Put in archive
86
+				}
87
+				// Put in archive
88 88
 //				$Marine->db = null;
89 89
 			}
90
-            	    }
91
-            	    unset($this->all_tracked[$key]);
92
-    	        }
93
-	    }
94
-        }
95
-    }
90
+					}
91
+					unset($this->all_tracked[$key]);
92
+				}
93
+		}
94
+		}
95
+	}
96 96
 
97
-    public function add($line) {
97
+	public function add($line) {
98 98
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine;
99 99
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
100 100
 	date_default_timezone_set('UTC');
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 	
104 104
 	// SBS format is CSV format
105 105
 	if(is_array($line) && isset($line['mmsi'])) {
106
-	    //print_r($line);
107
-  	    if (isset($line['mmsi'])) {
106
+		//print_r($line);
107
+  		if (isset($line['mmsi'])) {
108 108
 
109 109
 		/*
110 110
 		// Increment message number
@@ -121,64 +121,64 @@  discard block
 block discarded – undo
121 121
 		
122 122
 		$Common = new Common();
123 123
 		$AIS = new AIS();
124
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
125
-	        else $id = trim($line['id']);
124
+			if (!isset($line['id'])) $id = trim($line['mmsi']);
125
+			else $id = trim($line['id']);
126 126
 		
127 127
 		if (!isset($this->all_tracked[$id])) {
128
-		    $this->all_tracked[$id] = array();
129
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
130
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => ''));
131
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
132
-		    if (!isset($line['id'])) {
128
+			$this->all_tracked[$id] = array();
129
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
130
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => ''));
131
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
132
+			if (!isset($line['id'])) {
133 133
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
134 134
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
135
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
136
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
135
+			 } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
136
+			if ($globalAllTracked !== FALSE) $dataFound = true;
137 137
 		}
138 138
 		
139 139
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
140
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
141
-		    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
140
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
141
+			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
142 142
 			$Marine = new Marine($this->db);
143 143
 			$identity = $Marine->getIdentity($line['mmsi']);
144 144
 			if (!empty($identity)) {
145
-			    $this->all_tracked[$id]['ident'] = $identity['ship_name'];
146
-			    $this->all_tracked[$id]['type'] = $identity['type'];
145
+				$this->all_tracked[$id]['ident'] = $identity['ship_name'];
146
+				$this->all_tracked[$id]['type'] = $identity['type'];
147 147
 			}
148 148
 			//print_r($identity);
149 149
 			unset($Marine);
150 150
 			//$dataFound = true;
151
-		    }
151
+			}
152 152
 		}
153 153
 		if (isset($line['type_id']) && $line['type_id'] != '') {
154
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
154
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
155 155
 		}
156 156
 		if (isset($line['type']) && $line['type'] != '') {
157
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
157
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
158 158
 		}
159 159
 		if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') {
160
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
160
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
161 161
 		}
162 162
 		if (isset($line['imo']) && $line['imo'] != '') {
163
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
163
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
164 164
 		}
165 165
 		if (isset($line['callsign']) && $line['callsign'] != '') {
166
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
166
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
167 167
 		}
168 168
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
169
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
169
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
170 170
 		}
171 171
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
172
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
172
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
173 173
 		}
174 174
 
175 175
 
176 176
 		//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'])) {
177 177
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
178
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
179
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
178
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
179
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
180 180
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
181
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
181
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
182 182
 				$timeelapsed = microtime(true);
183 183
 				$Marine = new Marine($this->db);
184 184
 				$fromsource = NULL;
@@ -186,31 +186,31 @@  discard block
 block discarded – undo
186 186
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
187 187
 				$Marine->db = null;
188 188
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
189
-			    }
189
+				}
190 190
 			}
191
-		    }
192
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
191
+			}
192
+			if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
193 193
 		}
194 194
 
195 195
 		if (isset($line['speed']) && $line['speed'] != '') {
196
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
197
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
196
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
197
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
198 198
 		} else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
199
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
200
-		    if ($distance > 1000 && $distance < 10000) {
199
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
200
+			if ($distance > 1000 && $distance < 10000) {
201 201
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
202 202
 			$speed = $speed*3.6;
203 203
 			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
204 204
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
205
-		    }
205
+			}
206 206
 		}
207 207
 
208
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
209
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
210
-	    	    else unset($timediff);
211
-	    	    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')))) {
208
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
209
+				if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
210
+				else unset($timediff);
211
+				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')))) {
212 212
 			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'])) {
213
-			    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'])) {
213
+				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'])) {
214 214
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
215 215
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
216 216
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -218,84 +218,84 @@  discard block
 block discarded – undo
218 218
 				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
219 219
 				$timeelapsed = microtime(true);
220 220
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
221
-				    $Marine = new Marine($this->db);
222
-				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
223
-				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
224
-				    $Marine->db = null;
225
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
221
+					$Marine = new Marine($this->db);
222
+					$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
223
+					if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
224
+					$Marine->db = null;
225
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
226 226
 				}
227 227
 				$this->tmd = 0;
228 228
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
229
-			    }
229
+				}
230 230
 			}
231 231
 
232 232
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
233 233
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
234 234
 				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') {
235
-				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
236
-				    $dataFound = true;
237
-				    $this->all_tracked[$id]['time_last_coord'] = time();
235
+					$this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
236
+					$dataFound = true;
237
+					$this->all_tracked[$id]['time_last_coord'] = time();
238 238
 				}
239 239
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
240 240
 			}
241 241
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
242
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
242
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
243 243
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
244 244
 				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') {
245
-				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
246
-				    $dataFound = true;
247
-				    $this->all_tracked[$id]['time_last_coord'] = time();
245
+					$this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
246
+					$dataFound = true;
247
+					$this->all_tracked[$id]['time_last_coord'] = time();
248 248
 				}
249 249
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
250 250
 			}
251 251
 
252
-		    } else if ($globalDebug && $timediff > 20) {
252
+			} else if ($globalDebug && $timediff > 20) {
253 253
 			$this->tmd = $this->tmd + 1;
254 254
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
255 255
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
256 256
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
257 257
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
258
-		    }
258
+			}
259 259
 		}
260 260
 		if (isset($line['last_update']) && $line['last_update'] != '') {
261
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
262
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
261
+			if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
262
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
263 263
 		}
264 264
 		if (isset($line['format_source']) && $line['format_source'] != '') {
265
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
265
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
266 266
 		}
267 267
 		if (isset($line['source_name']) && $line['source_name'] != '') {
268
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
268
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
269 269
 		}
270 270
 		if (isset($line['status']) && $line['status'] != '') {
271
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
271
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
272 272
 		}
273 273
 
274 274
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
275
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
275
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
276 276
 		}
277 277
 		
278 278
 		if (isset($line['heading']) && $line['heading'] != '') {
279
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
280
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
281
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
282
-		    //$dataFound = true;
279
+			if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
280
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
281
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
282
+			//$dataFound = true;
283 283
   		} 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']) {
284
-  		    $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']);
285
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
286
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
287
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
284
+  			$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']);
285
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
286
+			if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
287
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
288 288
   		}
289 289
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
290 290
 
291 291
 		if (isset($line['datetime'])) {
292
-		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
292
+			if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
293 293
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
294
-		    } else {
294
+			} else {
295 295
 				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";
296 296
 				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";
297 297
 				return '';
298
-		    }
298
+			}
299 299
 		} else {
300 300
 			date_default_timezone_set('UTC');
301 301
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -303,50 +303,50 @@  discard block
 block discarded – undo
303 303
 
304 304
 
305 305
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
306
-		    $this->all_tracked[$id]['lastupdate'] = time();
307
-		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
308
-		        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'])) {
309
-			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
306
+			$this->all_tracked[$id]['lastupdate'] = time();
307
+			if ($this->all_tracked[$id]['addedMarine'] == 0) {
308
+				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'])) {
309
+				if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
310 310
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
311
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
312
-				    $timeelapsed = microtime(true);
313
-				    $MarineLive = new MarineLive($this->db);
314
-				    if (isset($line['id'])) {
311
+					if ($globalDebug) echo "Check if aircraft is already in DB...";
312
+					$timeelapsed = microtime(true);
313
+					$MarineLive = new MarineLive($this->db);
314
+					if (isset($line['id'])) {
315 315
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
316 316
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
317
-				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
317
+					} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
318 318
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
319 319
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
320
-				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
320
+					} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
321 321
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
322 322
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
323
-				    } else $recent_ident = '';
324
-				    $MarineLive->db=null;
325
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
326
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
323
+					} else $recent_ident = '';
324
+					$MarineLive->db=null;
325
+					if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
326
+					elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
327 327
 				} else $recent_ident = '';
328
-			    } else {
328
+				} else {
329 329
 				$recent_ident = '';
330 330
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
331
-			    }
332
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
333
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
334
-			    {
331
+				}
332
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
333
+				if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
334
+				{
335 335
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
336 336
 				//adds the spotter data for the archive
337
-				    $highlight = '';
338
-				    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')));
339
-				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
337
+					$highlight = '';
338
+					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')));
339
+					if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
340 340
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
341
-					    $timeelapsed = microtime(true);
342
-					    $Marine = new Marine($this->db);
343
-					    $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]['format_source'],$this->all_tracked[$id]['source_name']);
344
-					    $Marine->db = null;
345
-					    if ($globalDebug && isset($result)) echo $result."\n";
346
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
341
+						$timeelapsed = microtime(true);
342
+						$Marine = new Marine($this->db);
343
+						$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]['format_source'],$this->all_tracked[$id]['source_name']);
344
+						$Marine->db = null;
345
+						if ($globalDebug && isset($result)) echo $result."\n";
346
+						if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
347 347
 					}
348
-				    }
349
-				    /*
348
+					}
349
+					/*
350 350
 				    // Add source stat in DB
351 351
 				    $Stats = new Stats($this->db);
352 352
 				    if (!empty($this->stats)) {
@@ -373,56 +373,56 @@  discard block
 block discarded – undo
373 373
 				    }
374 374
 				    $Stats->db = null;
375 375
 				    */
376
-				    $this->del();
376
+					$this->del();
377 377
 				//$ignoreImport = false;
378 378
 				$this->all_tracked[$id]['addedMarine'] = 1;
379 379
 				//print_r($this->all_tracked[$id]);
380 380
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
381
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
382
-				    //MarineLive->deleteLiveMarineDataNotUpdated();
383
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
381
+					if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
382
+					//MarineLive->deleteLiveMarineDataNotUpdated();
383
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
384 384
 					$MarineLive = new MarineLive($this->db);
385 385
 					$MarineLive->deleteLiveMarineData();
386 386
 					$MarineLive->db=null;
387 387
 					if ($globalDebug) echo " Done\n";
388
-				    }
389
-				    $this->last_delete = time();
388
+					}
389
+					$this->last_delete = time();
390 390
 				}
391
-			    } elseif ($recent_ident != '') {
391
+				} elseif ($recent_ident != '') {
392 392
 				$this->all_tracked[$id]['id'] = $recent_ident;
393 393
 				$this->all_tracked[$id]['addedMarine'] = 1;
394 394
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
395
-				    if (isset($globalDaemon) && !$globalDaemon) {
395
+					if (isset($globalDaemon) && !$globalDaemon) {
396 396
 					$Marine = new Marine($this->db);
397 397
 					$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime']);
398 398
 					$Marine->db = null;
399
-				    }
399
+					}
400 400
 				}
401 401
 				
402
-			    }
402
+				}
403 403
 			}
404
-		    }
405
-		    //adds the spotter LIVE data
406
-		    if ($globalDebug) {
404
+			}
405
+			//adds the spotter LIVE data
406
+			if ($globalDebug) {
407 407
 			echo 'DATA : ident : '.$this->all_tracked[$id]['ident'].' - type : '.$this->all_tracked[$id]['type'].' - Latitude : '.$this->all_tracked[$id]['latitude'].' - Longitude : '.$this->all_tracked[$id]['longitude'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n";
408
-		    }
409
-		    $ignoreImport = false;
408
+			}
409
+			$ignoreImport = false;
410 410
 
411
-		    if (!$ignoreImport) {
411
+			if (!$ignoreImport) {
412 412
 			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'])) {
413 413
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
414 414
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
415
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
415
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
416 416
 					$timeelapsed = microtime(true);
417 417
 					$MarineLive = new MarineLive($this->db);
418 418
 					$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]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
419 419
 					$MarineLive->db = null;
420 420
 					if ($globalDebug) echo $result."\n";
421 421
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
422
-				    }
422
+					}
423 423
 				}
424 424
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
425
-				    $APRSMarine->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]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
425
+					$APRSMarine->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]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
426 426
 				}
427 427
 				$this->all_tracked[$id]['putinarchive'] = false;
428 428
 
@@ -487,24 +487,24 @@  discard block
 block discarded – undo
487 487
 			
488 488
 			
489 489
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
490
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
490
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
491 491
 				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
492 492
 				$MarineLive = new MarineLive($this->db);
493 493
 				$MarineLive->deleteLiveMarineDataNotUpdated();
494 494
 				$MarineLive->db = null;
495 495
 				//MarineLive->deleteLiveMarineData();
496 496
 				if ($globalDebug) echo " Done\n";
497
-			    }
498
-			    $this->last_delete_hourly = time();
497
+				}
498
+				$this->last_delete_hourly = time();
499 499
 			}
500 500
 			
501
-		    }
502
-		    //$ignoreImport = false;
501
+			}
502
+			//$ignoreImport = false;
503 503
 		}
504 504
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
505 505
 		if ($send) return $this->all_tracked[$id];
506
-	    }
506
+		}
507
+	}
507 508
 	}
508
-    }
509 509
 }
510 510
 ?>
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	    if (isset($this->all_tracked[$key]['id'])) {
59 59
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
60 60
     		$Marine = new Marine($this->db);
61
-        	$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']);
61
+        	$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']);
62 62
             }
63 63
 	}
64 64
     }
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
70 70
 	foreach ($this->all_tracked as $key => $flight) {
71 71
     	    if (isset($flight['lastupdate'])) {
72
-        	if ($flight['lastupdate'] < (time()-3000)) {
72
+        	if ($flight['lastupdate'] < (time() - 3000)) {
73 73
             	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
74 74
             		if (isset($this->all_tracked[$key]['id'])) {
75 75
             		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
             		    //$real_arrival = $this->arrival($key);
82 82
             		    $Marine = new Marine($this->db);
83 83
             		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
84
-				$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']);
84
+				$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']);
85 85
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
86 86
 			    }
87 87
 			    // Put in archive
@@ -95,14 +95,14 @@  discard block
 block discarded – undo
95 95
     }
96 96
 
97 97
     public function add($line) {
98
-	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine;
98
+	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS, $APRSMarine;
99 99
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
100 100
 	date_default_timezone_set('UTC');
101 101
 	$dataFound = false;
102 102
 	$send = false;
103 103
 	
104 104
 	// SBS format is CSV format
105
-	if(is_array($line) && isset($line['mmsi'])) {
105
+	if (is_array($line) && isset($line['mmsi'])) {
106 106
 	    //print_r($line);
107 107
   	    if (isset($line['mmsi'])) {
108 108
 
@@ -126,18 +126,18 @@  discard block
 block discarded – undo
126 126
 		
127 127
 		if (!isset($this->all_tracked[$id])) {
128 128
 		    $this->all_tracked[$id] = array();
129
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
130
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => ''));
131
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
129
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('addedMarine' => 0));
130
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => '', 'latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '', 'source_name' => '', 'comment'=> '', 'type' => '', 'typeid' => '', 'noarchive' => false, 'putinarchive' => true, 'over_country' => '', 'mmsi' => '', 'status' => '', 'imo' => '', 'callsign' => '', 'arrival_code' => '', 'arrival_date' => '', 'mmsi_type' => ''));
131
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('lastupdate' => time()));
132 132
 		    if (!isset($line['id'])) {
133 133
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
134
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
135
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
134
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $id.'-'.date('YmdHi')));
135
+		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $line['id']));
136 136
 		    if ($globalAllTracked !== FALSE) $dataFound = true;
137 137
 		}
138 138
 		
139 139
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
140
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
140
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi' => $line['mmsi']));
141 141
 		    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
142 142
 			$Marine = new Marine($this->db);
143 143
 			$identity = $Marine->getIdentity($line['mmsi']);
@@ -151,66 +151,66 @@  discard block
 block discarded – undo
151 151
 		    }
152 152
 		}
153 153
 		if (isset($line['type_id']) && $line['type_id'] != '') {
154
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
154
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $AIS->getShipType($line['type_id'])));
155 155
 		}
156 156
 		if (isset($line['type']) && $line['type'] != '') {
157
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
157
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type']));
158 158
 		}
159 159
 		if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') {
160
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
160
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi_type' => $line['mmsi_type']));
161 161
 		}
162 162
 		if (isset($line['imo']) && $line['imo'] != '') {
163
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
163
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('imo' => $line['imo']));
164 164
 		}
165 165
 		if (isset($line['callsign']) && $line['callsign'] != '') {
166
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
166
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('callsign' => $line['callsign']));
167 167
 		}
168 168
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
169
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
169
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code']));
170 170
 		}
171 171
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
172
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
172
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date']));
173 173
 		}
174 174
 
175 175
 
176 176
 		//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'])) {
177 177
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
178
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
178
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident'])));
179 179
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
180 180
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
181 181
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
182 182
 				$timeelapsed = microtime(true);
183 183
 				$Marine = new Marine($this->db);
184 184
 				$fromsource = NULL;
185
-				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
185
+				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource);
186 186
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
187 187
 				$Marine->db = null;
188
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
188
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
189 189
 			    }
190 190
 			}
191 191
 		    }
192
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
192
+		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['ident']));
193 193
 		}
194 194
 
195 195
 		if (isset($line['speed']) && $line['speed'] != '') {
196
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
197
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
196
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed'])));
197
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true));
198 198
 		} else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
199
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
199
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm');
200 200
 		    if ($distance > 1000 && $distance < 10000) {
201 201
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
202 202
 			$speed = $speed*3.6;
203
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
203
+			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed)));
204 204
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
205 205
 		    }
206 206
 		}
207 207
 
208 208
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
209
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
209
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']);
210 210
 	    	    else unset($timediff);
211
-	    	    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')))) {
211
+	    	    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')))) {
212 212
 			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'])) {
213
-			    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'])) {
213
+			    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'])) {
214 214
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
215 215
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
216 216
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -219,10 +219,10 @@  discard block
 block discarded – undo
219 219
 				$timeelapsed = microtime(true);
220 220
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
221 221
 				    $Marine = new Marine($this->db);
222
-				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
222
+				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
223 223
 				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
224 224
 				    $Marine->db = null;
225
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
225
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
226 226
 				}
227 227
 				$this->tmd = 0;
228 228
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
@@ -231,66 +231,66 @@  discard block
 block discarded – undo
231 231
 
232 232
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
233 233
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
234
-				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') {
234
+				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') {
235 235
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
236 236
 				    $dataFound = true;
237 237
 				    $this->all_tracked[$id]['time_last_coord'] = time();
238 238
 				}
239
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
239
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude']));
240 240
 			}
241 241
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
242 242
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
243 243
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
244
-				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') {
244
+				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') {
245 245
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
246 246
 				    $dataFound = true;
247 247
 				    $this->all_tracked[$id]['time_last_coord'] = time();
248 248
 				}
249
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
249
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude']));
250 250
 			}
251 251
 
252 252
 		    } else if ($globalDebug && $timediff > 20) {
253 253
 			$this->tmd = $this->tmd + 1;
254 254
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
255
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
256
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
255
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -";
256
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
257 257
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
258 258
 		    }
259 259
 		}
260 260
 		if (isset($line['last_update']) && $line['last_update'] != '') {
261 261
 		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
262
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
262
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update']));
263 263
 		}
264 264
 		if (isset($line['format_source']) && $line['format_source'] != '') {
265
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
265
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source']));
266 266
 		}
267 267
 		if (isset($line['source_name']) && $line['source_name'] != '') {
268
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
268
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name']));
269 269
 		}
270 270
 		if (isset($line['status']) && $line['status'] != '') {
271
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
271
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status']));
272 272
 		}
273 273
 
274 274
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
275
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
275
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true));
276 276
 		}
277 277
 		
278 278
 		if (isset($line['heading']) && $line['heading'] != '') {
279
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
280
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
281
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
279
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading'] - round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
280
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading'])));
281
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true));
282 282
 		    //$dataFound = true;
283 283
   		} 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']) {
284
-  		    $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']);
285
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
286
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
284
+  		    $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']);
285
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($heading)));
286
+		    if (abs($this->all_tracked[$id]['heading'] - round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
287 287
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
288 288
   		}
289 289
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
290 290
 
291 291
 		if (isset($line['datetime'])) {
292 292
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
293
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
293
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime']));
294 294
 		    } else {
295 295
 				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";
296 296
 				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";
@@ -298,14 +298,14 @@  discard block
 block discarded – undo
298 298
 		    }
299 299
 		} else {
300 300
 			date_default_timezone_set('UTC');
301
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
301
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s')));
302 302
 		}
303 303
 
304 304
 
305 305
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
306 306
 		    $this->all_tracked[$id]['lastupdate'] = time();
307 307
 		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
308
-		        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'])) {
308
+		        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'])) {
309 309
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
310 310
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
311 311
 				    if ($globalDebug) echo "Check if aircraft is already in DB...";
@@ -313,37 +313,37 @@  discard block
 block discarded – undo
313 313
 				    $MarineLive = new MarineLive($this->db);
314 314
 				    if (isset($line['id'])) {
315 315
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
316
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
316
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
317 317
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
318 318
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
319
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
319
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
320 320
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
321 321
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
322
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
322
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
323 323
 				    } else $recent_ident = '';
324
-				    $MarineLive->db=null;
324
+				    $MarineLive->db = null;
325 325
 				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
326 326
 				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
327 327
 				} else $recent_ident = '';
328 328
 			    } else {
329 329
 				$recent_ident = '';
330
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
330
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0));
331 331
 			    }
332 332
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
333
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
333
+			    if ($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
334 334
 			    {
335 335
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
336 336
 				//adds the spotter data for the archive
337 337
 				    $highlight = '';
338
-				    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')));
338
+				    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')));
339 339
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
340 340
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
341 341
 					    $timeelapsed = microtime(true);
342 342
 					    $Marine = new Marine($this->db);
343
-					    $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]['format_source'],$this->all_tracked[$id]['source_name']);
343
+					    $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]['format_source'], $this->all_tracked[$id]['source_name']);
344 344
 					    $Marine->db = null;
345 345
 					    if ($globalDebug && isset($result)) echo $result."\n";
346
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
346
+					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
347 347
 					}
348 348
 				    }
349 349
 				    /*
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
384 384
 					$MarineLive = new MarineLive($this->db);
385 385
 					$MarineLive->deleteLiveMarineData();
386
-					$MarineLive->db=null;
386
+					$MarineLive->db = null;
387 387
 					if ($globalDebug) echo " Done\n";
388 388
 				    }
389 389
 				    $this->last_delete = time();
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
395 395
 				    if (isset($globalDaemon) && !$globalDaemon) {
396 396
 					$Marine = new Marine($this->db);
397
-					$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime']);
397
+					$Marine->updateLatestMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime']);
398 398
 					$Marine->db = null;
399 399
 				    }
400 400
 				}
@@ -409,20 +409,20 @@  discard block
 block discarded – undo
409 409
 		    $ignoreImport = false;
410 410
 
411 411
 		    if (!$ignoreImport) {
412
-			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'])) {
412
+			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'])) {
413 413
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
414 414
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
415 415
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
416 416
 					$timeelapsed = microtime(true);
417 417
 					$MarineLive = new MarineLive($this->db);
418
-					$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]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
418
+					$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]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']);
419 419
 					$MarineLive->db = null;
420 420
 					if ($globalDebug) echo $result."\n";
421
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
421
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
422 422
 				    }
423 423
 				}
424 424
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
425
-				    $APRSMarine->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]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
425
+				    $APRSMarine->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]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']);
426 426
 				}
427 427
 				$this->all_tracked[$id]['putinarchive'] = false;
428 428
 
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
 
483 483
 				$this->all_tracked[$id]['lastupdate'] = time();
484 484
 				if ($this->all_tracked[$id]['putinarchive']) $send = true;
485
-			} 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";
485
+			} 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";
486 486
 			//$this->del();
487 487
 			
488 488
 			
Please login to merge, or discard this patch.
Braces   +152 added lines, -52 removed lines patch added patch discarded remove patch
@@ -53,7 +53,9 @@  discard block
 block discarded – undo
53 53
 
54 54
     public function checkAll() {
55 55
 	global $globalDebug;
56
-	if ($globalDebug) echo "Update last seen tracked data...\n";
56
+	if ($globalDebug) {
57
+		echo "Update last seen tracked data...\n";
58
+	}
57 59
 	foreach ($this->all_tracked as $key => $flight) {
58 60
 	    if (isset($this->all_tracked[$key]['id'])) {
59 61
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
@@ -66,13 +68,17 @@  discard block
 block discarded – undo
66 68
     public function del() {
67 69
 	global $globalDebug, $globalNoDB;
68 70
 	// Delete old infos
69
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
71
+	if ($globalDebug) {
72
+		echo 'Delete old values and update latest data...'."\n";
73
+	}
70 74
 	foreach ($this->all_tracked as $key => $flight) {
71 75
     	    if (isset($flight['lastupdate'])) {
72 76
         	if ($flight['lastupdate'] < (time()-3000)) {
73 77
             	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
74 78
             		if (isset($this->all_tracked[$key]['id'])) {
75
-            		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
79
+            		    if ($globalDebug) {
80
+            		    	echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
81
+            		    }
76 82
 			    /*
77 83
 			    $MarineLive = new MarineLive();
78 84
             		    $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
@@ -82,7 +88,9 @@  discard block
 block discarded – undo
82 88
             		    $Marine = new Marine($this->db);
83 89
             		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
84 90
 				$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']);
85
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
91
+				if ($globalDebug && $result != 'success') {
92
+					echo '!!! ERROR : '.$result."\n";
93
+				}
86 94
 			    }
87 95
 			    // Put in archive
88 96
 //				$Marine->db = null;
@@ -96,7 +104,9 @@  discard block
 block discarded – undo
96 104
 
97 105
     public function add($line) {
98 106
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine;
99
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
107
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
108
+		$globalCoordMinChange = '0.02';
109
+	}
100 110
 	date_default_timezone_set('UTC');
101 111
 	$dataFound = false;
102 112
 	$send = false;
@@ -121,8 +131,11 @@  discard block
 block discarded – undo
121 131
 		
122 132
 		$Common = new Common();
123 133
 		$AIS = new AIS();
124
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
125
-	        else $id = trim($line['id']);
134
+	        if (!isset($line['id'])) {
135
+	        	$id = trim($line['mmsi']);
136
+	        } else {
137
+	        	$id = trim($line['id']);
138
+	        }
126 139
 		
127 140
 		if (!isset($this->all_tracked[$id])) {
128 141
 		    $this->all_tracked[$id] = array();
@@ -130,10 +143,16 @@  discard block
 block discarded – undo
130 143
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => ''));
131 144
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
132 145
 		    if (!isset($line['id'])) {
133
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
146
+			if (!isset($globalDaemon)) {
147
+				$globalDaemon = TRUE;
148
+			}
134 149
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
135
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
136
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
150
+		     } else {
151
+		     	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
152
+		     }
153
+		    if ($globalAllTracked !== FALSE) {
154
+		    	$dataFound = true;
155
+		    }
137 156
 		}
138 157
 		
139 158
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
@@ -183,13 +202,19 @@  discard block
 block discarded – undo
183 202
 				$Marine = new Marine($this->db);
184 203
 				$fromsource = NULL;
185 204
 				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
186
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
205
+				if ($globalDebug && $result != 'success') {
206
+					echo '!!! ERROR : '.$result."\n";
207
+				}
187 208
 				$Marine->db = null;
188
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
209
+				if ($globalDebugTimeElapsed) {
210
+					echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
211
+				}
189 212
 			    }
190 213
 			}
191 214
 		    }
192
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
215
+		    if (!isset($this->all_tracked[$id]['id'])) {
216
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
217
+		    }
193 218
 		}
194 219
 
195 220
 		if (isset($line['speed']) && $line['speed'] != '') {
@@ -200,14 +225,21 @@  discard block
 block discarded – undo
200 225
 		    if ($distance > 1000 && $distance < 10000) {
201 226
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
202 227
 			$speed = $speed*3.6;
203
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
204
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
228
+			if ($speed < 1000) {
229
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
230
+			}
231
+  			if ($globalDebug) {
232
+  				echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
233
+  			}
205 234
 		    }
206 235
 		}
207 236
 
208 237
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
209
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
210
-	    	    else unset($timediff);
238
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) {
239
+	    	    	$timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
240
+	    	    } else {
241
+	    	    	unset($timediff);
242
+	    	    }
211 243
 	    	    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')))) {
212 244
 			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'])) {
213 245
 			    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'])) {
@@ -215,22 +247,32 @@  discard block
 block discarded – undo
215 247
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
216 248
 				$this->all_tracked[$id]['putinarchive'] = true;
217 249
 				
218
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
250
+				if ($globalDebug) {
251
+					echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
252
+				}
219 253
 				$timeelapsed = microtime(true);
220 254
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
221 255
 				    $Marine = new Marine($this->db);
222 256
 				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
223
-				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
257
+				    if (!empty($all_country)) {
258
+				    	$this->all_tracked[$id]['over_country'] = $all_country['iso2'];
259
+				    }
224 260
 				    $Marine->db = null;
225
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
261
+				    if ($globalDebugTimeElapsed) {
262
+				    	echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
263
+				    }
226 264
 				}
227 265
 				$this->tmd = 0;
228
-				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
266
+				if ($globalDebug) {
267
+					echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
268
+				}
229 269
 			    }
230 270
 			}
231 271
 
232 272
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
233
-				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
273
+				if (!isset($this->all_tracked[$id]['archive_latitude'])) {
274
+					$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
275
+				}
234 276
 				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') {
235 277
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
236 278
 				    $dataFound = true;
@@ -239,8 +281,12 @@  discard block
 block discarded – undo
239 281
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
240 282
 			}
241 283
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
242
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
243
-				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
284
+			    if ($line['longitude'] > 180) {
285
+			    	$line['longitude'] = $line['longitude'] - 360;
286
+			    }
287
+				if (!isset($this->all_tracked[$id]['archive_longitude'])) {
288
+					$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
289
+				}
244 290
 				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') {
245 291
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
246 292
 				    $dataFound = true;
@@ -258,7 +304,9 @@  discard block
 block discarded – undo
258 304
 		    }
259 305
 		}
260 306
 		if (isset($line['last_update']) && $line['last_update'] != '') {
261
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
307
+		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) {
308
+		    	$dataFound = true;
309
+		    }
262 310
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
263 311
 		}
264 312
 		if (isset($line['format_source']) && $line['format_source'] != '') {
@@ -276,15 +324,21 @@  discard block
 block discarded – undo
276 324
 		}
277 325
 		
278 326
 		if (isset($line['heading']) && $line['heading'] != '') {
279
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
327
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) {
328
+		    	$this->all_tracked[$id]['putinarchive'] = true;
329
+		    }
280 330
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
281 331
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
282 332
 		    //$dataFound = true;
283 333
   		} 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']) {
284 334
   		    $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']);
285 335
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
286
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
287
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
336
+		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) {
337
+		    	$this->all_tracked[$id]['putinarchive'] = true;
338
+		    }
339
+  		    if ($globalDebug) {
340
+  		    	echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
341
+  		    }
288 342
   		}
289 343
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
290 344
 
@@ -292,8 +346,11 @@  discard block
 block discarded – undo
292 346
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
293 347
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
294 348
 		    } else {
295
-				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";
296
-				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";
349
+				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
350
+					echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
351
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
352
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
353
+				}
297 354
 				return '';
298 355
 		    }
299 356
 		} else {
@@ -308,23 +365,38 @@  discard block
 block discarded – undo
308 365
 		        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'])) {
309 366
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
310 367
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
311
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
368
+				    if ($globalDebug) {
369
+				    	echo "Check if aircraft is already in DB...";
370
+				    }
312 371
 				    $timeelapsed = microtime(true);
313 372
 				    $MarineLive = new MarineLive($this->db);
314 373
 				    if (isset($line['id'])) {
315 374
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
316
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
375
+					if ($globalDebugTimeElapsed) {
376
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
377
+					}
317 378
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
318 379
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
319
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
380
+					if ($globalDebugTimeElapsed) {
381
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
382
+					}
320 383
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
321 384
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
322
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
323
-				    } else $recent_ident = '';
385
+					if ($globalDebugTimeElapsed) {
386
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
387
+					}
388
+				    } else {
389
+				    	$recent_ident = '';
390
+				    }
324 391
 				    $MarineLive->db=null;
325
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
326
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
327
-				} else $recent_ident = '';
392
+				    if ($globalDebug && $recent_ident == '') {
393
+				    	echo " Not in DB.\n";
394
+				    } elseif ($globalDebug && $recent_ident != '') {
395
+				    	echo " Already in DB.\n";
396
+				    }
397
+				} else {
398
+					$recent_ident = '';
399
+				}
328 400
 			    } else {
329 401
 				$recent_ident = '';
330 402
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
@@ -332,18 +404,26 @@  discard block
 block discarded – undo
332 404
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
333 405
 			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
334 406
 			    {
335
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
407
+				if ($globalDebug) {
408
+					echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
409
+				}
336 410
 				//adds the spotter data for the archive
337 411
 				    $highlight = '';
338
-				    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')));
412
+				    if (!isset($this->all_tracked[$id]['id'])) {
413
+				    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
414
+				    }
339 415
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
340 416
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
341 417
 					    $timeelapsed = microtime(true);
342 418
 					    $Marine = new Marine($this->db);
343 419
 					    $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]['format_source'],$this->all_tracked[$id]['source_name']);
344 420
 					    $Marine->db = null;
345
-					    if ($globalDebug && isset($result)) echo $result."\n";
346
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
421
+					    if ($globalDebug && isset($result)) {
422
+					    	echo $result."\n";
423
+					    }
424
+					    if ($globalDebugTimeElapsed) {
425
+					    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
426
+					    }
347 427
 					}
348 428
 				    }
349 429
 				    /*
@@ -378,13 +458,17 @@  discard block
 block discarded – undo
378 458
 				$this->all_tracked[$id]['addedMarine'] = 1;
379 459
 				//print_r($this->all_tracked[$id]);
380 460
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
381
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
461
+				    if ($globalDebug) {
462
+				    	echo "---- Deleting Live Marine data older than 9 hours...";
463
+				    }
382 464
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
383 465
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
384 466
 					$MarineLive = new MarineLive($this->db);
385 467
 					$MarineLive->deleteLiveMarineData();
386 468
 					$MarineLive->db=null;
387
-					if ($globalDebug) echo " Done\n";
469
+					if ($globalDebug) {
470
+						echo " Done\n";
471
+					}
388 472
 				    }
389 473
 				    $this->last_delete = time();
390 474
 				}
@@ -410,15 +494,21 @@  discard block
 block discarded – undo
410 494
 
411 495
 		    if (!$ignoreImport) {
412 496
 			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'])) {
413
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
497
+				if ($globalDebug) {
498
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
499
+				}
414 500
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
415 501
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
416 502
 					$timeelapsed = microtime(true);
417 503
 					$MarineLive = new MarineLive($this->db);
418 504
 					$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]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
419 505
 					$MarineLive->db = null;
420
-					if ($globalDebug) echo $result."\n";
421
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
506
+					if ($globalDebug) {
507
+						echo $result."\n";
508
+					}
509
+					if ($globalDebugTimeElapsed) {
510
+						echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
511
+					}
422 512
 				    }
423 513
 				}
424 514
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
@@ -481,19 +571,27 @@  discard block
 block discarded – undo
481 571
 				*/
482 572
 
483 573
 				$this->all_tracked[$id]['lastupdate'] = time();
484
-				if ($this->all_tracked[$id]['putinarchive']) $send = true;
485
-			} 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";
574
+				if ($this->all_tracked[$id]['putinarchive']) {
575
+					$send = true;
576
+				}
577
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
578
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
579
+			}
486 580
 			//$this->del();
487 581
 			
488 582
 			
489 583
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
490 584
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
491
-				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
585
+				if ($globalDebug) {
586
+					echo "---- Deleting Live Marine data Not updated since 2 hour...";
587
+				}
492 588
 				$MarineLive = new MarineLive($this->db);
493 589
 				$MarineLive->deleteLiveMarineDataNotUpdated();
494 590
 				$MarineLive->db = null;
495 591
 				//MarineLive->deleteLiveMarineData();
496
-				if ($globalDebug) echo " Done\n";
592
+				if ($globalDebug) {
593
+					echo " Done\n";
594
+				}
497 595
 			    }
498 596
 			    $this->last_delete_hourly = time();
499 597
 			}
@@ -502,7 +600,9 @@  discard block
 block discarded – undo
502 600
 		    //$ignoreImport = false;
503 601
 		}
504 602
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
505
-		if ($send) return $this->all_tracked[$id];
603
+		if ($send) {
604
+			return $this->all_tracked[$id];
605
+		}
506 606
 	    }
507 607
 	}
508 608
     }
Please login to merge, or discard this patch.