Completed
Push — master ( 9353a8...36e36d )
by Yannick
35:05 queued 03:27
created
require/class.MarineImport.php 1 patch
Spacing   +85 added lines, -85 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,65 +154,65 @@  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
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
173
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code']));
174 174
 		}
175 175
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
176
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
176
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date']));
177 177
 		}
178 178
 
179 179
 		//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'])) {
180 180
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
181
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
181
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident'])));
182 182
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
183 183
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
184 184
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
185 185
 				$timeelapsed = microtime(true);
186 186
 				$Marine = new Marine($this->db);
187 187
 				$fromsource = NULL;
188
-				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
188
+				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource);
189 189
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
190
-				$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']);
190
+				$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']);
191 191
 				$Marine->db = null;
192
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
192
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
193 193
 			    }
194 194
 			}
195 195
 		    }
196
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
196
+		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['ident']));
197 197
 		}
198 198
 
199
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
199
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 30*60 && strtotime($line['datetime']) < time() + 20*60) {
200 200
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
201
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
201
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime']));
202 202
 		    } else {
203 203
 				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";
204 204
 				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";
205 205
 				return '';
206 206
 		    }
207
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
207
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time() - 30*60) {
208 208
 			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
209 209
 			return '';
210
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
210
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time() + 20*60) {
211 211
 			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
212 212
 			return '';
213 213
 		} elseif (!isset($line['datetime'])) {
214 214
 			date_default_timezone_set('UTC');
215
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
215
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s')));
216 216
 		} else {
217 217
 			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!";
218 218
 			return '';
@@ -220,24 +220,24 @@  discard block
 block discarded – undo
220 220
 
221 221
 
222 222
 		if (isset($line['speed'])) {
223
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
224
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
223
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed'])));
224
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true));
225 225
 		} 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'])) {
226
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
226
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm');
227 227
 		    if ($distance > 1000 && $distance < 10000) {
228 228
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
229 229
 			$speed = $speed*3.6;
230
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
230
+			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed)));
231 231
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
232 232
 		    }
233 233
 		}
234 234
 
235 235
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
236
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
236
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']);
237 237
 	    	    else unset($timediff);
238
-	    	    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')))) {
238
+	    	    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')))) {
239 239
 			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'])) {
240
-			    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'])) {
240
+			    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'])) {
241 241
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
242 242
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
243 243
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -246,10 +246,10 @@  discard block
 block discarded – undo
246 246
 				$timeelapsed = microtime(true);
247 247
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
248 248
 				    $Marine = new Marine($this->db);
249
-				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
249
+				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
250 250
 				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
251 251
 				    $Marine->db = null;
252
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
252
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
253 253
 				}
254 254
 				$this->tmd = 0;
255 255
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
@@ -258,52 +258,52 @@  discard block
 block discarded – undo
258 258
 
259 259
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
260 260
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
261
-				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') {
261
+				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') {
262 262
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
263 263
 				    $dataFound = true;
264 264
 				    $this->all_tracked[$id]['time_last_coord'] = time();
265 265
 				}
266
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
266
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude']));
267 267
 			}
268 268
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
269 269
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
270 270
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
271
-				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') {
271
+				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') {
272 272
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
273 273
 				    $dataFound = true;
274 274
 				    $this->all_tracked[$id]['time_last_coord'] = time();
275 275
 				}
276
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
276
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude']));
277 277
 			}
278 278
 
279 279
 		    } else if ($globalDebug && $timediff > 20) {
280 280
 			$this->tmd = $this->tmd + 1;
281 281
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
282
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
283
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
282
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -";
283
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
284 284
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
285 285
 		    }
286 286
 		}
287 287
 		if (isset($line['last_update']) && $line['last_update'] != '') {
288 288
 		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
289
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
289
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update']));
290 290
 		}
291 291
 		if (isset($line['format_source']) && $line['format_source'] != '') {
292
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
292
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source']));
293 293
 		}
294 294
 		if (isset($line['source_name']) && $line['source_name'] != '') {
295
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
295
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name']));
296 296
 		}
297 297
 		if (isset($line['status']) && $line['status'] != '') {
298
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
298
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status']));
299 299
 		}
300 300
 		if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) {
301
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
301
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status_id' => $line['status_id']));
302 302
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
303 303
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
304 304
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
305 305
 				$Marine = new Marine($this->db);
306
-				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']);
306
+				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['status']);
307 307
 				unset($Marine);
308 308
 			    }
309 309
 			}
@@ -311,18 +311,18 @@  discard block
 block discarded – undo
311 311
 		}
312 312
 
313 313
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
314
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
314
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true));
315 315
 		}
316 316
 		
317 317
 		if (isset($line['heading']) && $line['heading'] != '') {
318
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
319
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
320
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
318
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading'] - round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
319
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading'])));
320
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true));
321 321
 		    //$dataFound = true;
322 322
   		} 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']) {
323
-  		    $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']);
324
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
325
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
323
+  		    $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']);
324
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($heading)));
325
+		    if (abs($this->all_tracked[$id]['heading'] - round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
326 326
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
327 327
   		}
328 328
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
333 333
 		    $this->all_tracked[$id]['lastupdate'] = time();
334 334
 		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
335
-		        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'])) {
335
+		        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'])) {
336 336
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
337 337
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
338 338
 				    if ($globalDebug) echo "Check if aircraft is already in DB...";
@@ -340,37 +340,37 @@  discard block
 block discarded – undo
340 340
 				    $MarineLive = new MarineLive($this->db);
341 341
 				    if (isset($line['id'])) {
342 342
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
343
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
343
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
344 344
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
345 345
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
346
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
346
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
347 347
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
348 348
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
349
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
349
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
350 350
 				    } else $recent_ident = '';
351
-				    $MarineLive->db=null;
351
+				    $MarineLive->db = null;
352 352
 				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
353 353
 				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
354 354
 				} else $recent_ident = '';
355 355
 			    } else {
356 356
 				$recent_ident = '';
357
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
357
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0));
358 358
 			    }
359 359
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
360
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
360
+			    if ($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
361 361
 			    {
362 362
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
363 363
 				//adds the spotter data for the archive
364 364
 				    $highlight = '';
365
-				    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')));
365
+				    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')));
366 366
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
367 367
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
368 368
 					    $timeelapsed = microtime(true);
369 369
 					    $Marine = new Marine($this->db);
370
-					    $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']);
370
+					    $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']);
371 371
 					    $Marine->db = null;
372 372
 					    if ($globalDebug && isset($result)) echo $result."\n";
373
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
373
+					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
374 374
 					}
375 375
 				    }
376 376
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
@@ -378,15 +378,15 @@  discard block
 block discarded – undo
378 378
 					$Stats = new Stats($this->db);
379 379
 					if (!empty($this->stats)) {
380 380
 					    if ($globalDebug) echo 'Add source stats : ';
381
-				    	    foreach($this->stats as $date => $data) {
382
-						foreach($data as $source => $sourced) {
381
+				    	    foreach ($this->stats as $date => $data) {
382
+						foreach ($data as $source => $sourced) {
383 383
 					    	    //print_r($sourced);
384
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
385
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
384
+				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar_marine', $date);
385
+				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist_marine', $date);
386 386
 				    		    if (isset($sourced['msg'])) {
387 387
 				    			if (time() - $sourced['msg']['date'] > 10) {
388 388
 				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
389
-				    		    	    echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
389
+				    		    	    echo $Stats->addStatSource($nbmsg, $source, 'msg_marine', $date);
390 390
 			    			    	    unset($this->stats[$date][$source]['msg']);
391 391
 			    				}
392 392
 			    			    }
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
411 411
 					$MarineLive = new MarineLive($this->db);
412 412
 					$MarineLive->deleteLiveMarineData();
413
-					$MarineLive->db=null;
413
+					$MarineLive->db = null;
414 414
 					if ($globalDebug) echo " Done\n";
415 415
 				    }
416 416
 				    $this->last_delete = time();
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
422 422
 				    if (isset($globalDaemon) && !$globalDaemon) {
423 423
 					$Marine = new Marine($this->db);
424
-					$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']);
424
+					$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']);
425 425
 					$Marine->db = null;
426 426
 				    }
427 427
 				}
@@ -436,20 +436,20 @@  discard block
 block discarded – undo
436 436
 		    $ignoreImport = false;
437 437
 
438 438
 		    if (!$ignoreImport) {
439
-			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'])) {
439
+			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'])) {
440 440
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
441 441
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
442 442
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
443 443
 					$timeelapsed = microtime(true);
444 444
 					$MarineLive = new MarineLive($this->db);
445
-					$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']);
445
+					$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']);
446 446
 					$MarineLive->db = null;
447 447
 					if ($globalDebug) echo $result."\n";
448
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
448
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
449 449
 				    }
450 450
 				}
451 451
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
452
-				    $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']);
452
+				    $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']);
453 453
 				}
454 454
 				$this->all_tracked[$id]['putinarchive'] = false;
455 455
 
@@ -468,19 +468,19 @@  discard block
 block discarded – undo
468 468
 							$latitude = $globalCenterLatitude;
469 469
 							$longitude = $globalCenterLongitude;
470 470
 						}
471
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
471
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
472 472
 					} else {
473 473
 						$latitude = $this->source_location[$source]['latitude'];
474 474
 						$longitude = $this->source_location[$source]['longitude'];
475 475
 					}
476
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
476
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
477 477
 					//$stats_heading = $stats_heading%22.5;
478 478
 					$stats_heading = round($stats_heading/22.5);
479
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
479
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
480 480
 					$current_date = date('Y-m-d');
481 481
 					if ($stats_heading == 16) $stats_heading = 0;
482 482
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
483
-						for ($i=0;$i<=15;$i++) {
483
+						for ($i = 0; $i <= 15; $i++) {
484 484
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
485 485
 						}
486 486
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -495,9 +495,9 @@  discard block
 block discarded – undo
495 495
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
496 496
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
497 497
 						    end($this->stats[$current_date][$source]['hist']);
498
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
498
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
499 499
 						} else $mini = 0;
500
-						for ($i=$mini;$i<=$distance;$i+=10) {
500
+						for ($i = $mini; $i <= $distance; $i += 10) {
501 501
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
502 502
 						}
503 503
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 
510 510
 				$this->all_tracked[$id]['lastupdate'] = time();
511 511
 				if ($this->all_tracked[$id]['putinarchive']) $send = true;
512
-			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
512
+			} 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";
513 513
 			//$this->del();
514 514
 			
515 515
 			
Please login to merge, or discard this patch.
require/class.Marine.php 1 patch
Spacing   +199 added lines, -199 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,17 +468,17 @@  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);
474
-		$imo = filter_var($imo,FILTER_SANITIZE_NUMBER_INT);
475
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
476
-		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
477
-		$type = filter_var($type,FILTER_SANITIZE_STRING);
473
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
474
+		$imo = filter_var($imo, FILTER_SANITIZE_NUMBER_INT);
475
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
476
+		$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
477
+		$type = filter_var($type, FILTER_SANITIZE_STRING);
478 478
 		if (empty($this->getIdentity)) {
479
-			$query  = "INSERT INTO marine_identity (mmsi,imo,call_sign,ship_name,type) VALUES (:mmsi,:imo,:call_sign,:ship_name,:type)";
479
+			$query = "INSERT INTO marine_identity (mmsi,imo,call_sign,ship_name,type) VALUES (:mmsi,:imo,:call_sign,:ship_name,:type)";
480 480
 			$sth = $this->db->prepare($query);
481
-			$sth->execute(array(':mmsi' => $mmsi,':imo' => $imo,':call_sign' => $callsign,':ship_name' => $ident,':type' => $type));
481
+			$sth->execute(array(':mmsi' => $mmsi, ':imo' => $imo, ':call_sign' => $callsign, ':ship_name' => $ident, ':type' => $type));
482 482
 		}
483 483
 	}
484 484
 
@@ -498,12 +498,12 @@  discard block
 block discarded – undo
498 498
 		} else $offset = '+00:00';
499 499
 
500 500
 		if ($globalDBdriver == 'mysql') {
501
-			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
501
+			$query = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
502 502
 								FROM marine_output
503 503
 								WHERE marine_output.date <> '' 
504 504
 								ORDER BY marine_output.date ASC LIMIT 0,100";
505 505
 		} else {
506
-			$query  = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
506
+			$query = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
507 507
 								FROM marine_output
508 508
 								WHERE marine_output.date <> '' 
509 509
 								ORDER BY marine_output.date ASC LIMIT 0,100";
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
 		$date_array = array();
516 516
 		$temp_array = array();
517 517
 		
518
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
518
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
519 519
 		{
520 520
 			$temp_array['date'] = $row['date'];
521 521
 
@@ -533,10 +533,10 @@  discard block
 block discarded – undo
533 533
 	* @return String success or false
534 534
 	*
535 535
 	*/
536
-	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL)
536
+	public function updateIdentMarineData($fammarine_id = '', $ident = '', $fromsource = NULL)
537 537
 	{
538 538
 		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id';
539
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
539
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident);
540 540
 		try {
541 541
 			$sth = $this->db->prepare($query);
542 542
 			$sth->execute($query_values);
@@ -555,11 +555,11 @@  discard block
 block discarded – undo
555 555
 	* @return String success or false
556 556
 	*
557 557
 	*/
558
-	public function updateStatusMarineData($fammarine_id = '', $status_id = '',$status = '')
558
+	public function updateStatusMarineData($fammarine_id = '', $status_id = '', $status = '')
559 559
 	{
560 560
 
561 561
 		$query = 'UPDATE marine_output SET status = :status, status_id = :status_id WHERE fammarine_id = :fammarine_id';
562
-                $query_values = array(':fammarine_id' => $fammarine_id,':status' => $status,':status_id' => $status_id);
562
+                $query_values = array(':fammarine_id' => $fammarine_id, ':status' => $status, ':status_id' => $status_id);
563 563
 
564 564
 		try {
565 565
 			$sth = $this->db->prepare($query);
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '')
583 583
 	{
584 584
 		$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';
585
-                $query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
585
+                $query_values = array(':fammarine_id' => $fammarine_id, ':last_latitude' => $latitude, ':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed, ':last_seen' => $date, ':ident' => $ident);
586 586
 
587 587
 		try {
588 588
 			$sth = $this->db->prepare($query);
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
 	* @param String $verticalrate vertival rate of flight
621 621
 	* @return String success or false
622 622
 	*/
623
-	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 = '')
623
+	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 = '')
624 624
 	{
625 625
 		global $globalURL, $globalMarineImageFetch;
626 626
 		
@@ -687,31 +687,31 @@  discard block
 block discarded – undo
687 687
 		}
688 688
 
689 689
     
690
-		if ($date == "" || strtotime($date) < time()-20*60)
690
+		if ($date == "" || strtotime($date) < time() - 20*60)
691 691
 		{
692 692
 			$date = date("Y-m-d H:i:s", time());
693 693
 		}
694 694
 
695
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
696
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
697
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
698
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
699
-		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
700
-		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
701
-		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
702
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING);
703
-		$type = filter_var($type,FILTER_SANITIZE_STRING);
704
-		$status = filter_var($status,FILTER_SANITIZE_STRING);
705
-		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
706
-		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
707
-		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
708
-		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
695
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
696
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
697
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
698
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
699
+		$heading = filter_var($heading, FILTER_SANITIZE_NUMBER_INT);
700
+		$groundspeed = filter_var($groundspeed, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
701
+		$format_source = filter_var($format_source, FILTER_SANITIZE_STRING);
702
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_STRING);
703
+		$type = filter_var($type, FILTER_SANITIZE_STRING);
704
+		$status = filter_var($status, FILTER_SANITIZE_STRING);
705
+		$imo = filter_var($imo, FILTER_SANITIZE_STRING);
706
+		$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
707
+		$arrival_code = filter_var($arrival_code, FILTER_SANITIZE_STRING);
708
+		$arrival_date = filter_var($arrival_date, FILTER_SANITIZE_STRING);
709 709
 	
710 710
 		if (isset($globalMarineImageFetch) && $globalMarineImageFetch === TRUE) {
711 711
 			$Image = new Image($this->db);
712
-			$image_array = $Image->getMarineImage($mmsi,$imo,$ident);
712
+			$image_array = $Image->getMarineImage($mmsi, $imo, $ident);
713 713
 			if (!isset($image_array[0]['mmsi'])) {
714
-				$Image->addMarineImage($mmsi,$imo,$ident);
714
+				$Image->addMarineImage($mmsi, $imo, $ident);
715 715
 			}
716 716
 			unset($Image);
717 717
 		}
@@ -723,10 +723,10 @@  discard block
 block discarded – undo
723 723
                 if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
724 724
                 if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
725 725
                 if ($arrival_date == '') $arrival_date = NULL;
726
-		$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) 
726
+		$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) 
727 727
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)";
728 728
 
729
-		$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);
729
+		$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);
730 730
 		try {
731 731
 		        
732 732
 			$sth = $this->db->prepare($query);
@@ -751,13 +751,13 @@  discard block
 block discarded – undo
751 751
 	{
752 752
 		global $globalDBdriver, $globalTimezone;
753 753
 		if ($globalDBdriver == 'mysql') {
754
-			$query  = "SELECT marine_output.ident FROM marine_output 
754
+			$query = "SELECT marine_output.ident FROM marine_output 
755 755
 								WHERE marine_output.ident = :ident 
756 756
 								AND marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
757 757
 								AND marine_output.date < UTC_TIMESTAMP()";
758 758
 			$query_data = array(':ident' => $ident);
759 759
 		} else {
760
-			$query  = "SELECT marine_output.ident FROM marine_output 
760
+			$query = "SELECT marine_output.ident FROM marine_output 
761 761
 								WHERE marine_output.ident = :ident 
762 762
 								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
763 763
 								AND marine_output.date < now() AT TIME ZONE 'UTC'";
@@ -766,8 +766,8 @@  discard block
 block discarded – undo
766 766
 		
767 767
 		$sth = $this->db->prepare($query);
768 768
 		$sth->execute($query_data);
769
-    		$ident_result='';
770
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
769
+    		$ident_result = '';
770
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
771 771
 		{
772 772
 			$ident_result = $row['ident'];
773 773
 		}
@@ -793,8 +793,8 @@  discard block
 block discarded – undo
793 793
 				return false;
794 794
 			} else {
795 795
 				$q_array = explode(" ", $q);
796
-				foreach ($q_array as $q_item){
797
-					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
796
+				foreach ($q_array as $q_item) {
797
+					$q_item = filter_var($q_item, FILTER_SANITIZE_STRING);
798 798
 					$additional_query .= " AND (";
799 799
 					$additional_query .= "(marine_output.ident like '%".$q_item."%')";
800 800
 					$additional_query .= ")";
@@ -802,11 +802,11 @@  discard block
 block discarded – undo
802 802
 			}
803 803
 		}
804 804
 		if ($globalDBdriver == 'mysql') {
805
-			$query  = "SELECT marine_output.* FROM marine_output 
805
+			$query = "SELECT marine_output.* FROM marine_output 
806 806
 				WHERE marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query." 
807 807
 				AND marine_output.date < UTC_TIMESTAMP()";
808 808
 		} else {
809
-			$query  = "SELECT marine_output.* FROM marine_output 
809
+			$query = "SELECT marine_output.* FROM marine_output 
810 810
 				WHERE marine_output.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query." 
811 811
 				AND marine_output.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
812 812
 		}
@@ -825,16 +825,16 @@  discard block
 block discarded – undo
825 825
 	*
826 826
 	*/
827 827
 
828
-	public function countAllMarineOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array())
828
+	public function countAllMarineOverCountries($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array())
829 829
 	{
830 830
 		global $globalDBdriver, $globalArchive;
831 831
 		//$filter_query = $this->getFilter($filters,true,true);
832
-		$Connection= new Connection($this->db);
832
+		$Connection = new Connection($this->db);
833 833
 		if (!$Connection->tableExists('countries')) return array();
834 834
 		require_once('class.SpotterLive.php');
835 835
 		if (!isset($globalArchive) || $globalArchive !== TRUE) {
836 836
 			$MarineLive = new MarineLive($this->db);
837
-			$filter_query = $MarineLive->getFilter($filters,true,true);
837
+			$filter_query = $MarineLive->getFilter($filters, true, true);
838 838
 			$filter_query .= " over_country IS NOT NULL AND over_country <> ''";
839 839
 			if ($olderthanmonths > 0) {
840 840
 				if ($globalDBdriver == 'mysql') {
@@ -854,7 +854,7 @@  discard block
 block discarded – undo
854 854
 		} else {
855 855
 			require_once(dirname(__FILE__)."/class.MarineArchive.php");
856 856
 			$MarineArchive = new MarineArchive($this->db);
857
-			$filter_query = $MarineArchive->getFilter($filters,true,true);
857
+			$filter_query = $MarineArchive->getFilter($filters, true, true);
858 858
 			$filter_query .= " over_country <> ''";
859 859
 			if ($olderthanmonths > 0) {
860 860
 				if ($globalDBdriver == 'mysql') {
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
 		$flight_array = array();
883 883
 		$temp_array = array();
884 884
         
885
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
885
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
886 886
 		{
887 887
 			$temp_array['marine_count'] = $row['nb'];
888 888
 			$temp_array['marine_country'] = $row['name'];
@@ -901,11 +901,11 @@  discard block
 block discarded – undo
901 901
 	* @return Array the callsign list
902 902
 	*
903 903
 	*/
904
-	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
904
+	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array(), $year = '', $month = '', $day = '')
905 905
 	{
906 906
 		global $globalDBdriver;
907
-		$filter_query = $this->getFilter($filters,true,true);
908
-		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
907
+		$filter_query = $this->getFilter($filters, true, true);
908
+		$query = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
909 909
                     FROM marine_output".$filter_query." marine_output.ident <> ''";
910 910
 		 if ($olderthanmonths > 0) {
911 911
 			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
@@ -919,28 +919,28 @@  discard block
 block discarded – undo
919 919
 		if ($year != '') {
920 920
 			if ($globalDBdriver == 'mysql') {
921 921
 				$query .= " AND YEAR(marine_output.date) = :year";
922
-				$query_values = array_merge($query_values,array(':year' => $year));
922
+				$query_values = array_merge($query_values, array(':year' => $year));
923 923
 			} else {
924 924
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
925
-				$query_values = array_merge($query_values,array(':year' => $year));
925
+				$query_values = array_merge($query_values, array(':year' => $year));
926 926
 			}
927 927
 		}
928 928
 		if ($month != '') {
929 929
 			if ($globalDBdriver == 'mysql') {
930 930
 				$query .= " AND MONTH(marine_output.date) = :month";
931
-				$query_values = array_merge($query_values,array(':month' => $month));
931
+				$query_values = array_merge($query_values, array(':month' => $month));
932 932
 			} else {
933 933
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
934
-				$query_values = array_merge($query_values,array(':month' => $month));
934
+				$query_values = array_merge($query_values, array(':month' => $month));
935 935
 			}
936 936
 		}
937 937
 		if ($day != '') {
938 938
 			if ($globalDBdriver == 'mysql') {
939 939
 				$query .= " AND DAY(marine_output.date) = :day";
940
-				$query_values = array_merge($query_values,array(':day' => $day));
940
+				$query_values = array_merge($query_values, array(':day' => $day));
941 941
 			} else {
942 942
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
943
-				$query_values = array_merge($query_values,array(':day' => $day));
943
+				$query_values = array_merge($query_values, array(':day' => $day));
944 944
 			}
945 945
 		}
946 946
 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
@@ -952,7 +952,7 @@  discard block
 block discarded – undo
952 952
 		$callsign_array = array();
953 953
 		$temp_array = array();
954 954
         
955
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
955
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
956 956
 		{
957 957
 			$temp_array['callsign_icao'] = $row['ident'];
958 958
 			$temp_array['airline_name'] = $row['airline_name'];
@@ -1004,7 +1004,7 @@  discard block
 block discarded – undo
1004 1004
 		$date_array = array();
1005 1005
 		$temp_array = array();
1006 1006
         
1007
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1007
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1008 1008
 		{
1009 1009
 			$temp_array['date_name'] = $row['date_name'];
1010 1010
 			$temp_array['date_count'] = $row['date_count'];
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
 			$datetime = new DateTime();
1031 1031
 			$offset = $datetime->format('P');
1032 1032
 		} else $offset = '+00:00';
1033
-		$filter_query = $this->getFilter($filters,true,true);
1033
+		$filter_query = $this->getFilter($filters, true, true);
1034 1034
 		if ($globalDBdriver == 'mysql') {
1035 1035
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1036 1036
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY)";
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
 		$date_array = array();
1052 1052
 		$temp_array = array();
1053 1053
         
1054
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1054
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1055 1055
 		{
1056 1056
 			$temp_array['date_name'] = $row['date_name'];
1057 1057
 			$temp_array['date_count'] = $row['date_count'];
@@ -1076,7 +1076,7 @@  discard block
 block discarded – undo
1076 1076
 			$datetime = new DateTime();
1077 1077
 			$offset = $datetime->format('P');
1078 1078
 		} else $offset = '+00:00';
1079
-		$filter_query = $this->getFilter($filters,true,true);
1079
+		$filter_query = $this->getFilter($filters, true, true);
1080 1080
 		if ($globalDBdriver == 'mysql') {
1081 1081
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1082 1082
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MONTH)";
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
 		$date_array = array();
1098 1098
 		$temp_array = array();
1099 1099
         
1100
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1100
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1101 1101
 		{
1102 1102
 			$temp_array['date_name'] = $row['date_name'];
1103 1103
 			$temp_array['date_count'] = $row['date_count'];
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
 		$date_array = array();
1145 1145
 		$temp_array = array();
1146 1146
         
1147
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1147
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1148 1148
 		{
1149 1149
 			$temp_array['month_name'] = $row['month_name'];
1150 1150
 			$temp_array['year_name'] = $row['year_name'];
@@ -1173,7 +1173,7 @@  discard block
 block discarded – undo
1173 1173
 			$datetime = new DateTime();
1174 1174
 			$offset = $datetime->format('P');
1175 1175
 		} else $offset = '+00:00';
1176
-		$filter_query = $this->getFilter($filters,true,true);
1176
+		$filter_query = $this->getFilter($filters, true, true);
1177 1177
 		if ($globalDBdriver == 'mysql') {
1178 1178
 			$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
1179 1179
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 YEAR)";
@@ -1194,7 +1194,7 @@  discard block
 block discarded – undo
1194 1194
 		$date_array = array();
1195 1195
 		$temp_array = array();
1196 1196
         
1197
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1197
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1198 1198
 		{
1199 1199
 			$temp_array['year_name'] = $row['year_name'];
1200 1200
 			$temp_array['month_name'] = $row['month_name'];
@@ -1214,7 +1214,7 @@  discard block
 block discarded – undo
1214 1214
 	* @return Array the hour list
1215 1215
 	*
1216 1216
 	*/
1217
-	public function countAllHours($orderby,$filters = array())
1217
+	public function countAllHours($orderby, $filters = array())
1218 1218
 	{
1219 1219
 		global $globalTimezone, $globalDBdriver;
1220 1220
 		if ($globalTimezone != '') {
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
 		$hour_array = array();
1263 1263
 		$temp_array = array();
1264 1264
         
1265
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1265
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1266 1266
 		{
1267 1267
 			$temp_array['hour_name'] = $row['hour_name'];
1268 1268
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1284,8 +1284,8 @@  discard block
 block discarded – undo
1284 1284
 	public function countAllHoursByDate($date, $filters = array())
1285 1285
 	{
1286 1286
 		global $globalTimezone, $globalDBdriver;
1287
-		$filter_query = $this->getFilter($filters,true,true);
1288
-		$date = filter_var($date,FILTER_SANITIZE_STRING);
1287
+		$filter_query = $this->getFilter($filters, true, true);
1288
+		$date = filter_var($date, FILTER_SANITIZE_STRING);
1289 1289
 		if ($globalTimezone != '') {
1290 1290
 			date_default_timezone_set($globalTimezone);
1291 1291
 			$datetime = new DateTime($date);
@@ -1293,12 +1293,12 @@  discard block
 block discarded – undo
1293 1293
 		} else $offset = '+00:00';
1294 1294
 
1295 1295
 		if ($globalDBdriver == 'mysql') {
1296
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1296
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1297 1297
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = :date
1298 1298
 								GROUP BY hour_name 
1299 1299
 								ORDER BY hour_name ASC";
1300 1300
 		} else {
1301
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1301
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1302 1302
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset, 'YYYY-mm-dd') = :date
1303 1303
 								GROUP BY hour_name 
1304 1304
 								ORDER BY hour_name ASC";
@@ -1310,7 +1310,7 @@  discard block
 block discarded – undo
1310 1310
 		$hour_array = array();
1311 1311
 		$temp_array = array();
1312 1312
         
1313
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1313
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1314 1314
 		{
1315 1315
 			$temp_array['hour_name'] = $row['hour_name'];
1316 1316
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1332,8 +1332,8 @@  discard block
 block discarded – undo
1332 1332
 	public function countAllHoursByIdent($ident, $filters = array())
1333 1333
 	{
1334 1334
 		global $globalTimezone, $globalDBdriver;
1335
-		$filter_query = $this->getFilter($filters,true,true);
1336
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
1335
+		$filter_query = $this->getFilter($filters, true, true);
1336
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
1337 1337
 		if ($globalTimezone != '') {
1338 1338
 			date_default_timezone_set($globalTimezone);
1339 1339
 			$datetime = new DateTime();
@@ -1341,12 +1341,12 @@  discard block
 block discarded – undo
1341 1341
 		} else $offset = '+00:00';
1342 1342
 
1343 1343
 		if ($globalDBdriver == 'mysql') {
1344
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1344
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1345 1345
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1346 1346
 								GROUP BY hour_name 
1347 1347
 								ORDER BY hour_name ASC";
1348 1348
 		} else {
1349
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1349
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1350 1350
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1351 1351
 								GROUP BY hour_name 
1352 1352
 								ORDER BY hour_name ASC";
@@ -1354,12 +1354,12 @@  discard block
 block discarded – undo
1354 1354
       
1355 1355
 		
1356 1356
 		$sth = $this->db->prepare($query);
1357
-		$sth->execute(array(':ident' => $ident,':offset' => $offset));
1357
+		$sth->execute(array(':ident' => $ident, ':offset' => $offset));
1358 1358
       
1359 1359
 		$hour_array = array();
1360 1360
 		$temp_array = array();
1361 1361
         
1362
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1362
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1363 1363
 		{
1364 1364
 			$temp_array['hour_name'] = $row['hour_name'];
1365 1365
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1378,33 +1378,33 @@  discard block
 block discarded – undo
1378 1378
 	* @return Integer the number of vessels
1379 1379
 	*
1380 1380
 	*/
1381
-	public function countOverallMarine($filters = array(),$year = '',$month = '')
1381
+	public function countOverallMarine($filters = array(), $year = '', $month = '')
1382 1382
 	{
1383 1383
 		global $globalDBdriver;
1384 1384
 		//$queryi  = "SELECT COUNT(marine_output.marine_id) AS flight_count FROM marine_output";
1385
-		$queryi  = "SELECT COUNT(DISTINCT marine_output.mmsi) AS flight_count FROM marine_output";
1385
+		$queryi = "SELECT COUNT(DISTINCT marine_output.mmsi) AS flight_count FROM marine_output";
1386 1386
 		$query_values = array();
1387 1387
 		$query = '';
1388 1388
 		if ($year != '') {
1389 1389
 			if ($globalDBdriver == 'mysql') {
1390 1390
 				$query .= " AND YEAR(marine_output.date) = :year";
1391
-				$query_values = array_merge($query_values,array(':year' => $year));
1391
+				$query_values = array_merge($query_values, array(':year' => $year));
1392 1392
 			} else {
1393 1393
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1394
-				$query_values = array_merge($query_values,array(':year' => $year));
1394
+				$query_values = array_merge($query_values, array(':year' => $year));
1395 1395
 			}
1396 1396
 		}
1397 1397
 		if ($month != '') {
1398 1398
 			if ($globalDBdriver == 'mysql') {
1399 1399
 				$query .= " AND MONTH(marine_output.date) = :month";
1400
-				$query_values = array_merge($query_values,array(':month' => $month));
1400
+				$query_values = array_merge($query_values, array(':month' => $month));
1401 1401
 			} else {
1402 1402
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1403
-				$query_values = array_merge($query_values,array(':month' => $month));
1403
+				$query_values = array_merge($query_values, array(':month' => $month));
1404 1404
 			}
1405 1405
 		}
1406 1406
 		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1407
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1407
+		else $queryi .= $this->getFilter($filters, true, true).substr($query, 4);
1408 1408
 		
1409 1409
 		$sth = $this->db->prepare($queryi);
1410 1410
 		$sth->execute($query_values);
@@ -1417,32 +1417,32 @@  discard block
 block discarded – undo
1417 1417
 	* @return Integer the number of vessels
1418 1418
 	*
1419 1419
 	*/
1420
-	public function countOverallMarineTypes($filters = array(),$year = '',$month = '')
1420
+	public function countOverallMarineTypes($filters = array(), $year = '', $month = '')
1421 1421
 	{
1422 1422
 		global $globalDBdriver;
1423
-		$queryi  = "SELECT COUNT(DISTINCT marine_output.type) AS marine_count FROM marine_output";
1423
+		$queryi = "SELECT COUNT(DISTINCT marine_output.type) AS marine_count FROM marine_output";
1424 1424
 		$query_values = array();
1425 1425
 		$query = '';
1426 1426
 		if ($year != '') {
1427 1427
 			if ($globalDBdriver == 'mysql') {
1428 1428
 				$query .= " AND YEAR(marine_output.date) = :year";
1429
-				$query_values = array_merge($query_values,array(':year' => $year));
1429
+				$query_values = array_merge($query_values, array(':year' => $year));
1430 1430
 			} else {
1431 1431
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1432
-				$query_values = array_merge($query_values,array(':year' => $year));
1432
+				$query_values = array_merge($query_values, array(':year' => $year));
1433 1433
 			}
1434 1434
 		}
1435 1435
 		if ($month != '') {
1436 1436
 			if ($globalDBdriver == 'mysql') {
1437 1437
 				$query .= " AND MONTH(marine_output.date) = :month";
1438
-				$query_values = array_merge($query_values,array(':month' => $month));
1438
+				$query_values = array_merge($query_values, array(':month' => $month));
1439 1439
 			} else {
1440 1440
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1441
-				$query_values = array_merge($query_values,array(':month' => $month));
1441
+				$query_values = array_merge($query_values, array(':month' => $month));
1442 1442
 			}
1443 1443
 		}
1444 1444
 		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1445
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1445
+		else $queryi .= $this->getFilter($filters, true, true).substr($query, 4);
1446 1446
 		
1447 1447
 		$sth = $this->db->prepare($queryi);
1448 1448
 		$sth->execute($query_values);
@@ -1459,7 +1459,7 @@  discard block
 block discarded – undo
1459 1459
 	public function countAllHoursFromToday($filters = array())
1460 1460
 	{
1461 1461
 		global $globalTimezone, $globalDBdriver;
1462
-		$filter_query = $this->getFilter($filters,true,true);
1462
+		$filter_query = $this->getFilter($filters, true, true);
1463 1463
 		if ($globalTimezone != '') {
1464 1464
 			date_default_timezone_set($globalTimezone);
1465 1465
 			$datetime = new DateTime();
@@ -1467,12 +1467,12 @@  discard block
 block discarded – undo
1467 1467
 		} else $offset = '+00:00';
1468 1468
 
1469 1469
 		if ($globalDBdriver == 'mysql') {
1470
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1470
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1471 1471
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = CURDATE()
1472 1472
 								GROUP BY hour_name 
1473 1473
 								ORDER BY hour_name ASC";
1474 1474
 		} else {
1475
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1475
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1476 1476
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = CAST(NOW() AS date)
1477 1477
 								GROUP BY hour_name 
1478 1478
 								ORDER BY hour_name ASC";
@@ -1484,7 +1484,7 @@  discard block
 block discarded – undo
1484 1484
 		$hour_array = array();
1485 1485
 		$temp_array = array();
1486 1486
         
1487
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1487
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1488 1488
 		{
1489 1489
 			$temp_array['hour_name'] = $row['hour_name'];
1490 1490
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1503,9 +1503,9 @@  discard block
 block discarded – undo
1503 1503
 	*/
1504 1504
 	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1505 1505
 	{
1506
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
1506
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
1507 1507
 
1508
-		$query  = "SELECT marine_output.marine_id
1508
+		$query = "SELECT marine_output.marine_id
1509 1509
 				FROM marine_output 
1510 1510
 				WHERE marine_output.fammarine_id = '".$fammarine_id."'";
1511 1511
         
@@ -1513,7 +1513,7 @@  discard block
 block discarded – undo
1513 1513
 		$sth = $this->db->prepare($query);
1514 1514
 		$sth->execute();
1515 1515
 
1516
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1516
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1517 1517
 		{
1518 1518
 			return $row['marine_id'];
1519 1519
 		}
@@ -1538,23 +1538,23 @@  discard block
 block discarded – undo
1538 1538
 		}
1539 1539
 		
1540 1540
 		$current_date = date("Y-m-d H:i:s");
1541
-		$date = date("Y-m-d H:i:s",strtotime($dateString." UTC"));
1541
+		$date = date("Y-m-d H:i:s", strtotime($dateString." UTC"));
1542 1542
 		
1543 1543
 		$diff = abs(strtotime($current_date) - strtotime($date));
1544 1544
 
1545
-		$time_array['years'] = floor($diff / (365*60*60*24)); 
1545
+		$time_array['years'] = floor($diff/(365*60*60*24)); 
1546 1546
 		$years = $time_array['years'];
1547 1547
 		
1548
-		$time_array['months'] = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
1548
+		$time_array['months'] = floor(($diff - $years*365*60*60*24)/(30*60*60*24));
1549 1549
 		$months = $time_array['months'];
1550 1550
 		
1551
-		$time_array['days'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
1551
+		$time_array['days'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24)/(60*60*24));
1552 1552
 		$days = $time_array['days'];
1553
-		$time_array['hours'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60));
1553
+		$time_array['hours'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/(60*60));
1554 1554
 		$hours = $time_array['hours'];
1555
-		$time_array['minutes'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60);
1555
+		$time_array['minutes'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/60);
1556 1556
 		$minutes = $time_array['minutes'];
1557
-		$time_array['seconds'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1557
+		$time_array['seconds'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1558 1558
 		
1559 1559
 		return $time_array;
1560 1560
 	}
@@ -1577,63 +1577,63 @@  discard block
 block discarded – undo
1577 1577
 			$temp_array['direction_degree'] = $direction;
1578 1578
 			$temp_array['direction_shortname'] = "N";
1579 1579
 			$temp_array['direction_fullname'] = "North";
1580
-		} elseif ($direction >= 22.5 && $direction < 45){
1580
+		} elseif ($direction >= 22.5 && $direction < 45) {
1581 1581
 			$temp_array['direction_degree'] = $direction;
1582 1582
 			$temp_array['direction_shortname'] = "NNE";
1583 1583
 			$temp_array['direction_fullname'] = "North-Northeast";
1584
-		} elseif ($direction >= 45 && $direction < 67.5){
1584
+		} elseif ($direction >= 45 && $direction < 67.5) {
1585 1585
 			$temp_array['direction_degree'] = $direction;
1586 1586
 			$temp_array['direction_shortname'] = "NE";
1587 1587
 			$temp_array['direction_fullname'] = "Northeast";
1588
-		} elseif ($direction >= 67.5 && $direction < 90){
1588
+		} elseif ($direction >= 67.5 && $direction < 90) {
1589 1589
 			$temp_array['direction_degree'] = $direction;
1590 1590
 			$temp_array['direction_shortname'] = "ENE";
1591 1591
 			$temp_array['direction_fullname'] = "East-Northeast";
1592
-		} elseif ($direction >= 90 && $direction < 112.5){
1592
+		} elseif ($direction >= 90 && $direction < 112.5) {
1593 1593
 			$temp_array['direction_degree'] = $direction;
1594 1594
 			$temp_array['direction_shortname'] = "E";
1595 1595
 			$temp_array['direction_fullname'] = "East";
1596
-		} elseif ($direction >= 112.5 && $direction < 135){
1596
+		} elseif ($direction >= 112.5 && $direction < 135) {
1597 1597
 			$temp_array['direction_degree'] = $direction;
1598 1598
 			$temp_array['direction_shortname'] = "ESE";
1599 1599
 			$temp_array['direction_fullname'] = "East-Southeast";
1600
-		} elseif ($direction >= 135 && $direction < 157.5){
1600
+		} elseif ($direction >= 135 && $direction < 157.5) {
1601 1601
 			$temp_array['direction_degree'] = $direction;
1602 1602
 			$temp_array['direction_shortname'] = "SE";
1603 1603
 			$temp_array['direction_fullname'] = "Southeast";
1604
-		} elseif ($direction >= 157.5 && $direction < 180){
1604
+		} elseif ($direction >= 157.5 && $direction < 180) {
1605 1605
 			$temp_array['direction_degree'] = $direction;
1606 1606
 			$temp_array['direction_shortname'] = "SSE";
1607 1607
 			$temp_array['direction_fullname'] = "South-Southeast";
1608
-		} elseif ($direction >= 180 && $direction < 202.5){
1608
+		} elseif ($direction >= 180 && $direction < 202.5) {
1609 1609
 			$temp_array['direction_degree'] = $direction;
1610 1610
 			$temp_array['direction_shortname'] = "S";
1611 1611
 			$temp_array['direction_fullname'] = "South";
1612
-		} elseif ($direction >= 202.5 && $direction < 225){
1612
+		} elseif ($direction >= 202.5 && $direction < 225) {
1613 1613
 			$temp_array['direction_degree'] = $direction;
1614 1614
 			$temp_array['direction_shortname'] = "SSW";
1615 1615
 			$temp_array['direction_fullname'] = "South-Southwest";
1616
-		} elseif ($direction >= 225 && $direction < 247.5){
1616
+		} elseif ($direction >= 225 && $direction < 247.5) {
1617 1617
 			$temp_array['direction_degree'] = $direction;
1618 1618
 			$temp_array['direction_shortname'] = "SW";
1619 1619
 			$temp_array['direction_fullname'] = "Southwest";
1620
-		} elseif ($direction >= 247.5 && $direction < 270){
1620
+		} elseif ($direction >= 247.5 && $direction < 270) {
1621 1621
 			$temp_array['direction_degree'] = $direction;
1622 1622
 			$temp_array['direction_shortname'] = "WSW";
1623 1623
 			$temp_array['direction_fullname'] = "West-Southwest";
1624
-		} elseif ($direction >= 270 && $direction < 292.5){
1624
+		} elseif ($direction >= 270 && $direction < 292.5) {
1625 1625
 			$temp_array['direction_degree'] = $direction;
1626 1626
 			$temp_array['direction_shortname'] = "W";
1627 1627
 			$temp_array['direction_fullname'] = "West";
1628
-		} elseif ($direction >= 292.5 && $direction < 315){
1628
+		} elseif ($direction >= 292.5 && $direction < 315) {
1629 1629
 			$temp_array['direction_degree'] = $direction;
1630 1630
 			$temp_array['direction_shortname'] = "WNW";
1631 1631
 			$temp_array['direction_fullname'] = "West-Northwest";
1632
-		} elseif ($direction >= 315 && $direction < 337.5){
1632
+		} elseif ($direction >= 315 && $direction < 337.5) {
1633 1633
 			$temp_array['direction_degree'] = $direction;
1634 1634
 			$temp_array['direction_shortname'] = "NW";
1635 1635
 			$temp_array['direction_fullname'] = "Northwest";
1636
-		} elseif ($direction >= 337.5 && $direction < 360){
1636
+		} elseif ($direction >= 337.5 && $direction < 360) {
1637 1637
 			$temp_array['direction_degree'] = $direction;
1638 1638
 			$temp_array['direction_shortname'] = "NNW";
1639 1639
 			$temp_array['direction_fullname'] = "North-Northwest";
@@ -1650,11 +1650,11 @@  discard block
 block discarded – undo
1650 1650
 	* @param Float $longitude longitute of the flight
1651 1651
 	* @return String the countrie
1652 1652
 	*/
1653
-	public function getCountryFromLatitudeLongitude($latitude,$longitude)
1653
+	public function getCountryFromLatitudeLongitude($latitude, $longitude)
1654 1654
 	{
1655 1655
 		global $globalDBdriver, $globalDebug;
1656
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1657
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1656
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1657
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1658 1658
 	
1659 1659
 		$Connection = new Connection($this->db);
1660 1660
 		if (!$Connection->tableExists('countries')) return '';
@@ -1694,7 +1694,7 @@  discard block
 block discarded – undo
1694 1694
 	public function getCountryFromISO2($iso2)
1695 1695
 	{
1696 1696
 		global $globalDBdriver, $globalDebug;
1697
-		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
1697
+		$iso2 = filter_var($iso2, FILTER_SANITIZE_STRING);
1698 1698
 	
1699 1699
 		$Connection = new Connection($this->db);
1700 1700
 		if (!$Connection->tableExists('countries')) return '';
@@ -1742,7 +1742,7 @@  discard block
 block discarded – undo
1742 1742
 		
1743 1743
 		$bitly_data = json_decode($bitly_data);
1744 1744
 		$bitly_url = '';
1745
-		if ($bitly_data->status_txt = "OK"){
1745
+		if ($bitly_data->status_txt = "OK") {
1746 1746
 			$bitly_url = $bitly_data->data->url;
1747 1747
 		}
1748 1748
 
@@ -1756,11 +1756,11 @@  discard block
 block discarded – undo
1756 1756
 	* @return Array the vessel type list
1757 1757
 	*
1758 1758
 	*/
1759
-	public function countAllMarineTypes($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array(),$year = '',$month = '',$day = '')
1759
+	public function countAllMarineTypes($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array(), $year = '', $month = '', $day = '')
1760 1760
 	{
1761 1761
 		global $globalDBdriver;
1762
-		$filter_query = $this->getFilter($filters,true,true);
1763
-		$query  = "SELECT marine_output.type AS marine_type, COUNT(marine_output.type) AS marine_type_count 
1762
+		$filter_query = $this->getFilter($filters, true, true);
1763
+		$query = "SELECT marine_output.type AS marine_type, COUNT(marine_output.type) AS marine_type_count 
1764 1764
 		    FROM marine_output ".$filter_query." marine_output.type  <> ''";
1765 1765
 		if ($olderthanmonths > 0) {
1766 1766
 			if ($globalDBdriver == 'mysql') {
@@ -1780,28 +1780,28 @@  discard block
 block discarded – undo
1780 1780
 		if ($year != '') {
1781 1781
 			if ($globalDBdriver == 'mysql') {
1782 1782
 				$query .= " AND YEAR(marine_output.date) = :year";
1783
-				$query_values = array_merge($query_values,array(':year' => $year));
1783
+				$query_values = array_merge($query_values, array(':year' => $year));
1784 1784
 			} else {
1785 1785
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1786
-				$query_values = array_merge($query_values,array(':year' => $year));
1786
+				$query_values = array_merge($query_values, array(':year' => $year));
1787 1787
 			}
1788 1788
 		}
1789 1789
 		if ($month != '') {
1790 1790
 			if ($globalDBdriver == 'mysql') {
1791 1791
 				$query .= " AND MONTH(marine_output.date) = :month";
1792
-				$query_values = array_merge($query_values,array(':month' => $month));
1792
+				$query_values = array_merge($query_values, array(':month' => $month));
1793 1793
 			} else {
1794 1794
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1795
-				$query_values = array_merge($query_values,array(':month' => $month));
1795
+				$query_values = array_merge($query_values, array(':month' => $month));
1796 1796
 			}
1797 1797
 		}
1798 1798
 		if ($day != '') {
1799 1799
 			if ($globalDBdriver == 'mysql') {
1800 1800
 				$query .= " AND DAY(marine_output.date) = :day";
1801
-				$query_values = array_merge($query_values,array(':day' => $day));
1801
+				$query_values = array_merge($query_values, array(':day' => $day));
1802 1802
 			} else {
1803 1803
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
1804
-				$query_values = array_merge($query_values,array(':day' => $day));
1804
+				$query_values = array_merge($query_values, array(':day' => $day));
1805 1805
 			}
1806 1806
 		}
1807 1807
 		$query .= " GROUP BY marine_output.type ORDER BY marine_type_count DESC";
@@ -1810,7 +1810,7 @@  discard block
 block discarded – undo
1810 1810
 		$sth->execute($query_values);
1811 1811
 		$marine_array = array();
1812 1812
 		$temp_array = array();
1813
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1813
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1814 1814
 		{
1815 1815
 			$temp_array['marine_type'] = $row['marine_type'];
1816 1816
 			$temp_array['marine_type_count'] = $row['marine_type_count'];
@@ -1825,13 +1825,13 @@  discard block
 block discarded – undo
1825 1825
 	* @return Array the tracker information
1826 1826
 	*
1827 1827
 	*/
1828
-	public function searchMarineData($q = '', $callsign = '',$mmsi = '', $imo = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '',$origLat = '',$origLon = '',$dist = '',$filters = array())
1828
+	public function searchMarineData($q = '', $callsign = '', $mmsi = '', $imo = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '', $origLat = '', $origLon = '', $dist = '', $filters = array())
1829 1829
 	{
1830 1830
 		global $globalTimezone, $globalDBdriver;
1831 1831
 		date_default_timezone_set('UTC');
1832 1832
 		$query_values = array();
1833 1833
 		$additional_query = '';
1834
-		$filter_query = $this->getFilter($filters,true,true);
1834
+		$filter_query = $this->getFilter($filters, true, true);
1835 1835
 		if ($q != "")
1836 1836
 		{
1837 1837
 			if (!is_string($q))
@@ -1839,8 +1839,8 @@  discard block
 block discarded – undo
1839 1839
 				return false;
1840 1840
 			} else {
1841 1841
 				$q_array = explode(" ", $q);
1842
-				foreach ($q_array as $q_item){
1843
-					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
1842
+				foreach ($q_array as $q_item) {
1843
+					$q_item = filter_var($q_item, FILTER_SANITIZE_STRING);
1844 1844
 					$additional_query .= " AND (";
1845 1845
 					if (is_int($q_item)) $additional_query .= "(marine_output.marine_id = '".$q_item."') OR ";
1846 1846
 					if (is_int($q_item)) $additional_query .= "(marine_output.mmsi = '".$q_item."') OR ";
@@ -1852,42 +1852,42 @@  discard block
 block discarded – undo
1852 1852
 		}
1853 1853
 		if ($callsign != "")
1854 1854
 		{
1855
-			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
1855
+			$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
1856 1856
 			if (!is_string($callsign))
1857 1857
 			{
1858 1858
 				return false;
1859 1859
 			} else {
1860 1860
 				$additional_query .= " AND marine_output.ident = :callsign";
1861
-				$query_values = array_merge($query_values,array(':callsign' => $callsign));
1861
+				$query_values = array_merge($query_values, array(':callsign' => $callsign));
1862 1862
 			}
1863 1863
 		}
1864 1864
 		if ($mmsi != "")
1865 1865
 		{
1866
-			$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING);
1866
+			$mmsi = filter_var($mmsi, FILTER_SANITIZE_STRING);
1867 1867
 			if (!is_numeric($mmsi))
1868 1868
 			{
1869 1869
 				return false;
1870 1870
 			} else {
1871 1871
 				$additional_query .= " AND marine_output.mmsi = :mmsi";
1872
-				$query_values = array_merge($query_values,array(':mmsi' => $mmsi));
1872
+				$query_values = array_merge($query_values, array(':mmsi' => $mmsi));
1873 1873
 			}
1874 1874
 		}
1875 1875
 		if ($imo != "")
1876 1876
 		{
1877
-			$imo = filter_var($imo,FILTER_SANITIZE_STRING);
1877
+			$imo = filter_var($imo, FILTER_SANITIZE_STRING);
1878 1878
 			if (!is_numeric($imo))
1879 1879
 			{
1880 1880
 				return false;
1881 1881
 			} else {
1882 1882
 				$additional_query .= " AND marine_output.imo = :imo";
1883
-				$query_values = array_merge($query_values,array(':imo' => $imo));
1883
+				$query_values = array_merge($query_values, array(':imo' => $imo));
1884 1884
 			}
1885 1885
 		}
1886 1886
 		if ($date_posted != "")
1887 1887
 		{
1888 1888
 			$date_array = explode(",", $date_posted);
1889
-			$date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING);
1890
-			$date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING);
1889
+			$date_array[0] = filter_var($date_array[0], FILTER_SANITIZE_STRING);
1890
+			$date_array[1] = filter_var($date_array[1], FILTER_SANITIZE_STRING);
1891 1891
 			if ($globalTimezone != '') {
1892 1892
 				date_default_timezone_set($globalTimezone);
1893 1893
 				$datetime = new DateTime();
@@ -1914,8 +1914,8 @@  discard block
 block discarded – undo
1914 1914
 		if ($limit != "")
1915 1915
 		{
1916 1916
 			$limit_array = explode(",", $limit);
1917
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1918
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1917
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
1918
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
1919 1919
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1920 1920
 			{
1921 1921
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
@@ -1933,28 +1933,28 @@  discard block
 block discarded – undo
1933 1933
 			}
1934 1934
 		}
1935 1935
 		if ($origLat != "" && $origLon != "" && $dist != "") {
1936
-			$dist = number_format($dist*0.621371,2,'.',''); // convert km to mile
1936
+			$dist = number_format($dist*0.621371, 2, '.', ''); // convert km to mile
1937 1937
 			if ($globalDBdriver == 'mysql') {
1938
-				$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 
1938
+				$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 
1939 1939
 				    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)) 
1940 1940
 				    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;
1941 1941
 			} else {
1942
-				$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 
1942
+				$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 
1943 1943
 				    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)) 
1944 1944
 				    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;
1945 1945
 			}
1946 1946
 		} else {
1947
-			$query  = "SELECT marine_output.* FROM marine_output".$filter_query." marine_output.ident <> '' 
1947
+			$query = "SELECT marine_output.* FROM marine_output".$filter_query." marine_output.ident <> '' 
1948 1948
 			    ".$additional_query."
1949 1949
 			    ".$orderby_query;
1950 1950
 		}
1951
-		$marine_array = $this->getDataFromDB($query, $query_values,$limit_query);
1951
+		$marine_array = $this->getDataFromDB($query, $query_values, $limit_query);
1952 1952
 		return $marine_array;
1953 1953
 	}
1954 1954
 
1955 1955
 	public function getOrderBy()
1956 1956
 	{
1957
-		$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"));
1957
+		$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"));
1958 1958
 		
1959 1959
 		return $orderby;
1960 1960
 		
Please login to merge, or discard this patch.