Completed
Push — master ( 3326da...2a1f3f )
by Yannick
30:39
created
require/class.MarineImport.php 1 patch
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		if (isset($this->all_tracked[$key]['id'])) {
60 60
 		    //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
61 61
     		    $Marine = new Marine($this->db);
62
-    		    $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
+    		    $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']);
63 63
 		}
64 64
 	    }
65 65
 	}
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
72 72
 	foreach ($this->all_tracked as $key => $flight) {
73 73
     	    if (isset($flight['lastupdate'])) {
74
-        	if ($flight['lastupdate'] < (time()-3000)) {
74
+        	if ($flight['lastupdate'] < (time() - 3000)) {
75 75
             	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
76 76
             		if (isset($this->all_tracked[$key]['id'])) {
77 77
             		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
             		    //$real_arrival = $this->arrival($key);
84 84
             		    $Marine = new Marine($this->db);
85 85
             		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
86
-				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
86
+				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime']);
87 87
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
88 88
 			    }
89 89
 			    // Put in archive
@@ -97,14 +97,14 @@  discard block
 block discarded – undo
97 97
     }
98 98
 
99 99
     public function add($line) {
100
-	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine;
100
+	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS, $APRSMarine;
101 101
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
102 102
 	date_default_timezone_set('UTC');
103 103
 	$dataFound = false;
104 104
 	$send = false;
105 105
 	
106 106
 	// SBS format is CSV format
107
-	if(is_array($line) && isset($line['mmsi'])) {
107
+	if (is_array($line) && isset($line['mmsi'])) {
108 108
 	    //print_r($line);
109 109
   	    if (isset($line['mmsi'])) {
110 110
 
@@ -129,18 +129,18 @@  discard block
 block discarded – undo
129 129
 		
130 130
 		if (!isset($this->all_tracked[$id])) {
131 131
 		    $this->all_tracked[$id] = array();
132
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
133
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => ''));
134
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
132
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('addedMarine' => 0));
133
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => '', 'latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '', 'source_name' => '', 'comment'=> '', 'type' => '', 'typeid' => '', 'noarchive' => false, 'putinarchive' => true, 'over_country' => '', 'mmsi' => '', 'status' => '', 'status_id' => '', 'imo' => '', 'callsign' => '', 'arrival_code' => '', 'arrival_date' => '', 'mmsi_type' => ''));
134
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('lastupdate' => time()));
135 135
 		    if (!isset($line['id'])) {
136 136
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
137
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
138
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
137
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $id.'-'.date('YmdHi')));
138
+		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $line['id']));
139 139
 		    if ($globalAllTracked !== FALSE) $dataFound = true;
140 140
 		}
141 141
 		
142 142
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
143
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
143
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi' => $line['mmsi']));
144 144
 		    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
145 145
 			$Marine = new Marine($this->db);
146 146
 			$identity = $Marine->getIdentity($line['mmsi']);
@@ -154,30 +154,30 @@  discard block
 block discarded – undo
154 154
 		    }
155 155
 		}
156 156
 		if (isset($line['type_id'])) {
157
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
158
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id']));
157
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $AIS->getShipType($line['type_id'])));
158
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $line['type_id']));
159 159
 		}
160 160
 		if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') {
161
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
161
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type']));
162 162
 		}
163 163
 		if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') {
164
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
164
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi_type' => $line['mmsi_type']));
165 165
 		}
166 166
 		if (isset($line['imo']) && $line['imo'] != '') {
167
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
167
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('imo' => $line['imo']));
168 168
 		}
169 169
 		if (isset($line['callsign']) && $line['callsign'] != '') {
170
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
170
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('callsign' => $line['callsign']));
171 171
 		}
172 172
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
173 173
 		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
174
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
174
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code']));
175 175
 			if ($this->all_tracked[$id]['addedMarine'] != 0) {
176 176
 			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
177 177
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
178 178
 				    $Marine = new Marine($this->db);
179 179
 				    $fromsource = NULL;
180
-				    $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource);
180
+				    $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['arrival_code'], $fromsource);
181 181
 				    $Marine->db = null;
182 182
 				}
183 183
 			    }
@@ -192,46 +192,46 @@  discard block
 block discarded – undo
192 192
 		    }
193 193
 		}
194 194
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
195
-		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
195
+		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date']));
196 196
 		}
197 197
 
198 198
 		//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'])) {
199 199
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
200
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
200
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident'])));
201 201
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
202 202
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
203 203
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
204 204
 				$timeelapsed = microtime(true);
205 205
 				$Marine = new Marine($this->db);
206 206
 				$fromsource = NULL;
207
-				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
207
+				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource);
208 208
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
209
-				$Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']);
209
+				$Marine->addIdentity($this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['type']);
210 210
 				$Marine->db = null;
211
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
211
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
212 212
 			    }
213 213
 			}
214 214
 		    }
215
-		    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'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['ident']));
216 216
 		}
217 217
 
218
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
218
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 30*60 && strtotime($line['datetime']) < time() + 20*60) {
219 219
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
220
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
220
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime']));
221 221
 		    } else {
222 222
 				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";
223 223
 				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";
224 224
 				return '';
225 225
 		    }
226
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
226
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time() - 30*60) {
227 227
 			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
228 228
 			return '';
229
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
229
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time() + 20*60) {
230 230
 			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
231 231
 			return '';
232 232
 		} elseif (!isset($line['datetime'])) {
233 233
 			date_default_timezone_set('UTC');
234
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
234
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s')));
235 235
 		} else {
236 236
 			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!";
237 237
 			return '';
@@ -239,24 +239,24 @@  discard block
 block discarded – undo
239 239
 
240 240
 
241 241
 		if (isset($line['speed'])) {
242
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
243
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
242
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed'])));
243
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true));
244 244
 		} 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'])) {
245
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
245
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm');
246 246
 		    if ($distance > 1000 && $distance < 10000) {
247 247
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
248 248
 			$speed = $speed*3.6;
249
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
249
+			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed)));
250 250
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
251 251
 		    }
252 252
 		}
253 253
 
254 254
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
255
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
255
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']);
256 256
 	    	    else unset($timediff);
257
-	    	    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')))) {
257
+	    	    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')))) {
258 258
 			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'])) {
259
-			    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'])) {
259
+			    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'])) {
260 260
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
261 261
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
262 262
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -265,10 +265,10 @@  discard block
 block discarded – undo
265 265
 				$timeelapsed = microtime(true);
266 266
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
267 267
 				    $Marine = new Marine($this->db);
268
-				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
268
+				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
269 269
 				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
270 270
 				    $Marine->db = null;
271
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
271
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
272 272
 				}
273 273
 				$this->tmd = 0;
274 274
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
@@ -277,52 +277,52 @@  discard block
 block discarded – undo
277 277
 
278 278
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
279 279
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
280
-				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') {
280
+				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') {
281 281
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
282 282
 				    $dataFound = true;
283 283
 				    $this->all_tracked[$id]['time_last_coord'] = time();
284 284
 				}
285
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
285
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude']));
286 286
 			}
287 287
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
288 288
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
289 289
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
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') {
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') {
291 291
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
292 292
 				    $dataFound = true;
293 293
 				    $this->all_tracked[$id]['time_last_coord'] = time();
294 294
 				}
295
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
295
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude']));
296 296
 			}
297 297
 
298 298
 		    } else if ($globalDebug && $timediff > 20) {
299 299
 			$this->tmd = $this->tmd + 1;
300 300
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
301
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
302
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
301
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -";
302
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
303 303
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
304 304
 		    }
305 305
 		}
306 306
 		if (isset($line['last_update']) && $line['last_update'] != '') {
307 307
 		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
308
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
308
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update']));
309 309
 		}
310 310
 		if (isset($line['format_source']) && $line['format_source'] != '') {
311
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
311
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source']));
312 312
 		}
313 313
 		if (isset($line['source_name']) && $line['source_name'] != '') {
314
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
314
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name']));
315 315
 		}
316 316
 		if (isset($line['status']) && $line['status'] != '') {
317
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
317
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status']));
318 318
 		}
319 319
 		if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) {
320
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
320
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status_id' => $line['status_id']));
321 321
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
322 322
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
323 323
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
324 324
 				$Marine = new Marine($this->db);
325
-				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']);
325
+				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['status']);
326 326
 				unset($Marine);
327 327
 			    }
328 328
 			}
@@ -330,18 +330,18 @@  discard block
 block discarded – undo
330 330
 		}
331 331
 
332 332
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
333
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
333
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true));
334 334
 		}
335 335
 		
336 336
 		if (isset($line['heading']) && $line['heading'] != '') {
337
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
338
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
339
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
337
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading'] - round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
338
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading'])));
339
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true));
340 340
 		    //$dataFound = true;
341 341
   		} 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']) {
342
-  		    $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']);
343
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
344
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
342
+  		    $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']);
343
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($heading)));
344
+		    if (abs($this->all_tracked[$id]['heading'] - round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
345 345
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
346 346
   		}
347 347
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
352 352
 		    $this->all_tracked[$id]['lastupdate'] = time();
353 353
 		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
354
-		        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'])) {
354
+		        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'])) {
355 355
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
356 356
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
357 357
 				    if ($globalDebug) echo "Check if vessel is already in DB...";
@@ -359,37 +359,37 @@  discard block
 block discarded – undo
359 359
 				    $MarineLive = new MarineLive($this->db);
360 360
 				    if (isset($line['id'])) {
361 361
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
362
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
362
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
363 363
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
364 364
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
365
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
365
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
366 366
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
367 367
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
368
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
368
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
369 369
 				    } else $recent_ident = '';
370
-				    $MarineLive->db=null;
370
+				    $MarineLive->db = null;
371 371
 				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
372 372
 				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
373 373
 				} else $recent_ident = '';
374 374
 			    } else {
375 375
 				$recent_ident = '';
376
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
376
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0));
377 377
 			    }
378 378
 			    //if there was no vessel with the same callsign within the last hour and go post it into the archive
379
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
379
+			    if ($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
380 380
 			    {
381 381
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
382 382
 				//adds the spotter data for the archive
383 383
 				    $highlight = '';
384
-				    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')));
384
+				    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')));
385 385
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
386 386
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
387 387
 					    $timeelapsed = microtime(true);
388 388
 					    $Marine = new Marine($this->db);
389
-					    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
389
+					    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name']);
390 390
 					    $Marine->db = null;
391 391
 					    if ($globalDebug && isset($result)) echo $result."\n";
392
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
392
+					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
393 393
 					}
394 394
 				    }
395 395
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
@@ -397,15 +397,15 @@  discard block
 block discarded – undo
397 397
 					$Stats = new Stats($this->db);
398 398
 					if (!empty($this->stats)) {
399 399
 					    if ($globalDebug) echo 'Add source stats : ';
400
-				    	    foreach($this->stats as $date => $data) {
401
-						foreach($data as $source => $sourced) {
400
+				    	    foreach ($this->stats as $date => $data) {
401
+						foreach ($data as $source => $sourced) {
402 402
 					    	    //print_r($sourced);
403
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
404
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
403
+				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar_marine', $date);
404
+				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist_marine', $date);
405 405
 				    		    if (isset($sourced['msg'])) {
406 406
 				    			if (time() - $sourced['msg']['date'] > 10) {
407 407
 				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
408
-				    		    	    echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
408
+				    		    	    echo $Stats->addStatSource($nbmsg, $source, 'msg_marine', $date);
409 409
 			    			    	    unset($this->stats[$date][$source]['msg']);
410 410
 			    				}
411 411
 			    			    }
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
430 430
 					$MarineLive = new MarineLive($this->db);
431 431
 					$MarineLive->deleteLiveMarineData();
432
-					$MarineLive->db=null;
432
+					$MarineLive->db = null;
433 433
 					if ($globalDebug) echo " Done\n";
434 434
 				    }
435 435
 				    $this->last_delete = time();
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
441 441
 				    if (isset($globalDaemon) && !$globalDaemon) {
442 442
 					$Marine = new Marine($this->db);
443
-					$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']);
443
+					$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']);
444 444
 					$Marine->db = null;
445 445
 				    }
446 446
 				}
@@ -455,20 +455,20 @@  discard block
 block discarded – undo
455 455
 		    $ignoreImport = false;
456 456
 
457 457
 		    if (!$ignoreImport) {
458
-			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'])) {
458
+			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'])) {
459 459
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
460 460
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
461 461
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
462 462
 					$timeelapsed = microtime(true);
463 463
 					$MarineLive = new MarineLive($this->db);
464
-					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
464
+					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']);
465 465
 					$MarineLive->db = null;
466 466
 					if ($globalDebug) echo $result."\n";
467
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
467
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
468 468
 				    }
469 469
 				}
470 470
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
471
-				    $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]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
471
+				    $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]['status_id'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']);
472 472
 				}
473 473
 				$this->all_tracked[$id]['putinarchive'] = false;
474 474
 
@@ -487,19 +487,19 @@  discard block
 block discarded – undo
487 487
 							$latitude = $globalCenterLatitude;
488 488
 							$longitude = $globalCenterLongitude;
489 489
 						}
490
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
490
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
491 491
 					} else {
492 492
 						$latitude = $this->source_location[$source]['latitude'];
493 493
 						$longitude = $this->source_location[$source]['longitude'];
494 494
 					}
495
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
495
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
496 496
 					//$stats_heading = $stats_heading%22.5;
497 497
 					$stats_heading = round($stats_heading/22.5);
498
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
498
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
499 499
 					$current_date = date('Y-m-d');
500 500
 					if ($stats_heading == 16) $stats_heading = 0;
501 501
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
502
-						for ($i=0;$i<=15;$i++) {
502
+						for ($i = 0; $i <= 15; $i++) {
503 503
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
504 504
 						}
505 505
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -514,9 +514,9 @@  discard block
 block discarded – undo
514 514
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
515 515
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
516 516
 						    end($this->stats[$current_date][$source]['hist']);
517
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
517
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
518 518
 						} else $mini = 0;
519
-						for ($i=$mini;$i<=$distance;$i+=10) {
519
+						for ($i = $mini; $i <= $distance; $i += 10) {
520 520
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
521 521
 						}
522 522
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
 
529 529
 				$this->all_tracked[$id]['lastupdate'] = time();
530 530
 				if ($this->all_tracked[$id]['putinarchive']) $send = true;
531
-			} 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";
531
+			} 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";
532 532
 			//$this->del();
533 533
 			
534 534
 			
Please login to merge, or discard this patch.
require/class.Marine.php 1 patch
Spacing   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 require_once(dirname(__FILE__).'/class.Image.php');
3 3
 $global_query = "SELECT marine_output.* FROM marine_output";
4 4
 
5
-class Marine{
5
+class Marine {
6 6
 	public $db;
7 7
 	
8 8
 	public function __construct($dbc = null) {
@@ -17,33 +17,33 @@  discard block
 block discarded – undo
17 17
 	* @return Array the SQL part
18 18
 	*/
19 19
 	
20
-	public function getFilter($filter = array(),$where = false,$and = false) {
20
+	public function getFilter($filter = array(), $where = false, $and = false) {
21 21
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
22 22
 		$filters = array();
23 23
 		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) {
24 24
 			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) {
25 25
 				$filters = $globalStatsFilters[$globalFilterName];
26 26
 			} else {
27
-				$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]);
27
+				$filter = array_merge($filter, $globalStatsFilters[$globalFilterName]);
28 28
 			}
29 29
 		}
30 30
 		if (isset($filter[0]['source'])) {
31
-			$filters = array_merge($filters,$filter);
31
+			$filters = array_merge($filters, $filter);
32 32
 		}
33
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
33
+		if (is_array($globalFilter)) $filter = array_merge($filter, $globalFilter);
34 34
 		$filter_query_join = '';
35 35
 		$filter_query_where = '';
36
-		foreach($filters as $flt) {
36
+		foreach ($filters as $flt) {
37 37
 			if (isset($flt['idents']) && !empty($flt['idents'])) {
38 38
 				if (isset($flt['source'])) {
39
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
39
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."') AND spotter_output.format_source IN ('".implode("','", $flt['source'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
40 40
 				} else {
41
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
41
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
42 42
 				}
43 43
 			}
44 44
 		}
45 45
 		if (isset($filter['source']) && !empty($filter['source'])) {
46
-			$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')";
46
+			$filter_query_where .= " AND format_source IN ('".implode("','", $filter['source'])."')";
47 47
 		}
48 48
 		if (isset($filter['ident']) && !empty($filter['ident'])) {
49 49
 			$filter_query_where .= " AND ident = '".$filter['ident']."'";
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
76 76
 		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
77 77
 		if ($filter_query_where != '') {
78
-			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
78
+			$filter_query_where = preg_replace('/^ AND/', ' WHERE', $filter_query_where);
79 79
 		}
80 80
 		$filter_query = $filter_query_join.$filter_query_where;
81 81
 		return $filter_query;
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	* @return Array the spotter information
91 91
 	*
92 92
 	*/
93
-	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false)
93
+	public function getDataFromDB($query, $params = array(), $limitQuery = '', $schedules = false)
94 94
 	{
95 95
 		date_default_timezone_set('UTC');
96 96
 		if (!is_string($query))
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 			$sth = $this->db->prepare($query.$limitQuery);
111 111
 			$sth->execute($params);
112 112
 		} catch (PDOException $e) {
113
-			printf("Invalid query : %s\nWhole query: %s\n",$e->getMessage(), $query.$limitQuery);
113
+			printf("Invalid query : %s\nWhole query: %s\n", $e->getMessage(), $query.$limitQuery);
114 114
 			exit();
115 115
 		}
116 116
 		
117 117
 		$num_rows = 0;
118 118
 		$spotter_array = array();
119
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
119
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
120 120
 		{
121 121
 			$num_rows++;
122 122
 			$temp_array = array();
@@ -148,10 +148,10 @@  discard block
 block discarded – undo
148 148
 			}
149 149
 			if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed'];
150 150
 
151
-			if(isset($temp_array['mmsi']) && $temp_array['mmsi'] != "")
151
+			if (isset($temp_array['mmsi']) && $temp_array['mmsi'] != "")
152 152
 			{
153 153
 				$Image = new Image($this->db);
154
-				if (isset($temp_array['ident']) && $temp_array['ident'] != '') $image_array = $Image->getMarineImage($temp_array['mmsi'],'',$temp_array['ident']);
154
+				if (isset($temp_array['ident']) && $temp_array['ident'] != '') $image_array = $Image->getMarineImage($temp_array['mmsi'], '', $temp_array['ident']);
155 155
 				else $image_array = $Image->getMarineImage($temp_array['mmsi']);
156 156
 				unset($Image);
157 157
 				if (count($image_array) > 0) {
@@ -187,17 +187,17 @@  discard block
 block discarded – undo
187 187
 				{
188 188
 					$temp_array['date'] = "about ".$dateArray['hours']." hours ago";
189 189
 				} else {
190
-					$temp_array['date'] = date("M j Y, g:i a",strtotime($row['date']." UTC"));
190
+					$temp_array['date'] = date("M j Y, g:i a", strtotime($row['date']." UTC"));
191 191
 				}
192 192
 				$temp_array['date_minutes_past'] = $dateArray['minutes'];
193
-				$temp_array['date_iso_8601'] = date("c",strtotime($row['date']." UTC"));
194
-				$temp_array['date_rfc_2822'] = date("r",strtotime($row['date']." UTC"));
193
+				$temp_array['date_iso_8601'] = date("c", strtotime($row['date']." UTC"));
194
+				$temp_array['date_rfc_2822'] = date("r", strtotime($row['date']." UTC"));
195 195
 				$temp_array['date_unix'] = strtotime($row['date']." UTC");
196 196
 				if (isset($row['last_seen']) && $row['last_seen'] != '') {
197 197
 					if (strtotime($row['last_seen']) > strtotime($row['date'])) {
198 198
 						$temp_array['duration'] = strtotime($row['last_seen']) - strtotime($row['date']);
199
-						$temp_array['last_seen_date_iso_8601'] = date("c",strtotime($row['last_seen']." UTC"));
200
-						$temp_array['last_seen_date_rfc_2822'] = date("r",strtotime($row['last_seen']." UTC"));
199
+						$temp_array['last_seen_date_iso_8601'] = date("c", strtotime($row['last_seen']." UTC"));
200
+						$temp_array['last_seen_date_rfc_2822'] = date("r", strtotime($row['last_seen']." UTC"));
201 201
 						$temp_array['last_seen_date_unix'] = strtotime($row['last_seen']." UTC");
202 202
 					}
203 203
 				}
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
 		if ($limit != "")
231 231
 		{
232 232
 			$limit_array = explode(",", $limit);
233
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
234
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
233
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
234
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
235 235
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
236 236
 			{
237 237
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
@@ -245,8 +245,8 @@  discard block
 block discarded – undo
245 245
 		} else {
246 246
 			$orderby_query = " ORDER BY marine_output.date DESC";
247 247
 		}
248
-		$query  = $global_query.$filter_query." ".$orderby_query;
249
-		$spotter_array = $this->getDataFromDB($query, array(),$limit_query,true);
248
+		$query = $global_query.$filter_query." ".$orderby_query;
249
+		$spotter_array = $this->getDataFromDB($query, array(), $limit_query, true);
250 250
 		return $spotter_array;
251 251
 	}
252 252
     
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
 		if ($id == '') return array();
265 265
 		$additional_query = "marine_output.fammarine_id = :id";
266 266
 		$query_values = array(':id' => $id);
267
-		$query  = $global_query." WHERE ".$additional_query." ";
268
-		$spotter_array = $this->getDataFromDB($query,$query_values);
267
+		$query = $global_query." WHERE ".$additional_query." ";
268
+		$spotter_array = $this->getDataFromDB($query, $query_values);
269 269
 		return $spotter_array;
270 270
 	}
271 271
 
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 		$query_values = array();
285 285
 		$limit_query = '';
286 286
 		$additional_query = '';
287
-		$filter_query = $this->getFilter($filter,true,true);
287
+		$filter_query = $this->getFilter($filter, true, true);
288 288
 		if ($ident != "")
289 289
 		{
290 290
 			if (!is_string($ident))
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
 		{
301 301
 			$limit_array = explode(",", $limit);
302 302
 			
303
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
304
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
303
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
304
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
305 305
 			
306 306
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
307 307
 			{
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 		return $spotter_array;
326 326
 	}
327 327
 	
328
-	public function getMarineDataByDate($date = '', $limit = '', $sort = '',$filter = array())
328
+	public function getMarineDataByDate($date = '', $limit = '', $sort = '', $filter = array())
329 329
 	{
330 330
 		global $global_query, $globalTimezone, $globalDBdriver;
331 331
 		
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 		$limit_query = '';
334 334
 		$additional_query = '';
335 335
 
336
-		$filter_query = $this->getFilter($filter,true,true);
336
+		$filter_query = $this->getFilter($filter, true, true);
337 337
 		
338 338
 		if ($date != "")
339 339
 		{
@@ -359,8 +359,8 @@  discard block
 block discarded – undo
359 359
 		{
360 360
 			$limit_array = explode(",", $limit);
361 361
 			
362
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
363
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
362
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
363
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
364 364
 			
365 365
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
366 366
 			{
@@ -391,11 +391,11 @@  discard block
 block discarded – undo
391 391
 	* @return Array list of source name
392 392
 	*
393 393
 	*/
394
-	public function getAllSourceName($type = '',$filters = array())
394
+	public function getAllSourceName($type = '', $filters = array())
395 395
 	{
396
-		$filter_query = $this->getFilter($filters,true,true);
396
+		$filter_query = $this->getFilter($filters, true, true);
397 397
 		$query_values = array();
398
-		$query  = "SELECT DISTINCT marine_output.source_name 
398
+		$query = "SELECT DISTINCT marine_output.source_name 
399 399
 				FROM marine_output".$filter_query." marine_output.source_name <> ''";
400 400
 		if ($type != '') {
401 401
 			$query_values = array(':type' => $type);
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 		$source_array = array();
411 411
 		$temp_array = array();
412 412
 		
413
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
413
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
414 414
 		{
415 415
 			$temp_array['source_name'] = $row['source_name'];
416 416
 			$source_array[] = $temp_array;
@@ -427,8 +427,8 @@  discard block
 block discarded – undo
427 427
 	*/
428 428
 	public function getAllIdents($filters = array())
429 429
 	{
430
-		$filter_query = $this->getFilter($filters,true,true);
431
-		$query  = "SELECT DISTINCT marine_output.ident
430
+		$filter_query = $this->getFilter($filters, true, true);
431
+		$query = "SELECT DISTINCT marine_output.ident
432 432
 								FROM marine_output".$filter_query." marine_output.ident <> '' 
433 433
 								ORDER BY marine_output.date ASC LIMIT 700 OFFSET 0";
434 434
 
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 		$ident_array = array();
439 439
 		$temp_array = array();
440 440
 		
441
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
441
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
442 442
 		{
443 443
 			$temp_array['ident'] = $row['ident'];
444 444
 			$ident_array[] = $temp_array;
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
 	*/
456 456
 	public function getIdentity($mmsi)
457 457
 	{
458
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
458
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
459 459
 		$query  = "SELECT * FROM marine_identity WHERE mmsi = :mmsi LIMIT 1";
460 460
 		$sth = $this->db->prepare($query);
461 461
 		$sth->execute(array(':mmsi' => $mmsi));
@@ -468,23 +468,23 @@  discard block
 block discarded – undo
468 468
 	* Add identity
469 469
 	*
470 470
 	*/
471
-	public function addIdentity($mmsi,$imo,$ident,$callsign,$type)
471
+	public function addIdentity($mmsi, $imo, $ident, $callsign, $type)
472 472
 	{
473
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
473
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
474 474
 		if ($mmsi != '') {
475
-			$imo = filter_var($imo,FILTER_SANITIZE_NUMBER_INT);
476
-			$ident = filter_var($ident,FILTER_SANITIZE_STRING);
477
-			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
478
-			$type = filter_var($type,FILTER_SANITIZE_STRING);
475
+			$imo = filter_var($imo, FILTER_SANITIZE_NUMBER_INT);
476
+			$ident = filter_var($ident, FILTER_SANITIZE_STRING);
477
+			$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
478
+			$type = filter_var($type, FILTER_SANITIZE_STRING);
479 479
 			$identinfo = $this->getIdentity($mmsi);
480 480
 			if (empty($identinfo)) {
481
-				$query  = "INSERT INTO marine_identity (mmsi,imo,call_sign,ship_name,type) VALUES (:mmsi,:imo,:call_sign,:ship_name,:type)";
481
+				$query = "INSERT INTO marine_identity (mmsi,imo,call_sign,ship_name,type) VALUES (:mmsi,:imo,:call_sign,:ship_name,:type)";
482 482
 				$sth = $this->db->prepare($query);
483
-				$sth->execute(array(':mmsi' => $mmsi,':imo' => $imo,':call_sign' => $callsign,':ship_name' => $ident,':type' => $type));
483
+				$sth->execute(array(':mmsi' => $mmsi, ':imo' => $imo, ':call_sign' => $callsign, ':ship_name' => $ident, ':type' => $type));
484 484
 			} elseif ($ident != '' && $identinfo['ship_name'] != $ident) {
485
-				$query  = "UPDATE marine_identity SET ship_name = :ship_name,type = :type WHERE mmsi = :mmsi";
485
+				$query = "UPDATE marine_identity SET ship_name = :ship_name,type = :type WHERE mmsi = :mmsi";
486 486
 				$sth = $this->db->prepare($query);
487
-				$sth->execute(array(':mmsi' => $mmsi,':ship_name' => $ident,':type' => $type));
487
+				$sth->execute(array(':mmsi' => $mmsi, ':ship_name' => $ident, ':type' => $type));
488 488
 			}
489 489
 		}
490 490
 	}
@@ -505,12 +505,12 @@  discard block
 block discarded – undo
505 505
 		} else $offset = '+00:00';
506 506
 
507 507
 		if ($globalDBdriver == 'mysql') {
508
-			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
508
+			$query = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
509 509
 								FROM marine_output
510 510
 								WHERE marine_output.date <> '' 
511 511
 								ORDER BY marine_output.date ASC LIMIT 0,100";
512 512
 		} else {
513
-			$query  = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
513
+			$query = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
514 514
 								FROM marine_output
515 515
 								WHERE marine_output.date <> '' 
516 516
 								ORDER BY marine_output.date ASC LIMIT 0,100";
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
 		$date_array = array();
523 523
 		$temp_array = array();
524 524
 		
525
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
525
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
526 526
 		{
527 527
 			$temp_array['date'] = $row['date'];
528 528
 
@@ -540,10 +540,10 @@  discard block
 block discarded – undo
540 540
 	* @return String success or false
541 541
 	*
542 542
 	*/
543
-	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL)
543
+	public function updateIdentMarineData($fammarine_id = '', $ident = '', $fromsource = NULL)
544 544
 	{
545 545
 		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id';
546
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
546
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident);
547 547
 		try {
548 548
 			$sth = $this->db->prepare($query);
549 549
 			$sth->execute($query_values);
@@ -561,10 +561,10 @@  discard block
 block discarded – undo
561 561
 	* @return String success or false
562 562
 	*
563 563
 	*/
564
-	public function updateArrivalPortNameMarineData($fammarine_id = '', $arrival_code = '',$fromsource = NULL)
564
+	public function updateArrivalPortNameMarineData($fammarine_id = '', $arrival_code = '', $fromsource = NULL)
565 565
 	{
566 566
 		$query = 'UPDATE marine_output SET arrival_port_name = :arrival_code WHERE fammarine_id = :fammarine_id';
567
-		$query_values = array(':fammarine_id' => $fammarine_id,':arrival_code' => $arrival_code);
567
+		$query_values = array(':fammarine_id' => $fammarine_id, ':arrival_code' => $arrival_code);
568 568
 		try {
569 569
 			$sth = $this->db->prepare($query);
570 570
 			$sth->execute($query_values);
@@ -583,11 +583,11 @@  discard block
 block discarded – undo
583 583
 	* @return String success or false
584 584
 	*
585 585
 	*/
586
-	public function updateStatusMarineData($fammarine_id = '', $status_id = '',$status = '')
586
+	public function updateStatusMarineData($fammarine_id = '', $status_id = '', $status = '')
587 587
 	{
588 588
 
589 589
 		$query = 'UPDATE marine_output SET status = :status, status_id = :status_id WHERE fammarine_id = :fammarine_id';
590
-                $query_values = array(':fammarine_id' => $fammarine_id,':status' => $status,':status_id' => $status_id);
590
+                $query_values = array(':fammarine_id' => $fammarine_id, ':status' => $status, ':status_id' => $status_id);
591 591
 
592 592
 		try {
593 593
 			$sth = $this->db->prepare($query);
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '')
611 611
 	{
612 612
 		$query = 'UPDATE marine_output SET ident = :ident, last_latitude = :last_latitude, last_longitude = :last_longitude, last_seen = :last_seen, last_ground_speed = :last_ground_speed WHERE fammarine_id = :fammarine_id';
613
-                $query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
613
+                $query_values = array(':fammarine_id' => $fammarine_id, ':last_latitude' => $latitude, ':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed, ':last_seen' => $date, ':ident' => $ident);
614 614
 
615 615
 		try {
616 616
 			$sth = $this->db->prepare($query);
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
 	* @param String $verticalrate vertival rate of flight
649 649
 	* @return String success or false
650 650
 	*/
651
-	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '',$type = '',$typeid = '',$imo = '',$callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$statusid = '',$format_source = '', $source_name = '')
651
+	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '', $type = '', $typeid = '', $imo = '', $callsign = '', $arrival_code = '', $arrival_date = '', $status = '', $statusid = '', $format_source = '', $source_name = '')
652 652
 	{
653 653
 		global $globalURL, $globalMarineImageFetch;
654 654
 		
@@ -715,30 +715,30 @@  discard block
 block discarded – undo
715 715
 		}
716 716
 
717 717
     
718
-		if ($date == "" || strtotime($date) < time()-20*60)
718
+		if ($date == "" || strtotime($date) < time() - 20*60)
719 719
 		{
720 720
 			$date = date("Y-m-d H:i:s", time());
721 721
 		}
722 722
 
723
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
724
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
725
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
726
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
727
-		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
728
-		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
729
-		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
730
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING);
731
-		$type = filter_var($type,FILTER_SANITIZE_STRING);
732
-		$status = filter_var($status,FILTER_SANITIZE_STRING);
733
-		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
734
-		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
735
-		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
736
-		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
723
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
724
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
725
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
726
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
727
+		$heading = filter_var($heading, FILTER_SANITIZE_NUMBER_INT);
728
+		$groundspeed = filter_var($groundspeed, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
729
+		$format_source = filter_var($format_source, FILTER_SANITIZE_STRING);
730
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_STRING);
731
+		$type = filter_var($type, FILTER_SANITIZE_STRING);
732
+		$status = filter_var($status, FILTER_SANITIZE_STRING);
733
+		$imo = filter_var($imo, FILTER_SANITIZE_STRING);
734
+		$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
735
+		$arrival_code = filter_var($arrival_code, FILTER_SANITIZE_STRING);
736
+		$arrival_date = filter_var($arrival_date, FILTER_SANITIZE_STRING);
737 737
 		if (isset($globalMarineImageFetch) && $globalMarineImageFetch === TRUE) {
738 738
 			$Image = new Image($this->db);
739
-			$image_array = $Image->getMarineImage($mmsi,$imo,$ident);
739
+			$image_array = $Image->getMarineImage($mmsi, $imo, $ident);
740 740
 			if (!isset($image_array[0]['mmsi'])) {
741
-				$Image->addMarineImage($mmsi,$imo,$ident);
741
+				$Image->addMarineImage($mmsi, $imo, $ident);
742 742
 			}
743 743
 			unset($Image);
744 744
 		}
@@ -749,10 +749,10 @@  discard block
 block discarded – undo
749 749
 		if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
750 750
 		if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
751 751
 		if ($arrival_date == '') $arrival_date = NULL;
752
-		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
752
+		$query = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
753 753
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)";
754 754
 
755
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':heading' => $heading,':speed' => $groundspeed,':date' => $date,':format_source' => $format_source, ':source_name' => $source_name,':mmsi' => $mmsi,':type' => $type,':status' => $status,':imo' => $imo,':arrival_port_name' => $arrival_code,':arrival_port_date' => $arrival_date);
755
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident, ':latitude' => $latitude, ':longitude' => $longitude, ':heading' => $heading, ':speed' => $groundspeed, ':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':mmsi' => $mmsi, ':type' => $type, ':status' => $status, ':imo' => $imo, ':arrival_port_name' => $arrival_code, ':arrival_port_date' => $arrival_date);
756 756
 		try {
757 757
 			$sth = $this->db->prepare($query);
758 758
 			$sth->execute($query_values);
@@ -776,13 +776,13 @@  discard block
 block discarded – undo
776 776
 	{
777 777
 		global $globalDBdriver, $globalTimezone;
778 778
 		if ($globalDBdriver == 'mysql') {
779
-			$query  = "SELECT marine_output.ident FROM marine_output 
779
+			$query = "SELECT marine_output.ident FROM marine_output 
780 780
 								WHERE marine_output.ident = :ident 
781 781
 								AND marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
782 782
 								AND marine_output.date < UTC_TIMESTAMP()";
783 783
 			$query_data = array(':ident' => $ident);
784 784
 		} else {
785
-			$query  = "SELECT marine_output.ident FROM marine_output 
785
+			$query = "SELECT marine_output.ident FROM marine_output 
786 786
 								WHERE marine_output.ident = :ident 
787 787
 								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
788 788
 								AND marine_output.date < now() AT TIME ZONE 'UTC'";
@@ -791,8 +791,8 @@  discard block
 block discarded – undo
791 791
 		
792 792
 		$sth = $this->db->prepare($query);
793 793
 		$sth->execute($query_data);
794
-    		$ident_result='';
795
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
794
+    		$ident_result = '';
795
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
796 796
 		{
797 797
 			$ident_result = $row['ident'];
798 798
 		}
@@ -818,8 +818,8 @@  discard block
 block discarded – undo
818 818
 				return false;
819 819
 			} else {
820 820
 				$q_array = explode(" ", $q);
821
-				foreach ($q_array as $q_item){
822
-					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
821
+				foreach ($q_array as $q_item) {
822
+					$q_item = filter_var($q_item, FILTER_SANITIZE_STRING);
823 823
 					$additional_query .= " AND (";
824 824
 					$additional_query .= "(marine_output.ident like '%".$q_item."%')";
825 825
 					$additional_query .= ")";
@@ -827,11 +827,11 @@  discard block
 block discarded – undo
827 827
 			}
828 828
 		}
829 829
 		if ($globalDBdriver == 'mysql') {
830
-			$query  = "SELECT marine_output.* FROM marine_output 
830
+			$query = "SELECT marine_output.* FROM marine_output 
831 831
 				WHERE marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query." 
832 832
 				AND marine_output.date < UTC_TIMESTAMP()";
833 833
 		} else {
834
-			$query  = "SELECT marine_output.* FROM marine_output 
834
+			$query = "SELECT marine_output.* FROM marine_output 
835 835
 				WHERE marine_output.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query." 
836 836
 				AND marine_output.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
837 837
 		}
@@ -850,16 +850,16 @@  discard block
 block discarded – undo
850 850
 	*
851 851
 	*/
852 852
 
853
-	public function countAllMarineOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array())
853
+	public function countAllMarineOverCountries($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array())
854 854
 	{
855 855
 		global $globalDBdriver, $globalArchive;
856 856
 		//$filter_query = $this->getFilter($filters,true,true);
857
-		$Connection= new Connection($this->db);
857
+		$Connection = new Connection($this->db);
858 858
 		if (!$Connection->tableExists('countries')) return array();
859 859
 		require_once('class.SpotterLive.php');
860 860
 		if (!isset($globalArchive) || $globalArchive !== TRUE) {
861 861
 			$MarineLive = new MarineLive($this->db);
862
-			$filter_query = $MarineLive->getFilter($filters,true,true);
862
+			$filter_query = $MarineLive->getFilter($filters, true, true);
863 863
 			$filter_query .= " over_country IS NOT NULL AND over_country <> ''";
864 864
 			if ($olderthanmonths > 0) {
865 865
 				if ($globalDBdriver == 'mysql') {
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
 		} else {
880 880
 			require_once(dirname(__FILE__)."/class.MarineArchive.php");
881 881
 			$MarineArchive = new MarineArchive($this->db);
882
-			$filter_query = $MarineArchive->getFilter($filters,true,true);
882
+			$filter_query = $MarineArchive->getFilter($filters, true, true);
883 883
 			$filter_query .= " over_country <> ''";
884 884
 			if ($olderthanmonths > 0) {
885 885
 				if ($globalDBdriver == 'mysql') {
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
 		$flight_array = array();
908 908
 		$temp_array = array();
909 909
         
910
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
910
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
911 911
 		{
912 912
 			$temp_array['marine_count'] = $row['nb'];
913 913
 			$temp_array['marine_country'] = $row['name'];
@@ -926,11 +926,11 @@  discard block
 block discarded – undo
926 926
 	* @return Array the callsign list
927 927
 	*
928 928
 	*/
929
-	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
929
+	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array(), $year = '', $month = '', $day = '')
930 930
 	{
931 931
 		global $globalDBdriver;
932
-		$filter_query = $this->getFilter($filters,true,true);
933
-		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
932
+		$filter_query = $this->getFilter($filters, true, true);
933
+		$query = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
934 934
                     FROM marine_output".$filter_query." marine_output.ident <> ''";
935 935
 		 if ($olderthanmonths > 0) {
936 936
 			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
@@ -944,28 +944,28 @@  discard block
 block discarded – undo
944 944
 		if ($year != '') {
945 945
 			if ($globalDBdriver == 'mysql') {
946 946
 				$query .= " AND YEAR(marine_output.date) = :year";
947
-				$query_values = array_merge($query_values,array(':year' => $year));
947
+				$query_values = array_merge($query_values, array(':year' => $year));
948 948
 			} else {
949 949
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
950
-				$query_values = array_merge($query_values,array(':year' => $year));
950
+				$query_values = array_merge($query_values, array(':year' => $year));
951 951
 			}
952 952
 		}
953 953
 		if ($month != '') {
954 954
 			if ($globalDBdriver == 'mysql') {
955 955
 				$query .= " AND MONTH(marine_output.date) = :month";
956
-				$query_values = array_merge($query_values,array(':month' => $month));
956
+				$query_values = array_merge($query_values, array(':month' => $month));
957 957
 			} else {
958 958
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
959
-				$query_values = array_merge($query_values,array(':month' => $month));
959
+				$query_values = array_merge($query_values, array(':month' => $month));
960 960
 			}
961 961
 		}
962 962
 		if ($day != '') {
963 963
 			if ($globalDBdriver == 'mysql') {
964 964
 				$query .= " AND DAY(marine_output.date) = :day";
965
-				$query_values = array_merge($query_values,array(':day' => $day));
965
+				$query_values = array_merge($query_values, array(':day' => $day));
966 966
 			} else {
967 967
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
968
-				$query_values = array_merge($query_values,array(':day' => $day));
968
+				$query_values = array_merge($query_values, array(':day' => $day));
969 969
 			}
970 970
 		}
971 971
 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
@@ -977,7 +977,7 @@  discard block
 block discarded – undo
977 977
 		$callsign_array = array();
978 978
 		$temp_array = array();
979 979
         
980
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
980
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
981 981
 		{
982 982
 			$temp_array['callsign_icao'] = $row['ident'];
983 983
 			$temp_array['airline_name'] = $row['airline_name'];
@@ -1029,7 +1029,7 @@  discard block
 block discarded – undo
1029 1029
 		$date_array = array();
1030 1030
 		$temp_array = array();
1031 1031
         
1032
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1032
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1033 1033
 		{
1034 1034
 			$temp_array['date_name'] = $row['date_name'];
1035 1035
 			$temp_array['date_count'] = $row['date_count'];
@@ -1055,7 +1055,7 @@  discard block
 block discarded – undo
1055 1055
 			$datetime = new DateTime();
1056 1056
 			$offset = $datetime->format('P');
1057 1057
 		} else $offset = '+00:00';
1058
-		$filter_query = $this->getFilter($filters,true,true);
1058
+		$filter_query = $this->getFilter($filters, true, true);
1059 1059
 		if ($globalDBdriver == 'mysql') {
1060 1060
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1061 1061
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY)";
@@ -1076,7 +1076,7 @@  discard block
 block discarded – undo
1076 1076
 		$date_array = array();
1077 1077
 		$temp_array = array();
1078 1078
         
1079
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1079
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1080 1080
 		{
1081 1081
 			$temp_array['date_name'] = $row['date_name'];
1082 1082
 			$temp_array['date_count'] = $row['date_count'];
@@ -1101,7 +1101,7 @@  discard block
 block discarded – undo
1101 1101
 			$datetime = new DateTime();
1102 1102
 			$offset = $datetime->format('P');
1103 1103
 		} else $offset = '+00:00';
1104
-		$filter_query = $this->getFilter($filters,true,true);
1104
+		$filter_query = $this->getFilter($filters, true, true);
1105 1105
 		if ($globalDBdriver == 'mysql') {
1106 1106
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1107 1107
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MONTH)";
@@ -1122,7 +1122,7 @@  discard block
 block discarded – undo
1122 1122
 		$date_array = array();
1123 1123
 		$temp_array = array();
1124 1124
         
1125
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1125
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1126 1126
 		{
1127 1127
 			$temp_array['date_name'] = $row['date_name'];
1128 1128
 			$temp_array['date_count'] = $row['date_count'];
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
 		$date_array = array();
1170 1170
 		$temp_array = array();
1171 1171
         
1172
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1172
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1173 1173
 		{
1174 1174
 			$temp_array['month_name'] = $row['month_name'];
1175 1175
 			$temp_array['year_name'] = $row['year_name'];
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
 			$datetime = new DateTime();
1199 1199
 			$offset = $datetime->format('P');
1200 1200
 		} else $offset = '+00:00';
1201
-		$filter_query = $this->getFilter($filters,true,true);
1201
+		$filter_query = $this->getFilter($filters, true, true);
1202 1202
 		if ($globalDBdriver == 'mysql') {
1203 1203
 			$query  = "SELECT MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count
1204 1204
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 YEAR)";
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
 		$date_array = array();
1220 1220
 		$temp_array = array();
1221 1221
         
1222
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1222
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1223 1223
 		{
1224 1224
 			$temp_array['year_name'] = $row['year_name'];
1225 1225
 			$temp_array['month_name'] = $row['month_name'];
@@ -1239,7 +1239,7 @@  discard block
 block discarded – undo
1239 1239
 	* @return Array the hour list
1240 1240
 	*
1241 1241
 	*/
1242
-	public function countAllHours($orderby,$filters = array())
1242
+	public function countAllHours($orderby, $filters = array())
1243 1243
 	{
1244 1244
 		global $globalTimezone, $globalDBdriver;
1245 1245
 		if ($globalTimezone != '') {
@@ -1287,7 +1287,7 @@  discard block
 block discarded – undo
1287 1287
 		$hour_array = array();
1288 1288
 		$temp_array = array();
1289 1289
         
1290
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1290
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1291 1291
 		{
1292 1292
 			$temp_array['hour_name'] = $row['hour_name'];
1293 1293
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1309,8 +1309,8 @@  discard block
 block discarded – undo
1309 1309
 	public function countAllHoursByDate($date, $filters = array())
1310 1310
 	{
1311 1311
 		global $globalTimezone, $globalDBdriver;
1312
-		$filter_query = $this->getFilter($filters,true,true);
1313
-		$date = filter_var($date,FILTER_SANITIZE_STRING);
1312
+		$filter_query = $this->getFilter($filters, true, true);
1313
+		$date = filter_var($date, FILTER_SANITIZE_STRING);
1314 1314
 		if ($globalTimezone != '') {
1315 1315
 			date_default_timezone_set($globalTimezone);
1316 1316
 			$datetime = new DateTime($date);
@@ -1318,12 +1318,12 @@  discard block
 block discarded – undo
1318 1318
 		} else $offset = '+00:00';
1319 1319
 
1320 1320
 		if ($globalDBdriver == 'mysql') {
1321
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1321
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1322 1322
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = :date
1323 1323
 								GROUP BY hour_name 
1324 1324
 								ORDER BY hour_name ASC";
1325 1325
 		} else {
1326
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1326
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1327 1327
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset, 'YYYY-mm-dd') = :date
1328 1328
 								GROUP BY hour_name 
1329 1329
 								ORDER BY hour_name ASC";
@@ -1335,7 +1335,7 @@  discard block
 block discarded – undo
1335 1335
 		$hour_array = array();
1336 1336
 		$temp_array = array();
1337 1337
         
1338
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1338
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1339 1339
 		{
1340 1340
 			$temp_array['hour_name'] = $row['hour_name'];
1341 1341
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1357,8 +1357,8 @@  discard block
 block discarded – undo
1357 1357
 	public function countAllHoursByIdent($ident, $filters = array())
1358 1358
 	{
1359 1359
 		global $globalTimezone, $globalDBdriver;
1360
-		$filter_query = $this->getFilter($filters,true,true);
1361
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
1360
+		$filter_query = $this->getFilter($filters, true, true);
1361
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
1362 1362
 		if ($globalTimezone != '') {
1363 1363
 			date_default_timezone_set($globalTimezone);
1364 1364
 			$datetime = new DateTime();
@@ -1366,12 +1366,12 @@  discard block
 block discarded – undo
1366 1366
 		} else $offset = '+00:00';
1367 1367
 
1368 1368
 		if ($globalDBdriver == 'mysql') {
1369
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1369
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1370 1370
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1371 1371
 								GROUP BY hour_name 
1372 1372
 								ORDER BY hour_name ASC";
1373 1373
 		} else {
1374
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1374
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1375 1375
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1376 1376
 								GROUP BY hour_name 
1377 1377
 								ORDER BY hour_name ASC";
@@ -1379,12 +1379,12 @@  discard block
 block discarded – undo
1379 1379
       
1380 1380
 		
1381 1381
 		$sth = $this->db->prepare($query);
1382
-		$sth->execute(array(':ident' => $ident,':offset' => $offset));
1382
+		$sth->execute(array(':ident' => $ident, ':offset' => $offset));
1383 1383
       
1384 1384
 		$hour_array = array();
1385 1385
 		$temp_array = array();
1386 1386
         
1387
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1387
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1388 1388
 		{
1389 1389
 			$temp_array['hour_name'] = $row['hour_name'];
1390 1390
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1403,33 +1403,33 @@  discard block
 block discarded – undo
1403 1403
 	* @return Integer the number of vessels
1404 1404
 	*
1405 1405
 	*/
1406
-	public function countOverallMarine($filters = array(),$year = '',$month = '')
1406
+	public function countOverallMarine($filters = array(), $year = '', $month = '')
1407 1407
 	{
1408 1408
 		global $globalDBdriver;
1409 1409
 		//$queryi  = "SELECT COUNT(marine_output.marine_id) AS flight_count FROM marine_output";
1410
-		$queryi  = "SELECT COUNT(DISTINCT marine_output.mmsi) AS flight_count FROM marine_output";
1410
+		$queryi = "SELECT COUNT(DISTINCT marine_output.mmsi) AS flight_count FROM marine_output";
1411 1411
 		$query_values = array();
1412 1412
 		$query = '';
1413 1413
 		if ($year != '') {
1414 1414
 			if ($globalDBdriver == 'mysql') {
1415 1415
 				$query .= " AND YEAR(marine_output.date) = :year";
1416
-				$query_values = array_merge($query_values,array(':year' => $year));
1416
+				$query_values = array_merge($query_values, array(':year' => $year));
1417 1417
 			} else {
1418 1418
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1419
-				$query_values = array_merge($query_values,array(':year' => $year));
1419
+				$query_values = array_merge($query_values, array(':year' => $year));
1420 1420
 			}
1421 1421
 		}
1422 1422
 		if ($month != '') {
1423 1423
 			if ($globalDBdriver == 'mysql') {
1424 1424
 				$query .= " AND MONTH(marine_output.date) = :month";
1425
-				$query_values = array_merge($query_values,array(':month' => $month));
1425
+				$query_values = array_merge($query_values, array(':month' => $month));
1426 1426
 			} else {
1427 1427
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1428
-				$query_values = array_merge($query_values,array(':month' => $month));
1428
+				$query_values = array_merge($query_values, array(':month' => $month));
1429 1429
 			}
1430 1430
 		}
1431 1431
 		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1432
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1432
+		else $queryi .= $this->getFilter($filters, true, true).substr($query, 4);
1433 1433
 		
1434 1434
 		$sth = $this->db->prepare($queryi);
1435 1435
 		$sth->execute($query_values);
@@ -1442,32 +1442,32 @@  discard block
 block discarded – undo
1442 1442
 	* @return Integer the number of vessels
1443 1443
 	*
1444 1444
 	*/
1445
-	public function countOverallMarineTypes($filters = array(),$year = '',$month = '')
1445
+	public function countOverallMarineTypes($filters = array(), $year = '', $month = '')
1446 1446
 	{
1447 1447
 		global $globalDBdriver;
1448
-		$queryi  = "SELECT COUNT(DISTINCT marine_output.type) AS marine_count FROM marine_output";
1448
+		$queryi = "SELECT COUNT(DISTINCT marine_output.type) AS marine_count FROM marine_output";
1449 1449
 		$query_values = array();
1450 1450
 		$query = '';
1451 1451
 		if ($year != '') {
1452 1452
 			if ($globalDBdriver == 'mysql') {
1453 1453
 				$query .= " AND YEAR(marine_output.date) = :year";
1454
-				$query_values = array_merge($query_values,array(':year' => $year));
1454
+				$query_values = array_merge($query_values, array(':year' => $year));
1455 1455
 			} else {
1456 1456
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1457
-				$query_values = array_merge($query_values,array(':year' => $year));
1457
+				$query_values = array_merge($query_values, array(':year' => $year));
1458 1458
 			}
1459 1459
 		}
1460 1460
 		if ($month != '') {
1461 1461
 			if ($globalDBdriver == 'mysql') {
1462 1462
 				$query .= " AND MONTH(marine_output.date) = :month";
1463
-				$query_values = array_merge($query_values,array(':month' => $month));
1463
+				$query_values = array_merge($query_values, array(':month' => $month));
1464 1464
 			} else {
1465 1465
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1466
-				$query_values = array_merge($query_values,array(':month' => $month));
1466
+				$query_values = array_merge($query_values, array(':month' => $month));
1467 1467
 			}
1468 1468
 		}
1469 1469
 		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1470
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1470
+		else $queryi .= $this->getFilter($filters, true, true).substr($query, 4);
1471 1471
 		
1472 1472
 		$sth = $this->db->prepare($queryi);
1473 1473
 		$sth->execute($query_values);
@@ -1484,7 +1484,7 @@  discard block
 block discarded – undo
1484 1484
 	public function countAllHoursFromToday($filters = array())
1485 1485
 	{
1486 1486
 		global $globalTimezone, $globalDBdriver;
1487
-		$filter_query = $this->getFilter($filters,true,true);
1487
+		$filter_query = $this->getFilter($filters, true, true);
1488 1488
 		if ($globalTimezone != '') {
1489 1489
 			date_default_timezone_set($globalTimezone);
1490 1490
 			$datetime = new DateTime();
@@ -1492,12 +1492,12 @@  discard block
 block discarded – undo
1492 1492
 		} else $offset = '+00:00';
1493 1493
 
1494 1494
 		if ($globalDBdriver == 'mysql') {
1495
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1495
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1496 1496
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = CURDATE()
1497 1497
 								GROUP BY hour_name 
1498 1498
 								ORDER BY hour_name ASC";
1499 1499
 		} else {
1500
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1500
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1501 1501
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = CAST(NOW() AS date)
1502 1502
 								GROUP BY hour_name 
1503 1503
 								ORDER BY hour_name ASC";
@@ -1509,7 +1509,7 @@  discard block
 block discarded – undo
1509 1509
 		$hour_array = array();
1510 1510
 		$temp_array = array();
1511 1511
         
1512
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1512
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1513 1513
 		{
1514 1514
 			$temp_array['hour_name'] = $row['hour_name'];
1515 1515
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1528,9 +1528,9 @@  discard block
 block discarded – undo
1528 1528
 	*/
1529 1529
 	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1530 1530
 	{
1531
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
1531
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
1532 1532
 
1533
-		$query  = "SELECT marine_output.marine_id
1533
+		$query = "SELECT marine_output.marine_id
1534 1534
 				FROM marine_output 
1535 1535
 				WHERE marine_output.fammarine_id = '".$fammarine_id."'";
1536 1536
         
@@ -1538,7 +1538,7 @@  discard block
 block discarded – undo
1538 1538
 		$sth = $this->db->prepare($query);
1539 1539
 		$sth->execute();
1540 1540
 
1541
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1541
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1542 1542
 		{
1543 1543
 			return $row['marine_id'];
1544 1544
 		}
@@ -1563,23 +1563,23 @@  discard block
 block discarded – undo
1563 1563
 		}
1564 1564
 		
1565 1565
 		$current_date = date("Y-m-d H:i:s");
1566
-		$date = date("Y-m-d H:i:s",strtotime($dateString." UTC"));
1566
+		$date = date("Y-m-d H:i:s", strtotime($dateString." UTC"));
1567 1567
 		
1568 1568
 		$diff = abs(strtotime($current_date) - strtotime($date));
1569 1569
 
1570
-		$time_array['years'] = floor($diff / (365*60*60*24)); 
1570
+		$time_array['years'] = floor($diff/(365*60*60*24)); 
1571 1571
 		$years = $time_array['years'];
1572 1572
 		
1573
-		$time_array['months'] = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
1573
+		$time_array['months'] = floor(($diff - $years*365*60*60*24)/(30*60*60*24));
1574 1574
 		$months = $time_array['months'];
1575 1575
 		
1576
-		$time_array['days'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
1576
+		$time_array['days'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24)/(60*60*24));
1577 1577
 		$days = $time_array['days'];
1578
-		$time_array['hours'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60));
1578
+		$time_array['hours'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/(60*60));
1579 1579
 		$hours = $time_array['hours'];
1580
-		$time_array['minutes'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60);
1580
+		$time_array['minutes'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/60);
1581 1581
 		$minutes = $time_array['minutes'];
1582
-		$time_array['seconds'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1582
+		$time_array['seconds'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1583 1583
 		
1584 1584
 		return $time_array;
1585 1585
 	}
@@ -1602,63 +1602,63 @@  discard block
 block discarded – undo
1602 1602
 			$temp_array['direction_degree'] = $direction;
1603 1603
 			$temp_array['direction_shortname'] = "N";
1604 1604
 			$temp_array['direction_fullname'] = "North";
1605
-		} elseif ($direction >= 22.5 && $direction < 45){
1605
+		} elseif ($direction >= 22.5 && $direction < 45) {
1606 1606
 			$temp_array['direction_degree'] = $direction;
1607 1607
 			$temp_array['direction_shortname'] = "NNE";
1608 1608
 			$temp_array['direction_fullname'] = "North-Northeast";
1609
-		} elseif ($direction >= 45 && $direction < 67.5){
1609
+		} elseif ($direction >= 45 && $direction < 67.5) {
1610 1610
 			$temp_array['direction_degree'] = $direction;
1611 1611
 			$temp_array['direction_shortname'] = "NE";
1612 1612
 			$temp_array['direction_fullname'] = "Northeast";
1613
-		} elseif ($direction >= 67.5 && $direction < 90){
1613
+		} elseif ($direction >= 67.5 && $direction < 90) {
1614 1614
 			$temp_array['direction_degree'] = $direction;
1615 1615
 			$temp_array['direction_shortname'] = "ENE";
1616 1616
 			$temp_array['direction_fullname'] = "East-Northeast";
1617
-		} elseif ($direction >= 90 && $direction < 112.5){
1617
+		} elseif ($direction >= 90 && $direction < 112.5) {
1618 1618
 			$temp_array['direction_degree'] = $direction;
1619 1619
 			$temp_array['direction_shortname'] = "E";
1620 1620
 			$temp_array['direction_fullname'] = "East";
1621
-		} elseif ($direction >= 112.5 && $direction < 135){
1621
+		} elseif ($direction >= 112.5 && $direction < 135) {
1622 1622
 			$temp_array['direction_degree'] = $direction;
1623 1623
 			$temp_array['direction_shortname'] = "ESE";
1624 1624
 			$temp_array['direction_fullname'] = "East-Southeast";
1625
-		} elseif ($direction >= 135 && $direction < 157.5){
1625
+		} elseif ($direction >= 135 && $direction < 157.5) {
1626 1626
 			$temp_array['direction_degree'] = $direction;
1627 1627
 			$temp_array['direction_shortname'] = "SE";
1628 1628
 			$temp_array['direction_fullname'] = "Southeast";
1629
-		} elseif ($direction >= 157.5 && $direction < 180){
1629
+		} elseif ($direction >= 157.5 && $direction < 180) {
1630 1630
 			$temp_array['direction_degree'] = $direction;
1631 1631
 			$temp_array['direction_shortname'] = "SSE";
1632 1632
 			$temp_array['direction_fullname'] = "South-Southeast";
1633
-		} elseif ($direction >= 180 && $direction < 202.5){
1633
+		} elseif ($direction >= 180 && $direction < 202.5) {
1634 1634
 			$temp_array['direction_degree'] = $direction;
1635 1635
 			$temp_array['direction_shortname'] = "S";
1636 1636
 			$temp_array['direction_fullname'] = "South";
1637
-		} elseif ($direction >= 202.5 && $direction < 225){
1637
+		} elseif ($direction >= 202.5 && $direction < 225) {
1638 1638
 			$temp_array['direction_degree'] = $direction;
1639 1639
 			$temp_array['direction_shortname'] = "SSW";
1640 1640
 			$temp_array['direction_fullname'] = "South-Southwest";
1641
-		} elseif ($direction >= 225 && $direction < 247.5){
1641
+		} elseif ($direction >= 225 && $direction < 247.5) {
1642 1642
 			$temp_array['direction_degree'] = $direction;
1643 1643
 			$temp_array['direction_shortname'] = "SW";
1644 1644
 			$temp_array['direction_fullname'] = "Southwest";
1645
-		} elseif ($direction >= 247.5 && $direction < 270){
1645
+		} elseif ($direction >= 247.5 && $direction < 270) {
1646 1646
 			$temp_array['direction_degree'] = $direction;
1647 1647
 			$temp_array['direction_shortname'] = "WSW";
1648 1648
 			$temp_array['direction_fullname'] = "West-Southwest";
1649
-		} elseif ($direction >= 270 && $direction < 292.5){
1649
+		} elseif ($direction >= 270 && $direction < 292.5) {
1650 1650
 			$temp_array['direction_degree'] = $direction;
1651 1651
 			$temp_array['direction_shortname'] = "W";
1652 1652
 			$temp_array['direction_fullname'] = "West";
1653
-		} elseif ($direction >= 292.5 && $direction < 315){
1653
+		} elseif ($direction >= 292.5 && $direction < 315) {
1654 1654
 			$temp_array['direction_degree'] = $direction;
1655 1655
 			$temp_array['direction_shortname'] = "WNW";
1656 1656
 			$temp_array['direction_fullname'] = "West-Northwest";
1657
-		} elseif ($direction >= 315 && $direction < 337.5){
1657
+		} elseif ($direction >= 315 && $direction < 337.5) {
1658 1658
 			$temp_array['direction_degree'] = $direction;
1659 1659
 			$temp_array['direction_shortname'] = "NW";
1660 1660
 			$temp_array['direction_fullname'] = "Northwest";
1661
-		} elseif ($direction >= 337.5 && $direction < 360){
1661
+		} elseif ($direction >= 337.5 && $direction < 360) {
1662 1662
 			$temp_array['direction_degree'] = $direction;
1663 1663
 			$temp_array['direction_shortname'] = "NNW";
1664 1664
 			$temp_array['direction_fullname'] = "North-Northwest";
@@ -1675,11 +1675,11 @@  discard block
 block discarded – undo
1675 1675
 	* @param Float $longitude longitute of the flight
1676 1676
 	* @return String the countrie
1677 1677
 	*/
1678
-	public function getCountryFromLatitudeLongitude($latitude,$longitude)
1678
+	public function getCountryFromLatitudeLongitude($latitude, $longitude)
1679 1679
 	{
1680 1680
 		global $globalDBdriver, $globalDebug;
1681
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1682
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1681
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1682
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1683 1683
 	
1684 1684
 		$Connection = new Connection($this->db);
1685 1685
 		if (!$Connection->tableExists('countries')) return '';
@@ -1719,7 +1719,7 @@  discard block
 block discarded – undo
1719 1719
 	public function getCountryFromISO2($iso2)
1720 1720
 	{
1721 1721
 		global $globalDBdriver, $globalDebug;
1722
-		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
1722
+		$iso2 = filter_var($iso2, FILTER_SANITIZE_STRING);
1723 1723
 	
1724 1724
 		$Connection = new Connection($this->db);
1725 1725
 		if (!$Connection->tableExists('countries')) return '';
@@ -1767,7 +1767,7 @@  discard block
 block discarded – undo
1767 1767
 		
1768 1768
 		$bitly_data = json_decode($bitly_data);
1769 1769
 		$bitly_url = '';
1770
-		if ($bitly_data->status_txt = "OK"){
1770
+		if ($bitly_data->status_txt = "OK") {
1771 1771
 			$bitly_url = $bitly_data->data->url;
1772 1772
 		}
1773 1773
 
@@ -1781,11 +1781,11 @@  discard block
 block discarded – undo
1781 1781
 	* @return Array the vessel type list
1782 1782
 	*
1783 1783
 	*/
1784
-	public function countAllMarineTypes($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array(),$year = '',$month = '',$day = '')
1784
+	public function countAllMarineTypes($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array(), $year = '', $month = '', $day = '')
1785 1785
 	{
1786 1786
 		global $globalDBdriver;
1787
-		$filter_query = $this->getFilter($filters,true,true);
1788
-		$query  = "SELECT marine_output.type AS marine_type, COUNT(marine_output.type) AS marine_type_count 
1787
+		$filter_query = $this->getFilter($filters, true, true);
1788
+		$query = "SELECT marine_output.type AS marine_type, COUNT(marine_output.type) AS marine_type_count 
1789 1789
 		    FROM marine_output ".$filter_query." marine_output.type  <> ''";
1790 1790
 		if ($olderthanmonths > 0) {
1791 1791
 			if ($globalDBdriver == 'mysql') {
@@ -1805,28 +1805,28 @@  discard block
 block discarded – undo
1805 1805
 		if ($year != '') {
1806 1806
 			if ($globalDBdriver == 'mysql') {
1807 1807
 				$query .= " AND YEAR(marine_output.date) = :year";
1808
-				$query_values = array_merge($query_values,array(':year' => $year));
1808
+				$query_values = array_merge($query_values, array(':year' => $year));
1809 1809
 			} else {
1810 1810
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1811
-				$query_values = array_merge($query_values,array(':year' => $year));
1811
+				$query_values = array_merge($query_values, array(':year' => $year));
1812 1812
 			}
1813 1813
 		}
1814 1814
 		if ($month != '') {
1815 1815
 			if ($globalDBdriver == 'mysql') {
1816 1816
 				$query .= " AND MONTH(marine_output.date) = :month";
1817
-				$query_values = array_merge($query_values,array(':month' => $month));
1817
+				$query_values = array_merge($query_values, array(':month' => $month));
1818 1818
 			} else {
1819 1819
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1820
-				$query_values = array_merge($query_values,array(':month' => $month));
1820
+				$query_values = array_merge($query_values, array(':month' => $month));
1821 1821
 			}
1822 1822
 		}
1823 1823
 		if ($day != '') {
1824 1824
 			if ($globalDBdriver == 'mysql') {
1825 1825
 				$query .= " AND DAY(marine_output.date) = :day";
1826
-				$query_values = array_merge($query_values,array(':day' => $day));
1826
+				$query_values = array_merge($query_values, array(':day' => $day));
1827 1827
 			} else {
1828 1828
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
1829
-				$query_values = array_merge($query_values,array(':day' => $day));
1829
+				$query_values = array_merge($query_values, array(':day' => $day));
1830 1830
 			}
1831 1831
 		}
1832 1832
 		$query .= " GROUP BY marine_output.type ORDER BY marine_type_count DESC";
@@ -1835,7 +1835,7 @@  discard block
 block discarded – undo
1835 1835
 		$sth->execute($query_values);
1836 1836
 		$marine_array = array();
1837 1837
 		$temp_array = array();
1838
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1838
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1839 1839
 		{
1840 1840
 			$temp_array['marine_type'] = $row['marine_type'];
1841 1841
 			$temp_array['marine_type_count'] = $row['marine_type_count'];
@@ -1850,13 +1850,13 @@  discard block
 block discarded – undo
1850 1850
 	* @return Array the tracker information
1851 1851
 	*
1852 1852
 	*/
1853
-	public function searchMarineData($q = '', $callsign = '',$mmsi = '', $imo = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '',$origLat = '',$origLon = '',$dist = '',$filters = array())
1853
+	public function searchMarineData($q = '', $callsign = '', $mmsi = '', $imo = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '', $origLat = '', $origLon = '', $dist = '', $filters = array())
1854 1854
 	{
1855 1855
 		global $globalTimezone, $globalDBdriver;
1856 1856
 		date_default_timezone_set('UTC');
1857 1857
 		$query_values = array();
1858 1858
 		$additional_query = '';
1859
-		$filter_query = $this->getFilter($filters,true,true);
1859
+		$filter_query = $this->getFilter($filters, true, true);
1860 1860
 		if ($q != "")
1861 1861
 		{
1862 1862
 			if (!is_string($q))
@@ -1864,8 +1864,8 @@  discard block
 block discarded – undo
1864 1864
 				return false;
1865 1865
 			} else {
1866 1866
 				$q_array = explode(" ", $q);
1867
-				foreach ($q_array as $q_item){
1868
-					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
1867
+				foreach ($q_array as $q_item) {
1868
+					$q_item = filter_var($q_item, FILTER_SANITIZE_STRING);
1869 1869
 					$additional_query .= " AND (";
1870 1870
 					if (is_int($q_item)) $additional_query .= "(marine_output.marine_id = '".$q_item."') OR ";
1871 1871
 					if (is_int($q_item)) $additional_query .= "(marine_output.mmsi = '".$q_item."') OR ";
@@ -1877,42 +1877,42 @@  discard block
 block discarded – undo
1877 1877
 		}
1878 1878
 		if ($callsign != "")
1879 1879
 		{
1880
-			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
1880
+			$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
1881 1881
 			if (!is_string($callsign))
1882 1882
 			{
1883 1883
 				return false;
1884 1884
 			} else {
1885 1885
 				$additional_query .= " AND marine_output.ident = :callsign";
1886
-				$query_values = array_merge($query_values,array(':callsign' => $callsign));
1886
+				$query_values = array_merge($query_values, array(':callsign' => $callsign));
1887 1887
 			}
1888 1888
 		}
1889 1889
 		if ($mmsi != "")
1890 1890
 		{
1891
-			$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING);
1891
+			$mmsi = filter_var($mmsi, FILTER_SANITIZE_STRING);
1892 1892
 			if (!is_numeric($mmsi))
1893 1893
 			{
1894 1894
 				return false;
1895 1895
 			} else {
1896 1896
 				$additional_query .= " AND marine_output.mmsi = :mmsi";
1897
-				$query_values = array_merge($query_values,array(':mmsi' => $mmsi));
1897
+				$query_values = array_merge($query_values, array(':mmsi' => $mmsi));
1898 1898
 			}
1899 1899
 		}
1900 1900
 		if ($imo != "")
1901 1901
 		{
1902
-			$imo = filter_var($imo,FILTER_SANITIZE_STRING);
1902
+			$imo = filter_var($imo, FILTER_SANITIZE_STRING);
1903 1903
 			if (!is_numeric($imo))
1904 1904
 			{
1905 1905
 				return false;
1906 1906
 			} else {
1907 1907
 				$additional_query .= " AND marine_output.imo = :imo";
1908
-				$query_values = array_merge($query_values,array(':imo' => $imo));
1908
+				$query_values = array_merge($query_values, array(':imo' => $imo));
1909 1909
 			}
1910 1910
 		}
1911 1911
 		if ($date_posted != "")
1912 1912
 		{
1913 1913
 			$date_array = explode(",", $date_posted);
1914
-			$date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING);
1915
-			$date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING);
1914
+			$date_array[0] = filter_var($date_array[0], FILTER_SANITIZE_STRING);
1915
+			$date_array[1] = filter_var($date_array[1], FILTER_SANITIZE_STRING);
1916 1916
 			if ($globalTimezone != '') {
1917 1917
 				date_default_timezone_set($globalTimezone);
1918 1918
 				$datetime = new DateTime();
@@ -1939,8 +1939,8 @@  discard block
 block discarded – undo
1939 1939
 		if ($limit != "")
1940 1940
 		{
1941 1941
 			$limit_array = explode(",", $limit);
1942
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1943
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1942
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
1943
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
1944 1944
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1945 1945
 			{
1946 1946
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
@@ -1958,28 +1958,28 @@  discard block
 block discarded – undo
1958 1958
 			}
1959 1959
 		}
1960 1960
 		if ($origLat != "" && $origLon != "" && $dist != "") {
1961
-			$dist = number_format($dist*0.621371,2,'.',''); // convert km to mile
1961
+			$dist = number_format($dist*0.621371, 2, '.', ''); // convert km to mile
1962 1962
 			if ($globalDBdriver == 'mysql') {
1963
-				$query="SELECT marine_output.*, 1.60935*3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - marine_archive.latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(marine_archive.latitude*pi()/180)*POWER(SIN(($origLon-marine_archive.longitude)*pi()/180/2),2))) as distance 
1963
+				$query = "SELECT marine_output.*, 1.60935*3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - marine_archive.latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(marine_archive.latitude*pi()/180)*POWER(SIN(($origLon-marine_archive.longitude)*pi()/180/2),2))) as distance 
1964 1964
 				    FROM marine_archive,marine_output".$filter_query." marine_output.fammarine_id = marine_archive.fammarine_id AND marine_output.ident <> '' ".$additional_query."AND marine_archive.longitude between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat)*69)) and marine_archive.latitude between ($origLat-($dist/69)) and ($origLat+($dist/69)) 
1965 1965
 				    AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - marine_archive.latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(marine_archive.latitude*pi()/180)*POWER(SIN(($origLon-marine_archive.longitude)*pi()/180/2),2)))) < $dist".$orderby_query;
1966 1966
 			} else {
1967
-				$query="SELECT marine_output.*, 1.60935 * 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(marine_archive.latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(marine_archive.latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(marine_archive.longitude as double precision))*pi()/180/2),2))) as distance 
1967
+				$query = "SELECT marine_output.*, 1.60935 * 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(marine_archive.latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(marine_archive.latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(marine_archive.longitude as double precision))*pi()/180/2),2))) as distance 
1968 1968
 				    FROM marine_archive,marine_output".$filter_query." marine_output.fammarine_id = marine_archive.fammarine_id AND marine_output.ident <> '' ".$additional_query."AND CAST(marine_archive.longitude as double precision) between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat))*69) and CAST(marine_archive.latitude as double precision) between ($origLat-($dist/69)) and ($origLat+($dist/69)) 
1969 1969
 				    AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(marine_archive.latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(marine_archive.latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(marine_archive.longitude as double precision))*pi()/180/2),2)))) < $dist".$filter_query.$orderby_query;
1970 1970
 			}
1971 1971
 		} else {
1972
-			$query  = "SELECT marine_output.* FROM marine_output".$filter_query." marine_output.ident <> '' 
1972
+			$query = "SELECT marine_output.* FROM marine_output".$filter_query." marine_output.ident <> '' 
1973 1973
 			    ".$additional_query."
1974 1974
 			    ".$orderby_query;
1975 1975
 		}
1976
-		$marine_array = $this->getDataFromDB($query, $query_values,$limit_query);
1976
+		$marine_array = $this->getDataFromDB($query, $query_values, $limit_query);
1977 1977
 		return $marine_array;
1978 1978
 	}
1979 1979
 
1980 1980
 	public function getOrderBy()
1981 1981
 	{
1982
-		$orderby = array("type_asc" => array("key" => "type_asc", "value" => "Type - ASC", "sql" => "ORDER BY marine_output.type ASC"), "type_desc" => array("key" => "type_desc", "value" => "Type - DESC", "sql" => "ORDER BY marine_output.type DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_output.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_output.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_output.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_output.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_output.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_output.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_output.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_output.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_output.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_output.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_output.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_output.date DESC"),"distance_asc" => array("key" => "distance_asc","value" => "Distance - ASC","sql" => "ORDER BY distance ASC"),"distance_desc" => array("key" => "distance_desc","value" => "Distance - DESC","sql" => "ORDER BY distance DESC"));
1982
+		$orderby = array("type_asc" => array("key" => "type_asc", "value" => "Type - ASC", "sql" => "ORDER BY marine_output.type ASC"), "type_desc" => array("key" => "type_desc", "value" => "Type - DESC", "sql" => "ORDER BY marine_output.type DESC"), "manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_output.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_output.aircraft_manufacturer DESC"), "airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_output.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_output.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_output.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_output.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_output.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_output.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_output.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_output.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_output.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_output.date DESC"), "distance_asc" => array("key" => "distance_asc", "value" => "Distance - ASC", "sql" => "ORDER BY distance ASC"), "distance_desc" => array("key" => "distance_desc", "value" => "Distance - DESC", "sql" => "ORDER BY distance DESC"));
1983 1983
 		
1984 1984
 		return $orderby;
1985 1985
 		
Please login to merge, or discard this patch.