Completed
Push — master ( f32ba6...d43b85 )
by Yannick
30:30
created
scripts/daemon-spotter.php 1 patch
Spacing   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -50,20 +50,20 @@  discard block
 block discarded – undo
50 50
 	    die;
51 51
 	}
52 52
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
53
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
53
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
54 54
     }
55 55
 }
56 56
 
57
-$options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine'));
57
+$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::', 'aprsserverssid::', 'aprsserverpass::', 'aprsserverhost::', 'aprsserverport::', 'format::', 'noaprsserver', 'enable-aircraft', 'disable-aircraft', 'enable-tracker', 'disable-tracker', 'enable-marine', 'disable-marine'));
58 58
 //if (isset($options['s'])) $hosts = array($options['s']);
59 59
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 60
 if (isset($options['s'])) {
61 61
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
62
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'], 'format' => $options['format']);
63 63
     else $globalSources[] = array('host' => $options['s']);
64 64
 } elseif (isset($options['source'])) {
65 65
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
66
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'], 'format' => $options['format']);
67 67
     else $globalSources[] = array('host' => $options['source']);
68 68
 }
69 69
 if (isset($options['aprsserverhost'])) {
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
 else $id_source = 1;
105 105
 if (isset($globalServer) && $globalServer) {
106 106
     if ($globalDebug) echo "Using Server Mode\n";
107
-    $SI=new SpotterServer();
107
+    $SI = new SpotterServer();
108 108
 /*
109 109
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 110
     $SI = new adsb2aprs();
111 111
     $SI->connect();
112 112
 */
113
-} else $SI=new SpotterImport($Connection->db);
113
+} else $SI = new SpotterImport($Connection->db);
114 114
 
115 115
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
116 116
 if (isset($globalMarine) && $globalMarine) {
@@ -124,17 +124,17 @@  discard block
 block discarded – undo
124 124
     $MI = new MarineImport($Connection->db);
125 125
 }
126 126
 //$APRS=new APRS($Connection->db);
127
-$SBS=new SBS();
127
+$SBS = new SBS();
128 128
 if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
129
-	$ACARS=new ACARS($Connection->db,true);
130
-	$Source=new Source($Connection->db);
129
+	$ACARS = new ACARS($Connection->db, true);
130
+	$Source = new Source($Connection->db);
131 131
 }
132
-$Common=new Common();
132
+$Common = new Common();
133 133
 date_default_timezone_set('UTC');
134 134
 //$servertz = system('date +%Z');
135 135
 // signal handler - playing nice with sockets and dump1090
136 136
 if (function_exists('pcntl_fork')) {
137
-    pcntl_signal(SIGINT,  function() {
137
+    pcntl_signal(SIGINT, function() {
138 138
         global $sockets;
139 139
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
140 140
         die("Bye!\n");
@@ -150,40 +150,40 @@  discard block
 block discarded – undo
150 150
 
151 151
 function connect_all($hosts) {
152 152
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
153
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
154 154
     $reset++;
155 155
     if ($globalDebug) echo 'Connect to all...'."\n";
156 156
     foreach ($hosts as $id => $value) {
157 157
 	$host = $value['host'];
158 158
 	$globalSources[$id]['last_exec'] = 0;
159 159
 	// Here we check type of source(s)
160
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
-            if (preg_match('/deltadb.txt$/i',$host)) {
160
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
+            if (preg_match('/deltadb.txt$/i', $host)) {
162 162
         	//$formats[$id] = 'deltadbtxt';
163 163
         	$globalSources[$id]['format'] = 'deltadbtxt';
164 164
         	//$last_exec['deltadbtxt'] = 0;
165 165
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
166
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
166
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
167 167
         	//$formats[$id] = 'vatsimtxt';
168 168
         	$globalSources[$id]['format'] = 'vatsimtxt';
169 169
         	//$last_exec['vatsimtxt'] = 0;
170 170
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
171
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
171
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
172 172
         	//$formats[$id] = 'aircraftlistjson';
173 173
         	$globalSources[$id]['format'] = 'aircraftlistjson';
174 174
         	//$last_exec['aircraftlistjson'] = 0;
175 175
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
176
-    	    } else if (preg_match('/aircraft.json$/i',$host)) {
176
+    	    } else if (preg_match('/aircraft.json$/i', $host)) {
177 177
         	//$formats[$id] = 'aircraftjson';
178 178
         	$globalSources[$id]['format'] = 'aircraftjson';
179 179
         	//$last_exec['aircraftlistjson'] = 0;
180 180
         	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
181
-    	    } else if (preg_match('/aircraft$/i',$host)) {
181
+    	    } else if (preg_match('/aircraft$/i', $host)) {
182 182
         	//$formats[$id] = 'planefinderclient';
183 183
         	$globalSources[$id]['format'] = 'planefinderclient';
184 184
         	//$last_exec['aircraftlistjson'] = 0;
185 185
         	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
186
-    	    } else if (preg_match('/opensky/i',$host)) {
186
+    	    } else if (preg_match('/opensky/i', $host)) {
187 187
         	//$formats[$id] = 'aircraftlistjson';
188 188
         	$globalSources[$id]['format'] = 'opensky';
189 189
         	//$last_exec['aircraftlistjson'] = 0;
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
         	    exit(0);
201 201
         	}
202 202
     	    */
203
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
203
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
204 204
         	//$formats[$id] = 'planeupdatefaa';
205 205
         	$globalSources[$id]['format'] = 'planeupdatefaa';
206 206
         	//$last_exec['planeupdatefaa'] = 0;
@@ -209,37 +209,37 @@  discard block
 block discarded – undo
209 209
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
210 210
         	    exit(0);
211 211
         	}
212
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
212
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
213 213
         	//$formats[$id] = 'phpvmacars';
214 214
         	$globalSources[$id]['format'] = 'phpvmacars';
215 215
         	//$last_exec['phpvmacars'] = 0;
216 216
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
217
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
217
+            } else if (preg_match('/\/api\/v1\/acars\/data$/i', $host)) {
218 218
         	//$formats[$id] = 'phpvmacars';
219 219
         	$globalSources[$id]['format'] = 'vaos';
220 220
         	//$last_exec['phpvmacars'] = 0;
221 221
         	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
222
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
222
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
223 223
         	//$formats[$id] = 'phpvmacars';
224 224
         	$globalSources[$id]['format'] = 'vam';
225 225
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
226
-            } else if (preg_match('/whazzup/i',$host)) {
226
+            } else if (preg_match('/whazzup/i', $host)) {
227 227
         	//$formats[$id] = 'whazzup';
228 228
         	$globalSources[$id]['format'] = 'whazzup';
229 229
         	//$last_exec['whazzup'] = 0;
230 230
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
231
-            } else if (preg_match('/blitzortung/i',$host)) {
231
+            } else if (preg_match('/blitzortung/i', $host)) {
232 232
         	$globalSources[$id]['format'] = 'blitzortung';
233 233
         	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
234
-            } else if (preg_match('/airwhere/i',$host)) {
234
+            } else if (preg_match('/airwhere/i', $host)) {
235 235
         	$globalSources[$id]['format'] = 'airwhere';
236 236
         	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
237
-            } else if (preg_match('/recentpireps/i',$host)) {
237
+            } else if (preg_match('/recentpireps/i', $host)) {
238 238
         	//$formats[$id] = 'pirepsjson';
239 239
         	$globalSources[$id]['format'] = 'pirepsjson';
240 240
         	//$last_exec['pirepsjson'] = 0;
241 241
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
242
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
242
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
243 243
         	//$formats[$id] = 'fr24json';
244 244
         	$globalSources[$id]['format'] = 'fr24json';
245 245
         	//$last_exec['fr24json'] = 0;
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
249 249
         	    exit(0);
250 250
         	}
251
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
251
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
252 252
         	//$formats[$id] = 'fr24json';
253 253
         	$globalSources[$id]['format'] = 'myshiptracking';
254 254
         	//$last_exec['fr24json'] = 0;
@@ -258,22 +258,22 @@  discard block
 block discarded – undo
258 258
         	    exit(0);
259 259
         	}
260 260
             //} else if (preg_match('/10001/',$host)) {
261
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
261
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
262 262
         	//$formats[$id] = 'tsv';
263 263
         	$globalSources[$id]['format'] = 'tsv';
264 264
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
265 265
             }
266
-        } elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway')) {
266
+        } elseif (filter_var($host, FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway')) {
267 267
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
268
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
268
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
269 269
     		    if ($idf !== false) {
270 270
     			$httpfeeds[$id] = $idf;
271 271
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
272 272
     		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
273 273
     		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
274 274
     		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
275
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
276
-	    $hostport = explode(':',$host);
275
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
276
+	    $hostport = explode(':', $host);
277 277
 	    if (isset($hostport[1])) {
278 278
 		$port = $hostport[1];
279 279
 		$hostn = $hostport[0];
@@ -283,19 +283,19 @@  discard block
 block discarded – undo
283 283
 	    }
284 284
 	    $Common = new Common();
285 285
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
286
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
286
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
287 287
     	    } else {
288
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
288
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
289 289
 	    }
290 290
 	    if ($s) {
291 291
     	        $sockets[$id] = $s;
292 292
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
293
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
293
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
294 294
 			//$formats[$id] = 'aprs';
295 295
 			$globalSources[$id]['format'] = 'aprs';
296 296
 			//$aprs_connect = 0;
297 297
 			//$use_aprs = true;
298
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
298
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
299 299
 			$globalSources[$id]['format'] = 'vrstcp';
300 300
     		    } elseif ($port == '10001') {
301 301
         		//$formats[$id] = 'tsv';
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
337 337
 else $timeout = 20;
338 338
 $errno = '';
339
-$errstr='';
339
+$errstr = '';
340 340
 
341 341
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
342 342
 /* Initiate connections to all the hosts simultaneously */
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 //connect_all($globalSources);
345 345
 
346 346
 if (isset($globalProxy) && $globalProxy) {
347
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
347
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
348 348
 } else {
349 349
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
350 350
 }
@@ -374,16 +374,16 @@  discard block
 block discarded – undo
374 374
 
375 375
 if ($use_aprs) {
376 376
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
377
-	$APRS=new APRS();
377
+	$APRS = new APRS();
378 378
 	$aprs_connect = 0;
379 379
 	$aprs_keep = 120;
380 380
 	$aprs_last_tx = time();
381 381
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
382
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
382
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
383 383
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
384
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
384
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
385 385
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
386
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
386
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
387 387
 	if ($aprs_full) $aprs_filter = '';
388 388
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
389 389
 	else $aprs_pass = '-1';
@@ -397,12 +397,12 @@  discard block
 block discarded – undo
397 397
 sleep(1);
398 398
 if ($globalDebug) echo "SCAN MODE \n\n";
399 399
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
400
-$endtime = time()+$globalCronEnd;
400
+$endtime = time() + $globalCronEnd;
401 401
 $i = 1;
402 402
 $tt = array();
403 403
 // Delete all ATC
404 404
 if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
405
-	$ATC=new ATC($Connection->db);
405
+	$ATC = new ATC($Connection->db);
406 406
 }
407 407
 if (!$globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
408 408
 	$ATC->deleteAll();
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
 while ($i > 0) {
413 413
     if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
414 414
 
415
-    if (!$globalDaemon) $i = $endtime-time();
415
+    if (!$globalDaemon) $i = $endtime - time();
416 416
     // Delete old ATC
417 417
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
418 418
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 	}
427 427
 	if ($max < $globalMinFetch) {
428 428
 	    if ($globalDebug) echo 'Sleeping...'."\n";
429
-	    sleep($globalMinFetch-$max+2);
429
+	    sleep($globalMinFetch - $max + 2);
430 430
 	}
431 431
     }
432 432
 
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
 	    //$buffer = $Common->getData($hosts[$id]);
446 446
 	    $buffer = $Common->getData($value['host']);
447 447
 	    if ($buffer != '') $reset = 0;
448
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
449
-	    $buffer = explode('\n',$buffer);
448
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
449
+	    $buffer = explode('\n', $buffer);
450 450
 	    foreach ($buffer as $line) {
451 451
     		if ($line != '' && count($line) > 7) {
452 452
     		    $line = explode(',', $line);
@@ -479,11 +479,11 @@  discard block
 block discarded – undo
479 479
 	    )
480 480
 	) {
481 481
 	    date_default_timezone_set('CET');
482
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
482
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
483 483
 	    date_default_timezone_set('UTC');
484 484
 	    if ($buffer != '') $reset = 0;
485
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
486
-	    $buffer = explode('\n',$buffer);
485
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
486
+	    $buffer = explode('\n', $buffer);
487 487
 	    foreach ($buffer as $line) {
488 488
 		if ($line != '') {
489 489
 		    //echo "'".$line."'\n";
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
 		    $ais_data = $AIS->parse_line(trim($line));
492 492
 		    $data = array();
493 493
 		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
494
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
494
+		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
495 495
 		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
496 496
 		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
497 497
 		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
504 504
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
505 505
 		    if (isset($ais_data['timestamp'])) {
506
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
506
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
507 507
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
508 508
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
509 509
 			    $add = true;
@@ -526,21 +526,21 @@  discard block
 block discarded – undo
526 526
 	    $w = $e = null;
527 527
 	    
528 528
 	    if (isset($arr[$id])) {
529
-		$nn = stream_select($arr,$w,$e,$timeout);
529
+		$nn = stream_select($arr, $w, $e, $timeout);
530 530
 		if ($nn > 0) {
531 531
 		    foreach ($httpfeeds as $feed) {
532
-			$buffer = stream_get_line($feed,2000,"\n");
532
+			$buffer = stream_get_line($feed, 2000, "\n");
533 533
 			if ($buffer === FALSE) {
534 534
 			    connect_all($globalSources);
535 535
 			}
536
-			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537
-			$buffer = explode('\n',$buffer);
536
+			$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
537
+			$buffer = explode('\n', $buffer);
538 538
 			foreach ($buffer as $line) {
539 539
 			    if ($line != '') {
540 540
 				$ais_data = $AIS->parse_line(trim($line));
541 541
 				$data = array();
542 542
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
543
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
543
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
544 544
 				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
545 545
 				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
546 546
 				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -552,9 +552,9 @@  discard block
 block discarded – undo
552 552
 				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
553 553
 				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
554 554
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
555
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
555
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
556 556
 				if (isset($ais_data['timestamp'])) {
557
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
557
+				    $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
558 558
 				} else {
559 559
 				    $data['datetime'] = date('Y-m-d H:i:s');
560 560
 				}
@@ -586,10 +586,10 @@  discard block
 block discarded – undo
586 586
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
587 587
 	    )
588 588
 	) {
589
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
589
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
590 590
 	    if ($buffer != '') {
591 591
 		//echo $buffer;
592
-		$all_data = json_decode($buffer,true);
592
+		$all_data = json_decode($buffer, true);
593 593
 		//print_r($all_data);
594 594
 		if (isset($all_data[0]['DATA'])) {
595 595
 		    foreach ($all_data[0]['DATA'] as $line) {
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 			    $data['ident'] = $line['NAME'];
599 599
 			    $data['mmsi'] = $line['MMSI'];
600 600
 			    if (strlen($data['mmsi']) > 9) {
601
-				$data['mmsi'] = substr($data['mmsi'],-9);
601
+				$data['mmsi'] = substr($data['mmsi'], -9);
602 602
 			    }
603 603
 			    $data['speed'] = $line['SOG'];
604 604
 			    $data['heading'] = $line['COG'];
@@ -608,8 +608,8 @@  discard block
 block discarded – undo
608 608
 			    //$data['type_id'] = $line['TYPE'];
609 609
 			    $data['imo'] = $line['IMO'];
610 610
 			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
611
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
612
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
611
+			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s', strtotime($line['ARV']));
612
+			    $data['datetime'] = date('Y-m-d H:i:s', $line['T']);
613 613
 			    $data['format_source'] = 'myshiptracking';
614 614
 			    $data['id_source'] = $id_source;
615 615
 			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -626,16 +626,16 @@  discard block
 block discarded – undo
626 626
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
627 627
 	    )
628 628
 	) {
629
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
629
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
630 630
 	    if ($buffer != '') {
631
-		$all_data = json_decode($buffer,true);
631
+		$all_data = json_decode($buffer, true);
632 632
 		if (isset($all_data[0]['mmsi'])) {
633 633
 		    foreach ($all_data as $line) {
634 634
 			if ($line != '') {
635 635
 			    $data = array();
636 636
 			    $data['ident'] = $line['shipname'];
637 637
 			    $data['callsign'] = $line['callsign'];
638
-			    $data['mmsi'] = substr($line['mmsi'],-9);
638
+			    $data['mmsi'] = substr($line['mmsi'], -9);
639 639
 			    $data['speed'] = $line['sog'];
640 640
 			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
641 641
 			    $data['latitude'] = $line['latitude'];
@@ -662,14 +662,14 @@  discard block
 block discarded – undo
662 662
 	) {
663 663
 	    $buffer = $Common->getData($value['host']);
664 664
 	    if ($buffer != '') {
665
-		$all_data = json_decode($buffer,true);
665
+		$all_data = json_decode($buffer, true);
666 666
 		if (isset($all_data['features'][0]['id'])) {
667 667
 		    foreach ($all_data['features'] as $line) {
668 668
 			print_r($line);
669 669
 			$data = array();
670 670
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
671 671
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
672
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
672
+			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'], -9);
673 673
 			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
674 674
 			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
675 675
 			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
@@ -696,31 +696,31 @@  discard block
 block discarded – undo
696 696
 	    )
697 697
 	) {
698 698
 	    if ($globalDebug) echo 'download...';
699
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
699
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
700 700
 	    if ($globalDebug) echo 'done !'."\n";
701 701
 	    // FIXME: Need more work
702 702
 	    if ($buffer != '') $reset = 0;
703
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
704
-	    $buffer = explode('\n',$buffer);
703
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
704
+	    $buffer = explode('\n', $buffer);
705 705
 	    foreach ($buffer as $line) {
706 706
 		if ($line != '') {
707 707
 		    $data = array();
708 708
 		    //echo $line."\n";
709
-		    $data['mmsi'] = (int)substr($line,0,9);
710
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
711
-		    $data['status_id'] = substr($line,21,2);
712
-		    $data['type_id'] = substr($line,24,3);
713
-		    $data['latitude'] = substr($line,29,9);
714
-		    $data['longitude'] = substr($line,41,9);
715
-		    $data['speed'] = round(substr($line,51,5));
709
+		    $data['mmsi'] = (int) substr($line, 0, 9);
710
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
711
+		    $data['status_id'] = substr($line, 21, 2);
712
+		    $data['type_id'] = substr($line, 24, 3);
713
+		    $data['latitude'] = substr($line, 29, 9);
714
+		    $data['longitude'] = substr($line, 41, 9);
715
+		    $data['speed'] = round(substr($line, 51, 5));
716 716
 		    //$data['course'] = substr($line,57,5);
717
-		    $data['heading'] = round(substr($line,63,3));
717
+		    $data['heading'] = round(substr($line, 63, 3));
718 718
 		    //$data['draft'] = substr($line,67,4);
719 719
 		    //$data['length'] = substr($line,72,3);
720 720
 		    //$data['beam'] = substr($line,76,2);
721
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
721
+		    $data['ident'] = trim(utf8_encode(substr($line, 78, 20)));
722 722
 		    //$data['callsign'] = trim(substr($line,100,7);
723
-		    $data['arrival_code'] = substr($line,108,20);
723
+		    $data['arrival_code'] = substr($line, 108, 20);
724 724
 		    //$data['etaDate'] = substr($line,129,5);
725 725
 		    //$data['etaTime'] = substr($line,135,5);
726 726
 		    $data['format_source'] = 'shipplotter';
@@ -740,20 +740,20 @@  discard block
 block discarded – undo
740 740
 	    )
741 741
 	) {
742 742
 	    if ($globalDebug) echo 'download...';
743
-	    for ($i =0; $i <= 1; $i++) {
743
+	    for ($i = 0; $i <= 1; $i++) {
744 744
 	    $buffer = $Common->getData('https://sailaway.world/cgi-bin/sailaway/GetMissions.pl?race=1&tutorial=0&hist=1&racetype='.$i);
745 745
 	    if ($globalDebug) echo 'done'."\n";
746 746
 	    if ($buffer != '') {
747
-		$all_data = json_decode($buffer,true);
747
+		$all_data = json_decode($buffer, true);
748 748
 		if (isset($all_data['missions'])) {
749 749
 			foreach ($all_data['missions'] as $mission) {
750 750
 				$mission_user = $mission['usrname'];
751 751
 				$mission_name = $mission['mistitle'];
752
-				if (!isset($globalFilter['sailway']['race']) || (isset($globalFilter['sailway']['race']) && in_array($mission['misnr'],$globalFilter['sailway']['race']))) {
752
+				if (!isset($globalFilter['sailway']['race']) || (isset($globalFilter['sailway']['race']) && in_array($mission['misnr'], $globalFilter['sailway']['race']))) {
753 753
 					$bufferm = $Common->getData('https://sailaway.world/cgi-bin/sailaway/GetLeaderboard.pl?misnr='.$mission['misnr']);
754 754
 				} else $bufferm = '';
755 755
 				if ($bufferm != '') {
756
-					$mission_data = json_decode($bufferm,true);
756
+					$mission_data = json_decode($bufferm, true);
757 757
 					if (isset($mission_data['leaderboard'][0]['results'])) {
758 758
 						foreach ($mission_data['leaderboard'][0]['results'] as $sail) {
759 759
 							//print_r($bufferm);
@@ -768,9 +768,9 @@  discard block
 block discarded – undo
768 768
 								$pos = $Common->convertDecLatLong($sail['pos']);
769 769
 								$data['latitude'] = $pos['latitude'];
770 770
 								$data['longitude'] = $pos['longitude'];
771
-								$resultdescr = explode(',',$sail['resultdescr']);
772
-								$data['speed'] = round(str_replace(array('Spd: ','kn.'),'',trim($resultdescr[2]))*0.539957);
773
-								$data['heading'] = str_replace(array('Hdg: ','°'),'',trim($resultdescr[1]));
771
+								$resultdescr = explode(',', $sail['resultdescr']);
772
+								$data['speed'] = round(str_replace(array('Spd: ', 'kn.'), '', trim($resultdescr[2]))*0.539957);
773
+								$data['heading'] = str_replace(array('Hdg: ', '°'), '', trim($resultdescr[1]));
774 774
 								$data['ident'] = trim(utf8_encode($sail['ubtname']));
775 775
 								$data['captain_id'] = $sail['usrnr'];
776 776
 								$data['captain_name'] = $sail['usrname'];
@@ -812,8 +812,8 @@  discard block
 block discarded – undo
812 812
 	) {
813 813
 	    //$buffer = $Common->getData($hosts[$id]);
814 814
 	    $buffer = $Common->getData($value['host']);
815
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
816
-	    $buffer = explode('\n',$buffer);
815
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
816
+	    $buffer = explode('\n', $buffer);
817 817
 	    $reset = 0;
818 818
 	    foreach ($buffer as $line) {
819 819
     		if ($line != '') {
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
825 825
 			$data['pilot_id'] = $line[1];
826 826
 			$data['pilot_name'] = $line[2];
827
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
827
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
828 828
 			$data['ident'] = $line[0]; // ident
829 829
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
830 830
 			$data['speed'] = $line[8]; // speed
@@ -840,7 +840,7 @@  discard block
 block discarded – undo
840 840
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
841 841
 			//if (isset($line[37])) $data['last_update'] = $line[37];
842 842
 		        $data['departure_airport_icao'] = $line[11];
843
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
843
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
844 844
 		        $data['arrival_airport_icao'] = $line[13];
845 845
 			$data['frequency'] = $line[4];
846 846
 			$data['type'] = $line[18];
@@ -849,7 +849,7 @@  discard block
 block discarded – undo
849 849
     			$data['id_source'] = $id_source;
850 850
 	    		//$data['arrival_airport_time'] = ;
851 851
 	    		if ($line[9] != '') {
852
-	    		    $aircraft_data = explode('/',$line[9]);
852
+	    		    $aircraft_data = explode('/', $line[9]);
853 853
 	    		    if (isset($aircraft_data[1])) {
854 854
 	    			$data['aircraft_icao'] = $aircraft_data[1];
855 855
 	    		    }
@@ -864,9 +864,9 @@  discard block
 block discarded – undo
864 864
     			if ($line[3] === 'PILOT') $SI->add($data);
865 865
 			elseif ($line[3] === 'ATC') {
866 866
 				//print_r($data);
867
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
868
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
869
-				$typec = substr($data['ident'],-3);
867
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
868
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
869
+				$typec = substr($data['ident'], -3);
870 870
 				if ($typec === 'APP') $data['type'] = 'Approach';
871 871
 				elseif ($typec === 'TWR') $data['type'] = 'Tower';
872 872
 				elseif ($typec === 'OBS') $data['type'] = 'Observer';
@@ -878,8 +878,8 @@  discard block
 block discarded – undo
878 878
 				elseif ($data['type'] === '') $data['type'] = 'Observer';
879 879
 				if (!isset($data['source_name'])) $data['source_name'] = '';
880 880
 				if (isset($ATC)) {
881
-					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
882
-					else echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
881
+					if (count($ATC->getByIdent($data['ident'], $data['format_source'])) > 0) echo $ATC->update($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']);
882
+					else echo $ATC->add($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']);
883 883
 				}
884 884
 			}
885 885
     			unset($data);
@@ -895,24 +895,24 @@  discard block
 block discarded – undo
895 895
     		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
896 896
     	    )
897 897
     	) {
898
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
898
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php', 'get', '', '', '', '', '20');
899 899
 	    if ($buffer != '') {
900 900
 		$all_data = simplexml_load_string($buffer);
901
-		foreach($all_data->children() as $childdata) {
901
+		foreach ($all_data->children() as $childdata) {
902 902
 			$data = array();
903 903
 			$line = $childdata;
904 904
 			//$data['hex'] = str_pad(dechex((int)$line['pktPilotID']),6,'000000',STR_PAD_LEFT);
905
-			$data['id'] = date('Ymd').(int)$line['pktPilotID'];
906
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
907
-			$data['latitude'] = (float)$line['pktLatitude'];
908
-			$data['longitude'] = (float)$line['pktLongitude'];
909
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
910
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
911
-			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
905
+			$data['id'] = date('Ymd').(int) $line['pktPilotID'];
906
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['entryTime'].' BST'));
907
+			$data['latitude'] = (float) $line['pktLatitude'];
908
+			$data['longitude'] = (float) $line['pktLongitude'];
909
+			if ((float) $line['pktTrack'] != 0) $data['heading'] = (float) $line['pktTrack'];
910
+			if ((int) $line['pktSpeed'] != 0) $data['speed'] = (int) $line['pktSpeed'];
911
+			$data['altitude'] = round((int) $line['pktAltitude']*3.28084);
912 912
 			$data['altitude_relative'] = 'AMSL';
913
-			$data['pilot_id'] = (int)$line['pktPilotID'];
913
+			$data['pilot_id'] = (int) $line['pktPilotID'];
914 914
 			$data['aircraft_icao'] = 'PARAGLIDER';
915
-			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
915
+			$pilot_data = explode(',', $Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
916 916
 			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
917 917
 			$data['format_source'] = $value['format'];
918 918
 			$SI->add($data);
@@ -920,22 +920,22 @@  discard block
 block discarded – undo
920 920
 		}
921 921
 	    }
922 922
 	    $Source->deleteOldLocationByType('gs');
923
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
923
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php', 'get', '', '', '', '', '20');
924 924
 	    if ($buffer != '') {
925 925
 		$all_data = simplexml_load_string($buffer);
926
-		foreach($all_data->children() as $childdata) {
926
+		foreach ($all_data->children() as $childdata) {
927 927
 			$data = array();
928 928
 			$line = $childdata;
929
-			$data['id'] = (int)$line['gsID'];
930
-			$data['latitude'] = (float)$line['gsLatitude'];
931
-			$data['longitude'] = (float)$line['gsLongitude'];
932
-			$data['altitude'] = round((int)$line['gsHeight']*3.28084);
929
+			$data['id'] = (int) $line['gsID'];
930
+			$data['latitude'] = (float) $line['gsLatitude'];
931
+			$data['longitude'] = (float) $line['gsLongitude'];
932
+			$data['altitude'] = round((int) $line['gsHeight']*3.28084);
933 933
 			$data['altitude_relative'] = 'AMSL';
934
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['gsLastUpdate'].' BST'));
934
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['gsLastUpdate'].' BST'));
935 935
 			if (count($Source->getLocationInfoByLocationID($data['id'])) > 0) {
936
-				$Source->updateLocationByLocationID('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
936
+				$Source->updateLocationByLocationID('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
937 937
 			} else {
938
-				$Source->addLocation('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
938
+				$Source->addLocation('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
939 939
 			}
940 940
 			unset($data);
941 941
 		}
@@ -953,9 +953,9 @@  discard block
 block discarded – undo
953 953
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
954 954
 	    )
955 955
 	) {
956
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
956
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
957 957
 	    if ($buffer != '') {
958
-	        $all_data = json_decode($buffer,true);
958
+	        $all_data = json_decode($buffer, true);
959 959
 		if (isset($all_data['acList'])) {
960 960
 		    $reset = 0;
961 961
 		    foreach ($all_data['acList'] as $line) {
@@ -971,7 +971,7 @@  discard block
 block discarded – undo
971 971
 			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
972 972
 			$data['emergency'] = ''; // emergency
973 973
 			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
974
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
974
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
975 975
 			else $data['datetime'] = date('Y-m-d H:i:s');
976 976
 			//$data['datetime'] = date('Y-m-d H:i:s');
977 977
 			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
 			$data['verticalrate'] = $line['vrt']; // verticale rate
997 997
 			$data['squawk'] = $line['squawk']; // squawk
998 998
 			$data['emergency'] = ''; // emergency
999
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
999
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
1000 1000
 			else $data['datetime'] = date('Y-m-d H:i:s');
1001 1001
 			$data['format_source'] = 'aircraftlistjson';
1002 1002
 			$data['id_source'] = $id_source;
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
     	    )
1018 1018
     	) {
1019 1019
 	    $buffer = $Common->getData($value['host']);
1020
-	    $all_data = json_decode($buffer,true);
1020
+	    $all_data = json_decode($buffer, true);
1021 1021
 	    if (isset($all_data['planes'])) {
1022 1022
 		$reset = 0;
1023 1023
 		foreach ($all_data['planes'] as $key => $line) {
@@ -1034,12 +1034,12 @@  discard block
 block discarded – undo
1034 1034
 		    $data['emergency'] = ''; // emergency
1035 1035
 		    $data['registration'] = $line[2];
1036 1036
 		    $data['aircraft_icao'] = $line[0];
1037
-		    $deparr = explode('-',$line[1]);
1037
+		    $deparr = explode('-', $line[1]);
1038 1038
 		    if (count($deparr) === 2) {
1039 1039
 			$data['departure_airport_icao'] = $deparr[0];
1040 1040
 			$data['arrival_airport_icao'] = $deparr[1];
1041 1041
 		    }
1042
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1042
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
1043 1043
 	    	    $data['format_source'] = 'planeupdatefaa';
1044 1044
     		    $data['id_source'] = $id_source;
1045 1045
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1057,7 +1057,7 @@  discard block
 block discarded – undo
1057 1057
 	    )
1058 1058
 	) {
1059 1059
 	    $buffer = $Common->getData($value['host']);
1060
-	    $all_data = json_decode($buffer,true);
1060
+	    $all_data = json_decode($buffer, true);
1061 1061
 	    if (isset($all_data['states'])) {
1062 1062
 		$reset = 0;
1063 1063
 		foreach ($all_data['states'] as $key => $line) {
@@ -1074,7 +1074,7 @@  discard block
 block discarded – undo
1074 1074
 		    //$data['emergency'] = ''; // emergency
1075 1075
 		    //$data['registration'] = $line[2];
1076 1076
 		    //$data['aircraft_icao'] = $line[0];
1077
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1077
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
1078 1078
 		    $data['format_source'] = 'opensky';
1079 1079
 		    $data['id_source'] = $id_source;
1080 1080
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1091,8 +1091,8 @@  discard block
 block discarded – undo
1091 1091
 	    )
1092 1092
 	) {
1093 1093
 	    $buffer = $Common->getData($value['host']);
1094
-	    $all_data = json_decode($buffer,true);
1095
-	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1094
+	    $all_data = json_decode($buffer, true);
1095
+	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time() - 1800) {
1096 1096
 		$reset = 0;
1097 1097
 		foreach ($all_data['aircraft'] as $key => $line) {
1098 1098
 		    $data = array();
@@ -1130,7 +1130,7 @@  discard block
 block discarded – undo
1130 1130
 	    )
1131 1131
 	) {
1132 1132
 	    $buffer = $Common->getData($value['host']);
1133
-	    $all_data = json_decode($buffer,true);
1133
+	    $all_data = json_decode($buffer, true);
1134 1134
 	    if (isset($all_data['aircraft'])) {
1135 1135
 		$reset = 0;
1136 1136
 		foreach ($all_data['aircraft'] as $key => $line) {
@@ -1147,7 +1147,7 @@  discard block
 block discarded – undo
1147 1147
 		    //$data['emergency'] = ''; // emergency
1148 1148
 		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1149 1149
 		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1150
-		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1150
+		    $data['datetime'] = date('Y-m-d H:i:s', $line['pos_update_time']);
1151 1151
 		    $data['format_source'] = 'planefinderclient';
1152 1152
 		    $data['id_source'] = $id_source;
1153 1153
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -1166,7 +1166,7 @@  discard block
 block discarded – undo
1166 1166
 	) {
1167 1167
 	    //$buffer = $Common->getData($hosts[$id]);
1168 1168
 	    $buffer = $Common->getData($value['host']);
1169
-	    $all_data = json_decode($buffer,true);
1169
+	    $all_data = json_decode($buffer, true);
1170 1170
 	    if (!empty($all_data)) $reset = 0;
1171 1171
 	    foreach ($all_data as $key => $line) {
1172 1172
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -1204,11 +1204,11 @@  discard block
 block discarded – undo
1204 1204
 	    )
1205 1205
 	) {
1206 1206
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1207
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1207
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
1208 1208
 	    //echo $buffer;
1209
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1210
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1211
-	    $all_data = json_decode($buffer,true);
1209
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
1210
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
1211
+	    $all_data = json_decode($buffer, true);
1212 1212
 	    if (json_last_error() != JSON_ERROR_NONE) {
1213 1213
 		die(json_last_error_msg());
1214 1214
 	    }
@@ -1231,7 +1231,7 @@  discard block
 block discarded – undo
1231 1231
 			//$data['departure_airport_iata'] = $line[11];
1232 1232
 			//$data['arrival_airport_iata'] = $line[12];
1233 1233
 	    		//$data['emergency'] = ''; // emergency
1234
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1234
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
1235 1235
 	    		$data['format_source'] = 'radarvirtueljson';
1236 1236
     			$data['id_source'] = $id_source;
1237 1237
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1252,14 +1252,14 @@  discard block
 block discarded – undo
1252 1252
 	) {
1253 1253
 	    //$buffer = $Common->getData($hosts[$id]);
1254 1254
 	    $buffer = $Common->getData($value['host'].'?'.time());
1255
-	    $all_data = json_decode(utf8_encode($buffer),true);
1255
+	    $all_data = json_decode(utf8_encode($buffer), true);
1256 1256
 	    
1257 1257
 	    if (isset($all_data['pireps'])) {
1258 1258
 		$reset = 0;
1259 1259
 	        foreach ($all_data['pireps'] as $line) {
1260 1260
 		    $data = array();
1261 1261
 		    $data['id'] = $line['id'];
1262
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1262
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
1263 1263
 		    $data['ident'] = $line['callsign']; // ident
1264 1264
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1265 1265
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -1289,9 +1289,9 @@  discard block
 block discarded – undo
1289 1289
 			$SI->add($data);
1290 1290
 		    //    print_r($data);
1291 1291
     		    } elseif ($line['icon'] === 'ct') {
1292
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1293
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1294
-			$typec = substr($data['ident'],-3);
1292
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
1293
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1294
+			$typec = substr($data['ident'], -3);
1295 1295
 			$data['type'] = '';
1296 1296
 			if ($typec === 'APP') $data['type'] = 'Approach';
1297 1297
 			elseif ($typec === 'TWR') $data['type'] = 'Tower';
@@ -1302,7 +1302,7 @@  discard block
 block discarded – undo
1302 1302
 			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1303 1303
 			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1304 1304
 			else $data['type'] = 'Observer';
1305
-			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
1305
+			if (isset($ATC)) echo $ATC->add($data['ident'], '', $data['latitude'], $data['longitude'], '0', $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source']);
1306 1306
 		    }
1307 1307
 		    unset($data);
1308 1308
 		}
@@ -1319,14 +1319,14 @@  discard block
 block discarded – undo
1319 1319
 	    //$buffer = $Common->getData($hosts[$id]);
1320 1320
 	    if ($globalDebug) echo 'Get Data...'."\n";
1321 1321
 	    $buffer = $Common->getData($value['host']);
1322
-	    $all_data = json_decode($buffer,true);
1322
+	    $all_data = json_decode($buffer, true);
1323 1323
 	    if ($buffer != '' && is_array($all_data)) {
1324 1324
 		$reset = 0;
1325 1325
 		foreach ($all_data as $line) {
1326 1326
 	    	    $data = array();
1327 1327
 	    	    //$data['id'] = $line['id']; // id not usable
1328 1328
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1329
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1329
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
1330 1330
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1331 1331
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1332 1332
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -1341,7 +1341,7 @@  discard block
 block discarded – undo
1341 1341
 	    	    //$data['datetime'] = $line['lastupdate'];
1342 1342
 	    	    //$data['last_update'] = $line['lastupdate'];
1343 1343
 	    	    if (isset($value['timezone'])) {
1344
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1344
+	    		$datetime = new DateTime($line['lastupdate'], new DateTimeZone($value['timezone']));
1345 1345
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1346 1346
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1347 1347
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1357,14 +1357,14 @@  discard block
 block discarded – undo
1357 1357
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1358 1358
 		    if (isset($line['aircraftname'])) {
1359 1359
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1360
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1361
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1360
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
1361
+	    		$aircraft_data = explode('-', $line['aircraftname']);
1362 1362
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1363 1363
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1364 1364
 	    		else {
1365
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1366
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1367
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1365
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
1366
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
1367
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
1368 1368
 	    		}
1369 1369
 	    	    }
1370 1370
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -1389,7 +1389,7 @@  discard block
 block discarded – undo
1389 1389
 	    //$buffer = $Common->getData($hosts[$id]);
1390 1390
 	    if ($globalDebug) echo 'Get Data...'."\n";
1391 1391
 	    $buffer = $Common->getData($value['host']);
1392
-	    $all_data = json_decode($buffer,true);
1392
+	    $all_data = json_decode($buffer, true);
1393 1393
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1394 1394
 		$reset = 0;
1395 1395
 		foreach ($all_data['ACARSData'] as $line) {
@@ -1400,7 +1400,7 @@  discard block
 block discarded – undo
1400 1400
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1401 1401
 	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1402 1402
 	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1403
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1403
+	    	    $data['ident'] = str_replace(' ', '', $line['bid']['flightnum']); // ident
1404 1404
 	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1405 1405
 	    	    $data['altitude'] = $line['altitude']; // altitude
1406 1406
 	    	    $data['speed'] = $line['groundspeed']; // speed
@@ -1411,7 +1411,7 @@  discard block
 block discarded – undo
1411 1411
 	    	    //$data['squawk'] = ''; // squawk
1412 1412
 	    	    //$data['emergency'] = ''; // emergency
1413 1413
 	    	    if (isset($value['timezone'])) {
1414
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1414
+	    		$datetime = new DateTime($line['updated_at'], new DateTimeZone($value['timezone']));
1415 1415
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1416 1416
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1417 1417
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1447,14 +1447,14 @@  discard block
 block discarded – undo
1447 1447
 	    //$buffer = $Common->getData($hosts[$id]);
1448 1448
 	    if ($globalDebug) echo 'Get Data...'."\n";
1449 1449
 	    $buffer = $Common->getData($value['host']);
1450
-	    $all_data = json_decode($buffer,true);
1450
+	    $all_data = json_decode($buffer, true);
1451 1451
 	    if ($buffer != '' && is_array($all_data)) {
1452 1452
 		$reset = 0;
1453 1453
 		foreach ($all_data as $line) {
1454 1454
 	    	    $data = array();
1455 1455
 	    	    //$data['id'] = $line['id']; // id not usable
1456 1456
 	    	    $data['id'] = trim($line['flight_id']);
1457
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1457
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
1458 1458
 	    	    $data['pilot_name'] = $line['pilot_name'];
1459 1459
 	    	    $data['pilot_id'] = $line['pilot_id'];
1460 1460
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1498,24 +1498,24 @@  discard block
 block discarded – undo
1498 1498
 	    //$buffer = $Common->getData($hosts[$id]);
1499 1499
 	    if ($globalDebug) echo 'Get Data...'."\n";
1500 1500
 	    $buffer = $Common->getData($value['host']);
1501
-	    $all_data = json_decode($buffer,true);
1501
+	    $all_data = json_decode($buffer, true);
1502 1502
 	    if ($buffer != '') {
1503 1503
 		$Source->deleteLocationBySource('blitzortung');
1504
-		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1505
-		$buffer = explode('\n',$buffer);
1504
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1505
+		$buffer = explode('\n', $buffer);
1506 1506
 		foreach ($buffer as $buffer_line) {
1507
-		    $line = json_decode($buffer_line,true);
1507
+		    $line = json_decode($buffer_line, true);
1508 1508
 		    if (isset($line['time'])) {
1509 1509
 			$data = array();
1510 1510
 			$data['altitude'] = $line['alt']; // altitude
1511 1511
 			$data['latitude'] = $line['lat']; // lat
1512 1512
 			$data['longitude'] = $line['lon']; // long
1513
-			$data['datetime'] = date('Y-m-d H:i:s',substr($line['time'],0,10));
1513
+			$data['datetime'] = date('Y-m-d H:i:s', substr($line['time'], 0, 10));
1514 1514
 			$data['id_source'] = $id_source;
1515 1515
 			$data['format_source'] = 'blitzortung';
1516 1516
 			$SI->add($data);
1517 1517
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1518
-			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1518
+			$Source->addLocation('', $data['latitude'], $data['longitude'], 0, '', '', 'blitzortung', 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime']);
1519 1519
 			unset($data);
1520 1520
 		    }
1521 1521
 		}
@@ -1538,11 +1538,11 @@  discard block
 block discarded – undo
1538 1538
 		    //$value = $formats[$nb];
1539 1539
 		    $format = $globalSources[$nb]['format'];
1540 1540
 		    if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1541
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1541
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1542 1542
 		    } elseif ($format === 'vrstcp') {
1543 1543
 			$buffer = @socket_read($r, 6000);
1544 1544
 		    } else {
1545
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1545
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1546 1546
 		    }
1547 1547
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1548 1548
 		    //echo $buffer."\n";
@@ -1552,8 +1552,8 @@  discard block
 block discarded – undo
1552 1552
 		    //$SI::del();
1553 1553
 		    if ($buffer !== FALSE) {
1554 1554
 			if ($format === 'vrstcp') {
1555
-			    $buffer = explode('},{',$buffer);
1556
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1555
+			    $buffer = explode('},{', $buffer);
1556
+			} else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1557 1557
 		    }
1558 1558
 		    // SBS format is CSV format
1559 1559
 		    if ($buffer !== FALSE && $buffer !== '') {
@@ -1577,7 +1577,7 @@  discard block
 block discarded – undo
1577 1577
 			    $ais_data = $AIS->parse_line(trim($buffer));
1578 1578
 			    $data = array();
1579 1579
 			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1580
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1580
+			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
1581 1581
 			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1582 1582
 			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1583 1583
 			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -1588,13 +1588,13 @@  discard block
 block discarded – undo
1588 1588
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1589 1589
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1590 1590
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1591
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1591
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1592 1592
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1593 1593
 			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1594 1594
 			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1595 1595
 
1596 1596
 			    if (isset($ais_data['timestamp'])) {
1597
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1597
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1598 1598
 			    } else {
1599 1599
 				$data['datetime'] = date('Y-m-d H:i:s');
1600 1600
 			    }
@@ -1605,10 +1605,10 @@  discard block
 block discarded – undo
1605 1605
                         } elseif ($format === 'flightgearsp') {
1606 1606
                     	    //echo $buffer."\n";
1607 1607
                     	    if (strlen($buffer) > 5) {
1608
-				$line = explode(',',$buffer);
1608
+				$line = explode(',', $buffer);
1609 1609
 				$data = array();
1610 1610
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1611
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1611
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1612 1612
 				$data['ident'] = $line[6];
1613 1613
 				$data['aircraft_name'] = $line[7];
1614 1614
 				$data['longitude'] = $line[1];
@@ -1625,16 +1625,16 @@  discard block
 block discarded – undo
1625 1625
                         } elseif ($format === 'acars') {
1626 1626
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1627 1627
 			    $ACARS->add(trim($buffer));
1628
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1628
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1629 1629
 			    $ACARS->deleteLiveAcarsData();
1630 1630
 			} elseif ($format === 'flightgearmp') {
1631
-			    if (substr($buffer,0,1) != '#') {
1631
+			    if (substr($buffer, 0, 1) != '#') {
1632 1632
 				$data = array();
1633 1633
 				//echo $buffer."\n";
1634
-				$line = explode(' ',$buffer);
1634
+				$line = explode(' ', $buffer);
1635 1635
 				if (count($line) === 11) {
1636
-				    $userserver = explode('@',$line[0]);
1637
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1636
+				    $userserver = explode('@', $line[0]);
1637
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1638 1638
 				    $data['ident'] = $userserver[0];
1639 1639
 				    $data['registration'] = $userserver[0];
1640 1640
 				    $data['latitude'] = $line[4];
@@ -1642,8 +1642,8 @@  discard block
 block discarded – undo
1642 1642
 				    $data['altitude'] = $line[6];
1643 1643
 				    $data['datetime'] = date('Y-m-d H:i:s');
1644 1644
 				    $aircraft_type = $line[10];
1645
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1646
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1645
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1646
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1647 1647
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1648 1648
 				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1649 1649
 				}
@@ -1652,8 +1652,8 @@  discard block
 block discarded – undo
1652 1652
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1653 1653
 			    die;
1654 1654
 			} elseif ($format === 'vrstcp') {
1655
-			    foreach($buffer as $all_data) {
1656
-				$line = json_decode('{'.$all_data.'}',true);
1655
+			    foreach ($buffer as $all_data) {
1656
+				$line = json_decode('{'.$all_data.'}', true);
1657 1657
 				$data = array();
1658 1658
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1659 1659
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1679,16 +1679,16 @@  discard block
 block discarded – undo
1679 1679
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1680 1680
 				unset($data);
1681 1681
 			    }
1682
-			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
1682
+			} elseif ($format === 'tsv' || substr($buffer, 0, 4) === 'clock') {
1683 1683
 			    $line = explode("\t", $buffer);
1684
-			    for($k = 0; $k < count($line); $k=$k+2) {
1684
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1685 1685
 				$key = $line[$k];
1686
-			        $lined[$key] = $line[$k+1];
1686
+			        $lined[$key] = $line[$k + 1];
1687 1687
 			    }
1688 1688
     			    if (count($lined) > 3) {
1689 1689
     				$data['hex'] = $lined['hexid'];
1690 1690
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1691
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1691
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1692 1692
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1693 1693
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1694 1694
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1707,23 +1707,23 @@  discard block
 block discarded – undo
1707 1707
     			    } else $error = true;
1708 1708
 			} elseif ($format === 'aprs' && $use_aprs) {
1709 1709
 			    if ($aprs_connect === 0) {
1710
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1710
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1711 1711
 				$aprs_connect = 1;
1712 1712
 			    }
1713 1713
 			    
1714
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1714
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1715 1715
 				$aprs_last_tx = time();
1716 1716
 				$data_aprs = "# Keep alive";
1717
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1717
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1718 1718
 			    }
1719 1719
 			    
1720 1720
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1721 1721
 			    //echo 'APRS data : '.$buffer."\n";
1722
-			    $buffer = str_replace('APRS <- ','',$buffer);
1723
-			    $buffer = str_replace('APRS -> ','',$buffer);
1722
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1723
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1724 1724
 			    //echo $buffer."\n";
1725 1725
 			    date_default_timezone_set('UTC');
1726
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1726
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1727 1727
 				$line = $APRS->parse($buffer);
1728 1728
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1729 1729
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1738,7 +1738,7 @@  discard block
 block discarded – undo
1738 1738
 				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1739 1739
 				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1740 1740
 				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1741
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1741
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1742 1742
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1743 1743
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1744 1744
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1826,29 +1826,29 @@  discard block
 block discarded – undo
1826 1826
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1827 1827
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1828 1828
 					$Source->deleteOldLocationByType('gs');
1829
-					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1830
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1829
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'gs')) > 0) {
1830
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1831 1831
 					} else {
1832
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1832
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1833 1833
 					}
1834 1834
 				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
1835 1835
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1836 1836
 					if ($globalDebug) echo '# Weather Station added'."\n";
1837 1837
 					$Source->deleteOldLocationByType('wx');
1838 1838
 					$weather_data = json_encode($line);
1839
-					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
1840
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1839
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'wx')) > 0) {
1840
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1841 1841
 					} else {
1842
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1842
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1843 1843
 					}
1844 1844
 				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
1845 1845
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1846 1846
 					if ($globalDebug) echo '☈ Lightning added'."\n";
1847 1847
 					$Source->deleteOldLocationByType('lightning');
1848
-					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1849
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1848
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'lightning')) > 0) {
1849
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1850 1850
 					} else {
1851
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1851
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1852 1852
 					}
1853 1853
 				    } elseif ($globalDebug) {
1854 1854
 				    	echo '/!\ Not added: '.$buffer."\n";
@@ -1857,7 +1857,7 @@  discard block
 block discarded – undo
1857 1857
 				    unset($data);
1858 1858
 				}
1859 1859
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1860
-					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1860
+					$Source->updateLocationDescByName($line['ident'], $line['source'], $id, $line['comment']);
1861 1861
 				}
1862 1862
 				/*
1863 1863
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] === 'Car' || $line['symbol'] === 'Ambulance' || $line['symbol'] === 'Van' || $line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || $line['symbol'] === 'Motorcycle')) {
@@ -1866,7 +1866,7 @@  discard block
 block discarded – undo
1866 1866
 				*/
1867 1867
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1868 1868
 				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1869
-				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1869
+				if (isset($globalSources[$nb]['last_weather_clean']) && time() - $globalSources[$nb]['last_weather_clean'] > 60*5) {
1870 1870
 					$Source->deleteOldLocationByType('lightning');
1871 1871
 					$Source->deleteOldLocationByType('wx');
1872 1872
 					$globalSources[$nb]['last_weather_clean'] = time();
@@ -1952,7 +1952,7 @@  discard block
 block discarded – undo
1952 1952
 				connect_all($sourceee);
1953 1953
 				$sourceee = array();
1954 1954
 				//connect_all($globalSources);
1955
-				$tt[$format]=0;
1955
+				$tt[$format] = 0;
1956 1956
 				break;
1957 1957
 			    } 
1958 1958
 			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
@@ -1962,14 +1962,14 @@  discard block
 block discarded – undo
1962 1962
 	    } else {
1963 1963
 		$error = socket_strerror(socket_last_error());
1964 1964
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1965
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1965
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1966 1966
 			if (isset($globalDebug)) echo "Restarting...\n";
1967 1967
 			// Restart the script if possible
1968 1968
 			if (is_array($sockets)) {
1969 1969
 			    if ($globalDebug) echo "Shutdown all sockets...";
1970 1970
 			    
1971 1971
 			    foreach ($sockets as $sock) {
1972
-				@socket_shutdown($sock,2);
1972
+				@socket_shutdown($sock, 2);
1973 1973
 				@socket_close($sock);
1974 1974
 			    }
1975 1975
 			    
Please login to merge, or discard this patch.
require/class.MarineImport.php 1 patch
Spacing   +92 added lines, -92 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']) || isset($line['id']))) {
107
+	if (is_array($line) && (isset($line['mmsi']) || isset($line['id']))) {
108 108
 	    //print_r($line);
109 109
   	    if (isset($line['mmsi']) || isset($line['id'])) {
110 110
 
@@ -129,25 +129,25 @@  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' => '','captain_id' => '','captain_name' => '','race_id' => '','race_name' => ''));
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' => '', 'captain_id' => '', 'captain_name' => '', 'race_id' => '', 'race_name' => ''));
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']);
147 147
 			if (!empty($identity)) {
148 148
 			    $this->all_tracked[$id]['ident'] = $identity['ship_name'];
149 149
 			    $this->all_tracked[$id]['type'] = $identity['type'];
150
-			    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($identity['type'])));
150
+			    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $AIS->getShipTypeID($identity['type'])));
151 151
 			}
152 152
 			//print_r($identity);
153 153
 			unset($Marine);
@@ -155,23 +155,23 @@  discard block
 block discarded – undo
155 155
 		    }
156 156
 		}
157 157
 		if (isset($line['type_id'])) {
158
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
159
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id']));
158
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $AIS->getShipType($line['type_id'])));
159
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $line['type_id']));
160 160
 		}
161 161
 		if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') {
162
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
163
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type'])));
162
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type']));
163
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $AIS->getShipTypeID($line['type'])));
164 164
 		}
165 165
 		if (isset($line['status']) && $line['status'] != '') {
166
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
166
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status']));
167 167
 		}
168 168
 		if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) {
169
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
169
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status_id' => $line['status_id']));
170 170
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
171 171
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
172 172
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
173 173
 				$Marine = new Marine($this->db);
174
-				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']);
174
+				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['status']);
175 175
 				unset($Marine);
176 176
 			    }
177 177
 			}
@@ -180,24 +180,24 @@  discard block
 block discarded – undo
180 180
 
181 181
 
182 182
 		if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') {
183
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
183
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi_type' => $line['mmsi_type']));
184 184
 		}
185 185
 		if (isset($line['imo']) && $line['imo'] != '') {
186
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
186
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('imo' => $line['imo']));
187 187
 		}
188 188
 		if (isset($line['callsign']) && $line['callsign'] != '') {
189
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
189
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('callsign' => $line['callsign']));
190 190
 		}
191 191
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
192 192
 		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
193
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
193
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code']));
194 194
 			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
195 195
 			if ($this->all_tracked[$id]['addedMarine'] != 0) {
196 196
 			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
197 197
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
198 198
 				    $Marine = new Marine($this->db);
199 199
 				    $fromsource = NULL;
200
-				    $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource);
200
+				    $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['arrival_code'], $fromsource);
201 201
 				    $Marine->db = null;
202 202
 				}
203 203
 			    }
@@ -213,19 +213,19 @@  discard block
 block discarded – undo
213 213
 		    }
214 214
 		}
215 215
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
216
-		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
216
+		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date']));
217 217
 		}
218 218
 		if (isset($line['captain_id']) && $line['captain_id'] != '') {
219
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_id' => $line['captain_id']));
219
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('captain_id' => $line['captain_id']));
220 220
 		}
221 221
 		if (isset($line['captain_name']) && $line['captain_name'] != '') {
222
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_name' => $line['captain_name']));
222
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('captain_name' => $line['captain_name']));
223 223
 		}
224 224
 		if (isset($line['race_id']) && $line['race_id'] != '') {
225
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_id' => $line['race_id']));
225
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('race_id' => $line['race_id']));
226 226
 		}
227 227
 		if (isset($line['race_name']) && $line['race_name'] != '') {
228
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_name' => $line['race_name']));
228
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('race_name' => $line['race_name']));
229 229
 		}
230 230
 
231 231
 		//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'])) {
@@ -234,44 +234,44 @@  discard block
 block discarded – undo
234 234
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
235 235
 			    $timeelapsed = microtime(true);
236 236
 			    $Marine = new Marine($this->db);
237
-			    $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']);
237
+			    $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']);
238 238
 			    $Marine->db = null;
239 239
 			}
240 240
 		    }
241
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
241
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident'])));
242 242
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
243 243
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
244 244
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
245 245
 				$timeelapsed = microtime(true);
246 246
 				$Marine = new Marine($this->db);
247 247
 				$fromsource = NULL;
248
-				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
248
+				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource);
249 249
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
250 250
 				$Marine->db = null;
251
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
251
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
252 252
 			    }
253 253
 			}
254 254
 		    }
255
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
255
+		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['ident']));
256 256
 		}
257 257
 
258
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
258
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 30*60 && strtotime($line['datetime']) < time() + 20*60) {
259 259
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
260
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
260
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime']));
261 261
 		    } else {
262 262
 				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
263 263
 				elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
264 264
 				return '';
265 265
 		    }
266
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
266
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time() - 30*60) {
267 267
 			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
268 268
 			return '';
269
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
269
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time() + 20*60) {
270 270
 			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
271 271
 			return '';
272 272
 		} elseif (!isset($line['datetime'])) {
273 273
 			date_default_timezone_set('UTC');
274
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
274
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s')));
275 275
 		} else {
276 276
 			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
277 277
 			return '';
@@ -279,24 +279,24 @@  discard block
 block discarded – undo
279 279
 
280 280
 
281 281
 		if (isset($line['speed'])) {
282
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
283
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
282
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed'])));
283
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true));
284 284
 		} 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'])) {
285
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
285
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm');
286 286
 		    if ($distance > 1000 && $distance < 10000) {
287 287
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
288 288
 			$speed = $speed*3.6;
289
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
289
+			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed)));
290 290
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
291 291
 		    }
292 292
 		}
293 293
 
294 294
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
295
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
295
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']);
296 296
 	    	    else unset($timediff);
297
-	    	    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')))) {
297
+	    	    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')))) {
298 298
 			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'])) {
299
-			    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'])) {
299
+			    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'])) {
300 300
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
301 301
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
302 302
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -305,10 +305,10 @@  discard block
 block discarded – undo
305 305
 				$timeelapsed = microtime(true);
306 306
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
307 307
 				    $Marine = new Marine($this->db);
308
-				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
308
+				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
309 309
 				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
310 310
 				    $Marine->db = null;
311
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
311
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
312 312
 				}
313 313
 				$this->tmd = 0;
314 314
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
@@ -317,55 +317,55 @@  discard block
 block discarded – undo
317 317
 
318 318
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
319 319
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
320
-				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') {
320
+				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') {
321 321
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
322 322
 				    $dataFound = true;
323 323
 				    $this->all_tracked[$id]['time_last_coord'] = time();
324 324
 				}
325
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
325
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude']));
326 326
 			}
327 327
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
328 328
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
329 329
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
330
-				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') {
330
+				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') {
331 331
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
332 332
 				    $dataFound = true;
333 333
 				    $this->all_tracked[$id]['time_last_coord'] = time();
334 334
 				}
335
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
335
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude']));
336 336
 			}
337 337
 
338 338
 		    } else if ($globalDebug && $timediff > 20) {
339 339
 			$this->tmd = $this->tmd + 1;
340 340
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
341
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
342
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
341
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -";
342
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
343 343
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
344 344
 		    }
345 345
 		}
346 346
 		if (isset($line['last_update']) && $line['last_update'] != '') {
347 347
 		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
348
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
348
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update']));
349 349
 		}
350 350
 		if (isset($line['format_source']) && $line['format_source'] != '') {
351
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
351
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source']));
352 352
 		}
353 353
 		if (isset($line['source_name']) && $line['source_name'] != '') {
354
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
354
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name']));
355 355
 		}
356 356
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
357
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
357
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true));
358 358
 		}
359 359
 		
360 360
 		if (isset($line['heading']) && $line['heading'] != '') {
361
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
362
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
363
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
361
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading'] - round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
362
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading'])));
363
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true));
364 364
 		    //$dataFound = true;
365 365
   		} 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']) {
366
-  		    $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']);
367
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
368
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
366
+  		    $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']);
367
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($heading)));
368
+		    if (abs($this->all_tracked[$id]['heading'] - round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
369 369
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
370 370
   		}
371 371
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 		if ($dataFound === true && (isset($this->all_tracked[$id]['mmsi']) || isset($this->all_tracked[$id]['id']))) {
376 376
 		    $this->all_tracked[$id]['lastupdate'] = time();
377 377
 		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
378
-		        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'])) {
378
+		        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'])) {
379 379
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
380 380
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
381 381
 				    if ($globalDebug) echo "Check if vessel is already in DB...";
@@ -383,37 +383,37 @@  discard block
 block discarded – undo
383 383
 				    $MarineLive = new MarineLive($this->db);
384 384
 				    if (isset($line['id'])) {
385 385
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
386
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
386
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
387 387
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
388 388
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
389
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
389
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
390 390
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
391 391
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
392
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
392
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
393 393
 				    } else $recent_ident = '';
394
-				    $MarineLive->db=null;
394
+				    $MarineLive->db = null;
395 395
 				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
396 396
 				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
397 397
 				} else $recent_ident = '';
398 398
 			    } else {
399 399
 				$recent_ident = '';
400
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
400
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0));
401 401
 			    }
402 402
 			    //if there was no vessel with the same callsign within the last hour and go post it into the archive
403
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
403
+			    if ($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
404 404
 			    {
405 405
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
406 406
 				//adds the spotter data for the archive
407 407
 				    $highlight = '';
408
-				    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')));
408
+				    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')));
409 409
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
410 410
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
411 411
 					    $timeelapsed = microtime(true);
412 412
 					    $Marine = new Marine($this->db);
413
-					    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name']);
413
+					    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['captain_id'], $this->all_tracked[$id]['captain_name'], $this->all_tracked[$id]['race_id'], $this->all_tracked[$id]['race_name']);
414 414
 					    $Marine->db = null;
415 415
 					    if ($globalDebug && isset($result)) echo $result."\n";
416
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
416
+					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
417 417
 					}
418 418
 				    }
419 419
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
@@ -421,15 +421,15 @@  discard block
 block discarded – undo
421 421
 					$Stats = new Stats($this->db);
422 422
 					if (!empty($this->stats)) {
423 423
 					    if ($globalDebug) echo 'Add source stats : ';
424
-				    	    foreach($this->stats as $date => $data) {
425
-						foreach($data as $source => $sourced) {
424
+				    	    foreach ($this->stats as $date => $data) {
425
+						foreach ($data as $source => $sourced) {
426 426
 					    	    //print_r($sourced);
427
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
428
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
427
+				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar_marine', $date);
428
+				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist_marine', $date);
429 429
 				    		    if (isset($sourced['msg'])) {
430 430
 				    			if (time() - $sourced['msg']['date'] > 10) {
431 431
 				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
432
-				    		    	    echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
432
+				    		    	    echo $Stats->addStatSource($nbmsg, $source, 'msg_marine', $date);
433 433
 			    			    	    unset($this->stats[$date][$source]['msg']);
434 434
 			    				}
435 435
 			    			    }
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
454 454
 					$MarineLive = new MarineLive($this->db);
455 455
 					$MarineLive->deleteLiveMarineData();
456
-					$MarineLive->db=null;
456
+					$MarineLive->db = null;
457 457
 					if ($globalDebug) echo " Done\n";
458 458
 				    }
459 459
 				    $this->last_delete = time();
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
465 465
 				    if (isset($globalDaemon) && !$globalDaemon) {
466 466
 					$Marine = new Marine($this->db);
467
-					$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']);
467
+					$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']);
468 468
 					$Marine->db = null;
469 469
 				    }
470 470
 				}
@@ -479,20 +479,20 @@  discard block
 block discarded – undo
479 479
 		    $ignoreImport = false;
480 480
 
481 481
 		    if (!$ignoreImport) {
482
-			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'])) {
482
+			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'])) {
483 483
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
484 484
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
485 485
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
486 486
 					$timeelapsed = microtime(true);
487 487
 					$MarineLive = new MarineLive($this->db);
488
-					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name']);
488
+					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country'], $this->all_tracked[$id]['captain_id'], $this->all_tracked[$id]['captain_name'], $this->all_tracked[$id]['race_id'], $this->all_tracked[$id]['race_name']);
489 489
 					$MarineLive->db = null;
490 490
 					if ($globalDebug) echo $result."\n";
491
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
491
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
492 492
 				    }
493 493
 				}
494 494
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
495
-					$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']);
495
+					$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']);
496 496
 				}
497 497
 				$this->all_tracked[$id]['putinarchive'] = false;
498 498
 
@@ -511,19 +511,19 @@  discard block
 block discarded – undo
511 511
 							$latitude = $globalCenterLatitude;
512 512
 							$longitude = $globalCenterLongitude;
513 513
 						}
514
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
514
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
515 515
 					} else {
516 516
 						$latitude = $this->source_location[$source]['latitude'];
517 517
 						$longitude = $this->source_location[$source]['longitude'];
518 518
 					}
519
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
519
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
520 520
 					//$stats_heading = $stats_heading%22.5;
521 521
 					$stats_heading = round($stats_heading/22.5);
522
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
522
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
523 523
 					$current_date = date('Y-m-d');
524 524
 					if ($stats_heading == 16) $stats_heading = 0;
525 525
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
526
-						for ($i=0;$i<=15;$i++) {
526
+						for ($i = 0; $i <= 15; $i++) {
527 527
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
528 528
 						}
529 529
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -538,9 +538,9 @@  discard block
 block discarded – undo
538 538
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
539 539
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
540 540
 						    end($this->stats[$current_date][$source]['hist']);
541
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
541
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
542 542
 						} else $mini = 0;
543
-						for ($i=$mini;$i<=$distance;$i+=10) {
543
+						for ($i = $mini; $i <= $distance; $i += 10) {
544 544
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
545 545
 						}
546 546
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
 
553 553
 				$this->all_tracked[$id]['lastupdate'] = time();
554 554
 				if ($this->all_tracked[$id]['putinarchive']) $send = true;
555
-			} 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";
555
+			} 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";
556 556
 			//$this->del();
557 557
 			
558 558
 			
Please login to merge, or discard this patch.
require/class.Connection.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 require_once(dirname(__FILE__).'/settings.php');
3 3
 
4
-class Connection{
4
+class Connection {
5 5
 	public $db = null;
6 6
 	public $dbs = array();
7 7
 	public $latest_schema = 52;
8 8
 
9
-	public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) {
9
+	public function __construct($dbc = null, $dbname = null, $user = null, $pass = null) {
10 10
 		global $globalNoDB;
11 11
 		if (isset($globalNoDB) && $globalNoDB === TRUE) {
12 12
 			$this->db = null;
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 					if ($user === null && $pass === null) {
17 17
 						$this->createDBConnection();
18 18
 					} else {
19
-						$this->createDBConnection(null,$user,$pass);
19
+						$this->createDBConnection(null, $user, $pass);
20 20
 					}
21 21
 				} else {
22 22
 					$this->createDBConnection($dbname);
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
 		while (true) {
101 101
 			try {
102 102
 				if ($globalDBSdriver == 'mysql') {
103
-					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser,  $globalDBSpass);
103
+					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser, $globalDBSpass);
104 104
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
105 105
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
106
-					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
107
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500);
108
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
109
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
110
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
106
+					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
107
+					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 500);
108
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut);
109
+					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true);
110
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent);
111 111
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
112 112
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
113 113
 					// Workaround against "ONLY_FULL_GROUP_BY" mode
@@ -117,19 +117,19 @@  discard block
 block discarded – undo
117 117
 					$this->dbs[$DBname]->exec('SET SESSION time_zone = "+00:00"');
118 118
 					//$this->dbs[$DBname]->exec('SET @@session.time_zone = "+00:00"');
119 119
 				} else {
120
-					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser,  $globalDBSpass);
120
+					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser, $globalDBSpass);
121 121
 					//$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
122 122
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
123
-					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
124
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200);
125
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
126
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
127
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
123
+					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
124
+					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 200);
125
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut);
126
+					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true);
127
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent);
128 128
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
129 129
 					$this->dbs[$DBname]->exec('SET timezone="UTC"');
130 130
 				}
131 131
 				break;
132
-			} catch(PDOException $e) {
132
+			} catch (PDOException $e) {
133 133
 				$i++;
134 134
 				if (isset($globalDebug) && $globalDebug) echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n";
135 135
 				//exit;
@@ -154,10 +154,10 @@  discard block
 block discarded – undo
154 154
 		try {
155 155
 			//$Connection = new Connection();
156 156
 			$results = $this->db->query($query);
157
-		} catch(PDOException $e) {
157
+		} catch (PDOException $e) {
158 158
 			return false;
159 159
 		}
160
-		if($results->rowCount()>0) {
160
+		if ($results->rowCount() > 0) {
161 161
 		    return true; 
162 162
 		}
163 163
 		else return false;
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
 			     return false;
180 180
 			}
181 181
 			
182
-		} catch(PDOException $e) {
183
-			if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
182
+		} catch (PDOException $e) {
183
+			if ($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
184 184
             			throw $e;
185 185
 	                }
186 186
 	                //echo 'error ! '.$e->getMessage();
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	/*
193 193
 	* Check if index exist
194 194
 	*/
195
-	public function indexExists($table,$index)
195
+	public function indexExists($table, $index)
196 196
 	{
197 197
 		global $globalDBdriver, $globalDBname;
198 198
 		if ($globalDBdriver == 'mysql') {
@@ -203,11 +203,11 @@  discard block
 block discarded – undo
203 203
 		try {
204 204
 			//$Connection = new Connection();
205 205
 			$results = $this->db->query($query);
206
-		} catch(PDOException $e) {
206
+		} catch (PDOException $e) {
207 207
 			return false;
208 208
 		}
209 209
 		$nb = $results->fetchAll(PDO::FETCH_ASSOC);
210
-		if($nb[0]['nb'] > 0) {
210
+		if ($nb[0]['nb'] > 0) {
211 211
 			return true; 
212 212
 		}
213 213
 		else return false;
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 		$query = "SELECT * FROM ".$table." LIMIT 0";
223 223
 		try {
224 224
 			$results = $this->db->query($query);
225
-		} catch(PDOException $e) {
225
+		} catch (PDOException $e) {
226 226
 			return "error : ".$e->getMessage()."\n";
227 227
 		}
228 228
 		$columns = array();
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 		return $columns;
235 235
 	}
236 236
 
237
-	public function getColumnType($table,$column) {
237
+	public function getColumnType($table, $column) {
238 238
 		$select = $this->db->query('SELECT '.$column.' FROM '.$table);
239 239
 		$tomet = $select->getColumnMeta(0);
240 240
 		return $tomet['native_type'];
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 	* Check if a column name exist in a table
245 245
 	* @return Boolean column exist or not
246 246
 	*/
247
-	public function checkColumnName($table,$name)
247
+	public function checkColumnName($table, $name)
248 248
 	{
249 249
 		global $globalDBdriver, $globalDBname;
250 250
 		if ($globalDBdriver == 'mysql') {
@@ -254,8 +254,8 @@  discard block
 block discarded – undo
254 254
 		}
255 255
 			try {
256 256
 				$sth = $this->db()->prepare($query);
257
-				$sth->execute(array(':database' => $globalDBname,':table' => $table,':name' => $name));
258
-			} catch(PDOException $e) {
257
+				$sth->execute(array(':database' => $globalDBname, ':table' => $table, ':name' => $name));
258
+			} catch (PDOException $e) {
259 259
 				echo "error : ".$e->getMessage()."\n";
260 260
 			}
261 261
 			$result = $sth->fetch(PDO::FETCH_ASSOC);
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 				try {
295 295
 					$sth = $this->db->prepare($query);
296 296
 					$sth->execute();
297
-				} catch(PDOException $e) {
297
+				} catch (PDOException $e) {
298 298
 					return "error : ".$e->getMessage()."\n";
299 299
 				}
300 300
 				$result = $sth->fetch(PDO::FETCH_ASSOC);
Please login to merge, or discard this patch.
require/class.Weather.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -3,12 +3,12 @@  discard block
 block discarded – undo
3 3
 	public function buildcloudlayer($metar) {
4 4
 		//print_r($metar);
5 5
 		$result = array();
6
-		foreach($metar['cloud'] as $key => $data) {
6
+		foreach ($metar['cloud'] as $key => $data) {
7 7
 			$alt_m = $metar['cloud'][$key]['level'];
8 8
 			$alt_ft = $alt_m*3.28084;
9 9
 			$pressure = $metar['QNH'];
10
-			$cumulus_base = 122.0 * ($metar['temperature'] - $metar['dew']);
11
-			$stratus_base = 100.0 * (100.0 * $metar['rh'])*0.3048;
10
+			$cumulus_base = 122.0*($metar['temperature'] - $metar['dew']);
11
+			$stratus_base = 100.0*(100.0*$metar['rh'])*0.3048;
12 12
 			$coverage_norm = 0.0;
13 13
 			if ($metar['cloud'][$key]['type'] == 'Few') {
14 14
 				$coverage_norm = 2.0/8.0;
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
 					$layer_type = 'ns';
31 31
 				}
32 32
 			} else {
33
-				if ($cumulus_base * 0.80 < $alt_m && $cumulus_base * 1.20 > $alt_m) {
33
+				if ($cumulus_base*0.80 < $alt_m && $cumulus_base*1.20 > $alt_m) {
34 34
 					$layer_type = 'cu';
35
-				} elseif ($stratus_base * 0.80 < $alt_m && $stratus_base * 1.40 > $alt_m) {
35
+				} elseif ($stratus_base*0.80 < $alt_m && $stratus_base*1.40 > $alt_m) {
36 36
 					$layer_type = 'st';
37 37
 				} else {
38 38
 					if ($alt_ft < 2000) {
@@ -45,10 +45,10 @@  discard block
 block discarded – undo
45 45
 				}
46 46
 			}
47 47
 			//echo 'coverage norm : '.$coverage_norm.' - layer_type: '.$layer_type."\n";
48
-			$result[] = array('cov' => $coverage_norm, 'type' => $layer_type,'alt' => $alt_m,'rh' => $metar['rh']);
48
+			$result[] = array('cov' => $coverage_norm, 'type' => $layer_type, 'alt' => $alt_m, 'rh' => $metar['rh']);
49 49
 		}
50 50
 		if (count($result) < 2 && $metar['rh'] > 60) {
51
-			$result[] = array('cov' => 0.75, 'type' => 'ci','alt' => 4000,'rh' => $metar['rh']);
51
+			$result[] = array('cov' => 0.75, 'type' => 'ci', 'alt' => 4000, 'rh' => $metar['rh']);
52 52
 		}
53 53
 		return $result;
54 54
 	}
Please login to merge, or discard this patch.
require/class.MarineLive.php 1 patch
Spacing   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -17,33 +17,33 @@  discard block
 block discarded – undo
17 17
 	* @param Array $filter the filter
18 18
 	* @return Array the SQL part
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 marine_output.format_source IN ('".implode("','",$flt['source'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
39
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."') AND marine_output.format_source IN ('".implode("','", $flt['source'])."')) spid ON spid.fammarine_id = marine_live.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'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
41
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."')) spid ON spid.fammarine_id = marine_live.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']."'";
@@ -81,15 +81,15 @@  discard block
 block discarded – undo
81 81
 					$filter_query_date .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'";
82 82
 				}
83 83
 			}
84
-			$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output".preg_replace('/^ AND/',' WHERE',$filter_query_date).") sd ON sd.fammarine_id = marine_live.fammarine_id";
84
+			$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output".preg_replace('/^ AND/', ' WHERE', $filter_query_date).") sd ON sd.fammarine_id = marine_live.fammarine_id";
85 85
 		}
86 86
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
87
-			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
87
+			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')";
88 88
 		}
89 89
 		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
90 90
 		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
91 91
 		if ($filter_query_where != '') {
92
-			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
92
+			$filter_query_where = preg_replace('/^ AND/', ' WHERE', $filter_query_where);
93 93
 		}
94 94
 		$filter_query = $filter_query_join.$filter_query_where;
95 95
 		return $filter_query;
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 		if ($limit != '')
113 113
 		{
114 114
 			$limit_array = explode(',', $limit);
115
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
116
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
115
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
116
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
117 117
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
118 118
 			{
119 119
 				$limit_query = ' LIMIT '.$limit_array[1].' OFFSET '.$limit_array[0];
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 				$orderby_query = ' '.$search_orderby_array[$sort]['sql'];
129 129
 			}
130 130
 		}
131
-		if ($orderby_query == '') $orderby_query= ' ORDER BY date DESC';
131
+		if ($orderby_query == '') $orderby_query = ' ORDER BY date DESC';
132 132
 
133 133
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
134 134
 		if ($globalDBdriver == 'mysql') {
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 		} else {
138 138
 			$query  = "SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate".$filter_query.$orderby_query;
139 139
 		}
140
-		$spotter_array = $Marine->getDataFromDB($query.$limit_query,array(),'',true);
140
+		$spotter_array = $Marine->getDataFromDB($query.$limit_query, array(), '', true);
141 141
 
142 142
 		return $spotter_array;
143 143
 	}
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 		global $globalDBdriver, $globalLiveInterval;
154 154
 		date_default_timezone_set('UTC');
155 155
 
156
-		$filter_query = $this->getFilter($filter,true,true);
156
+		$filter_query = $this->getFilter($filter, true, true);
157 157
 
158 158
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
159 159
 		if ($globalDBdriver == 'mysql') {
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 		try {
168 168
 			$sth = $this->db->prepare($query);
169 169
 			$sth->execute();
170
-		} catch(PDOException $e) {
170
+		} catch (PDOException $e) {
171 171
 			echo $e->getMessage();
172 172
 			die;
173 173
 		}
@@ -182,19 +182,19 @@  discard block
 block discarded – undo
182 182
 	* @return Array the spotter information
183 183
 	*
184 184
 	*/
185
-	public function getMinLastLiveMarineData($coord = array(),$filter = array(), $limit = false)
185
+	public function getMinLastLiveMarineData($coord = array(), $filter = array(), $limit = false)
186 186
 	{
187 187
 		global $globalDBdriver, $globalLiveInterval, $globalMap3DMarinesLimit, $globalArchive;
188 188
 		date_default_timezone_set('UTC');
189 189
 		$usecoord = false;
190 190
 		if (is_array($coord) && !empty($coord)) {
191
-			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
192
-			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
193
-			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
194
-			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
191
+			$minlong = filter_var($coord[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
192
+			$minlat = filter_var($coord[1], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
193
+			$maxlong = filter_var($coord[2], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
194
+			$maxlat = filter_var($coord[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
195 195
 			$usecoord = true;
196 196
 		}
197
-		$filter_query = $this->getFilter($filter,true,true);
197
+		$filter_query = $this->getFilter($filter, true, true);
198 198
 
199 199
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
200 200
 		if (!isset($globalMap3DMarinesLimit) || $globalMap3DMarinesLimit == '') $globalMap3DMarinesLimit = '300';
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 		try {
244 244
 			$sth = $this->db->prepare($query);
245 245
 			$sth->execute();
246
-		} catch(PDOException $e) {
246
+		} catch (PDOException $e) {
247 247
 			echo $e->getMessage();
248 248
 			die;
249 249
 		}
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	public function getLiveMarineCount($filter = array())
261 261
 	{
262 262
 		global $globalDBdriver, $globalLiveInterval;
263
-		$filter_query = $this->getFilter($filter,true,true);
263
+		$filter_query = $this->getFilter($filter, true, true);
264 264
 
265 265
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
266 266
 		if ($globalDBdriver == 'mysql') {
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 		try {
272 272
 			$sth = $this->db->prepare($query);
273 273
 			$sth->execute();
274
-		} catch(PDOException $e) {
274
+		} catch (PDOException $e) {
275 275
 			echo $e->getMessage();
276 276
 			die;
277 277
 		}
@@ -294,10 +294,10 @@  discard block
 block discarded – undo
294 294
 		$filter_query = $this->getFilter($filter);
295 295
 
296 296
 		if (is_array($coord)) {
297
-			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
298
-			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
299
-			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
300
-			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
297
+			$minlong = filter_var($coord[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
298
+			$minlat = filter_var($coord[1], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
299
+			$maxlong = filter_var($coord[2], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
300
+			$maxlat = filter_var($coord[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
301 301
 		} else return array();
302 302
 		if ($globalDBdriver == 'mysql') {
303 303
 			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND marine_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY marine_live.fammarine_id ORDER BY date DESC'.$filter_query;
@@ -319,13 +319,13 @@  discard block
 block discarded – undo
319 319
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
320 320
 		$Marine = new Marine($this->db);
321 321
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
322
-		$filter_query = $this->getFilter($filter,true,true);
322
+		$filter_query = $this->getFilter($filter, true, true);
323 323
 
324 324
 		if (is_array($coord)) {
325
-			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
326
-			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
327
-			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
328
-			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
325
+			$minlong = filter_var($coord[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
326
+			$minlat = filter_var($coord[1], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
327
+			$maxlong = filter_var($coord[2], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
328
+			$maxlat = filter_var($coord[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
329 329
 		} else return array();
330 330
 		/*
331 331
 		if ($globalDBdriver == 'mysql') {
@@ -340,13 +340,13 @@  discard block
 block discarded – undo
340 340
 		*/
341 341
 		if ($globalDBdriver == 'mysql') {
342 342
 			if (isset($globalArchive) && $globalArchive === TRUE) {
343
-				$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name 
343
+				$query = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name 
344 344
 				    FROM marine_live 
345 345
 				    '.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= marine_live.date 
346 346
 				    AND marine_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.'
347 347
 				    AND marine_live.latitude <> 0 AND marine_live.longitude <> 0 ORDER BY date DESC';
348 348
 			} else {
349
-				$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name 
349
+				$query = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name 
350 350
 				    FROM marine_live 
351 351
 				    INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate 
352 352
 				    FROM marine_live l 
@@ -358,14 +358,14 @@  discard block
 block discarded – undo
358 358
 			}
359 359
 		} else {
360 360
 			if (isset($globalArchive) && $globalArchive === TRUE) {
361
-				$query  = "SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name 
361
+				$query = "SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name 
362 362
 				    FROM marine_live 
363 363
 				    ".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date 
364 364
 				    AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." 
365 365
 				    AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." 
366 366
 				    AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' ORDER BY date DESC";
367 367
 			} else {
368
-				$query  = "SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name 
368
+				$query = "SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name 
369 369
 				    FROM marine_live 
370 370
 				    INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate 
371 371
 				    FROM marine_live l 
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
                 if ($interval == '1m')
423 423
                 {
424 424
                     $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
425
-                } else if ($interval == '15m'){
425
+                } else if ($interval == '15m') {
426 426
                     $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
427 427
                 } 
428 428
             }
@@ -430,14 +430,14 @@  discard block
 block discarded – undo
430 430
          $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';   
431 431
         }
432 432
 
433
-                $query  = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
433
+                $query = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
434 434
                    WHERE marine_live.latitude <> '' 
435 435
                                    AND marine_live.longitude <> '' 
436 436
                    ".$additional_query."
437 437
                    HAVING distance < :radius  
438 438
                                    ORDER BY distance";
439 439
 
440
-                $spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
440
+                $spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng, ':radius' => $radius));
441 441
 
442 442
                 return $spotter_array;
443 443
         }
@@ -455,9 +455,9 @@  discard block
 block discarded – undo
455 455
 		date_default_timezone_set('UTC');
456 456
 
457 457
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
458
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
458
+                $query = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
459 459
 
460
-		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident),'',true);
460
+		$spotter_array = $Marine->getDataFromDB($query, array(':ident' => $ident), '', true);
461 461
 
462 462
 		return $spotter_array;
463 463
 	}
@@ -468,14 +468,14 @@  discard block
 block discarded – undo
468 468
 	* @return Array the spotter information
469 469
 	*
470 470
 	*/
471
-	public function getDateLiveMarineDataByIdent($ident,$date)
471
+	public function getDateLiveMarineDataByIdent($ident, $date)
472 472
 	{
473 473
 		$Marine = new Marine($this->db);
474 474
 		date_default_timezone_set('UTC');
475 475
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
476 476
 		$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
477
-		$date = date('c',$date);
478
-		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
477
+		$date = date('c', $date);
478
+		$spotter_array = $Marine->getDataFromDB($query, array(':ident' => $ident, ':date' => $date));
479 479
 		return $spotter_array;
480 480
 	}
481 481
 
@@ -485,14 +485,14 @@  discard block
 block discarded – undo
485 485
 	* @return Array the spotter information
486 486
 	*
487 487
 	*/
488
-	public function getDateLiveMarineDataByMMSI($mmsi,$date)
488
+	public function getDateLiveMarineDataByMMSI($mmsi, $date)
489 489
 	{
490 490
 		$Marine = new Marine($this->db);
491 491
 		date_default_timezone_set('UTC');
492 492
 		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
493 493
 		$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.mmsi = :mmsi AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
494
-		$date = date('c',$date);
495
-		$spotter_array = $Marine->getDataFromDB($query,array(':mmsi' => $mmsi,':date' => $date));
494
+		$date = date('c', $date);
495
+		$spotter_array = $Marine->getDataFromDB($query, array(':mmsi' => $mmsi, ':date' => $date));
496 496
 		return $spotter_array;
497 497
 	}
498 498
 
@@ -508,9 +508,9 @@  discard block
 block discarded – undo
508 508
 		date_default_timezone_set('UTC');
509 509
 
510 510
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
511
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
511
+                $query = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
512 512
 
513
-		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id),'',true);
513
+		$spotter_array = $Marine->getDataFromDB($query, array(':id' => $id), '', true);
514 514
 
515 515
 		return $spotter_array;
516 516
 	}
@@ -521,15 +521,15 @@  discard block
 block discarded – undo
521 521
 	* @return Array the spotter information
522 522
 	*
523 523
 	*/
524
-	public function getDateLiveMarineDataById($id,$date)
524
+	public function getDateLiveMarineDataById($id, $date)
525 525
 	{
526 526
 		$Marine = new Marine($this->db);
527 527
 		date_default_timezone_set('UTC');
528 528
 
529 529
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
530
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
531
-                $date = date('c',$date);
532
-		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
530
+                $query = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
531
+                $date = date('c', $date);
532
+		$spotter_array = $Marine->getDataFromDB($query, array(':id' => $id, ':date' => $date), '', true);
533 533
 
534 534
 		return $spotter_array;
535 535
 	}
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
 	* @return Array the spotter information
542 542
 	*
543 543
 	*/
544
-	public function getAllLiveMarineDataById($id,$liveinterval = false)
544
+	public function getAllLiveMarineDataById($id, $liveinterval = false)
545 545
 	{
546 546
 		global $globalDBdriver, $globalLiveInterval;
547 547
 		date_default_timezone_set('UTC');
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
 		try {
561 561
 			$sth = $this->db->prepare($query);
562 562
 			$sth->execute(array(':id' => $id));
563
-		} catch(PDOException $e) {
563
+		} catch (PDOException $e) {
564 564
 			echo $e->getMessage();
565 565
 			die;
566 566
 		}
@@ -578,12 +578,12 @@  discard block
 block discarded – undo
578 578
 	{
579 579
 		date_default_timezone_set('UTC');
580 580
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
581
-		$query  = self::$global_query.' WHERE marine_live.ident = :ident';
581
+		$query = self::$global_query.' WHERE marine_live.ident = :ident';
582 582
     		try {
583 583
 			
584 584
 			$sth = $this->db->prepare($query);
585 585
 			$sth->execute(array(':ident' => $ident));
586
-		} catch(PDOException $e) {
586
+		} catch (PDOException $e) {
587 587
 			echo $e->getMessage();
588 588
 			die;
589 589
 		}
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
 			
614 614
 			$sth = $this->db->prepare($query);
615 615
 			$sth->execute();
616
-		} catch(PDOException $e) {
616
+		} catch (PDOException $e) {
617 617
 			return "error";
618 618
 		}
619 619
 
@@ -636,14 +636,14 @@  discard block
 block discarded – undo
636 636
 				
637 637
 				$sth = $this->db->prepare($query);
638 638
 				$sth->execute();
639
-			} catch(PDOException $e) {
639
+			} catch (PDOException $e) {
640 640
 				return "error";
641 641
 			}
642 642
 			$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
643 643
                         $i = 0;
644
-                        $j =0;
644
+                        $j = 0;
645 645
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
646
-			foreach($all as $row)
646
+			foreach ($all as $row)
647 647
 			{
648 648
 				$i++;
649 649
 				$j++;
@@ -651,9 +651,9 @@  discard block
 block discarded – undo
651 651
 					if ($globalDebug) echo ".";
652 652
 				    	try {
653 653
 						
654
-						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
654
+						$sth = $this->db->prepare(substr($query_delete, 0, -1).")");
655 655
 						$sth->execute();
656
-					} catch(PDOException $e) {
656
+					} catch (PDOException $e) {
657 657
 						return "error";
658 658
 					}
659 659
                                 	$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
@@ -664,9 +664,9 @@  discard block
 block discarded – undo
664 664
 			if ($i > 0) {
665 665
     				try {
666 666
 					
667
-					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
667
+					$sth = $this->db->prepare(substr($query_delete, 0, -1).")");
668 668
 					$sth->execute();
669
-				} catch(PDOException $e) {
669
+				} catch (PDOException $e) {
670 670
 					return "error";
671 671
 				}
672 672
 			}
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
 				
680 680
 				$sth = $this->db->prepare($query);
681 681
 				$sth->execute();
682
-			} catch(PDOException $e) {
682
+			} catch (PDOException $e) {
683 683
 				return "error";
684 684
 			}
685 685
 /*			$query_delete = "DELETE FROM marine_live WHERE fammarine_id IN (";
@@ -727,13 +727,13 @@  discard block
 block discarded – undo
727 727
 	public function deleteLiveMarineDataByIdent($ident)
728 728
 	{
729 729
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
730
-		$query  = 'DELETE FROM marine_live WHERE ident = :ident';
730
+		$query = 'DELETE FROM marine_live WHERE ident = :ident';
731 731
         
732 732
     		try {
733 733
 			
734 734
 			$sth = $this->db->prepare($query);
735 735
 			$sth->execute(array(':ident' => $ident));
736
-		} catch(PDOException $e) {
736
+		} catch (PDOException $e) {
737 737
 			return "error";
738 738
 		}
739 739
 
@@ -749,13 +749,13 @@  discard block
 block discarded – undo
749 749
 	public function deleteLiveMarineDataById($id)
750 750
 	{
751 751
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
752
-		$query  = 'DELETE FROM marine_live WHERE fammarine_id = :id';
752
+		$query = 'DELETE FROM marine_live WHERE fammarine_id = :id';
753 753
         
754 754
     		try {
755 755
 			
756 756
 			$sth = $this->db->prepare($query);
757 757
 			$sth->execute(array(':id' => $id));
758
-		} catch(PDOException $e) {
758
+		} catch (PDOException $e) {
759 759
 			return "error";
760 760
 		}
761 761
 
@@ -771,10 +771,10 @@  discard block
 block discarded – undo
771 771
 	*/
772 772
 	public function getAllRaces()
773 773
 	{
774
-		$query  = 'SELECT DISTINCT marine_live.race_id, marine_live.race_name FROM marine_live ORDER BY marine_live.race_name';
774
+		$query = 'SELECT DISTINCT marine_live.race_id, marine_live.race_name FROM marine_live ORDER BY marine_live.race_name';
775 775
 		$sth = $this->db->prepare($query);
776 776
 		$sth->execute();
777
-		$ident_result='';
777
+		$ident_result = '';
778 778
 		return $sth->fetchAll(PDO::FETCH_ASSOC);
779 779
 	}
780 780
 
@@ -788,13 +788,13 @@  discard block
 block discarded – undo
788 788
 	{
789 789
 		global $globalDBdriver, $globalTimezone;
790 790
 		if ($globalDBdriver == 'mysql') {
791
-			$query  = 'SELECT marine_live.ident FROM marine_live 
791
+			$query = 'SELECT marine_live.ident FROM marine_live 
792 792
 				WHERE marine_live.ident = :ident 
793 793
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
794 794
 				AND marine_live.date < UTC_TIMESTAMP()';
795 795
 			$query_data = array(':ident' => $ident);
796 796
 		} else {
797
-			$query  = "SELECT marine_live.ident FROM marine_live 
797
+			$query = "SELECT marine_live.ident FROM marine_live 
798 798
 				WHERE marine_live.ident = :ident 
799 799
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
800 800
 				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -803,8 +803,8 @@  discard block
 block discarded – undo
803 803
 		
804 804
 		$sth = $this->db->prepare($query);
805 805
 		$sth->execute($query_data);
806
-		$ident_result='';
807
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
806
+		$ident_result = '';
807
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
808 808
 		{
809 809
 			$ident_result = $row['ident'];
810 810
 		}
@@ -821,13 +821,13 @@  discard block
 block discarded – undo
821 821
 	{
822 822
 		global $globalDBdriver, $globalTimezone;
823 823
 		if ($globalDBdriver == 'mysql') {
824
-			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
824
+			$query = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
825 825
 				WHERE marine_live.ident = :ident 
826 826
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; 
827 827
 //				AND marine_live.date < UTC_TIMESTAMP()";
828 828
 			$query_data = array(':ident' => $ident);
829 829
 		} else {
830
-			$query  = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
830
+			$query = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
831 831
 				WHERE marine_live.ident = :ident 
832 832
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '30 MINUTES'";
833 833
 //				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -836,8 +836,8 @@  discard block
 block discarded – undo
836 836
 		
837 837
 		$sth = $this->db->prepare($query);
838 838
 		$sth->execute($query_data);
839
-		$ident_result='';
840
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
839
+		$ident_result = '';
840
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
841 841
 		{
842 842
 			$ident_result = $row['fammarine_id'];
843 843
 		}
@@ -854,13 +854,13 @@  discard block
 block discarded – undo
854 854
 	{
855 855
 		global $globalDBdriver, $globalTimezone;
856 856
 		if ($globalDBdriver == 'mysql') {
857
-			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
857
+			$query = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
858 858
 				WHERE marine_live.fammarine_id = :id 
859 859
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; 
860 860
 //				AND marine_live.date < UTC_TIMESTAMP()";
861 861
 			$query_data = array(':id' => $id);
862 862
 		} else {
863
-			$query  = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
863
+			$query = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
864 864
 				WHERE marine_live.fammarine_id = :id 
865 865
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'";
866 866
 //				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -869,8 +869,8 @@  discard block
 block discarded – undo
869 869
 		
870 870
 		$sth = $this->db->prepare($query);
871 871
 		$sth->execute($query_data);
872
-		$ident_result='';
873
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
872
+		$ident_result = '';
873
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
874 874
 		{
875 875
 			$ident_result = $row['fammarine_id'];
876 876
 		}
@@ -887,13 +887,13 @@  discard block
 block discarded – undo
887 887
 	{
888 888
 		global $globalDBdriver, $globalTimezone;
889 889
 		if ($globalDBdriver == 'mysql') {
890
-			$query  = 'SELECT marine_live.fammarine_id FROM marine_live 
890
+			$query = 'SELECT marine_live.fammarine_id FROM marine_live 
891 891
 				WHERE marine_live.mmsi = :mmsi 
892 892
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; 
893 893
 //				AND marine_live.date < UTC_TIMESTAMP()";
894 894
 			$query_data = array(':mmsi' => $mmsi);
895 895
 		} else {
896
-			$query  = "SELECT marine_live.fammarine_id FROM marine_live 
896
+			$query = "SELECT marine_live.fammarine_id FROM marine_live 
897 897
 				WHERE marine_live.mmsi = :mmsi 
898 898
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'";
899 899
 //				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -902,8 +902,8 @@  discard block
 block discarded – undo
902 902
 		
903 903
 		$sth = $this->db->prepare($query);
904 904
 		$sth->execute($query_data);
905
-		$ident_result='';
906
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
905
+		$ident_result = '';
906
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
907 907
 		{
908 908
 			$ident_result = $row['fammarine_id'];
909 909
 		}
@@ -921,7 +921,7 @@  discard block
 block discarded – undo
921 921
 	* @return String success or false
922 922
 	*
923 923
 	*/
924
-	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '',$type = '',$typeid = '',$imo = '', $callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$statusid = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '',$captain_id = '',$captain_name = '',$race_id = '', $race_name = '')
924
+	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '', $type = '', $typeid = '', $imo = '', $callsign = '', $arrival_code = '', $arrival_date = '', $status = '', $statusid = '', $noarchive = false, $format_source = '', $source_name = '', $over_country = '', $captain_id = '', $captain_name = '', $race_id = '', $race_name = '')
925 925
 	{
926 926
 		global $globalURL, $globalArchive, $globalDebug;
927 927
 		$Common = new Common();
@@ -973,33 +973,33 @@  discard block
 block discarded – undo
973 973
 		if ($date == '') $date = date("Y-m-d H:i:s", time());
974 974
 
975 975
         
976
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
977
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
978
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
979
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
980
-		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
981
-		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
982
-		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
983
-		$source_name = filter_var($source_name,FILTER_SANITIZE_STRING);
984
-		$over_country = filter_var($over_country,FILTER_SANITIZE_STRING);
985
-		$type = filter_var($type,FILTER_SANITIZE_STRING);
986
-		$typeid = filter_var($typeid,FILTER_SANITIZE_NUMBER_INT);
987
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
988
-		$status = filter_var($status,FILTER_SANITIZE_STRING);
989
-		$statusid = filter_var($statusid,FILTER_SANITIZE_NUMBER_INT);
990
-		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
991
-		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
992
-		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
993
-		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
994
-		$captain_id = filter_var($captain_id,FILTER_SANITIZE_STRING);
995
-		$captain_name = filter_var($captain_name,FILTER_SANITIZE_STRING);
996
-		$race_id = filter_var($race_id,FILTER_SANITIZE_STRING);
997
-		$race_name = filter_var($race_name,FILTER_SANITIZE_STRING);
976
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
977
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
978
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
979
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
980
+		$heading = filter_var($heading, FILTER_SANITIZE_NUMBER_INT);
981
+		$groundspeed = filter_var($groundspeed, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
982
+		$format_source = filter_var($format_source, FILTER_SANITIZE_STRING);
983
+		$source_name = filter_var($source_name, FILTER_SANITIZE_STRING);
984
+		$over_country = filter_var($over_country, FILTER_SANITIZE_STRING);
985
+		$type = filter_var($type, FILTER_SANITIZE_STRING);
986
+		$typeid = filter_var($typeid, FILTER_SANITIZE_NUMBER_INT);
987
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
988
+		$status = filter_var($status, FILTER_SANITIZE_STRING);
989
+		$statusid = filter_var($statusid, FILTER_SANITIZE_NUMBER_INT);
990
+		$imo = filter_var($imo, FILTER_SANITIZE_STRING);
991
+		$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
992
+		$arrival_code = filter_var($arrival_code, FILTER_SANITIZE_STRING);
993
+		$arrival_date = filter_var($arrival_date, FILTER_SANITIZE_STRING);
994
+		$captain_id = filter_var($captain_id, FILTER_SANITIZE_STRING);
995
+		$captain_name = filter_var($captain_name, FILTER_SANITIZE_STRING);
996
+		$race_id = filter_var($race_id, FILTER_SANITIZE_STRING);
997
+		$race_name = filter_var($race_name, FILTER_SANITIZE_STRING);
998 998
 		if ($typeid == '') $typeid = NULL;
999 999
 		if ($statusid == '') $statusid = NULL;
1000 1000
 
1001
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1002
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1001
+            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
1002
+            	if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
1003 1003
             	if ($arrival_date == '') $arrival_date = NULL;
1004 1004
             	$query = '';
1005 1005
 		if ($globalArchive) {
@@ -1008,19 +1008,19 @@  discard block
 block discarded – undo
1008 1008
 		}
1009 1009
 		$query .= 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,type_id,status,status_id,imo,arrival_port_name,arrival_port_date,captain_id,captain_name,race_id,race_name) 
1010 1010
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:mmsi,:type,:typeid,:status,:statusid,:imo,:arrival_port_name,:arrival_port_date,:captain_id,:captain_name,:race_id,:race_name)';
1011
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':over_country' => $over_country,':mmsi' => $mmsi,':type' => $type,':typeid' => $typeid,':status' => $status,':statusid' => $statusid,':imo' => $imo,':arrival_port_name' => $arrival_code,':arrival_port_date' => $arrival_date,':captain_id' => $captain_id,':captain_name' => $captain_name,':race_id' => $race_id,':race_name' => $race_name);
1011
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident, ':latitude' => $latitude, ':longitude' => $longitude, ':heading' => $heading, ':groundspeed' => $groundspeed, ':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':over_country' => $over_country, ':mmsi' => $mmsi, ':type' => $type, ':typeid' => $typeid, ':status' => $status, ':statusid' => $statusid, ':imo' => $imo, ':arrival_port_name' => $arrival_code, ':arrival_port_date' => $arrival_date, ':captain_id' => $captain_id, ':captain_name' => $captain_name, ':race_id' => $race_id, ':race_name' => $race_name);
1012 1012
 		try {
1013 1013
 			$sth = $this->db->prepare($query);
1014 1014
 			$sth->execute($query_values);
1015 1015
 			$sth->closeCursor();
1016
-		} catch(PDOException $e) {
1016
+		} catch (PDOException $e) {
1017 1017
 			return "error : ".$e->getMessage();
1018 1018
 		}
1019 1019
 		
1020 1020
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
1021 1021
 			if ($globalDebug) echo '(Add to Marine archive : ';
1022 1022
 			$MarineArchive = new MarineArchive($this->db);
1023
-			$result =  $MarineArchive->addMarineArchiveData($fammarine_id, $ident, $latitude, $longitude, $heading, $groundspeed, $date, $putinarchive, $mmsi,$type,$typeid,$imo, $callsign,$arrival_code,$arrival_date,$status,$statusid,$noarchive,$format_source, $source_name, $over_country,$captain_id,$captain_name,$race_id,$race_name);
1023
+			$result = $MarineArchive->addMarineArchiveData($fammarine_id, $ident, $latitude, $longitude, $heading, $groundspeed, $date, $putinarchive, $mmsi, $type, $typeid, $imo, $callsign, $arrival_code, $arrival_date, $status, $statusid, $noarchive, $format_source, $source_name, $over_country, $captain_id, $captain_name, $race_id, $race_name);
1024 1024
 			if ($globalDebug) echo $result.')';
1025 1025
 		}
1026 1026
 		return "success";
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
 
1029 1029
 	public function getOrderBy()
1030 1030
 	{
1031
-		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_live.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_live.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_live.date DESC"));
1031
+		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_live.aircraft_icao DESC"), "manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_live.aircraft_manufacturer DESC"), "airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_live.date DESC"));
1032 1032
 		return $orderby;
1033 1033
 	}
1034 1034
 
Please login to merge, or discard this patch.
require/class.Marine.php 1 patch
Spacing   +212 added lines, -212 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']."'";
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
82 82
 		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
83 83
 		if ($filter_query_where != '') {
84
-			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
84
+			$filter_query_where = preg_replace('/^ AND/', ' WHERE', $filter_query_where);
85 85
 		}
86 86
 		$filter_query = $filter_query_join.$filter_query_where;
87 87
 		return $filter_query;
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	* @return Array the spotter information
97 97
 	*
98 98
 	*/
99
-	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false)
99
+	public function getDataFromDB($query, $params = array(), $limitQuery = '', $schedules = false)
100 100
 	{
101 101
 		date_default_timezone_set('UTC');
102 102
 		if (!is_string($query))
@@ -116,13 +116,13 @@  discard block
 block discarded – undo
116 116
 			$sth = $this->db->prepare($query.$limitQuery);
117 117
 			$sth->execute($params);
118 118
 		} catch (PDOException $e) {
119
-			printf("Invalid query : %s\nWhole query: %s\n",$e->getMessage(), $query.$limitQuery);
119
+			printf("Invalid query : %s\nWhole query: %s\n", $e->getMessage(), $query.$limitQuery);
120 120
 			exit();
121 121
 		}
122 122
 		
123 123
 		$num_rows = 0;
124 124
 		$spotter_array = array();
125
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
125
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
126 126
 		{
127 127
 			$num_rows++;
128 128
 			$temp_array = array();
@@ -161,10 +161,10 @@  discard block
 block discarded – undo
161 161
 			}
162 162
 			if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed'];
163 163
 
164
-			if(isset($temp_array['mmsi']) && $temp_array['mmsi'] != "")
164
+			if (isset($temp_array['mmsi']) && $temp_array['mmsi'] != "")
165 165
 			{
166 166
 				$Image = new Image($this->db);
167
-				if (isset($temp_array['ident']) && $temp_array['ident'] != '') $image_array = $Image->getMarineImage($temp_array['mmsi'],'',$temp_array['ident']);
167
+				if (isset($temp_array['ident']) && $temp_array['ident'] != '') $image_array = $Image->getMarineImage($temp_array['mmsi'], '', $temp_array['ident']);
168 168
 				else $image_array = $Image->getMarineImage($temp_array['mmsi']);
169 169
 				unset($Image);
170 170
 				if (count($image_array) > 0) {
@@ -200,17 +200,17 @@  discard block
 block discarded – undo
200 200
 				{
201 201
 					$temp_array['date'] = "about ".$dateArray['hours']." hours ago";
202 202
 				} else {
203
-					$temp_array['date'] = date("M j Y, g:i a",strtotime($row['date']." UTC"));
203
+					$temp_array['date'] = date("M j Y, g:i a", strtotime($row['date']." UTC"));
204 204
 				}
205 205
 				$temp_array['date_minutes_past'] = $dateArray['minutes'];
206
-				$temp_array['date_iso_8601'] = date("c",strtotime($row['date']." UTC"));
207
-				$temp_array['date_rfc_2822'] = date("r",strtotime($row['date']." UTC"));
206
+				$temp_array['date_iso_8601'] = date("c", strtotime($row['date']." UTC"));
207
+				$temp_array['date_rfc_2822'] = date("r", strtotime($row['date']." UTC"));
208 208
 				$temp_array['date_unix'] = strtotime($row['date']." UTC");
209 209
 				if (isset($row['last_seen']) && $row['last_seen'] != '') {
210 210
 					if (strtotime($row['last_seen']) > strtotime($row['date'])) {
211 211
 						$temp_array['duration'] = strtotime($row['last_seen']) - strtotime($row['date']);
212
-						$temp_array['last_seen_date_iso_8601'] = date("c",strtotime($row['last_seen']." UTC"));
213
-						$temp_array['last_seen_date_rfc_2822'] = date("r",strtotime($row['last_seen']." UTC"));
212
+						$temp_array['last_seen_date_iso_8601'] = date("c", strtotime($row['last_seen']." UTC"));
213
+						$temp_array['last_seen_date_rfc_2822'] = date("r", strtotime($row['last_seen']." UTC"));
214 214
 						$temp_array['last_seen_date_unix'] = strtotime($row['last_seen']." UTC");
215 215
 					}
216 216
 				}
@@ -243,8 +243,8 @@  discard block
 block discarded – undo
243 243
 		if ($limit != "")
244 244
 		{
245 245
 			$limit_array = explode(",", $limit);
246
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
247
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
246
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
247
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
248 248
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
249 249
 			{
250 250
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
@@ -258,8 +258,8 @@  discard block
 block discarded – undo
258 258
 		} else {
259 259
 			$orderby_query = " ORDER BY marine_output.date DESC";
260 260
 		}
261
-		$query  = $global_query.$filter_query." ".$orderby_query;
262
-		$spotter_array = $this->getDataFromDB($query, array(),$limit_query,true);
261
+		$query = $global_query.$filter_query." ".$orderby_query;
262
+		$spotter_array = $this->getDataFromDB($query, array(), $limit_query, true);
263 263
 		return $spotter_array;
264 264
 	}
265 265
     
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 		if ($id == '') return array();
278 278
 		$additional_query = "marine_output.fammarine_id = :id";
279 279
 		$query_values = array(':id' => $id);
280
-		$query  = $global_query." WHERE ".$additional_query." ";
281
-		$spotter_array = $this->getDataFromDB($query,$query_values);
280
+		$query = $global_query." WHERE ".$additional_query." ";
281
+		$spotter_array = $this->getDataFromDB($query, $query_values);
282 282
 		return $spotter_array;
283 283
 	}
284 284
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 		$query_values = array();
298 298
 		$limit_query = '';
299 299
 		$additional_query = '';
300
-		$filter_query = $this->getFilter($filter,true,true);
300
+		$filter_query = $this->getFilter($filter, true, true);
301 301
 		if ($ident != "")
302 302
 		{
303 303
 			if (!is_string($ident))
@@ -313,8 +313,8 @@  discard block
 block discarded – undo
313 313
 		{
314 314
 			$limit_array = explode(",", $limit);
315 315
 			
316
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
317
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
316
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
317
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
318 318
 			
319 319
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
320 320
 			{
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 		$query_values = array();
354 354
 		$limit_query = '';
355 355
 		$additional_query = '';
356
-		$filter_query = $this->getFilter($filter,true,true);
356
+		$filter_query = $this->getFilter($filter, true, true);
357 357
 		if (!is_string($type))
358 358
 		{
359 359
 			return false;
@@ -366,8 +366,8 @@  discard block
 block discarded – undo
366 366
 		{
367 367
 			$limit_array = explode(",", $limit);
368 368
 			
369
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
370
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
369
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
370
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
371 371
 			
372 372
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
373 373
 			{
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 		return $spotter_array;
392 392
 	}
393 393
 	
394
-	public function getMarineDataByDate($date = '', $limit = '', $sort = '',$filter = array())
394
+	public function getMarineDataByDate($date = '', $limit = '', $sort = '', $filter = array())
395 395
 	{
396 396
 		global $global_query, $globalTimezone, $globalDBdriver;
397 397
 		
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 		$limit_query = '';
400 400
 		$additional_query = '';
401 401
 
402
-		$filter_query = $this->getFilter($filter,true,true);
402
+		$filter_query = $this->getFilter($filter, true, true);
403 403
 		
404 404
 		if ($date != "")
405 405
 		{
@@ -425,8 +425,8 @@  discard block
 block discarded – undo
425 425
 		{
426 426
 			$limit_array = explode(",", $limit);
427 427
 			
428
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
429
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
428
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
429
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
430 430
 			
431 431
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
432 432
 			{
@@ -457,11 +457,11 @@  discard block
 block discarded – undo
457 457
 	* @return Array list of source name
458 458
 	*
459 459
 	*/
460
-	public function getAllSourceName($type = '',$filters = array())
460
+	public function getAllSourceName($type = '', $filters = array())
461 461
 	{
462
-		$filter_query = $this->getFilter($filters,true,true);
462
+		$filter_query = $this->getFilter($filters, true, true);
463 463
 		$query_values = array();
464
-		$query  = "SELECT DISTINCT marine_output.source_name 
464
+		$query = "SELECT DISTINCT marine_output.source_name 
465 465
 				FROM marine_output".$filter_query." marine_output.source_name <> ''";
466 466
 		if ($type != '') {
467 467
 			$query_values = array(':type' => $type);
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 		$source_array = array();
477 477
 		$temp_array = array();
478 478
 		
479
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
479
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
480 480
 		{
481 481
 			$temp_array['source_name'] = $row['source_name'];
482 482
 			$source_array[] = $temp_array;
@@ -493,8 +493,8 @@  discard block
 block discarded – undo
493 493
 	*/
494 494
 	public function getAllIdents($filters = array())
495 495
 	{
496
-		$filter_query = $this->getFilter($filters,true,true);
497
-		$query  = "SELECT DISTINCT marine_output.ident
496
+		$filter_query = $this->getFilter($filters, true, true);
497
+		$query = "SELECT DISTINCT marine_output.ident
498 498
 								FROM marine_output".$filter_query." marine_output.ident <> '' 
499 499
 								ORDER BY marine_output.date ASC LIMIT 700 OFFSET 0";
500 500
 
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
 		$ident_array = array();
505 505
 		$temp_array = array();
506 506
 		
507
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
507
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
508 508
 		{
509 509
 			$temp_array['ident'] = $row['ident'];
510 510
 			$ident_array[] = $temp_array;
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 	*/
522 522
 	public function getIdentity($mmsi)
523 523
 	{
524
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
524
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
525 525
 		$query  = "SELECT * FROM marine_identity WHERE mmsi = :mmsi LIMIT 1";
526 526
 		$sth = $this->db->prepare($query);
527 527
 		$sth->execute(array(':mmsi' => $mmsi));
@@ -534,23 +534,23 @@  discard block
 block discarded – undo
534 534
 	* Add identity
535 535
 	*
536 536
 	*/
537
-	public function addIdentity($mmsi,$imo,$ident,$callsign,$type)
537
+	public function addIdentity($mmsi, $imo, $ident, $callsign, $type)
538 538
 	{
539
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
539
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
540 540
 		if ($mmsi != '') {
541
-			$imo = filter_var($imo,FILTER_SANITIZE_NUMBER_INT);
542
-			$ident = filter_var($ident,FILTER_SANITIZE_STRING);
543
-			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
544
-			$type = filter_var($type,FILTER_SANITIZE_STRING);
541
+			$imo = filter_var($imo, FILTER_SANITIZE_NUMBER_INT);
542
+			$ident = filter_var($ident, FILTER_SANITIZE_STRING);
543
+			$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
544
+			$type = filter_var($type, FILTER_SANITIZE_STRING);
545 545
 			$identinfo = $this->getIdentity($mmsi);
546 546
 			if (empty($identinfo)) {
547
-				$query  = "INSERT INTO marine_identity (mmsi,imo,call_sign,ship_name,type) VALUES (:mmsi,:imo,:call_sign,:ship_name,:type)";
547
+				$query = "INSERT INTO marine_identity (mmsi,imo,call_sign,ship_name,type) VALUES (:mmsi,:imo,:call_sign,:ship_name,:type)";
548 548
 				$sth = $this->db->prepare($query);
549
-				$sth->execute(array(':mmsi' => $mmsi,':imo' => $imo,':call_sign' => $callsign,':ship_name' => $ident,':type' => $type));
549
+				$sth->execute(array(':mmsi' => $mmsi, ':imo' => $imo, ':call_sign' => $callsign, ':ship_name' => $ident, ':type' => $type));
550 550
 			} elseif ($ident != '' && $identinfo['ship_name'] != $ident) {
551
-				$query  = "UPDATE marine_identity SET ship_name = :ship_name,type = :type WHERE mmsi = :mmsi";
551
+				$query = "UPDATE marine_identity SET ship_name = :ship_name,type = :type WHERE mmsi = :mmsi";
552 552
 				$sth = $this->db->prepare($query);
553
-				$sth->execute(array(':mmsi' => $mmsi,':ship_name' => $ident,':type' => $type));
553
+				$sth->execute(array(':mmsi' => $mmsi, ':ship_name' => $ident, ':type' => $type));
554 554
 			}
555 555
 		}
556 556
 	}
@@ -571,12 +571,12 @@  discard block
 block discarded – undo
571 571
 		} else $offset = '+00:00';
572 572
 
573 573
 		if ($globalDBdriver == 'mysql') {
574
-			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
574
+			$query = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
575 575
 								FROM marine_output
576 576
 								WHERE marine_output.date <> '' 
577 577
 								ORDER BY marine_output.date ASC LIMIT 0,100";
578 578
 		} else {
579
-			$query  = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
579
+			$query = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
580 580
 								FROM marine_output
581 581
 								WHERE marine_output.date <> '' 
582 582
 								ORDER BY marine_output.date ASC LIMIT 0,100";
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 		$date_array = array();
589 589
 		$temp_array = array();
590 590
 		
591
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
591
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
592 592
 		{
593 593
 			$temp_array['date'] = $row['date'];
594 594
 
@@ -606,10 +606,10 @@  discard block
 block discarded – undo
606 606
 	* @return String success or false
607 607
 	*
608 608
 	*/
609
-	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL)
609
+	public function updateIdentMarineData($fammarine_id = '', $ident = '', $fromsource = NULL)
610 610
 	{
611 611
 		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id';
612
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
612
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident);
613 613
 		try {
614 614
 			$sth = $this->db->prepare($query);
615 615
 			$sth->execute($query_values);
@@ -627,10 +627,10 @@  discard block
 block discarded – undo
627 627
 	* @return String success or false
628 628
 	*
629 629
 	*/
630
-	public function updateArrivalPortNameMarineData($fammarine_id = '', $arrival_code = '',$fromsource = NULL)
630
+	public function updateArrivalPortNameMarineData($fammarine_id = '', $arrival_code = '', $fromsource = NULL)
631 631
 	{
632 632
 		$query = 'UPDATE marine_output SET arrival_port_name = :arrival_code WHERE fammarine_id = :fammarine_id';
633
-		$query_values = array(':fammarine_id' => $fammarine_id,':arrival_code' => $arrival_code);
633
+		$query_values = array(':fammarine_id' => $fammarine_id, ':arrival_code' => $arrival_code);
634 634
 		try {
635 635
 			$sth = $this->db->prepare($query);
636 636
 			$sth->execute($query_values);
@@ -649,11 +649,11 @@  discard block
 block discarded – undo
649 649
 	* @return String success or false
650 650
 	*
651 651
 	*/
652
-	public function updateStatusMarineData($fammarine_id = '', $status_id = '',$status = '')
652
+	public function updateStatusMarineData($fammarine_id = '', $status_id = '', $status = '')
653 653
 	{
654 654
 
655 655
 		$query = 'UPDATE marine_output SET status = :status, status_id = :status_id WHERE fammarine_id = :fammarine_id';
656
-                $query_values = array(':fammarine_id' => $fammarine_id,':status' => $status,':status_id' => $status_id);
656
+                $query_values = array(':fammarine_id' => $fammarine_id, ':status' => $status, ':status_id' => $status_id);
657 657
 
658 658
 		try {
659 659
 			$sth = $this->db->prepare($query);
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '')
677 677
 	{
678 678
 		$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';
679
-                $query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
679
+                $query_values = array(':fammarine_id' => $fammarine_id, ':last_latitude' => $latitude, ':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed, ':last_seen' => $date, ':ident' => $ident);
680 680
 
681 681
 		try {
682 682
 			$sth = $this->db->prepare($query);
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
 	* @param String $verticalrate vertival rate of flight
715 715
 	* @return String success or false
716 716
 	*/
717
-	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 = '', $captain_id = '',$captain_name = '',$race_id = '', $race_name = '')
717
+	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 = '', $captain_id = '', $captain_name = '', $race_id = '', $race_name = '')
718 718
 	{
719 719
 		global $globalURL, $globalMarineImageFetch;
720 720
 		
@@ -781,36 +781,36 @@  discard block
 block discarded – undo
781 781
 		}
782 782
 
783 783
     
784
-		if ($date == "" || strtotime($date) < time()-20*60)
784
+		if ($date == "" || strtotime($date) < time() - 20*60)
785 785
 		{
786 786
 			$date = date("Y-m-d H:i:s", time());
787 787
 		}
788 788
 
789
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
790
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
791
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
792
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
793
-		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
794
-		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
795
-		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
796
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING);
797
-		$type = filter_var($type,FILTER_SANITIZE_STRING);
798
-		$status = filter_var($status,FILTER_SANITIZE_STRING);
799
-		$type_id = filter_var($typeid,FILTER_SANITIZE_NUMBER_INT);
800
-		$status_id = filter_var($statusid,FILTER_SANITIZE_NUMBER_INT);
801
-		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
802
-		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
803
-		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
804
-		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
805
-		$captain_id = filter_var($captain_id,FILTER_SANITIZE_STRING);
806
-		$captain_name = filter_var($captain_name,FILTER_SANITIZE_STRING);
807
-		$race_id = filter_var($race_id,FILTER_SANITIZE_STRING);
808
-		$race_name = filter_var($race_name,FILTER_SANITIZE_STRING);
789
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
790
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
791
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
792
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
793
+		$heading = filter_var($heading, FILTER_SANITIZE_NUMBER_INT);
794
+		$groundspeed = filter_var($groundspeed, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
795
+		$format_source = filter_var($format_source, FILTER_SANITIZE_STRING);
796
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_STRING);
797
+		$type = filter_var($type, FILTER_SANITIZE_STRING);
798
+		$status = filter_var($status, FILTER_SANITIZE_STRING);
799
+		$type_id = filter_var($typeid, FILTER_SANITIZE_NUMBER_INT);
800
+		$status_id = filter_var($statusid, FILTER_SANITIZE_NUMBER_INT);
801
+		$imo = filter_var($imo, FILTER_SANITIZE_STRING);
802
+		$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
803
+		$arrival_code = filter_var($arrival_code, FILTER_SANITIZE_STRING);
804
+		$arrival_date = filter_var($arrival_date, FILTER_SANITIZE_STRING);
805
+		$captain_id = filter_var($captain_id, FILTER_SANITIZE_STRING);
806
+		$captain_name = filter_var($captain_name, FILTER_SANITIZE_STRING);
807
+		$race_id = filter_var($race_id, FILTER_SANITIZE_STRING);
808
+		$race_name = filter_var($race_name, FILTER_SANITIZE_STRING);
809 809
 		if (isset($globalMarineImageFetch) && $globalMarineImageFetch === TRUE) {
810 810
 			$Image = new Image($this->db);
811
-			$image_array = $Image->getMarineImage($mmsi,$imo,$ident);
811
+			$image_array = $Image->getMarineImage($mmsi, $imo, $ident);
812 812
 			if (!isset($image_array[0]['mmsi'])) {
813
-				$Image->addMarineImage($mmsi,$imo,$ident);
813
+				$Image->addMarineImage($mmsi, $imo, $ident);
814 814
 			}
815 815
 			unset($Image);
816 816
 		}
@@ -823,10 +823,10 @@  discard block
 block discarded – undo
823 823
 		if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
824 824
 		if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
825 825
 		if ($arrival_date == '') $arrival_date = NULL;
826
-		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, type_id, status,status_id,imo,arrival_port_name,arrival_port_date,captain_id,captain_name,race_id,race_name) 
826
+		$query = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, type_id, status,status_id,imo,arrival_port_name,arrival_port_date,captain_id,captain_name,race_id,race_name) 
827 827
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:type_id,:status,:status_id,:imo,:arrival_port_name,:arrival_port_date,:captain_id,:captain_name,:race_id,:race_name)";
828 828
 
829
-		$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,':type_id' => $type_id,':status' => $status,':status_id' => $status_id,':imo' => $imo,':arrival_port_name' => $arrival_code,':arrival_port_date' => $arrival_date,':captain_id' => $captain_id,':captain_name' => $captain_name,':race_id' => $race_id,':race_name' => $race_name);
829
+		$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, ':type_id' => $type_id, ':status' => $status, ':status_id' => $status_id, ':imo' => $imo, ':arrival_port_name' => $arrival_code, ':arrival_port_date' => $arrival_date, ':captain_id' => $captain_id, ':captain_name' => $captain_name, ':race_id' => $race_id, ':race_name' => $race_name);
830 830
 		try {
831 831
 			$sth = $this->db->prepare($query);
832 832
 			$sth->execute($query_values);
@@ -850,13 +850,13 @@  discard block
 block discarded – undo
850 850
 	{
851 851
 		global $globalDBdriver, $globalTimezone;
852 852
 		if ($globalDBdriver == 'mysql') {
853
-			$query  = "SELECT marine_output.ident FROM marine_output 
853
+			$query = "SELECT marine_output.ident FROM marine_output 
854 854
 								WHERE marine_output.ident = :ident 
855 855
 								AND marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
856 856
 								AND marine_output.date < UTC_TIMESTAMP()";
857 857
 			$query_data = array(':ident' => $ident);
858 858
 		} else {
859
-			$query  = "SELECT marine_output.ident FROM marine_output 
859
+			$query = "SELECT marine_output.ident FROM marine_output 
860 860
 								WHERE marine_output.ident = :ident 
861 861
 								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
862 862
 								AND marine_output.date < now() AT TIME ZONE 'UTC'";
@@ -865,8 +865,8 @@  discard block
 block discarded – undo
865 865
 		
866 866
 		$sth = $this->db->prepare($query);
867 867
 		$sth->execute($query_data);
868
-    		$ident_result='';
869
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
868
+    		$ident_result = '';
869
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
870 870
 		{
871 871
 			$ident_result = $row['ident'];
872 872
 		}
@@ -892,8 +892,8 @@  discard block
 block discarded – undo
892 892
 				return false;
893 893
 			} else {
894 894
 				$q_array = explode(" ", $q);
895
-				foreach ($q_array as $q_item){
896
-					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
895
+				foreach ($q_array as $q_item) {
896
+					$q_item = filter_var($q_item, FILTER_SANITIZE_STRING);
897 897
 					$additional_query .= " AND (";
898 898
 					$additional_query .= "(marine_output.ident like '%".$q_item."%')";
899 899
 					$additional_query .= ")";
@@ -901,11 +901,11 @@  discard block
 block discarded – undo
901 901
 			}
902 902
 		}
903 903
 		if ($globalDBdriver == 'mysql') {
904
-			$query  = "SELECT marine_output.* FROM marine_output 
904
+			$query = "SELECT marine_output.* FROM marine_output 
905 905
 				WHERE marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query." 
906 906
 				AND marine_output.date < UTC_TIMESTAMP()";
907 907
 		} else {
908
-			$query  = "SELECT marine_output.* FROM marine_output 
908
+			$query = "SELECT marine_output.* FROM marine_output 
909 909
 				WHERE marine_output.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query." 
910 910
 				AND marine_output.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
911 911
 		}
@@ -924,16 +924,16 @@  discard block
 block discarded – undo
924 924
 	*
925 925
 	*/
926 926
 
927
-	public function countAllMarineOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array())
927
+	public function countAllMarineOverCountries($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array())
928 928
 	{
929 929
 		global $globalDBdriver, $globalArchive;
930 930
 		//$filter_query = $this->getFilter($filters,true,true);
931
-		$Connection= new Connection($this->db);
931
+		$Connection = new Connection($this->db);
932 932
 		if (!$Connection->tableExists('countries')) return array();
933 933
 		require_once('class.SpotterLive.php');
934 934
 		if (!isset($globalArchive) || $globalArchive !== TRUE) {
935 935
 			$MarineLive = new MarineLive($this->db);
936
-			$filter_query = $MarineLive->getFilter($filters,true,true);
936
+			$filter_query = $MarineLive->getFilter($filters, true, true);
937 937
 			$filter_query .= " over_country IS NOT NULL AND over_country <> ''";
938 938
 			if ($olderthanmonths > 0) {
939 939
 				if ($globalDBdriver == 'mysql') {
@@ -953,7 +953,7 @@  discard block
 block discarded – undo
953 953
 		} else {
954 954
 			require_once(dirname(__FILE__)."/class.MarineArchive.php");
955 955
 			$MarineArchive = new MarineArchive($this->db);
956
-			$filter_query = $MarineArchive->getFilter($filters,true,true);
956
+			$filter_query = $MarineArchive->getFilter($filters, true, true);
957 957
 			$filter_query .= " over_country <> ''";
958 958
 			if ($olderthanmonths > 0) {
959 959
 				if ($globalDBdriver == 'mysql') {
@@ -981,7 +981,7 @@  discard block
 block discarded – undo
981 981
 		$flight_array = array();
982 982
 		$temp_array = array();
983 983
         
984
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
984
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
985 985
 		{
986 986
 			$temp_array['marine_count'] = $row['nb'];
987 987
 			$temp_array['marine_country'] = $row['name'];
@@ -1000,11 +1000,11 @@  discard block
 block discarded – undo
1000 1000
 	* @return Array the callsign list
1001 1001
 	*
1002 1002
 	*/
1003
-	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
1003
+	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array(), $year = '', $month = '', $day = '')
1004 1004
 	{
1005 1005
 		global $globalDBdriver;
1006
-		$filter_query = $this->getFilter($filters,true,true);
1007
-		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
1006
+		$filter_query = $this->getFilter($filters, true, true);
1007
+		$query = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
1008 1008
                     FROM marine_output".$filter_query." marine_output.ident <> ''";
1009 1009
 		 if ($olderthanmonths > 0) {
1010 1010
 			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
@@ -1018,28 +1018,28 @@  discard block
 block discarded – undo
1018 1018
 		if ($year != '') {
1019 1019
 			if ($globalDBdriver == 'mysql') {
1020 1020
 				$query .= " AND YEAR(marine_output.date) = :year";
1021
-				$query_values = array_merge($query_values,array(':year' => $year));
1021
+				$query_values = array_merge($query_values, array(':year' => $year));
1022 1022
 			} else {
1023 1023
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1024
-				$query_values = array_merge($query_values,array(':year' => $year));
1024
+				$query_values = array_merge($query_values, array(':year' => $year));
1025 1025
 			}
1026 1026
 		}
1027 1027
 		if ($month != '') {
1028 1028
 			if ($globalDBdriver == 'mysql') {
1029 1029
 				$query .= " AND MONTH(marine_output.date) = :month";
1030
-				$query_values = array_merge($query_values,array(':month' => $month));
1030
+				$query_values = array_merge($query_values, array(':month' => $month));
1031 1031
 			} else {
1032 1032
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1033
-				$query_values = array_merge($query_values,array(':month' => $month));
1033
+				$query_values = array_merge($query_values, array(':month' => $month));
1034 1034
 			}
1035 1035
 		}
1036 1036
 		if ($day != '') {
1037 1037
 			if ($globalDBdriver == 'mysql') {
1038 1038
 				$query .= " AND DAY(marine_output.date) = :day";
1039
-				$query_values = array_merge($query_values,array(':day' => $day));
1039
+				$query_values = array_merge($query_values, array(':day' => $day));
1040 1040
 			} else {
1041 1041
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
1042
-				$query_values = array_merge($query_values,array(':day' => $day));
1042
+				$query_values = array_merge($query_values, array(':day' => $day));
1043 1043
 			}
1044 1044
 		}
1045 1045
 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
 		$callsign_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['callsign_icao'] = $row['ident'];
1057 1057
 			$temp_array['airline_name'] = $row['airline_name'];
@@ -1103,7 +1103,7 @@  discard block
 block discarded – undo
1103 1103
 		$date_array = array();
1104 1104
 		$temp_array = array();
1105 1105
         
1106
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1106
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1107 1107
 		{
1108 1108
 			$temp_array['date_name'] = $row['date_name'];
1109 1109
 			$temp_array['date_count'] = $row['date_count'];
@@ -1129,7 +1129,7 @@  discard block
 block discarded – undo
1129 1129
 			$datetime = new DateTime();
1130 1130
 			$offset = $datetime->format('P');
1131 1131
 		} else $offset = '+00:00';
1132
-		$filter_query = $this->getFilter($filters,true,true);
1132
+		$filter_query = $this->getFilter($filters, true, true);
1133 1133
 		if ($globalDBdriver == 'mysql') {
1134 1134
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1135 1135
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY)";
@@ -1150,7 +1150,7 @@  discard block
 block discarded – undo
1150 1150
 		$date_array = array();
1151 1151
 		$temp_array = array();
1152 1152
         
1153
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1153
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1154 1154
 		{
1155 1155
 			$temp_array['date_name'] = $row['date_name'];
1156 1156
 			$temp_array['date_count'] = $row['date_count'];
@@ -1175,7 +1175,7 @@  discard block
 block discarded – undo
1175 1175
 			$datetime = new DateTime();
1176 1176
 			$offset = $datetime->format('P');
1177 1177
 		} else $offset = '+00:00';
1178
-		$filter_query = $this->getFilter($filters,true,true);
1178
+		$filter_query = $this->getFilter($filters, true, true);
1179 1179
 		if ($globalDBdriver == 'mysql') {
1180 1180
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1181 1181
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MONTH)";
@@ -1196,7 +1196,7 @@  discard block
 block discarded – undo
1196 1196
 		$date_array = array();
1197 1197
 		$temp_array = array();
1198 1198
         
1199
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1199
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1200 1200
 		{
1201 1201
 			$temp_array['date_name'] = $row['date_name'];
1202 1202
 			$temp_array['date_count'] = $row['date_count'];
@@ -1243,7 +1243,7 @@  discard block
 block discarded – undo
1243 1243
 		$date_array = array();
1244 1244
 		$temp_array = array();
1245 1245
         
1246
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1246
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1247 1247
 		{
1248 1248
 			$temp_array['month_name'] = $row['month_name'];
1249 1249
 			$temp_array['year_name'] = $row['year_name'];
@@ -1272,7 +1272,7 @@  discard block
 block discarded – undo
1272 1272
 			$datetime = new DateTime();
1273 1273
 			$offset = $datetime->format('P');
1274 1274
 		} else $offset = '+00:00';
1275
-		$filter_query = $this->getFilter($filters,true,true);
1275
+		$filter_query = $this->getFilter($filters, true, true);
1276 1276
 		if ($globalDBdriver == 'mysql') {
1277 1277
 			$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
1278 1278
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 YEAR)";
@@ -1293,7 +1293,7 @@  discard block
 block discarded – undo
1293 1293
 		$date_array = array();
1294 1294
 		$temp_array = array();
1295 1295
         
1296
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1296
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1297 1297
 		{
1298 1298
 			$temp_array['year_name'] = $row['year_name'];
1299 1299
 			$temp_array['month_name'] = $row['month_name'];
@@ -1313,7 +1313,7 @@  discard block
 block discarded – undo
1313 1313
 	* @return Array the hour list
1314 1314
 	*
1315 1315
 	*/
1316
-	public function countAllHours($orderby,$filters = array())
1316
+	public function countAllHours($orderby, $filters = array())
1317 1317
 	{
1318 1318
 		global $globalTimezone, $globalDBdriver;
1319 1319
 		if ($globalTimezone != '') {
@@ -1361,7 +1361,7 @@  discard block
 block discarded – undo
1361 1361
 		$hour_array = array();
1362 1362
 		$temp_array = array();
1363 1363
         
1364
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1364
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1365 1365
 		{
1366 1366
 			$temp_array['hour_name'] = $row['hour_name'];
1367 1367
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1383,8 +1383,8 @@  discard block
 block discarded – undo
1383 1383
 	public function countAllHoursByDate($date, $filters = array())
1384 1384
 	{
1385 1385
 		global $globalTimezone, $globalDBdriver;
1386
-		$filter_query = $this->getFilter($filters,true,true);
1387
-		$date = filter_var($date,FILTER_SANITIZE_STRING);
1386
+		$filter_query = $this->getFilter($filters, true, true);
1387
+		$date = filter_var($date, FILTER_SANITIZE_STRING);
1388 1388
 		if ($globalTimezone != '') {
1389 1389
 			date_default_timezone_set($globalTimezone);
1390 1390
 			$datetime = new DateTime($date);
@@ -1392,12 +1392,12 @@  discard block
 block discarded – undo
1392 1392
 		} else $offset = '+00:00';
1393 1393
 
1394 1394
 		if ($globalDBdriver == 'mysql') {
1395
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1395
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1396 1396
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = :date
1397 1397
 								GROUP BY hour_name 
1398 1398
 								ORDER BY hour_name ASC";
1399 1399
 		} else {
1400
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1400
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1401 1401
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset, 'YYYY-mm-dd') = :date
1402 1402
 								GROUP BY hour_name 
1403 1403
 								ORDER BY hour_name ASC";
@@ -1409,7 +1409,7 @@  discard block
 block discarded – undo
1409 1409
 		$hour_array = array();
1410 1410
 		$temp_array = array();
1411 1411
         
1412
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1412
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1413 1413
 		{
1414 1414
 			$temp_array['hour_name'] = $row['hour_name'];
1415 1415
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1431,8 +1431,8 @@  discard block
 block discarded – undo
1431 1431
 	public function countAllHoursByIdent($ident, $filters = array())
1432 1432
 	{
1433 1433
 		global $globalTimezone, $globalDBdriver;
1434
-		$filter_query = $this->getFilter($filters,true,true);
1435
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
1434
+		$filter_query = $this->getFilter($filters, true, true);
1435
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
1436 1436
 		if ($globalTimezone != '') {
1437 1437
 			date_default_timezone_set($globalTimezone);
1438 1438
 			$datetime = new DateTime();
@@ -1440,12 +1440,12 @@  discard block
 block discarded – undo
1440 1440
 		} else $offset = '+00:00';
1441 1441
 
1442 1442
 		if ($globalDBdriver == 'mysql') {
1443
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1443
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1444 1444
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1445 1445
 								GROUP BY hour_name 
1446 1446
 								ORDER BY hour_name ASC";
1447 1447
 		} else {
1448
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1448
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1449 1449
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1450 1450
 								GROUP BY hour_name 
1451 1451
 								ORDER BY hour_name ASC";
@@ -1453,12 +1453,12 @@  discard block
 block discarded – undo
1453 1453
       
1454 1454
 		
1455 1455
 		$sth = $this->db->prepare($query);
1456
-		$sth->execute(array(':ident' => $ident,':offset' => $offset));
1456
+		$sth->execute(array(':ident' => $ident, ':offset' => $offset));
1457 1457
       
1458 1458
 		$hour_array = array();
1459 1459
 		$temp_array = array();
1460 1460
         
1461
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1461
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1462 1462
 		{
1463 1463
 			$temp_array['hour_name'] = $row['hour_name'];
1464 1464
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1477,33 +1477,33 @@  discard block
 block discarded – undo
1477 1477
 	* @return Integer the number of vessels
1478 1478
 	*
1479 1479
 	*/
1480
-	public function countOverallMarine($filters = array(),$year = '',$month = '')
1480
+	public function countOverallMarine($filters = array(), $year = '', $month = '')
1481 1481
 	{
1482 1482
 		global $globalDBdriver;
1483 1483
 		//$queryi  = "SELECT COUNT(marine_output.marine_id) AS flight_count FROM marine_output";
1484
-		$queryi  = "SELECT COUNT(DISTINCT marine_output.mmsi) AS flight_count FROM marine_output";
1484
+		$queryi = "SELECT COUNT(DISTINCT marine_output.mmsi) AS flight_count FROM marine_output";
1485 1485
 		$query_values = array();
1486 1486
 		$query = '';
1487 1487
 		if ($year != '') {
1488 1488
 			if ($globalDBdriver == 'mysql') {
1489 1489
 				$query .= " AND YEAR(marine_output.date) = :year";
1490
-				$query_values = array_merge($query_values,array(':year' => $year));
1490
+				$query_values = array_merge($query_values, array(':year' => $year));
1491 1491
 			} else {
1492 1492
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1493
-				$query_values = array_merge($query_values,array(':year' => $year));
1493
+				$query_values = array_merge($query_values, array(':year' => $year));
1494 1494
 			}
1495 1495
 		}
1496 1496
 		if ($month != '') {
1497 1497
 			if ($globalDBdriver == 'mysql') {
1498 1498
 				$query .= " AND MONTH(marine_output.date) = :month";
1499
-				$query_values = array_merge($query_values,array(':month' => $month));
1499
+				$query_values = array_merge($query_values, array(':month' => $month));
1500 1500
 			} else {
1501 1501
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1502
-				$query_values = array_merge($query_values,array(':month' => $month));
1502
+				$query_values = array_merge($query_values, array(':month' => $month));
1503 1503
 			}
1504 1504
 		}
1505 1505
 		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1506
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1506
+		else $queryi .= $this->getFilter($filters, true, true).substr($query, 4);
1507 1507
 		
1508 1508
 		$sth = $this->db->prepare($queryi);
1509 1509
 		$sth->execute($query_values);
@@ -1516,32 +1516,32 @@  discard block
 block discarded – undo
1516 1516
 	* @return Integer the number of vessels
1517 1517
 	*
1518 1518
 	*/
1519
-	public function countOverallMarineTypes($filters = array(),$year = '',$month = '')
1519
+	public function countOverallMarineTypes($filters = array(), $year = '', $month = '')
1520 1520
 	{
1521 1521
 		global $globalDBdriver;
1522
-		$queryi  = "SELECT COUNT(DISTINCT marine_output.type) AS marine_count FROM marine_output";
1522
+		$queryi = "SELECT COUNT(DISTINCT marine_output.type) AS marine_count FROM marine_output";
1523 1523
 		$query_values = array();
1524 1524
 		$query = '';
1525 1525
 		if ($year != '') {
1526 1526
 			if ($globalDBdriver == 'mysql') {
1527 1527
 				$query .= " AND YEAR(marine_output.date) = :year";
1528
-				$query_values = array_merge($query_values,array(':year' => $year));
1528
+				$query_values = array_merge($query_values, array(':year' => $year));
1529 1529
 			} else {
1530 1530
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1531
-				$query_values = array_merge($query_values,array(':year' => $year));
1531
+				$query_values = array_merge($query_values, array(':year' => $year));
1532 1532
 			}
1533 1533
 		}
1534 1534
 		if ($month != '') {
1535 1535
 			if ($globalDBdriver == 'mysql') {
1536 1536
 				$query .= " AND MONTH(marine_output.date) = :month";
1537
-				$query_values = array_merge($query_values,array(':month' => $month));
1537
+				$query_values = array_merge($query_values, array(':month' => $month));
1538 1538
 			} else {
1539 1539
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1540
-				$query_values = array_merge($query_values,array(':month' => $month));
1540
+				$query_values = array_merge($query_values, array(':month' => $month));
1541 1541
 			}
1542 1542
 		}
1543 1543
 		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1544
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1544
+		else $queryi .= $this->getFilter($filters, true, true).substr($query, 4);
1545 1545
 		
1546 1546
 		$sth = $this->db->prepare($queryi);
1547 1547
 		$sth->execute($query_values);
@@ -1558,7 +1558,7 @@  discard block
 block discarded – undo
1558 1558
 	public function countAllHoursFromToday($filters = array())
1559 1559
 	{
1560 1560
 		global $globalTimezone, $globalDBdriver;
1561
-		$filter_query = $this->getFilter($filters,true,true);
1561
+		$filter_query = $this->getFilter($filters, true, true);
1562 1562
 		if ($globalTimezone != '') {
1563 1563
 			date_default_timezone_set($globalTimezone);
1564 1564
 			$datetime = new DateTime();
@@ -1566,12 +1566,12 @@  discard block
 block discarded – undo
1566 1566
 		} else $offset = '+00:00';
1567 1567
 
1568 1568
 		if ($globalDBdriver == 'mysql') {
1569
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1569
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1570 1570
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = CURDATE()
1571 1571
 								GROUP BY hour_name 
1572 1572
 								ORDER BY hour_name ASC";
1573 1573
 		} else {
1574
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1574
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1575 1575
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = CAST(NOW() AS date)
1576 1576
 								GROUP BY hour_name 
1577 1577
 								ORDER BY hour_name ASC";
@@ -1583,7 +1583,7 @@  discard block
 block discarded – undo
1583 1583
 		$hour_array = array();
1584 1584
 		$temp_array = array();
1585 1585
         
1586
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1586
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1587 1587
 		{
1588 1588
 			$temp_array['hour_name'] = $row['hour_name'];
1589 1589
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1602,9 +1602,9 @@  discard block
 block discarded – undo
1602 1602
 	*/
1603 1603
 	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1604 1604
 	{
1605
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
1605
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
1606 1606
 
1607
-		$query  = "SELECT marine_output.marine_id
1607
+		$query = "SELECT marine_output.marine_id
1608 1608
 				FROM marine_output 
1609 1609
 				WHERE marine_output.fammarine_id = '".$fammarine_id."'";
1610 1610
         
@@ -1612,7 +1612,7 @@  discard block
 block discarded – undo
1612 1612
 		$sth = $this->db->prepare($query);
1613 1613
 		$sth->execute();
1614 1614
 
1615
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1615
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1616 1616
 		{
1617 1617
 			return $row['marine_id'];
1618 1618
 		}
@@ -1637,23 +1637,23 @@  discard block
 block discarded – undo
1637 1637
 		}
1638 1638
 		
1639 1639
 		$current_date = date("Y-m-d H:i:s");
1640
-		$date = date("Y-m-d H:i:s",strtotime($dateString." UTC"));
1640
+		$date = date("Y-m-d H:i:s", strtotime($dateString." UTC"));
1641 1641
 		
1642 1642
 		$diff = abs(strtotime($current_date) - strtotime($date));
1643 1643
 
1644
-		$time_array['years'] = floor($diff / (365*60*60*24)); 
1644
+		$time_array['years'] = floor($diff/(365*60*60*24)); 
1645 1645
 		$years = $time_array['years'];
1646 1646
 		
1647
-		$time_array['months'] = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
1647
+		$time_array['months'] = floor(($diff - $years*365*60*60*24)/(30*60*60*24));
1648 1648
 		$months = $time_array['months'];
1649 1649
 		
1650
-		$time_array['days'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
1650
+		$time_array['days'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24)/(60*60*24));
1651 1651
 		$days = $time_array['days'];
1652
-		$time_array['hours'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60));
1652
+		$time_array['hours'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/(60*60));
1653 1653
 		$hours = $time_array['hours'];
1654
-		$time_array['minutes'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60);
1654
+		$time_array['minutes'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/60);
1655 1655
 		$minutes = $time_array['minutes'];
1656
-		$time_array['seconds'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1656
+		$time_array['seconds'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1657 1657
 		
1658 1658
 		return $time_array;
1659 1659
 	}
@@ -1676,63 +1676,63 @@  discard block
 block discarded – undo
1676 1676
 			$temp_array['direction_degree'] = $direction;
1677 1677
 			$temp_array['direction_shortname'] = "N";
1678 1678
 			$temp_array['direction_fullname'] = "North";
1679
-		} elseif ($direction >= 22.5 && $direction < 45){
1679
+		} elseif ($direction >= 22.5 && $direction < 45) {
1680 1680
 			$temp_array['direction_degree'] = $direction;
1681 1681
 			$temp_array['direction_shortname'] = "NNE";
1682 1682
 			$temp_array['direction_fullname'] = "North-Northeast";
1683
-		} elseif ($direction >= 45 && $direction < 67.5){
1683
+		} elseif ($direction >= 45 && $direction < 67.5) {
1684 1684
 			$temp_array['direction_degree'] = $direction;
1685 1685
 			$temp_array['direction_shortname'] = "NE";
1686 1686
 			$temp_array['direction_fullname'] = "Northeast";
1687
-		} elseif ($direction >= 67.5 && $direction < 90){
1687
+		} elseif ($direction >= 67.5 && $direction < 90) {
1688 1688
 			$temp_array['direction_degree'] = $direction;
1689 1689
 			$temp_array['direction_shortname'] = "ENE";
1690 1690
 			$temp_array['direction_fullname'] = "East-Northeast";
1691
-		} elseif ($direction >= 90 && $direction < 112.5){
1691
+		} elseif ($direction >= 90 && $direction < 112.5) {
1692 1692
 			$temp_array['direction_degree'] = $direction;
1693 1693
 			$temp_array['direction_shortname'] = "E";
1694 1694
 			$temp_array['direction_fullname'] = "East";
1695
-		} elseif ($direction >= 112.5 && $direction < 135){
1695
+		} elseif ($direction >= 112.5 && $direction < 135) {
1696 1696
 			$temp_array['direction_degree'] = $direction;
1697 1697
 			$temp_array['direction_shortname'] = "ESE";
1698 1698
 			$temp_array['direction_fullname'] = "East-Southeast";
1699
-		} elseif ($direction >= 135 && $direction < 157.5){
1699
+		} elseif ($direction >= 135 && $direction < 157.5) {
1700 1700
 			$temp_array['direction_degree'] = $direction;
1701 1701
 			$temp_array['direction_shortname'] = "SE";
1702 1702
 			$temp_array['direction_fullname'] = "Southeast";
1703
-		} elseif ($direction >= 157.5 && $direction < 180){
1703
+		} elseif ($direction >= 157.5 && $direction < 180) {
1704 1704
 			$temp_array['direction_degree'] = $direction;
1705 1705
 			$temp_array['direction_shortname'] = "SSE";
1706 1706
 			$temp_array['direction_fullname'] = "South-Southeast";
1707
-		} elseif ($direction >= 180 && $direction < 202.5){
1707
+		} elseif ($direction >= 180 && $direction < 202.5) {
1708 1708
 			$temp_array['direction_degree'] = $direction;
1709 1709
 			$temp_array['direction_shortname'] = "S";
1710 1710
 			$temp_array['direction_fullname'] = "South";
1711
-		} elseif ($direction >= 202.5 && $direction < 225){
1711
+		} elseif ($direction >= 202.5 && $direction < 225) {
1712 1712
 			$temp_array['direction_degree'] = $direction;
1713 1713
 			$temp_array['direction_shortname'] = "SSW";
1714 1714
 			$temp_array['direction_fullname'] = "South-Southwest";
1715
-		} elseif ($direction >= 225 && $direction < 247.5){
1715
+		} elseif ($direction >= 225 && $direction < 247.5) {
1716 1716
 			$temp_array['direction_degree'] = $direction;
1717 1717
 			$temp_array['direction_shortname'] = "SW";
1718 1718
 			$temp_array['direction_fullname'] = "Southwest";
1719
-		} elseif ($direction >= 247.5 && $direction < 270){
1719
+		} elseif ($direction >= 247.5 && $direction < 270) {
1720 1720
 			$temp_array['direction_degree'] = $direction;
1721 1721
 			$temp_array['direction_shortname'] = "WSW";
1722 1722
 			$temp_array['direction_fullname'] = "West-Southwest";
1723
-		} elseif ($direction >= 270 && $direction < 292.5){
1723
+		} elseif ($direction >= 270 && $direction < 292.5) {
1724 1724
 			$temp_array['direction_degree'] = $direction;
1725 1725
 			$temp_array['direction_shortname'] = "W";
1726 1726
 			$temp_array['direction_fullname'] = "West";
1727
-		} elseif ($direction >= 292.5 && $direction < 315){
1727
+		} elseif ($direction >= 292.5 && $direction < 315) {
1728 1728
 			$temp_array['direction_degree'] = $direction;
1729 1729
 			$temp_array['direction_shortname'] = "WNW";
1730 1730
 			$temp_array['direction_fullname'] = "West-Northwest";
1731
-		} elseif ($direction >= 315 && $direction < 337.5){
1731
+		} elseif ($direction >= 315 && $direction < 337.5) {
1732 1732
 			$temp_array['direction_degree'] = $direction;
1733 1733
 			$temp_array['direction_shortname'] = "NW";
1734 1734
 			$temp_array['direction_fullname'] = "Northwest";
1735
-		} elseif ($direction >= 337.5 && $direction < 360){
1735
+		} elseif ($direction >= 337.5 && $direction < 360) {
1736 1736
 			$temp_array['direction_degree'] = $direction;
1737 1737
 			$temp_array['direction_shortname'] = "NNW";
1738 1738
 			$temp_array['direction_fullname'] = "North-Northwest";
@@ -1749,11 +1749,11 @@  discard block
 block discarded – undo
1749 1749
 	* @param Float $longitude longitute of the flight
1750 1750
 	* @return String the countrie
1751 1751
 	*/
1752
-	public function getCountryFromLatitudeLongitude($latitude,$longitude)
1752
+	public function getCountryFromLatitudeLongitude($latitude, $longitude)
1753 1753
 	{
1754 1754
 		global $globalDBdriver, $globalDebug;
1755
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1756
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1755
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1756
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1757 1757
 	
1758 1758
 		$Connection = new Connection($this->db);
1759 1759
 		if (!$Connection->tableExists('countries')) return '';
@@ -1793,7 +1793,7 @@  discard block
 block discarded – undo
1793 1793
 	public function getCountryFromISO2($iso2)
1794 1794
 	{
1795 1795
 		global $globalDBdriver, $globalDebug;
1796
-		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
1796
+		$iso2 = filter_var($iso2, FILTER_SANITIZE_STRING);
1797 1797
 	
1798 1798
 		$Connection = new Connection($this->db);
1799 1799
 		if (!$Connection->tableExists('countries')) return '';
@@ -1841,7 +1841,7 @@  discard block
 block discarded – undo
1841 1841
 		
1842 1842
 		$bitly_data = json_decode($bitly_data);
1843 1843
 		$bitly_url = '';
1844
-		if ($bitly_data->status_txt = "OK"){
1844
+		if ($bitly_data->status_txt = "OK") {
1845 1845
 			$bitly_url = $bitly_data->data->url;
1846 1846
 		}
1847 1847
 
@@ -1855,11 +1855,11 @@  discard block
 block discarded – undo
1855 1855
 	* @return Array the vessel type list
1856 1856
 	*
1857 1857
 	*/
1858
-	public function countAllMarineTypes($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array(),$year = '',$month = '',$day = '')
1858
+	public function countAllMarineTypes($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array(), $year = '', $month = '', $day = '')
1859 1859
 	{
1860 1860
 		global $globalDBdriver;
1861
-		$filter_query = $this->getFilter($filters,true,true);
1862
-		$query  = "SELECT marine_output.type AS marine_type, COUNT(marine_output.type) AS marine_type_count, marine_output.type_id AS marine_type_id 
1861
+		$filter_query = $this->getFilter($filters, true, true);
1862
+		$query = "SELECT marine_output.type AS marine_type, COUNT(marine_output.type) AS marine_type_count, marine_output.type_id AS marine_type_id 
1863 1863
 		    FROM marine_output ".$filter_query." marine_output.type <> '' AND marine_output.type_id IS NOT NULL";
1864 1864
 		if ($olderthanmonths > 0) {
1865 1865
 			if ($globalDBdriver == 'mysql') {
@@ -1879,28 +1879,28 @@  discard block
 block discarded – undo
1879 1879
 		if ($year != '') {
1880 1880
 			if ($globalDBdriver == 'mysql') {
1881 1881
 				$query .= " AND YEAR(marine_output.date) = :year";
1882
-				$query_values = array_merge($query_values,array(':year' => $year));
1882
+				$query_values = array_merge($query_values, array(':year' => $year));
1883 1883
 			} else {
1884 1884
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1885
-				$query_values = array_merge($query_values,array(':year' => $year));
1885
+				$query_values = array_merge($query_values, array(':year' => $year));
1886 1886
 			}
1887 1887
 		}
1888 1888
 		if ($month != '') {
1889 1889
 			if ($globalDBdriver == 'mysql') {
1890 1890
 				$query .= " AND MONTH(marine_output.date) = :month";
1891
-				$query_values = array_merge($query_values,array(':month' => $month));
1891
+				$query_values = array_merge($query_values, array(':month' => $month));
1892 1892
 			} else {
1893 1893
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1894
-				$query_values = array_merge($query_values,array(':month' => $month));
1894
+				$query_values = array_merge($query_values, array(':month' => $month));
1895 1895
 			}
1896 1896
 		}
1897 1897
 		if ($day != '') {
1898 1898
 			if ($globalDBdriver == 'mysql') {
1899 1899
 				$query .= " AND DAY(marine_output.date) = :day";
1900
-				$query_values = array_merge($query_values,array(':day' => $day));
1900
+				$query_values = array_merge($query_values, array(':day' => $day));
1901 1901
 			} else {
1902 1902
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
1903
-				$query_values = array_merge($query_values,array(':day' => $day));
1903
+				$query_values = array_merge($query_values, array(':day' => $day));
1904 1904
 			}
1905 1905
 		}
1906 1906
 		$query .= " GROUP BY marine_output.type, marine_output.type_id ORDER BY marine_type_count DESC";
@@ -1909,7 +1909,7 @@  discard block
 block discarded – undo
1909 1909
 		$sth->execute($query_values);
1910 1910
 		$marine_array = array();
1911 1911
 		$temp_array = array();
1912
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1912
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1913 1913
 		{
1914 1914
 			$temp_array['marine_type'] = $row['marine_type'];
1915 1915
 			$temp_array['marine_type_id'] = $row['marine_type_id'];
@@ -1925,13 +1925,13 @@  discard block
 block discarded – undo
1925 1925
 	* @return Array the tracker information
1926 1926
 	*
1927 1927
 	*/
1928
-	public function searchMarineData($q = '', $callsign = '',$mmsi = '', $imo = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '',$origLat = '',$origLon = '',$dist = '',$filters = array())
1928
+	public function searchMarineData($q = '', $callsign = '', $mmsi = '', $imo = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '', $origLat = '', $origLon = '', $dist = '', $filters = array())
1929 1929
 	{
1930 1930
 		global $globalTimezone, $globalDBdriver;
1931 1931
 		date_default_timezone_set('UTC');
1932 1932
 		$query_values = array();
1933 1933
 		$additional_query = '';
1934
-		$filter_query = $this->getFilter($filters,true,true);
1934
+		$filter_query = $this->getFilter($filters, true, true);
1935 1935
 		if ($q != "")
1936 1936
 		{
1937 1937
 			if (!is_string($q))
@@ -1939,8 +1939,8 @@  discard block
 block discarded – undo
1939 1939
 				return false;
1940 1940
 			} else {
1941 1941
 				$q_array = explode(" ", $q);
1942
-				foreach ($q_array as $q_item){
1943
-					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
1942
+				foreach ($q_array as $q_item) {
1943
+					$q_item = filter_var($q_item, FILTER_SANITIZE_STRING);
1944 1944
 					$additional_query .= " AND (";
1945 1945
 					if (is_int($q_item)) $additional_query .= "(marine_output.marine_id = '".$q_item."') OR ";
1946 1946
 					if (is_int($q_item)) $additional_query .= "(marine_output.mmsi = '".$q_item."') OR ";
@@ -1952,42 +1952,42 @@  discard block
 block discarded – undo
1952 1952
 		}
1953 1953
 		if ($callsign != "")
1954 1954
 		{
1955
-			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
1955
+			$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
1956 1956
 			if (!is_string($callsign))
1957 1957
 			{
1958 1958
 				return false;
1959 1959
 			} else {
1960 1960
 				$additional_query .= " AND marine_output.ident = :callsign";
1961
-				$query_values = array_merge($query_values,array(':callsign' => $callsign));
1961
+				$query_values = array_merge($query_values, array(':callsign' => $callsign));
1962 1962
 			}
1963 1963
 		}
1964 1964
 		if ($mmsi != "")
1965 1965
 		{
1966
-			$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING);
1966
+			$mmsi = filter_var($mmsi, FILTER_SANITIZE_STRING);
1967 1967
 			if (!is_numeric($mmsi))
1968 1968
 			{
1969 1969
 				return false;
1970 1970
 			} else {
1971 1971
 				$additional_query .= " AND marine_output.mmsi = :mmsi";
1972
-				$query_values = array_merge($query_values,array(':mmsi' => $mmsi));
1972
+				$query_values = array_merge($query_values, array(':mmsi' => $mmsi));
1973 1973
 			}
1974 1974
 		}
1975 1975
 		if ($imo != "")
1976 1976
 		{
1977
-			$imo = filter_var($imo,FILTER_SANITIZE_STRING);
1977
+			$imo = filter_var($imo, FILTER_SANITIZE_STRING);
1978 1978
 			if (!is_numeric($imo))
1979 1979
 			{
1980 1980
 				return false;
1981 1981
 			} else {
1982 1982
 				$additional_query .= " AND marine_output.imo = :imo";
1983
-				$query_values = array_merge($query_values,array(':imo' => $imo));
1983
+				$query_values = array_merge($query_values, array(':imo' => $imo));
1984 1984
 			}
1985 1985
 		}
1986 1986
 		if ($date_posted != "")
1987 1987
 		{
1988 1988
 			$date_array = explode(",", $date_posted);
1989
-			$date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING);
1990
-			$date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING);
1989
+			$date_array[0] = filter_var($date_array[0], FILTER_SANITIZE_STRING);
1990
+			$date_array[1] = filter_var($date_array[1], FILTER_SANITIZE_STRING);
1991 1991
 			if ($globalTimezone != '') {
1992 1992
 				date_default_timezone_set($globalTimezone);
1993 1993
 				$datetime = new DateTime();
@@ -2014,8 +2014,8 @@  discard block
 block discarded – undo
2014 2014
 		if ($limit != "")
2015 2015
 		{
2016 2016
 			$limit_array = explode(",", $limit);
2017
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
2018
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
2017
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
2018
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
2019 2019
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
2020 2020
 			{
2021 2021
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
@@ -2033,28 +2033,28 @@  discard block
 block discarded – undo
2033 2033
 			}
2034 2034
 		}
2035 2035
 		if ($origLat != "" && $origLon != "" && $dist != "") {
2036
-			$dist = number_format($dist*0.621371,2,'.',''); // convert km to mile
2036
+			$dist = number_format($dist*0.621371, 2, '.', ''); // convert km to mile
2037 2037
 			if ($globalDBdriver == 'mysql') {
2038
-				$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 
2038
+				$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 
2039 2039
 				    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)) 
2040 2040
 				    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;
2041 2041
 			} else {
2042
-				$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 
2042
+				$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 
2043 2043
 				    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)) 
2044 2044
 				    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;
2045 2045
 			}
2046 2046
 		} else {
2047
-			$query  = "SELECT marine_output.* FROM marine_output".$filter_query." marine_output.ident <> '' 
2047
+			$query = "SELECT marine_output.* FROM marine_output".$filter_query." marine_output.ident <> '' 
2048 2048
 			    ".$additional_query."
2049 2049
 			    ".$orderby_query;
2050 2050
 		}
2051
-		$marine_array = $this->getDataFromDB($query, $query_values,$limit_query);
2051
+		$marine_array = $this->getDataFromDB($query, $query_values, $limit_query);
2052 2052
 		return $marine_array;
2053 2053
 	}
2054 2054
 
2055 2055
 	public function getOrderBy()
2056 2056
 	{
2057
-		$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"));
2057
+		$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"));
2058 2058
 		
2059 2059
 		return $orderby;
2060 2060
 		
Please login to merge, or discard this patch.
require/class.MarineArchive.php 1 patch
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -14,33 +14,33 @@  discard block
 block discarded – undo
14 14
 	* @param Array $filter the filter
15 15
 	* @return Array the SQL part
16 16
 	*/
17
-	public function getFilter($filter = array(),$where = false,$and = false) {
17
+	public function getFilter($filter = array(), $where = false, $and = false) {
18 18
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
19 19
 		$filters = array();
20 20
 		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) {
21 21
 			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) {
22 22
 				$filters = $globalStatsFilters[$globalFilterName];
23 23
 			} else {
24
-				$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]);
24
+				$filter = array_merge($filter, $globalStatsFilters[$globalFilterName]);
25 25
 			}
26 26
 		}
27 27
 		if (isset($filter[0]['source'])) {
28
-			$filters = array_merge($filters,$filter);
28
+			$filters = array_merge($filters, $filter);
29 29
 		}
30
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
30
+		if (is_array($globalFilter)) $filter = array_merge($filter, $globalFilter);
31 31
 		$filter_query_join = '';
32 32
 		$filter_query_where = '';
33
-		foreach($filters as $flt) {
33
+		foreach ($filters as $flt) {
34 34
 			if (isset($flt['idents']) && !empty($flt['idents'])) {
35 35
 				if (isset($flt['source'])) {
36
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_archive_output WHERE marine_archive_output.ident IN ('".implode("','",$flt['idents'])."') AND marine_archive_output.format_source IN ('".implode("','",$flt['source'])."')) spid ON spid.fammarine_id = marine_archive.fammarine_id";
36
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_archive_output WHERE marine_archive_output.ident IN ('".implode("','", $flt['idents'])."') AND marine_archive_output.format_source IN ('".implode("','", $flt['source'])."')) spid ON spid.fammarine_id = marine_archive.fammarine_id";
37 37
 				} else {
38
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_archive_output WHERE marine_archive_output.ident IN ('".implode("','",$flt['idents'])."')) spid ON spid.fammarine_id = marine_archive.fammarine_id";
38
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_archive_output WHERE marine_archive_output.ident IN ('".implode("','", $flt['idents'])."')) spid ON spid.fammarine_id = marine_archive.fammarine_id";
39 39
 				}
40 40
 			}
41 41
 		}
42 42
 		if (isset($filter['source']) && !empty($filter['source'])) {
43
-			$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')";
43
+			$filter_query_where .= " AND format_source IN ('".implode("','", $filter['source'])."')";
44 44
 		}
45 45
 		if (isset($filter['ident']) && !empty($filter['ident'])) {
46 46
 			$filter_query_where .= " AND ident = '".$filter['ident']."'";
@@ -68,42 +68,42 @@  discard block
 block discarded – undo
68 68
 					$filter_query_date .= " AND EXTRACT(DAY FROM marine_archive_output.date) = '".$filter['day']."'";
69 69
 				}
70 70
 			}
71
-			$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_archive_output".preg_replace('/^ AND/',' WHERE',$filter_query_date).") sd ON sd.fammarine_id = marine_archive.fammarine_id";
71
+			$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_archive_output".preg_replace('/^ AND/', ' WHERE', $filter_query_date).") sd ON sd.fammarine_id = marine_archive.fammarine_id";
72 72
 		}
73 73
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
74
-			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
74
+			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')";
75 75
 		}
76 76
 		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
77 77
 		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
78 78
 		if ($filter_query_where != '') {
79
-			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
79
+			$filter_query_where = preg_replace('/^ AND/', ' WHERE', $filter_query_where);
80 80
 		}
81 81
 		$filter_query = $filter_query_join.$filter_query_where;
82 82
 		return $filter_query;
83 83
 	}
84 84
 
85 85
 	// marine_archive
86
-	public function addMarineArchiveData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '',$type = '',$typeid = '',$imo = '', $callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$statusid = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '',$captain_id = '',$captain_name = '',$race_id = '',$race_name = '') {
86
+	public function addMarineArchiveData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '', $type = '', $typeid = '', $imo = '', $callsign = '', $arrival_code = '', $arrival_date = '', $status = '', $statusid = '', $noarchive = false, $format_source = '', $source_name = '', $over_country = '', $captain_id = '', $captain_name = '', $race_id = '', $race_name = '') {
87 87
 		require_once(dirname(__FILE__).'/class.Marine.php');
88 88
 		if ($over_country == '') {
89 89
 			$Marine = new Marine($this->db);
90
-			$data_country = $Marine->getCountryFromLatitudeLongitude($latitude,$longitude);
90
+			$data_country = $Marine->getCountryFromLatitudeLongitude($latitude, $longitude);
91 91
 			if (!empty($data_country)) $country = $data_country['iso2'];
92 92
 			else $country = '';
93 93
 		} else $country = $over_country;
94 94
 		
95 95
 		//$country = $over_country;
96 96
 		// Route is not added in marine_archive
97
-		$query  = 'INSERT INTO marine_archive (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,type_id,status,status_id,imo,arrival_port_name,arrival_port_date,captain_id,captain_name,race_id,race_name) 
97
+		$query = 'INSERT INTO marine_archive (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,type_id,status,status_id,imo,arrival_port_name,arrival_port_date,captain_id,captain_name,race_id,race_name) 
98 98
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:mmsi,:type,:type_id,:status,:status_id,:imo,:arrival_port_name,:arrival_port_date,:captain_id,:captain_name,:race_id,:race_name)';
99 99
 
100
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':over_country' => $country,':mmsi' => $mmsi,':type' => $type,':type_id' => $typeid,':status' => $status,':status_id' => $statusid,':imo' => $imo,':arrival_port_name' => $arrival_code,':arrival_port_date' => $arrival_date,':captain_id' => $captain_id,':captain_name' => $captain_name,':race_id' => $race_id,':race_name' => $race_name);
100
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident, ':latitude' => $latitude, ':longitude' => $longitude, ':heading' => $heading, ':groundspeed' => $groundspeed, ':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':over_country' => $country, ':mmsi' => $mmsi, ':type' => $type, ':type_id' => $typeid, ':status' => $status, ':status_id' => $statusid, ':imo' => $imo, ':arrival_port_name' => $arrival_code, ':arrival_port_date' => $arrival_date, ':captain_id' => $captain_id, ':captain_name' => $captain_name, ':race_id' => $race_id, ':race_name' => $race_name);
101 101
 
102 102
 		try {
103 103
 			$sth = $this->db->prepare($query);
104 104
 			$sth->execute($query_values);
105 105
 			$sth->closeCursor();
106
-		} catch(PDOException $e) {
106
+		} catch (PDOException $e) {
107 107
 			return "error : ".$e->getMessage();
108 108
 		}
109 109
 		return "success";
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 
124 124
                 $ident = filter_var($ident, FILTER_SANITIZE_STRING);
125 125
                 //$query  = "SELECT marine_archive.* FROM marine_archive INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_archive l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_archive.fammarine_id = s.fammarine_id AND marine_archive.date = s.maxdate LIMIT 1";
126
-                $query  = "SELECT marine_archive.* FROM marine_archive WHERE ident = :ident ORDER BY date DESC LIMIT 1";
126
+                $query = "SELECT marine_archive.* FROM marine_archive WHERE ident = :ident ORDER BY date DESC LIMIT 1";
127 127
 
128
-                $spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident));
128
+                $spotter_array = $Marine->getDataFromDB($query, array(':ident' => $ident));
129 129
 
130 130
                 return $spotter_array;
131 131
         }
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
                 $id = filter_var($id, FILTER_SANITIZE_STRING);
145 145
                 //$query  = MarineArchive->$global_query." WHERE marine_archive.fammarine_id = :id";
146 146
                 //$query  = "SELECT marine_archive.* FROM marine_archive INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_archive l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_archive.fammarine_id = s.fammarine_id AND marine_archive.date = s.maxdate LIMIT 1";
147
-                $query  = "SELECT * FROM marine_archive WHERE fammarine_id = :id ORDER BY date DESC LIMIT 1";
147
+                $query = "SELECT * FROM marine_archive WHERE fammarine_id = :id ORDER BY date DESC LIMIT 1";
148 148
 
149 149
 //              $spotter_array = Marine->getDataFromDB($query,array(':id' => $id));
150 150
                   /*
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
                 }
158 158
                 $spotter_array = $sth->fetchAll(PDO->FETCH_ASSOC);
159 159
                 */
160
-                $spotter_array = $Marine->getDataFromDB($query,array(':id' => $id));
160
+                $spotter_array = $Marine->getDataFromDB($query, array(':id' => $id));
161 161
 
162 162
                 return $spotter_array;
163 163
         }
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
 	{
173 173
                 date_default_timezone_set('UTC');
174 174
                 $id = filter_var($id, FILTER_SANITIZE_STRING);
175
-                $query  = $this->global_query." WHERE marine_archive.fammarine_id = :id ORDER BY date";
175
+                $query = $this->global_query." WHERE marine_archive.fammarine_id = :id ORDER BY date";
176 176
 
177 177
 //              $spotter_array = Marine->getDataFromDB($query,array(':id' => $id));
178 178
 
179 179
                 try {
180 180
                         $sth = $this->db->prepare($query);
181 181
                         $sth->execute(array(':id' => $id));
182
-                } catch(PDOException $e) {
182
+                } catch (PDOException $e) {
183 183
                         echo $e->getMessage();
184 184
                         die;
185 185
                 }
@@ -198,14 +198,14 @@  discard block
 block discarded – undo
198 198
         {
199 199
                 date_default_timezone_set('UTC');
200 200
                 $id = filter_var($id, FILTER_SANITIZE_STRING);
201
-                $query  = "SELECT marine_archive.latitude, marine_archive.longitude, marine_archive.date FROM marine_archive WHERE marine_archive.fammarine_id = :id";
201
+                $query = "SELECT marine_archive.latitude, marine_archive.longitude, marine_archive.date FROM marine_archive WHERE marine_archive.fammarine_id = :id";
202 202
 
203 203
 //              $spotter_array = Marine->getDataFromDB($query,array(':id' => $id));
204 204
 
205 205
                 try {
206 206
                         $sth = $this->db->prepare($query);
207 207
                         $sth->execute(array(':id' => $id));
208
-                } catch(PDOException $e) {
208
+                } catch (PDOException $e) {
209 209
                         echo $e->getMessage();
210 210
                         die;
211 211
                 }
@@ -227,12 +227,12 @@  discard block
 block discarded – undo
227 227
                 date_default_timezone_set('UTC');
228 228
 
229 229
                 $ident = filter_var($ident, FILTER_SANITIZE_STRING);
230
-                $query  = "SELECT marine_archive.altitude, marine_archive.date FROM marine_archive WHERE marine_archive.ident = :ident AND marine_archive.latitude <> 0 AND marine_archive.longitude <> 0 ORDER BY date";
230
+                $query = "SELECT marine_archive.altitude, marine_archive.date FROM marine_archive WHERE marine_archive.ident = :ident AND marine_archive.latitude <> 0 AND marine_archive.longitude <> 0 ORDER BY date";
231 231
 
232 232
                 try {
233 233
                         $sth = $this->db->prepare($query);
234 234
                         $sth->execute(array(':ident' => $ident));
235
-                } catch(PDOException $e) {
235
+                } catch (PDOException $e) {
236 236
                         echo $e->getMessage();
237 237
                         die;
238 238
                 }
@@ -253,12 +253,12 @@  discard block
 block discarded – undo
253 253
                 date_default_timezone_set('UTC');
254 254
 
255 255
                 $id = filter_var($id, FILTER_SANITIZE_STRING);
256
-                $query  = "SELECT marine_archive.altitude, marine_archive.date FROM marine_archive WHERE marine_archive.fammarine_id = :id AND marine_archive.latitude <> 0 AND marine_archive.longitude <> 0 ORDER BY date";
256
+                $query = "SELECT marine_archive.altitude, marine_archive.date FROM marine_archive WHERE marine_archive.fammarine_id = :id AND marine_archive.latitude <> 0 AND marine_archive.longitude <> 0 ORDER BY date";
257 257
 
258 258
                 try {
259 259
                         $sth = $this->db->prepare($query);
260 260
                         $sth->execute(array(':id' => $id));
261
-                } catch(PDOException $e) {
261
+                } catch (PDOException $e) {
262 262
                         echo $e->getMessage();
263 263
                         die;
264 264
                 }
@@ -279,12 +279,12 @@  discard block
 block discarded – undo
279 279
                 date_default_timezone_set('UTC');
280 280
 
281 281
                 $id = filter_var($id, FILTER_SANITIZE_STRING);
282
-                $query  = "SELECT marine_archive.altitude, marine_archive.ground_speed, marine_archive.date FROM marine_archive WHERE marine_archive.fammarine_id = :id ORDER BY date";
282
+                $query = "SELECT marine_archive.altitude, marine_archive.ground_speed, marine_archive.date FROM marine_archive WHERE marine_archive.fammarine_id = :id ORDER BY date";
283 283
 
284 284
                 try {
285 285
                         $sth = $this->db->prepare($query);
286 286
                         $sth->execute(array(':id' => $id));
287
-                } catch(PDOException $e) {
287
+                } catch (PDOException $e) {
288 288
                         echo $e->getMessage();
289 289
                         die;
290 290
                 }
@@ -306,13 +306,13 @@  discard block
 block discarded – undo
306 306
                 date_default_timezone_set('UTC');
307 307
 
308 308
                 $ident = filter_var($ident, FILTER_SANITIZE_STRING);
309
-                $query  = "SELECT marine_archive.altitude, marine_archive.date FROM marine_archive INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_archive l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_archive.fammarine_id = s.fammarine_id AND marine_archive.date = s.maxdate LIMIT 1";
309
+                $query = "SELECT marine_archive.altitude, marine_archive.date FROM marine_archive INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_archive l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_archive.fammarine_id = s.fammarine_id AND marine_archive.date = s.maxdate LIMIT 1";
310 310
 //                $query  = "SELECT marine_archive.altitude, marine_archive.date FROM marine_archive WHERE marine_archive.ident = :ident";
311 311
 
312 312
                 try {
313 313
                         $sth = $this->db->prepare($query);
314 314
                         $sth->execute(array(':ident' => $ident));
315
-                } catch(PDOException $e) {
315
+                } catch (PDOException $e) {
316 316
                         echo $e->getMessage();
317 317
                         die;
318 318
                 }
@@ -329,12 +329,12 @@  discard block
 block discarded – undo
329 329
         * @return Array the spotter information
330 330
         *
331 331
         */
332
-	public function getMarineArchiveData($ident,$fammarine_id,$date)
332
+	public function getMarineArchiveData($ident, $fammarine_id, $date)
333 333
 	{
334 334
 		$Marine = new Marine($this->db);
335 335
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
336 336
 		$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident AND l.fammarine_id = :fammarine_id AND l.date LIKE :date GROUP BY l.fammarine_id) s on spotter_live.fammarine_id = s.fammarine_id AND spotter_live.date = s.maxdate";
337
-		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident,':fammarine_id' => $fammarine_id,':date' => $date.'%'));
337
+		$spotter_array = $Marine->getDataFromDB($query, array(':ident' => $ident, ':fammarine_id' => $fammarine_id, ':date' => $date.'%'));
338 338
 		return $spotter_array;
339 339
 	}
340 340
 
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 		try {
354 354
 			$sth = $this->db->prepare($query);
355 355
 			$sth->execute();
356
-		} catch(PDOException $e) {
356
+		} catch (PDOException $e) {
357 357
 			echo $e->getMessage();
358 358
 			die;
359 359
 		}
@@ -365,24 +365,24 @@  discard block
 block discarded – undo
365 365
         * @return Array the spotter information
366 366
         *
367 367
         */
368
-        public function getMinLiveMarineData($begindate,$enddate,$filter = array())
368
+        public function getMinLiveMarineData($begindate, $enddate, $filter = array())
369 369
         {
370 370
                 global $globalDBdriver, $globalLiveInterval;
371 371
                 date_default_timezone_set('UTC');
372 372
 
373 373
                 $filter_query = '';
374 374
                 if (isset($filter['source']) && !empty($filter['source'])) {
375
-                        $filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') ";
375
+                        $filter_query .= " AND format_source IN ('".implode("','", $filter['source'])."') ";
376 376
                 }
377 377
                 // Use spotter_output also ?
378 378
                 if (isset($filter['airlines']) && !empty($filter['airlines'])) {
379
-                        $filter_query .= " INNER JOIN (SELECT fammarine_id FROM marine_archive_output WHERE marine_archive_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.fammarine_id = marine_archive.fammarine_id ";
379
+                        $filter_query .= " INNER JOIN (SELECT fammarine_id FROM marine_archive_output WHERE marine_archive_output.airline_icao IN ('".implode("','", $filter['airlines'])."')) so ON so.fammarine_id = marine_archive.fammarine_id ";
380 380
                 }
381 381
                 if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
382 382
                         $filter_query .= " INNER JOIN (SELECT fammarine_id FROM marine_archive_output WHERE marine_archive_output.airline_type = '".$filter['airlinestype']."') sa ON sa.fammarine_id = marine_archive.fammarine_id ";
383 383
                 }
384 384
                 if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
385
-                        $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
385
+                        $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')";
386 386
                 }
387 387
 
388 388
                 //if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
@@ -401,14 +401,14 @@  discard block
 block discarded – undo
401 401
 						GROUP BY l.fammarine_id) s on marine_archive.fammarine_id = s.fammarine_id 
402 402
 				    AND marine_archive.date = s.maxdate '.$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON marine_archive.aircraft_icao = a.icao';
403 403
 */
404
-			$query  = 'SELECT marine_archive.date,marine_archive.fammarine_id, marine_archive.ident, marine_archive.aircraft_icao, marine_archive.departure_airport_icao as departure_airport, marine_archive.arrival_airport_icao as arrival_airport, marine_archive.latitude, marine_archive.longitude, marine_archive.altitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.squawk, a.aircraft_shadow,a.engine_type, a.engine_count, a.wake_category 
404
+			$query = 'SELECT marine_archive.date,marine_archive.fammarine_id, marine_archive.ident, marine_archive.aircraft_icao, marine_archive.departure_airport_icao as departure_airport, marine_archive.arrival_airport_icao as arrival_airport, marine_archive.latitude, marine_archive.longitude, marine_archive.altitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.squawk, a.aircraft_shadow,a.engine_type, a.engine_count, a.wake_category 
405 405
 				    FROM marine_archive 
406 406
 				    INNER JOIN (SELECT * FROM aircraft) a on marine_archive.aircraft_icao = a.icao
407 407
 				    WHERE marine_archive.date BETWEEN '."'".$begindate."'".' AND '."'".$begindate."'".' 
408 408
                         	    '.$filter_query.' ORDER BY fammarine_id';
409 409
                 } else {
410 410
                         //$query  = 'SELECT marine_archive.ident, marine_archive.fammarine_id, marine_archive.aircraft_icao, marine_archive.departure_airport_icao as departure_airport, marine_archive.arrival_airport_icao as arrival_airport, marine_archive.latitude, marine_archive.longitude, marine_archive.altitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.squawk, a.aircraft_shadow FROM marine_archive INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_archive l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_archive.fammarine_id = s.fammarine_id AND marine_archive.date = s.maxdate '.$filter_query.'INNER JOIN (SELECT * FROM aircraft) a on marine_archive.aircraft_icao = a.icao';
411
-                        $query  = 'SELECT marine_archive.date,marine_archive.fammarine_id, marine_archive.ident, marine_archive.aircraft_icao, marine_archive.departure_airport_icao as departure_airport, marine_archive.arrival_airport_icao as arrival_airport, marine_archive.latitude, marine_archive.longitude, marine_archive.altitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.squawk, a.aircraft_shadow,a.engine_type, a.engine_count, a.wake_category 
411
+                        $query = 'SELECT marine_archive.date,marine_archive.fammarine_id, marine_archive.ident, marine_archive.aircraft_icao, marine_archive.departure_airport_icao as departure_airport, marine_archive.arrival_airport_icao as arrival_airport, marine_archive.latitude, marine_archive.longitude, marine_archive.altitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.squawk, a.aircraft_shadow,a.engine_type, a.engine_count, a.wake_category 
412 412
                         	    FROM marine_archive 
413 413
                         	    INNER JOIN (SELECT * FROM aircraft) a on marine_archive.aircraft_icao = a.icao
414 414
                         	    WHERE marine_archive.date >= '."'".$begindate."'".' AND marine_archive.date <= '."'".$enddate."'".'
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
                 try {
419 419
                         $sth = $this->db->prepare($query);
420 420
                         $sth->execute();
421
-                } catch(PDOException $e) {
421
+                } catch (PDOException $e) {
422 422
                         echo $e->getMessage();
423 423
                         die;
424 424
                 }
@@ -433,24 +433,24 @@  discard block
 block discarded – undo
433 433
         * @return Array the spotter information
434 434
         *
435 435
         */
436
-        public function getMinLiveMarineDataPlayback($begindate,$enddate,$filter = array())
436
+        public function getMinLiveMarineDataPlayback($begindate, $enddate, $filter = array())
437 437
         {
438 438
                 global $globalDBdriver, $globalLiveInterval;
439 439
                 date_default_timezone_set('UTC');
440 440
 
441 441
                 $filter_query = '';
442 442
                 if (isset($filter['source']) && !empty($filter['source'])) {
443
-                        $filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') ";
443
+                        $filter_query .= " AND format_source IN ('".implode("','", $filter['source'])."') ";
444 444
                 }
445 445
                 // Should use spotter_output also ?
446 446
                 if (isset($filter['airlines']) && !empty($filter['airlines'])) {
447
-                        $filter_query .= " INNER JOIN (SELECT fammarine_id FROM marine_archive_output WHERE marine_archive_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.fammarine_id = marine_archive.fammarine_id ";
447
+                        $filter_query .= " INNER JOIN (SELECT fammarine_id FROM marine_archive_output WHERE marine_archive_output.airline_icao IN ('".implode("','", $filter['airlines'])."')) so ON so.fammarine_id = marine_archive.fammarine_id ";
448 448
                 }
449 449
                 if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
450 450
                         $filter_query .= " INNER JOIN (SELECT fammarine_id FROM marine_archive_output WHERE marine_archive_output.airline_type = '".$filter['airlinestype']."') sa ON sa.fammarine_id = marine_archive.fammarine_id ";
451 451
                 }
452 452
                 if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
453
-                        $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
453
+                        $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')";
454 454
                 }
455 455
 
456 456
                 //if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
                     		    FROM marine_archive 
461 461
                     		    INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_archive l WHERE (l.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".') GROUP BY l.fammarine_id) s on marine_archive.fammarine_id = s.fammarine_id AND marine_archive.date = s.maxdate '.$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON marine_archive.aircraft_icao = a.icao';
462 462
 			*/
463
-			$query  = 'SELECT a.aircraft_shadow, marine_archive_output.ident, marine_archive_output.fammarine_id, marine_archive_output.aircraft_icao, marine_archive_output.departure_airport_icao as departure_airport, marine_archive_output.arrival_airport_icao as arrival_airport, marine_archive_output.latitude, marine_archive_output.longitude, marine_archive_output.altitude, marine_archive_output.heading, marine_archive_output.ground_speed, marine_archive_output.squawk 
463
+			$query = 'SELECT a.aircraft_shadow, marine_archive_output.ident, marine_archive_output.fammarine_id, marine_archive_output.aircraft_icao, marine_archive_output.departure_airport_icao as departure_airport, marine_archive_output.arrival_airport_icao as arrival_airport, marine_archive_output.latitude, marine_archive_output.longitude, marine_archive_output.altitude, marine_archive_output.heading, marine_archive_output.ground_speed, marine_archive_output.squawk 
464 464
 				    FROM marine_archive_output 
465 465
 				    LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON marine_archive_output.aircraft_icao = a.icao 
466 466
 				    WHERE (marine_archive_output.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".') 
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
                         	    WHERE marine_archive_output.date >= '."'".$begindate."'".' AND marine_archive_output.date <= '."'".$enddate."'".'
476 476
                         	    '.$filter_query.' GROUP BY marine_archive_output.fammarine_id, marine_archive_output.ident, marine_archive_output.aircraft_icao, marine_archive_output.departure_airport_icao, marine_archive_output.arrival_airport_icao, marine_archive_output.latitude, marine_archive_output.longitude, marine_archive_output.altitude, marine_archive_output.heading, marine_archive_output.ground_speed, marine_archive_output.squawk, a.aircraft_shadow';
477 477
                         */
478
-                        $query  = 'SELECT DISTINCT marine_archive_output.fammarine_id, marine_archive_output.ident, marine_archive_output.aircraft_icao, marine_archive_output.departure_airport_icao as departure_airport, marine_archive_output.arrival_airport_icao as arrival_airport, marine_archive_output.latitude, marine_archive_output.longitude, marine_archive_output.altitude, marine_archive_output.heading, marine_archive_output.ground_speed, marine_archive_output.squawk, a.aircraft_shadow
478
+                        $query = 'SELECT DISTINCT marine_archive_output.fammarine_id, marine_archive_output.ident, marine_archive_output.aircraft_icao, marine_archive_output.departure_airport_icao as departure_airport, marine_archive_output.arrival_airport_icao as arrival_airport, marine_archive_output.latitude, marine_archive_output.longitude, marine_archive_output.altitude, marine_archive_output.heading, marine_archive_output.ground_speed, marine_archive_output.squawk, a.aircraft_shadow
479 479
                         	    FROM marine_archive_output 
480 480
                         	    INNER JOIN (SELECT * FROM aircraft) a on marine_archive_output.aircraft_icao = a.icao
481 481
                         	    WHERE marine_archive_output.date >= '."'".$begindate."'".' AND marine_archive_output.date <= '."'".$enddate."'".'
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
                 try {
488 488
                         $sth = $this->db->prepare($query);
489 489
                         $sth->execute();
490
-                } catch(PDOException $e) {
490
+                } catch (PDOException $e) {
491 491
                         echo $e->getMessage();
492 492
                         die;
493 493
                 }
@@ -502,23 +502,23 @@  discard block
 block discarded – undo
502 502
         * @return Array the spotter information
503 503
         *
504 504
         */
505
-        public function getLiveMarineCount($begindate,$enddate,$filter = array())
505
+        public function getLiveMarineCount($begindate, $enddate, $filter = array())
506 506
         {
507 507
                 global $globalDBdriver, $globalLiveInterval;
508 508
                 date_default_timezone_set('UTC');
509 509
 
510 510
                 $filter_query = '';
511 511
                 if (isset($filter['source']) && !empty($filter['source'])) {
512
-                        $filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') ";
512
+                        $filter_query .= " AND format_source IN ('".implode("','", $filter['source'])."') ";
513 513
                 }
514 514
                 if (isset($filter['airlines']) && !empty($filter['airlines'])) {
515
-                        $filter_query .= " INNER JOIN (SELECT fammarine_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.fammarine_id = marine_archive.fammarine_id ";
515
+                        $filter_query .= " INNER JOIN (SELECT fammarine_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','", $filter['airlines'])."')) so ON so.fammarine_id = marine_archive.fammarine_id ";
516 516
                 }
517 517
                 if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
518 518
                         $filter_query .= " INNER JOIN (SELECT fammarine_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.fammarine_id = marine_archive.fammarine_id ";
519 519
                 }
520 520
                 if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
521
-                        $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
521
+                        $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')";
522 522
                 }
523 523
 
524 524
                 //if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
                 try {
534 534
                         $sth = $this->db->prepare($query);
535 535
                         $sth->execute();
536
-                } catch(PDOException $e) {
536
+                } catch (PDOException $e) {
537 537
                         echo $e->getMessage();
538 538
                         die;
539 539
                 }
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
     * @return Array the spotter information
554 554
     *
555 555
     */
556
-    public function searchMarineData($q = '', $registration = '', $aircraft_icao = '', $aircraft_manufacturer = '', $highlights = '', $airline_icao = '', $airline_country = '', $airline_type = '', $airport = '', $airport_country = '', $callsign = '', $departure_airport_route = '', $arrival_airport_route = '', $owner = '',$pilot_id = '',$pilot_name = '',$altitude = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '',$origLat = '',$origLon = '',$dist = '', $filters=array())
556
+    public function searchMarineData($q = '', $registration = '', $aircraft_icao = '', $aircraft_manufacturer = '', $highlights = '', $airline_icao = '', $airline_country = '', $airline_type = '', $airport = '', $airport_country = '', $callsign = '', $departure_airport_route = '', $arrival_airport_route = '', $owner = '', $pilot_id = '', $pilot_name = '', $altitude = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '', $origLat = '', $origLon = '', $dist = '', $filters = array())
557 557
     {
558 558
 	global $globalTimezone, $globalDBdriver;
559 559
 	require_once(dirname(__FILE__).'/class.Translation.php');
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
 	        
576 576
 		$q_array = explode(" ", $q);
577 577
 		
578
-		foreach ($q_array as $q_item){
578
+		foreach ($q_array as $q_item) {
579 579
 		    $additional_query .= " AND (";
580 580
 		    $additional_query .= "(marine_archive_output.spotter_id like '%".$q_item."%') OR ";
581 581
 		    $additional_query .= "(marine_archive_output.aircraft_icao like '%".$q_item."%') OR ";
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 	
608 608
 	if ($registration != "")
609 609
 	{
610
-	    $registration = filter_var($registration,FILTER_SANITIZE_STRING);
610
+	    $registration = filter_var($registration, FILTER_SANITIZE_STRING);
611 611
 	    if (!is_string($registration))
612 612
 	    {
613 613
 		return false;
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
 	
619 619
 	if ($aircraft_icao != "")
620 620
 	{
621
-	    $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
621
+	    $aircraft_icao = filter_var($aircraft_icao, FILTER_SANITIZE_STRING);
622 622
 	    if (!is_string($aircraft_icao))
623 623
 	    {
624 624
 		return false;
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
 	
630 630
 	if ($aircraft_manufacturer != "")
631 631
 	{
632
-	    $aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING);
632
+	    $aircraft_manufacturer = filter_var($aircraft_manufacturer, FILTER_SANITIZE_STRING);
633 633
 	    if (!is_string($aircraft_manufacturer))
634 634
 	    {
635 635
 		return false;
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
 	
651 651
 	if ($airline_icao != "")
652 652
 	{
653
-	    $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING);
653
+	    $airline_icao = filter_var($airline_icao, FILTER_SANITIZE_STRING);
654 654
 	    if (!is_string($airline_icao))
655 655
 	    {
656 656
 		return false;
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
 	
662 662
 	if ($airline_country != "")
663 663
 	{
664
-	    $airline_country = filter_var($airline_country,FILTER_SANITIZE_STRING);
664
+	    $airline_country = filter_var($airline_country, FILTER_SANITIZE_STRING);
665 665
 	    if (!is_string($airline_country))
666 666
 	    {
667 667
 		return false;
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
 	
673 673
 	if ($airline_type != "")
674 674
 	{
675
-	    $airline_type = filter_var($airline_type,FILTER_SANITIZE_STRING);
675
+	    $airline_type = filter_var($airline_type, FILTER_SANITIZE_STRING);
676 676
 	    if (!is_string($airline_type))
677 677
 	    {
678 678
 		return false;
@@ -694,7 +694,7 @@  discard block
 block discarded – undo
694 694
 	
695 695
 	if ($airport != "")
696 696
 	{
697
-	    $airport = filter_var($airport,FILTER_SANITIZE_STRING);
697
+	    $airport = filter_var($airport, FILTER_SANITIZE_STRING);
698 698
 	    if (!is_string($airport))
699 699
 	    {
700 700
 		return false;
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
 	
706 706
 	if ($airport_country != "")
707 707
 	{
708
-	    $airport_country = filter_var($airport_country,FILTER_SANITIZE_STRING);
708
+	    $airport_country = filter_var($airport_country, FILTER_SANITIZE_STRING);
709 709
 	    if (!is_string($airport_country))
710 710
 	    {
711 711
 		return false;
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
     
717 717
 	if ($callsign != "")
718 718
 	{
719
-	    $callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
719
+	    $callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
720 720
 	    if (!is_string($callsign))
721 721
 	    {
722 722
 		return false;
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
 		$translate = $Translation->ident2icao($callsign);
725 725
 		if ($translate != $callsign) {
726 726
 			$additional_query .= " AND (marine_archive_output.ident = :callsign OR marine_archive_output.ident = :translate)";
727
-			$query_values = array_merge($query_values,array(':callsign' => $callsign,':translate' => $translate));
727
+			$query_values = array_merge($query_values, array(':callsign' => $callsign, ':translate' => $translate));
728 728
 		} else {
729 729
 			$additional_query .= " AND (marine_archive_output.ident = '".$callsign."')";
730 730
 		}
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
 
734 734
 	if ($owner != "")
735 735
 	{
736
-	    $owner = filter_var($owner,FILTER_SANITIZE_STRING);
736
+	    $owner = filter_var($owner, FILTER_SANITIZE_STRING);
737 737
 	    if (!is_string($owner))
738 738
 	    {
739 739
 		return false;
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 
745 745
 	if ($pilot_name != "")
746 746
 	{
747
-	    $pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING);
747
+	    $pilot_name = filter_var($pilot_name, FILTER_SANITIZE_STRING);
748 748
 	    if (!is_string($pilot_name))
749 749
 	    {
750 750
 		return false;
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 	
756 756
 	if ($pilot_id != "")
757 757
 	{
758
-	    $pilot_id = filter_var($pilot_id,FILTER_SANITIZE_NUMBER_INT);
758
+	    $pilot_id = filter_var($pilot_id, FILTER_SANITIZE_NUMBER_INT);
759 759
 	    if (!is_string($pilot_id))
760 760
 	    {
761 761
 		return false;
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
 	
767 767
 	if ($departure_airport_route != "")
768 768
 	{
769
-	    $departure_airport_route = filter_var($departure_airport_route,FILTER_SANITIZE_STRING);
769
+	    $departure_airport_route = filter_var($departure_airport_route, FILTER_SANITIZE_STRING);
770 770
 	    if (!is_string($departure_airport_route))
771 771
 	    {
772 772
 		return false;
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
 	
778 778
 	if ($arrival_airport_route != "")
779 779
 	{
780
-	    $arrival_airport_route = filter_var($arrival_airport_route,FILTER_SANITIZE_STRING);
780
+	    $arrival_airport_route = filter_var($arrival_airport_route, FILTER_SANITIZE_STRING);
781 781
 	    if (!is_string($arrival_airport_route))
782 782
 	    {
783 783
 		return false;
@@ -790,8 +790,8 @@  discard block
 block discarded – undo
790 790
 	{
791 791
 	    $altitude_array = explode(",", $altitude);
792 792
 	    
793
-	    $altitude_array[0] = filter_var($altitude_array[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
794
-	    $altitude_array[1] = filter_var($altitude_array[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
793
+	    $altitude_array[0] = filter_var($altitude_array[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
794
+	    $altitude_array[1] = filter_var($altitude_array[1], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
795 795
 	    
796 796
 
797 797
 	    if ($altitude_array[1] != "")
@@ -809,8 +809,8 @@  discard block
 block discarded – undo
809 809
 	{
810 810
 	    $date_array = explode(",", $date_posted);
811 811
 	    
812
-	    $date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING);
813
-	    $date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING);
812
+	    $date_array[0] = filter_var($date_array[0], FILTER_SANITIZE_STRING);
813
+	    $date_array[1] = filter_var($date_array[1], FILTER_SANITIZE_STRING);
814 814
 	    
815 815
 	    if ($globalTimezone != '') {
816 816
 		date_default_timezone_set($globalTimezone);
@@ -842,8 +842,8 @@  discard block
 block discarded – undo
842 842
 	{
843 843
 	    $limit_array = explode(",", $limit);
844 844
 	    
845
-	    $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
846
-	    $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
845
+	    $limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
846
+	    $limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
847 847
 	    
848 848
 	    if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
849 849
 	    {
@@ -854,8 +854,8 @@  discard block
 block discarded – undo
854 854
 	
855 855
 
856 856
 	if ($origLat != "" && $origLon != "" && $dist != "") {
857
-		$dist = number_format($dist*0.621371,2,'.','');
858
-		$query="SELECT marine_archive_output.*, 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - ABS(CAST(marine_archive.latitude as double precision)))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(ABS(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 
857
+		$dist = number_format($dist*0.621371, 2, '.', '');
858
+		$query = "SELECT marine_archive_output.*, 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - ABS(CAST(marine_archive.latitude as double precision)))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(ABS(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 
859 859
                           FROM marine_archive_output, marine_archive WHERE spotter_output_archive.fammarine_id = marine_archive.fammarine_id AND spotter_output.ident <> '' ".$additional_query."AND CAST(marine_archive.longitude as double precision) between ($origLon-$dist/ABS(cos(radians($origLat))*69)) and ($origLon+$dist/ABS(cos(radians($origLat))*69)) and CAST(marine_archive.latitude as double precision) between ($origLat-($dist/69)) and ($origLat+($dist/69)) 
860 860
                           AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - ABS(CAST(marine_archive.latitude as double precision)))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(ABS(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." ORDER BY distance";
861 861
 	} else {
@@ -872,12 +872,12 @@  discard block
 block discarded – undo
872 872
 			$additional_query .= " AND (marine_archive_output.waypoints <> '')";
873 873
 		}
874 874
 
875
-		$query  = "SELECT marine_archive_output.* FROM marine_archive_output 
875
+		$query = "SELECT marine_archive_output.* FROM marine_archive_output 
876 876
 		    WHERE marine_archive_output.ident <> '' 
877 877
 		    ".$additional_query."
878 878
 		    ".$filter_query.$orderby_query;
879 879
 	}
880
-	$spotter_array = $Marine->getDataFromDB($query, $query_values,$limit_query);
880
+	$spotter_array = $Marine->getDataFromDB($query, $query_values, $limit_query);
881 881
 
882 882
 	return $spotter_array;
883 883
     }
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
                 try {
895 895
                         $sth = $this->db->prepare($query);
896 896
                         $sth->execute();
897
-                } catch(PDOException $e) {
897
+                } catch (PDOException $e) {
898 898
                         return "error";
899 899
                 }
900 900
 	}
@@ -931,8 +931,8 @@  discard block
 block discarded – undo
931 931
 	{
932 932
 	    $limit_array = explode(",", $limit);
933 933
 	    
934
-	    $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
935
-	    $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
934
+	    $limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
935
+	    $limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
936 936
 	    
937 937
 	    if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
938 938
 	    {
@@ -973,7 +973,7 @@  discard block
 block discarded – undo
973 973
 	$query_values = array();
974 974
 	$limit_query = '';
975 975
 	$additional_query = '';
976
-	$filter_query = $this->getFilter($filter,true,true);
976
+	$filter_query = $this->getFilter($filter, true, true);
977 977
 	
978 978
 	if ($owner != "")
979 979
 	{
@@ -990,8 +990,8 @@  discard block
 block discarded – undo
990 990
 	{
991 991
 	    $limit_array = explode(",", $limit);
992 992
 	    
993
-	    $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
994
-	    $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
993
+	    $limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
994
+	    $limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
995 995
 	    
996 996
 	    if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
997 997
 	    {
@@ -1031,7 +1031,7 @@  discard block
 block discarded – undo
1031 1031
 	$query_values = array();
1032 1032
 	$limit_query = '';
1033 1033
 	$additional_query = '';
1034
-	$filter_query = $this->getFilter($filter,true,true);
1034
+	$filter_query = $this->getFilter($filter, true, true);
1035 1035
 	
1036 1036
 	if ($pilot != "")
1037 1037
 	{
@@ -1043,8 +1043,8 @@  discard block
 block discarded – undo
1043 1043
 	{
1044 1044
 	    $limit_array = explode(",", $limit);
1045 1045
 	    
1046
-	    $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1047
-	    $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1046
+	    $limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
1047
+	    $limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
1048 1048
 	    
1049 1049
 	    if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1050 1050
 	    {
@@ -1074,7 +1074,7 @@  discard block
 block discarded – undo
1074 1074
     * @return Array the airline country list
1075 1075
     *
1076 1076
     */
1077
-    public function countAllFlightOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '')
1077
+    public function countAllFlightOverCountries($limit = true, $olderthanmonths = 0, $sincedate = '')
1078 1078
     {
1079 1079
 	global $globalDBdriver;
1080 1080
 	/*
@@ -1103,7 +1103,7 @@  discard block
 block discarded – undo
1103 1103
 	$flight_array = array();
1104 1104
 	$temp_array = array();
1105 1105
         
1106
-	while($row = $sth->fetch(PDO::FETCH_ASSOC))
1106
+	while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1107 1107
 	{
1108 1108
 	    $temp_array['flight_count'] = $row['nb'];
1109 1109
 	    $temp_array['flight_country'] = $row['name'];
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
     * @return Array the airline country list
1121 1121
     *
1122 1122
     */
1123
-    public function countAllFlightOverCountriesByAirlines($limit = true,$olderthanmonths = 0,$sincedate = '')
1123
+    public function countAllFlightOverCountriesByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '')
1124 1124
     {
1125 1125
 	global $globalDBdriver;
1126 1126
 	/*
@@ -1149,7 +1149,7 @@  discard block
 block discarded – undo
1149 1149
 	$flight_array = array();
1150 1150
 	$temp_array = array();
1151 1151
         
1152
-	while($row = $sth->fetch(PDO::FETCH_ASSOC))
1152
+	while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1153 1153
 	{
1154 1154
 	    $temp_array['airline_icao'] = $row['airline_icao'];
1155 1155
 	    $temp_array['flight_count'] = $row['nb'];
@@ -1167,14 +1167,14 @@  discard block
 block discarded – undo
1167 1167
     * @return Array the spotter information
1168 1168
     *
1169 1169
     */
1170
-    public function getDateArchiveMarineDataById($id,$date)
1170
+    public function getDateArchiveMarineDataById($id, $date)
1171 1171
     {
1172 1172
 	$Marine = new Marine($this->db);
1173 1173
 	date_default_timezone_set('UTC');
1174 1174
 	$id = filter_var($id, FILTER_SANITIZE_STRING);
1175 1175
 	$query  = 'SELECT marine_archive.* FROM marine_archive INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_archive l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_archive.fammarine_id = s.fammarine_id AND marine_archive.date = s.maxdate ORDER BY marine_archive.date DESC';
1176
-	$date = date('c',$date);
1177
-	$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id,':date' => $date));
1176
+	$date = date('c', $date);
1177
+	$spotter_array = $Marine->getDataFromDB($query, array(':id' => $id, ':date' => $date));
1178 1178
 	return $spotter_array;
1179 1179
     }
1180 1180
 
@@ -1184,14 +1184,14 @@  discard block
 block discarded – undo
1184 1184
     * @return Array the spotter information
1185 1185
     *
1186 1186
     */
1187
-    public function getDateArchiveMarineDataByIdent($ident,$date)
1187
+    public function getDateArchiveMarineDataByIdent($ident, $date)
1188 1188
     {
1189 1189
 	$Marine = new Marine($this->db);
1190 1190
 	date_default_timezone_set('UTC');
1191 1191
 	$ident = filter_var($ident, FILTER_SANITIZE_STRING);
1192 1192
 	$query  = 'SELECT marine_archive.* FROM marine_archive INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_archive l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_archive.fammarine_id = s.fammarine_id AND marine_archive.date = s.maxdate ORDER BY marine_archive.date DESC';
1193
-	$date = date('c',$date);
1194
-	$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
1193
+	$date = date('c', $date);
1194
+	$spotter_array = $Marine->getDataFromDB($query, array(':ident' => $ident, ':date' => $date));
1195 1195
 	return $spotter_array;
1196 1196
     }
1197 1197
 
@@ -1201,7 +1201,7 @@  discard block
 block discarded – undo
1201 1201
     * @return Array the spotter information
1202 1202
     *
1203 1203
     */
1204
-    public function getMarineDataByAirport($airport = '', $limit = '', $sort = '',$filters = array())
1204
+    public function getMarineDataByAirport($airport = '', $limit = '', $sort = '', $filters = array())
1205 1205
     {
1206 1206
 	global $global_query;
1207 1207
 	$Marine = new Marine($this->db);
@@ -1209,7 +1209,7 @@  discard block
 block discarded – undo
1209 1209
 	$query_values = array();
1210 1210
 	$limit_query = '';
1211 1211
 	$additional_query = '';
1212
-	$filter_query = $this->getFilter($filters,true,true);
1212
+	$filter_query = $this->getFilter($filters, true, true);
1213 1213
 	
1214 1214
 	if ($airport != "")
1215 1215
 	{
@@ -1226,8 +1226,8 @@  discard block
 block discarded – undo
1226 1226
 	{
1227 1227
 	    $limit_array = explode(",", $limit);
1228 1228
 	    
1229
-	    $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1230
-	    $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1229
+	    $limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
1230
+	    $limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
1231 1231
 	    
1232 1232
 	    if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1233 1233
 	    {
Please login to merge, or discard this patch.
require/class.METAR.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 			$Connection = new Connection();
69 69
 			$sth = $Connection->db->prepare($query);
70 70
 			$sth->execute();
71
-		} catch(PDOException $e) {
71
+		} catch (PDOException $e) {
72 72
 			return "error : ".$e->getMessage();
73 73
 		}
74 74
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 			$Connection = new Connection();
88 88
 			$sth = $Connection->db->prepare($query);
89 89
 			$sth->execute();
90
-		} catch(PDOException $e) {
90
+		} catch (PDOException $e) {
91 91
 			return "error : ".$e->getMessage();
92 92
 		}
93 93
 	}
@@ -100,9 +100,9 @@  discard block
 block discarded – undo
100 100
 	public function parse($data) {
101 101
 		//$data = str_replace(array('\n','\r','\r','\n'),'',$data);
102 102
 		$codes = implode('|', array_keys($this->texts));
103
-		$regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#';
103
+		$regWeather = '#^(\+|\-|VC)?('.$codes.')('.$codes.')?$#';
104 104
 		//$pieces = explode(' ',$data);
105
-		$pieces = preg_split('/\s/',$data);
105
+		$pieces = preg_split('/\s/', $data);
106 106
 		$pos = 0;
107 107
 		if ($pieces[0] == 'METAR') $pos++;
108 108
 		elseif ($pieces[0] == 'SPECI') $pos++;
@@ -112,25 +112,25 @@  discard block
 block discarded – undo
112 112
 		$result['location'] = $pieces[$pos];
113 113
 		$pos++;
114 114
 		if (!isset($pieces[$pos])) return $result;
115
-		$result['dayofmonth'] = substr($pieces[$pos],0,2);
116
-		$result['time'] = substr($pieces[$pos],2,4);
115
+		$result['dayofmonth'] = substr($pieces[$pos], 0, 2);
116
+		$result['time'] = substr($pieces[$pos], 2, 4);
117 117
 		$c = count($pieces);
118
-		for($pos++; $pos < $c; $pos++) {
118
+		for ($pos++; $pos < $c; $pos++) {
119 119
 			$piece = $pieces[$pos];
120 120
 			if ($piece == 'RMK') break;
121 121
 			if ($piece == 'AUTO') $result['auto'] = true;
122 122
 			if ($piece == 'COR') $result['correction'] = true;
123 123
 			// Wind Speed
124 124
 			if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) {
125
-				$result['wind']['direction'] = (float)$matches[1];
125
+				$result['wind']['direction'] = (float) $matches[1];
126 126
 				$result['wind']['unit'] = $matches[4];
127
-				if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2);
128
-				elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2);
129
-				elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2);
130
-				$result['wind']['gust'] = (float)$matches[3];
127
+				if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float) $matches[2])*0.51444444444, 2);
128
+				elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float) $matches[2])*1000, 2);
129
+				elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float) $matches[2]), 2);
130
+				$result['wind']['gust'] = (float) $matches[3];
131 131
 				$result['wind']['unit'] = $matches[4];
132
-				$result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0;
133
-				$result['wind']['max_variation'] = array_key_exists(6,$matches) ? $matches[6] : 0;
132
+				$result['wind']['min_variation'] = array_key_exists(5, $matches) ? $matches[5] : 0;
133
+				$result['wind']['max_variation'] = array_key_exists(6, $matches) ? $matches[6] : 0;
134 134
 			}
135 135
 
136 136
 /*    			if (preg_match('#^([0-9]{3})([0-9]{2})(G([0-9]{2}))?(KT|MPS)$#', $piece, $matches)) {
@@ -151,17 +151,17 @@  discard block
 block discarded – undo
151 151
 
152 152
 			// Temperature
153 153
 			if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) {
154
-				$temp = (float)$matches[1];
154
+				$temp = (float) $matches[1];
155 155
 				if ($matches[1]{0} == 'M') {
156
-					$temp = ((float)substr($matches[1], 1)) * -1;
156
+					$temp = ((float) substr($matches[1], 1))*-1;
157 157
 				}
158 158
 				$result['temperature'] = $temp;
159
-				$dew = (float)$matches[2];
159
+				$dew = (float) $matches[2];
160 160
 				if ($matches[2]{0} == 'M') {
161
-					$dew = ((float)substr($matches[2], 1)) * -1;
161
+					$dew = ((float) substr($matches[2], 1))*-1;
162 162
 				}
163 163
 				$result['dew'] = $dew;
164
-				$result['rh'] = round(100*(exp((17.625*$dew)/(243.04+$dew))/exp((17.625*$temp)/(243.04+$temp))));
164
+				$result['rh'] = round(100*(exp((17.625*$dew)/(243.04 + $dew))/exp((17.625*$temp)/(243.04 + $temp))));
165 165
 			}
166 166
 			// QNH
167 167
 			if (preg_match('#^(A|Q)([0-9]{4})$#', $piece, $matches)) {
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 					$result['QNH'] = $matches[2];
172 172
 				} else {
173 173
 					// inHg
174
-					$result['QNH'] = round(($matches[2] / 100)*33.86389,2);
174
+					$result['QNH'] = round(($matches[2]/100)*33.86389, 2);
175 175
 				}
176 176
 				/*
177 177
     				$result['QNH'] = $matches[1] == 'Q' ? $matches[2] : ($matches[2] / 100);
@@ -192,12 +192,12 @@  discard block
 block discarded – undo
192 192
     			// Visibility
193 193
 			if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) {
194 194
 				if (isset($matches[3]) && strlen($matches[3]) > 0) {
195
-					$result['visibility'] = (float)$matches[3] * 1609.34;
195
+					$result['visibility'] = (float) $matches[3]*1609.34;
196 196
 				} else {
197 197
 					if ($matches[1] == '9999') {
198 198
 						$result['visibility'] = '> 10000';
199 199
 					} else {
200
-						$result['visibility'] = (float)$matches[1];
200
+						$result['visibility'] = (float) $matches[1];
201 201
 					}
202 202
 				}
203 203
 			}
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 				elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage';
221 221
 				elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility';
222 222
 				$cloud['type_code'] = $type;
223
-				$cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048);
223
+				$cloud['level'] = round(((float) $matches[2])*100*0.3048);
224 224
 				if (isset($matches[3])) $significant = $matches[3];
225 225
 				else $significant = '';
226 226
 				if ($significant == 'CB') $cloud['significant'] = 'Cumulonimbus';
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
 				$rvr['runway'] = $matches[1];
242 242
 				$rvr['assessment'] = $matches[2];
243 243
 				$rvr['rvr'] = $matches[3];
244
-				$rvr['rvr_max'] = array_key_exists(4,$matches) ? $matches[4] : 0;
245
-				$rvr['unit'] = array_key_exists(5,$matches) ? $matches[5] : '';
244
+				$rvr['rvr_max'] = array_key_exists(4, $matches) ? $matches[4] : 0;
245
+				$rvr['unit'] = array_key_exists(5, $matches) ? $matches[5] : '';
246 246
 				$result['RVR'] = $rvr;
247 247
 			}
248 248
 			//if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
@@ -255,12 +255,12 @@  discard block
 block discarded – undo
255 255
 				$result['RVR']['friction'] = $matches[5];
256 256
 			}
257 257
 			if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
258
-				if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
259
-				else $range = array('exact' => (float)$matches[2], 'unit' => 'M');
258
+				if (isset($matches[5])) $range = array('exact' => (float) $matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
259
+				else $range = array('exact' => (float) $matches[2], 'unit' => 'M');
260 260
 				if (isset($matches[3])) {
261 261
 					$range = Array(
262
-					    'from' => (float)$matches[2],
263
-					    'to'   => (float)$matches[4],
262
+					    'from' => (float) $matches[2],
263
+					    'to'   => (float) $matches[4],
264 264
 					    'unit' => $matches[5] ? 'FT' : 'M'
265 265
 					);
266 266
 				}
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 		try {
314 314
 			$sth = $this->db->prepare($query);
315 315
 			$sth->execute($query_values);
316
-		} catch(PDOException $e) {
316
+		} catch (PDOException $e) {
317 317
 			return "error : ".$e->getMessage();
318 318
 		}
319 319
 		$all = $sth->fetchAll(PDO::FETCH_ASSOC);
@@ -329,19 +329,19 @@  discard block
 block discarded – undo
329 329
 	 * @param String $metar METAR text
330 330
 	 * @param String $date date of the METAR
331 331
 	*/
332
-	public function addMETAR($location,$metar,$date) {
332
+	public function addMETAR($location, $metar, $date) {
333 333
 		global $globalDBdriver;
334
-		$date = date('Y-m-d H:i:s',strtotime($date));
334
+		$date = date('Y-m-d H:i:s', strtotime($date));
335 335
 		if ($globalDBdriver == 'mysql') {
336 336
 			$query = "INSERT INTO metar (metar_location,metar_date,metar) VALUES (:location,:date,:metar) ON DUPLICATE KEY UPDATE metar_date = :date, metar = :metar";
337 337
 		} else {
338 338
 			$query = "UPDATE metar SET metar_date = :date, metar = :metar WHERE metar_location = :location;INSERT INTO metar (metar_location,metar_date,metar) SELECT :location,:date,:metar WHERE NOT EXISTS (SELECT 1 FROM metar WHERE metar_location = :location);";
339 339
 		}
340
-		$query_values = array(':location' => $location,':date' => $date,':metar' => utf8_encode($metar));
340
+		$query_values = array(':location' => $location, ':date' => $date, ':metar' => utf8_encode($metar));
341 341
 		try {
342 342
 			$sth = $this->db->prepare($query);
343 343
 			$sth->execute($query_values);
344
-		} catch(PDOException $e) {
344
+		} catch (PDOException $e) {
345 345
 			return "error : ".$e->getMessage();
346 346
 		}
347 347
 	}
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 		try {
357 357
 			$sth = $this->db->prepare($query);
358 358
 			$sth->execute($query_values);
359
-		} catch(PDOException $e) {
359
+		} catch (PDOException $e) {
360 360
 			return "error : ".$e->getMessage();
361 361
 		}
362 362
 	}
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 		try {
370 370
 			$sth = $this->db->prepare($query);
371 371
 			$sth->execute();
372
-		} catch(PDOException $e) {
372
+		} catch (PDOException $e) {
373 373
 			return "error : ".$e->getMessage();
374 374
 		}
375 375
 	}
@@ -383,29 +383,29 @@  discard block
 block discarded – undo
383 383
 		date_default_timezone_set("UTC");
384 384
 		$Common = new Common();
385 385
 		if (isset($globalIVAO) && $globalIVAO) {
386
-			$Common->download('http://wx.ivao.aero/metar.php',dirname(__FILE__).'/../install/tmp/ivaometar.txt');
387
-			$handle = fopen(dirname(__FILE__).'/../install/tmp/ivaometar.txt',"r");
386
+			$Common->download('http://wx.ivao.aero/metar.php', dirname(__FILE__).'/../install/tmp/ivaometar.txt');
387
+			$handle = fopen(dirname(__FILE__).'/../install/tmp/ivaometar.txt', "r");
388 388
 		} else {
389
-			$Common->download('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT',dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT');
390
-			$handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT',"r");
389
+			$Common->download('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT', dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT');
390
+			$handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT', "r");
391 391
 		}
392 392
 		if ($handle) {
393 393
 			if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB...";
394 394
 			$date = '';
395 395
 			if ($globalTransaction) $this->db->beginTransaction();
396
-			while(($line = fgets($handle,4096)) !== false) {
397
-				$line = str_replace(array("\r\n","\r", "\n"), '', $line);
398
-				if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) {
396
+			while (($line = fgets($handle, 4096)) !== false) {
397
+				$line = str_replace(array("\r\n", "\r", "\n"), '', $line);
398
+				if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) {
399 399
 					$date = $line;
400 400
 				} elseif (trim($line) != '') {
401 401
 					if ($date == '') $date = date('Y/m/d H:m');
402 402
 					$pos = 0;
403
-					$pieces = preg_split('/\s/',$line);
403
+					$pieces = preg_split('/\s/', $line);
404 404
 					if ($pieces[0] == 'METAR') $pos++;
405 405
 					if (strlen($pieces[$pos]) != 4) $pos++;
406 406
 					$location = $pieces[$pos];
407 407
 					//if ($location == 'LFLL') echo 'location: '.$location.' - date: '.$date.' - data: '.$line."\n";
408
-					echo $this->addMETAR($location,$line,$date);
408
+					echo $this->addMETAR($location, $line, $date);
409 409
 				}
410 410
 			}
411 411
 			fclose($handle);
@@ -424,23 +424,23 @@  discard block
 block discarded – undo
424 424
 		if ($globalMETARurl == '') return array();
425 425
 		date_default_timezone_set("UTC");
426 426
 		$Common = new Common();
427
-		$url = str_replace('{icao}',$icao,$globalMETARurl);
427
+		$url = str_replace('{icao}', $icao, $globalMETARurl);
428 428
 		$cycle = $Common->getData($url);
429 429
 		$date = '';
430
-		foreach(explode("\n",$cycle) as $line) {
431
-			$line = str_replace(array("\r\n","\r", "\n"), '', $line);
432
-			if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) {
430
+		foreach (explode("\n", $cycle) as $line) {
431
+			$line = str_replace(array("\r\n", "\r", "\n"), '', $line);
432
+			if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) {
433 433
 				$date = $line;
434 434
 			} 
435 435
 			if (trim($line) != '') {
436 436
 				if ($date == '') $date = date('Y/m/d H:m');
437 437
 				$pos = 0;
438
-				$pieces = preg_split('/\s/',$line);
438
+				$pieces = preg_split('/\s/', $line);
439 439
 				if ($pieces[0] == 'METAR') $pos++;
440 440
 				if (strlen($pieces[$pos]) != 4) $pos++;
441 441
 				$location = $pieces[$pos];
442 442
 				if (strlen($location == 4)) {
443
-					$this->addMETAR($location,$line,$date);
443
+					$this->addMETAR($location, $line, $date);
444 444
 					return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line));
445 445
 				} else return array();
446 446
 			}
Please login to merge, or discard this patch.
require/class.Common.php 1 patch
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -14,12 +14,12 @@  discard block
 block discarded – undo
14 14
 	* @param Array $headers header to submit with the form
15 15
 	* @return String the result
16 16
 	*/
17
-	public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '', $sizelimit = false, $async = false) {
17
+	public function getData($url, $type = 'get', $data = '', $headers = '', $cookie = '', $referer = '', $timeout = '', $useragent = '', $sizelimit = false, $async = false) {
18 18
 		global $globalProxy, $globalForceIPv4;
19 19
 		$ch = curl_init();
20 20
 		curl_setopt($ch, CURLOPT_URL, $url);
21 21
 		if (isset($globalForceIPv4) && $globalForceIPv4) {
22
-			if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
22
+			if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) {
23 23
 				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
24 24
 			}
25 25
 		}
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
30 30
 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
31 31
 		curl_setopt($ch, CURLINFO_HEADER_OUT, true); 
32
-		curl_setopt($ch,CURLOPT_ENCODING , "gzip");
32
+		curl_setopt($ch, CURLOPT_ENCODING, "gzip");
33 33
 		//curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
34 34
 //		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0');
35 35
 		if ($useragent == '') {
@@ -39,13 +39,13 @@  discard block
 block discarded – undo
39 39
 		}
40 40
 		if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
41 41
 		else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 
42
-		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback"));
42
+		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common', "curlResponseHeaderCallback"));
43 43
 		if ($type == 'post') {
44 44
 			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
45 45
 			if (is_array($data)) {
46 46
 				curl_setopt($ch, CURLOPT_POST, count($data));
47 47
 				$data_string = '';
48
-				foreach($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; }
48
+				foreach ($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; }
49 49
 				rtrim($data_string, '&');
50 50
 				curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
51 51
 			} else {
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		}
58 58
 		if ($cookie != '') {
59 59
 			if (is_array($cookie)) {
60
-				curl_setopt($ch, CURLOPT_COOKIE, implode($cookie,';'));
60
+				curl_setopt($ch, CURLOPT_COOKIE, implode($cookie, ';'));
61 61
 			} else {
62 62
 				curl_setopt($ch, CURLOPT_COOKIE, $cookie);
63 63
 			}
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		if ($sizelimit === true) {
69 69
 			curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);
70 70
 			curl_setopt($ch, CURLOPT_NOPROGRESS, false);
71
-			curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($curlr,$downloadsize, $downloaded, $uploadsize, $uploaded){
71
+			curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($curlr, $downloadsize, $downloaded, $uploadsize, $uploaded) {
72 72
 				return ($downloaded > (3*1024)) ? 1 : 0;
73 73
 			});
74 74
 		}
@@ -79,13 +79,13 @@  discard block
 block discarded – undo
79 79
 		$result = curl_exec($ch);
80 80
 		$info = curl_getinfo($ch);
81 81
 		curl_close($ch);
82
-		if ($info['http_code'] == '503' && strstr($result,'DDoS protection by CloudFlare')) {
82
+		if ($info['http_code'] == '503' && strstr($result, 'DDoS protection by CloudFlare')) {
83 83
 			echo "Cloudflare Detected\n";
84 84
 			require_once(dirname(__FILE__).'/libs/cloudflare-bypass/libraries/cloudflareClass.php');
85 85
 			$useragent = UAgent::random();
86 86
 			cloudflare::useUserAgent($useragent);
87 87
 			if ($clearanceCookie = cloudflare::bypass($url)) {
88
-				return $this->getData($url,'get',$data,$headers,$clearanceCookie,$referer,$timeout,$useragent);
88
+				return $this->getData($url, 'get', $data, $headers, $clearanceCookie, $referer, $timeout, $useragent);
89 89
 			}
90 90
 		} else {
91 91
 			return $result;
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
110 110
 		if ($referer != '') curl_setopt($ch, CURLOPT_REFERER, $referer);
111 111
 		if (isset($globalForceIPv4) && $globalForceIPv4) {
112
-			if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
112
+			if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) {
113 113
 				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
114 114
 			}
115 115
 		}
@@ -124,20 +124,20 @@  discard block
 block discarded – undo
124 124
 		fclose($fp);
125 125
 	}
126 126
 
127
-	public static function gunzip($in_file,$out_file_name = '') {
127
+	public static function gunzip($in_file, $out_file_name = '') {
128 128
 		//echo $in_file.' -> '.$out_file_name."\n";
129 129
 		$buffer_size = 4096; // read 4kb at a time
130 130
 		if ($out_file_name == '') $out_file_name = str_replace('.gz', '', $in_file); 
131 131
 		if ($in_file != '' && file_exists($in_file)) {
132 132
 			// PHP version of Ubuntu use gzopen64 instead of gzopen
133
-			if (function_exists('gzopen')) $file = gzopen($in_file,'rb');
134
-			elseif (function_exists('gzopen64')) $file = gzopen64($in_file,'rb');
133
+			if (function_exists('gzopen')) $file = gzopen($in_file, 'rb');
134
+			elseif (function_exists('gzopen64')) $file = gzopen64($in_file, 'rb');
135 135
 			else {
136 136
 				echo 'gzopen not available';
137 137
 				die;
138 138
 			}
139 139
 			$out_file = fopen($out_file_name, 'wb'); 
140
-			while(!gzeof($file)) {
140
+			while (!gzeof($file)) {
141 141
 				fwrite($out_file, gzread($file, $buffer_size));
142 142
 			}  
143 143
 			fclose($out_file);
@@ -145,19 +145,19 @@  discard block
 block discarded – undo
145 145
 		}
146 146
 	}
147 147
 
148
-	public static function bunzip2($in_file,$out_file_name = '') {
148
+	public static function bunzip2($in_file, $out_file_name = '') {
149 149
 		//echo $in_file.' -> '.$out_file_name."\n";
150 150
 		$buffer_size = 4096; // read 4kb at a time
151 151
 		if ($out_file_name == '') $out_file_name = str_replace('.bz2', '', $in_file); 
152 152
 		if ($in_file != '' && file_exists($in_file)) {
153 153
 			// PHP version of Ubuntu use gzopen64 instead of gzopen
154
-			if (function_exists('bzopen')) $file = bzopen($in_file,'rb');
154
+			if (function_exists('bzopen')) $file = bzopen($in_file, 'rb');
155 155
 			else {
156 156
 				echo 'bzopen not available';
157 157
 				die;
158 158
 			}
159 159
 			$out_file = fopen($out_file_name, 'wb'); 
160
-			while(!feof($file)) {
160
+			while (!feof($file)) {
161 161
 				fwrite($out_file, bzread($file, $buffer_size));
162 162
 			}  
163 163
 			fclose($out_file);
@@ -175,27 +175,27 @@  discard block
 block discarded – undo
175 175
 		if ($data == '') return array();
176 176
 		$html = str_get_html($data);
177 177
 		if ($html === false) return array();
178
-		$tabledata=array();
179
-		foreach($html->find('tr') as $element)
178
+		$tabledata = array();
179
+		foreach ($html->find('tr') as $element)
180 180
 		{
181 181
 			$td = array();
182
-			foreach( $element->find('th') as $row)
182
+			foreach ($element->find('th') as $row)
183 183
 			{
184 184
 				$td [] = trim($row->plaintext);
185 185
 			}
186
-			$td=array_filter($td);
186
+			$td = array_filter($td);
187 187
 			$tabledata[] = $td;
188 188
 
189 189
 			$td = array();
190 190
 			$tdi = array();
191
-			foreach( $element->find('td') as $row)
191
+			foreach ($element->find('td') as $row)
192 192
 			{
193 193
 				$td [] = trim($row->plaintext);
194 194
 				$tdi [] = trim($row->innertext);
195 195
 			}
196
-			$td=array_filter($td);
197
-			$tdi=array_filter($tdi);
198
-			$tabledata[]=array_merge($td,$tdi);
196
+			$td = array_filter($td);
197
+			$tdi = array_filter($tdi);
198
+			$tabledata[] = array_merge($td, $tdi);
199 199
 		}
200 200
 		$html->clear();
201 201
 		unset($html);
@@ -210,8 +210,8 @@  discard block
 block discarded – undo
210 210
 	public function text2array($data) {
211 211
 		$html = str_get_html($data);
212 212
 		if ($html === false) return array();
213
-		$tabledata=array();
214
-		foreach($html->find('p') as $element)
213
+		$tabledata = array();
214
+		foreach ($html->find('p') as $element)
215 215
 		{
216 216
 			$tabledata [] = trim($element->plaintext);
217 217
 		}
@@ -231,11 +231,11 @@  discard block
 block discarded – undo
231 231
 	*/
232 232
 	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
233 233
 		if ($lat == $latc && $lon == $lonc) return 0;
234
-		$dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515;
234
+		$dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc))) + cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon) - floatval($lonc)))))*60*1.1515;
235 235
 		if ($unit == "km") {
236
-			return round($dist * 1.609344);
236
+			return round($dist*1.609344);
237 237
 		} elseif ($unit == "m") {
238
-			return round($dist * 1.609344 * 1000);
238
+			return round($dist*1.609344*1000);
239 239
 		} elseif ($unit == "mile" || $unit == "mi") {
240 240
 			return round($dist);
241 241
 		} elseif ($unit == "nm") {
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 	* @param String $distance distance between two points in m
253 253
 	* @return Float plunge
254 254
 	*/
255
-	public function plunge($initial_altitude,$final_altitude,$distance) {
256
-		$plunge = rad2deg(asin(($final_altitude-$initial_altitude)/$distance));
255
+	public function plunge($initial_altitude, $final_altitude, $distance) {
256
+		$plunge = rad2deg(asin(($final_altitude - $initial_altitude)/$distance));
257 257
 		/*
258 258
 		$siter = 6378137.0 + $initial_altitude;
259 259
 		$planer = 6378137.0 + $final_altitude;
@@ -275,8 +275,8 @@  discard block
 block discarded – undo
275 275
 	public function azimuth($lat, $lon, $latc, $lonc) {
276 276
 		$dX = $latc - $lat;
277 277
 		$dY = $lonc - $lon;
278
-		$azimuth = rad2deg(atan2($dY,$dX));
279
-		if ($azimuth < 0) return $azimuth+360;
278
+		$azimuth = rad2deg(atan2($dY, $dX));
279
+		if ($azimuth < 0) return $azimuth + 360;
280 280
 		return $azimuth;
281 281
 	}
282 282
 	
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 	* @param float $distance distance covered
288 288
 	* @return whether distance is realistic
289 289
 	*/
290
-	public function withinThreshold ($timeDifference, $distance) {
290
+	public function withinThreshold($timeDifference, $distance) {
291 291
 		$x = abs($timeDifference);
292 292
 		$d = abs($distance);
293 293
 		if ($x == 0 || $d == 0) return true;
@@ -303,13 +303,13 @@  discard block
 block discarded – undo
303 303
 		return ($array !== array_values($array));
304 304
 	}
305 305
 
306
-	public function isInteger($input){
306
+	public function isInteger($input) {
307 307
 		//return(ctype_digit(strval($input)));
308
-		return preg_match('/^-?[0-9]+$/', (string)$input) ? true : false;
308
+		return preg_match('/^-?[0-9]+$/', (string) $input) ? true : false;
309 309
 	}
310 310
 
311 311
 
312
-	public function convertDec($dms,$latlong) {
312
+	public function convertDec($dms, $latlong) {
313 313
 		if ($latlong == 'latitude') {
314 314
 			$deg = substr($dms, 0, 2);
315 315
 			$min = substr($dms, 2, 4);
@@ -317,33 +317,33 @@  discard block
 block discarded – undo
317 317
 			$deg = substr($dms, 0, 3);
318 318
 			$min = substr($dms, 3, 5);
319 319
 		}
320
-		return $deg+(($min*60)/3600);
320
+		return $deg + (($min*60)/3600);
321 321
 	}
322 322
 	
323 323
 	public function convertDecLatLong($coord) {
324 324
 		//N43°36.763' W5°46.845'
325
-		$coords = explode(' ',$coord);
325
+		$coords = explode(' ', $coord);
326 326
 		$latitude = '';
327 327
 		$longitude = '';
328 328
 		foreach ($coords as $latlong) {
329
-			$type = substr($latlong,0,1);
330
-			$degmin = explode('°',substr($latlong,1,-1));
329
+			$type = substr($latlong, 0, 1);
330
+			$degmin = explode('°', substr($latlong, 1, -1));
331 331
 			$deg = $degmin[0];
332 332
 			$min = $degmin[1];
333 333
 			if ($type == 'N') {
334
-				$latitude = $deg+(($min*60)/3600);
334
+				$latitude = $deg + (($min*60)/3600);
335 335
 			} elseif ($type == 'S') {
336
-				$latitude = -($deg+(($min*60)/3600));
336
+				$latitude = -($deg + (($min*60)/3600));
337 337
 			} elseif ($type == 'E') {
338
-				$longitude = ($deg+(($min*60)/3600));
338
+				$longitude = ($deg + (($min*60)/3600));
339 339
 			} elseif ($type == 'W') {
340
-				$longitude = -($deg+(($min*60)/3600));
340
+				$longitude = -($deg + (($min*60)/3600));
341 341
 			}
342 342
 		}
343
-		return array('latitude' => round($latitude,5),'longitude' => round($longitude,5));
343
+		return array('latitude' => round($latitude, 5), 'longitude' => round($longitude, 5));
344 344
 	}
345 345
 	
346
-	public function convertDM($coord,$latlong) {
346
+	public function convertDM($coord, $latlong) {
347 347
 		if ($latlong == 'latitude') {
348 348
 			if ($coord < 0) $NSEW = 'S';
349 349
 			else $NSEW = 'N';
@@ -353,9 +353,9 @@  discard block
 block discarded – undo
353 353
 		}
354 354
 		$coord = abs($coord);
355 355
 		$deg = floor($coord);
356
-		$coord = ($coord-$deg)*60;
356
+		$coord = ($coord - $deg)*60;
357 357
 		$min = $coord;
358
-		return array('deg' => $deg,'min' => $min,'NSEW' => $NSEW);
358
+		return array('deg' => $deg, 'min' => $min, 'NSEW' => $NSEW);
359 359
 	}
360 360
 	
361 361
 	/**
@@ -367,8 +367,8 @@  discard block
 block discarded – undo
367 367
 	public function xcopy($source, $dest)
368 368
 	{
369 369
 		$files = glob($source.'*.*');
370
-		foreach($files as $file){
371
-			$file_to_go = str_replace($source,$dest,$file);
370
+		foreach ($files as $file) {
371
+			$file_to_go = str_replace($source, $dest, $file);
372 372
 			copy($file, $file_to_go);
373 373
 		}
374 374
 		return true;
@@ -379,9 +379,9 @@  discard block
 block discarded – undo
379 379
 	* @param	String $url url to check
380 380
 	* @return	bool Return true on succes false on failure
381 381
 	*/
382
-	public function urlexist($url){
383
-		$headers=get_headers($url);
384
-		return stripos($headers[0],"200 OK")?true:false;
382
+	public function urlexist($url) {
383
+		$headers = get_headers($url);
384
+		return stripos($headers[0], "200 OK") ?true:false;
385 385
 	}
386 386
 	
387 387
 	/**
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 	public function hex2str($hex) {
393 393
 		$str = '';
394 394
 		$hexln = strlen($hex);
395
-		for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
395
+		for ($i = 0; $i < $hexln; $i += 2) $str .= chr(hexdec(substr($hex, $i, 2)));
396 396
 		return $str;
397 397
 	}
398 398
 	
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 	* @return	String Return result
403 403
 	*/
404 404
 	public function hex2rgb($hex) {
405
-		$hex = str_replace('#','',$hex);
405
+		$hex = str_replace('#', '', $hex);
406 406
 		return sscanf($hex, "%02x%02x%02x"); 
407 407
 	}
408 408
 	
@@ -410,33 +410,33 @@  discard block
 block discarded – undo
410 410
 		//difference in longitudinal coordinates
411 411
 		$dLon = deg2rad($lon2) - deg2rad($lon1);
412 412
 		//difference in the phi of latitudinal coordinates
413
-		$dPhi = log(tan(deg2rad($lat2) / 2 + M_PI / 4) / tan(deg2rad($lat1) / 2 + M_PI / 4));
413
+		$dPhi = log(tan(deg2rad($lat2)/2 + M_PI/4)/tan(deg2rad($lat1)/2 + M_PI/4));
414 414
 		//we need to recalculate $dLon if it is greater than pi
415
-		if(abs($dLon) > M_PI) {
416
-			if($dLon > 0) {
417
-				$dLon = (2 * M_PI - $dLon) * -1;
415
+		if (abs($dLon) > M_PI) {
416
+			if ($dLon > 0) {
417
+				$dLon = (2*M_PI - $dLon)*-1;
418 418
 			} else {
419
-				$dLon = 2 * M_PI + $dLon;
419
+				$dLon = 2*M_PI + $dLon;
420 420
 			}
421 421
 		}
422 422
 		//return the angle, normalized
423
-		return (rad2deg(atan2($dLon, $dPhi)) + 360) % 360;
423
+		return (rad2deg(atan2($dLon, $dPhi)) + 360)%360;
424 424
 	}
425 425
 
426
-	public function checkLine($lat1,$lon1,$lat2,$lon2,$lat3,$lon3,$approx = 0.15) {
426
+	public function checkLine($lat1, $lon1, $lat2, $lon2, $lat3, $lon3, $approx = 0.15) {
427 427
 		//$a = ($lon2-$lon1)*$lat3+($lat2-$lat1)*$lon3+($lat1*$lon2+$lat2*$lon1);
428
-		$a = -($lon2-$lon1);
428
+		$a = -($lon2 - $lon1);
429 429
 		$b = $lat2 - $lat1;
430
-		$c = -($a*$lat1+$b*$lon1);
431
-		$d = $a*$lat3+$b*$lon3+$c;
430
+		$c = -($a*$lat1 + $b*$lon1);
431
+		$d = $a*$lat3 + $b*$lon3 + $c;
432 432
 		if ($d > -$approx && $d < $approx) return true;
433 433
 		else return false;
434 434
 	}
435 435
 	
436 436
 	public function array_merge_noappend() {
437 437
 		$output = array();
438
-		foreach(func_get_args() as $array) {
439
-			foreach($array as $key => $value) {
438
+		foreach (func_get_args() as $array) {
439
+			foreach ($array as $key => $value) {
440 440
 				$output[$key] = isset($output[$key]) ?
441 441
 				array_merge($output[$key], $value) : $value;
442 442
 			}
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 		return $result;
501 501
 	}
502 502
 
503
-	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1, $seconds = ''){
503
+	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1, $seconds = '') {
504 504
 		global $globalMapRefresh;
505 505
 		if ($seconds == '') {
506 506
 			$distance = ($speed*0.514444*$globalMapRefresh*$archivespeed)/1000;
@@ -511,27 +511,27 @@  discard block
 block discarded – undo
511 511
 		$latitude = deg2rad($latitude);
512 512
 		$longitude = deg2rad($longitude);
513 513
 		$bearing = deg2rad($heading); 
514
-		$latitude2 =  asin( (sin($latitude) * cos($distance/$r)) + (cos($latitude) * sin($distance/$r) * cos($bearing)) );
515
-		$longitude2 = $longitude + atan2( sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r)-(sin($latitude)*sin($latitude2)) );
516
-		return array('latitude' => number_format(rad2deg($latitude2),5,'.',''),'longitude' => number_format(rad2deg($longitude2),5,'.',''));
514
+		$latitude2 = asin((sin($latitude)*cos($distance/$r)) + (cos($latitude)*sin($distance/$r)*cos($bearing)));
515
+		$longitude2 = $longitude + atan2(sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r) - (sin($latitude)*sin($latitude2)));
516
+		return array('latitude' => number_format(rad2deg($latitude2), 5, '.', ''), 'longitude' => number_format(rad2deg($longitude2), 5, '.', ''));
517 517
 	}
518 518
 	
519
-	public function getCoordfromDistanceBearing($latitude,$longitude,$bearing,$distance) {
519
+	public function getCoordfromDistanceBearing($latitude, $longitude, $bearing, $distance) {
520 520
 		// distance in meter
521 521
 		$R = 6378.14;
522
-		$latitude1 = $latitude * (M_PI/180);
523
-		$longitude1 = $longitude * (M_PI/180);
524
-		$brng = $bearing * (M_PI/180);
522
+		$latitude1 = $latitude*(M_PI/180);
523
+		$longitude1 = $longitude*(M_PI/180);
524
+		$brng = $bearing*(M_PI/180);
525 525
 		$d = $distance;
526 526
 
527 527
 		$latitude2 = asin(sin($latitude1)*cos($d/$R) + cos($latitude1)*sin($d/$R)*cos($brng));
528
-		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1),cos($d/$R)-sin($latitude1)*sin($latitude2));
528
+		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1), cos($d/$R) - sin($latitude1)*sin($latitude2));
529 529
 
530
-		$latitude2 = $latitude2 * (180/M_PI);
531
-		$longitude2 = $longitude2 * (180/M_PI);
530
+		$latitude2 = $latitude2*(180/M_PI);
531
+		$longitude2 = $longitude2*(180/M_PI);
532 532
 
533
-		$flat = round ($latitude2,6);
534
-		$flong = round ($longitude2,6);
533
+		$flat = round($latitude2, 6);
534
+		$flong = round($longitude2, 6);
535 535
 /*
536 536
 		$dx = $distance*cos($bearing);
537 537
 		$dy = $distance*sin($bearing);
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
 		$flong = $longitude + $dlong;
541 541
 		$flat = $latitude + $dlat;
542 542
 */
543
-		return array('latitude' => $flat,'longitude' => $flong);
543
+		return array('latitude' => $flat, 'longitude' => $flong);
544 544
 	}
545 545
 
546 546
 	/**
@@ -554,14 +554,14 @@  discard block
 block discarded – undo
554 554
 	 * @param integer $level GZIP compression level (default: 9)
555 555
 	 * @return string New filename (with .gz appended) if success, or false if operation fails
556 556
 	 */
557
-	public function gzCompressFile($source, $level = 9){ 
558
-		$dest = $source . '.gz'; 
559
-		$mode = 'wb' . $level; 
557
+	public function gzCompressFile($source, $level = 9) { 
558
+		$dest = $source.'.gz'; 
559
+		$mode = 'wb'.$level; 
560 560
 		$error = false; 
561 561
 		if ($fp_out = gzopen($dest, $mode)) { 
562
-			if ($fp_in = fopen($source,'rb')) { 
562
+			if ($fp_in = fopen($source, 'rb')) { 
563 563
 				while (!feof($fp_in)) 
564
-					gzwrite($fp_out, fread($fp_in, 1024 * 512)); 
564
+					gzwrite($fp_out, fread($fp_in, 1024*512)); 
565 565
 				fclose($fp_in); 
566 566
 			} else {
567 567
 				$error = true; 
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 	} 
578 578
 	
579 579
 	public function remove_accents($string) {
580
-		if ( !preg_match('/[\x80-\xff]/', $string) ) return $string;
580
+		if (!preg_match('/[\x80-\xff]/', $string)) return $string;
581 581
 		$chars = array(
582 582
 		    // Decompositions for Latin-1 Supplement
583 583
 		    chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
 		    chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
635 635
 		    chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
636 636
 		    chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
637
-		    chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
637
+		    chr(196).chr(178) => 'IJ', chr(196).chr(179) => 'ij',
638 638
 		    chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
639 639
 		    chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
640 640
 		    chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
@@ -650,13 +650,13 @@  discard block
 block discarded – undo
650 650
 		    chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
651 651
 		    chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
652 652
 		    chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
653
-		    chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
654
-		    chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
655
-		    chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
656
-		    chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
657
-		    chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
658
-		    chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
659
-		    chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
653
+		    chr(197).chr(146) => 'OE', chr(197).chr(147) => 'oe',
654
+		    chr(197).chr(148) => 'R', chr(197).chr(149) => 'r',
655
+		    chr(197).chr(150) => 'R', chr(197).chr(151) => 'r',
656
+		    chr(197).chr(152) => 'R', chr(197).chr(153) => 'r',
657
+		    chr(197).chr(154) => 'S', chr(197).chr(155) => 's',
658
+		    chr(197).chr(156) => 'S', chr(197).chr(157) => 's',
659
+		    chr(197).chr(158) => 'S', chr(197).chr(159) => 's',
660 660
 		    chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
661 661
 		    chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
662 662
 		    chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
 		for ($i = 0, $int = '', $concat_flag = true; $i < $length; $i++) {
691 691
 			if (is_numeric($string[$i]) && $concat_flag) {
692 692
 				$int .= $string[$i];
693
-			} elseif(!$concat && $concat_flag && strlen($int) > 0) {
693
+			} elseif (!$concat && $concat_flag && strlen($int) > 0) {
694 694
 				$concat_flag = false;
695 695
 			}
696 696
 		}
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
 			$slice = array_slice($arr, $offset + 1, $length);
737 737
 			return implode("", $slice);
738 738
 		} else {
739
-			return mb_substr($string,$offset,$length,'UTF-8');
739
+			return mb_substr($string, $offset, $length, 'UTF-8');
740 740
 		}
741 741
 	}
742 742
 
@@ -746,14 +746,14 @@  discard block
 block discarded – undo
746 746
 		//NOTE: use a trailing slash for folders!!!
747 747
 		//see http://bugs.php.net/bug.php?id=27609
748 748
 		//see http://bugs.php.net/bug.php?id=30931
749
-		if ($path{strlen($path)-1}=='/') // recursively return a temporary file path
749
+		if ($path{strlen($path) - 1} == '/') // recursively return a temporary file path
750 750
 			return $this->is__writable($path.uniqid(mt_rand()).'.tmp');
751 751
 		else if (is_dir($path))
752 752
 			return $this->is__writable($path.'/'.uniqid(mt_rand()).'.tmp');
753 753
 		// check tmp file for read/write capabilities
754 754
 		$rm = file_exists($path);
755 755
 		$f = @fopen($path, 'a');
756
-		if ($f===false)
756
+		if ($f === false)
757 757
 			return false;
758 758
 		fclose($f);
759 759
 		if (!$rm)
@@ -772,29 +772,29 @@  discard block
 block discarded – undo
772 772
 	 * @param Integer $offset Controls the likelyhood that lines will be split which cross the dateline
773 773
 	 * @return Array Coordinate of the route
774 774
 	*/
775
-	public function greatcircle($begin_lat,$begin_lon,$end_lat,$end_lon,$nbpts = 20, $offset = 10) {
776
-		if ($nbpts <= 2) return array(array($begin_lon,$begin_lat),array($end_lon,$end_lat));
775
+	public function greatcircle($begin_lat, $begin_lon, $end_lat, $end_lon, $nbpts = 20, $offset = 10) {
776
+		if ($nbpts <= 2) return array(array($begin_lon, $begin_lat), array($end_lon, $end_lat));
777 777
 		$sx = deg2rad($begin_lon);
778 778
 		$sy = deg2rad($begin_lat);
779 779
 		$ex = deg2rad($end_lon);
780 780
 		$ey = deg2rad($end_lat);
781 781
 		$w = $sx - $ex;
782 782
 		$h = $sy - $ey;
783
-		$z = pow(sin($h/2.0),2) + cos($sy)*cos($ey)*pow(sin($w/2.0),2);
783
+		$z = pow(sin($h/2.0), 2) + cos($sy)*cos($ey)*pow(sin($w/2.0), 2);
784 784
 		$g = 2.0*asin(sqrt($z));
785
-		if ($g == M_PI || is_nan($g)) return array(array($begin_lon,$begin_lat),array($end_lon,$end_lat));
785
+		if ($g == M_PI || is_nan($g)) return array(array($begin_lon, $begin_lat), array($end_lon, $end_lat));
786 786
 		$first_pass = array();
787
-		$delta = 1.0/($nbpts-1);
788
-		for ($i =0; $i < $nbpts; ++$i) {
787
+		$delta = 1.0/($nbpts - 1);
788
+		for ($i = 0; $i < $nbpts; ++$i) {
789 789
 			$step = $delta*$i;
790
-			$A = sin((1 - $step) * $g) / sin($g);
791
-			$B = sin($step * $g) / sin($g);
792
-			$x = $A * cos($sy) * cos($sx) + $B * cos($ey) * cos($ex);
793
-			$y = $A * cos($sy) * sin($sx) + $B * cos($ey) * sin($ex);
794
-			$z = $A * sin($sy) + $B * sin($ey);
790
+			$A = sin((1 - $step)*$g)/sin($g);
791
+			$B = sin($step*$g)/sin($g);
792
+			$x = $A*cos($sy)*cos($sx) + $B*cos($ey)*cos($ex);
793
+			$y = $A*cos($sy)*sin($sx) + $B*cos($ey)*sin($ex);
794
+			$z = $A*sin($sy) + $B*sin($ey);
795 795
 			$lat = rad2deg(atan2($z, sqrt(pow($x, 2) + pow($y, 2))));
796 796
 			$lon = rad2deg(atan2($y, $x));
797
-			$first_pass[] = array($lon,$lat);
797
+			$first_pass[] = array($lon, $lat);
798 798
 		}
799 799
 		$bHasBigDiff = false;
800 800
 		$dfMaxSmallDiffLong = 0;
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
 		// https://github.com/OSGeo/gdal/blob/7bfb9c452a59aac958bff0c8386b891edf8154ca/gdal/ogr/ogrgeometryfactory.cpp#L2342
810 810
 		$first_pass_ln = count($first_pass);
811 811
 		for ($j = 1; $j < $first_pass_ln; ++$j) {
812
-			$dfPrevX = $first_pass[$j-1][0];
812
+			$dfPrevX = $first_pass[$j - 1][0];
813 813
 			$dfX = $first_pass[$j][0];
814 814
 			$dfDiffLong = abs($dfX - $dfPrevX);
815 815
 			if ($dfDiffLong > $dfDiffSpace &&
@@ -827,14 +827,14 @@  discard block
 block discarded – undo
827 827
 			//$poMulti[] = $poNewLS;
828 828
 			for ($k = 0; $k < $first_pass_ln; ++$k) {
829 829
 				$dfX0 = floatval($first_pass[$k][0]);
830
-				if ($k > 0 &&  abs($dfX0 - $first_pass[$k-1][0]) > $dfDiffSpace) {
831
-					$dfX1 = floatval($first_pass[$k-1][0]);
832
-					$dfY1 = floatval($first_pass[$k-1][1]);
830
+				if ($k > 0 && abs($dfX0 - $first_pass[$k - 1][0]) > $dfDiffSpace) {
831
+					$dfX1 = floatval($first_pass[$k - 1][0]);
832
+					$dfY1 = floatval($first_pass[$k - 1][1]);
833 833
 					$dfX2 = floatval($first_pass[$k][0]);
834 834
 					$dfY2 = floatval($first_pass[$k][1]);
835 835
 					if ($dfX1 > -180 && $dfX1 < $dfRightBorderX && $dfX2 == 180 &&
836
-					    $k+1 < count($first_pass) &&
837
-					    $first_pass[$k-1][0] > -180 && $first_pass[$k-1][0] < $dfRightBorderX)
836
+					    $k + 1 < count($first_pass) &&
837
+					    $first_pass[$k - 1][0] > -180 && $first_pass[$k - 1][0] < $dfRightBorderX)
838 838
 					{
839 839
 						$poNewLS[] = array(-180, $first_pass[$k][1]);
840 840
 						$k++;
@@ -842,8 +842,8 @@  discard block
 block discarded – undo
842 842
 						$poNewLS[] = array($first_pass[$k][0], $first_pass[$k][1]);
843 843
 						continue;
844 844
 					} else if ($dfX1 > $dfLeftBorderX && $dfX1 < 180 && $dfX2 == -180 &&
845
-					    $k+1 < $first_pass_ln &&
846
-					    $first_pass[$k-1][0] > $dfLeftBorderX && $first_pass[$k-1][0] < 180)
845
+					    $k + 1 < $first_pass_ln &&
846
+					    $first_pass[$k - 1][0] > $dfLeftBorderX && $first_pass[$k - 1][0] < 180)
847 847
 					{
848 848
 						$poNewLS[] = array(180, $first_pass[$k][1]);
849 849
 						$k++;
@@ -866,12 +866,12 @@  discard block
 block discarded – undo
866 866
 					}
867 867
 					if ($dfX1 <= 180 && $dfX2 >= 180 && $dfX1 < $dfX2)
868 868
 					{
869
-						$dfRatio = (180 - $dfX1) / ($dfX2 - $dfX1);
870
-						$dfY = $dfRatio * $dfY2 + (1 - $dfRatio) * $dfY1;
871
-						$poNewLS[] = array($first_pass[$k-1][0] > $dfLeftBorderX ? 180 : -180, $dfY);
869
+						$dfRatio = (180 - $dfX1)/($dfX2 - $dfX1);
870
+						$dfY = $dfRatio*$dfY2 + (1 - $dfRatio)*$dfY1;
871
+						$poNewLS[] = array($first_pass[$k - 1][0] > $dfLeftBorderX ? 180 : -180, $dfY);
872 872
 						$poMulti[] = $poNewLS;
873 873
 						$poNewLS = array();
874
-						$poNewLS[] = array($first_pass[$k-1][0] > $dfLeftBorderX ? -180 : 180, $dfY);
874
+						$poNewLS[] = array($first_pass[$k - 1][0] > $dfLeftBorderX ? -180 : 180, $dfY);
875 875
 						//$poMulti[] = $poNewLS;
876 876
 					} else {
877 877
 						//$poNewLS[] = array();
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
 			$poNewLS0 = array();
890 890
 			//$poMulti[] = $poNewLS0;
891 891
 			for ($l = 0; $l < $first_pass_ln; ++$l) {
892
-				$poNewLS0[] = array($first_pass[$l][0],$first_pass[$l][1]);
892
+				$poNewLS0[] = array($first_pass[$l][0], $first_pass[$l][1]);
893 893
 			}
894 894
 			$poMulti[] = $poNewLS0;
895 895
 		}
Please login to merge, or discard this patch.