Completed
Push — master ( f32ba6...d43b85 )
by Yannick
30:30
created
require/class.Common.php 2 patches
Doc Comments   +15 added lines, -2 removed lines patch added patch discarded remove patch
@@ -100,6 +100,10 @@  discard block
 block discarded – undo
100 100
 		return strlen($headerLine); // Needed by curl
101 101
 	}
102 102
 
103
+	/**
104
+	 * @param string $url
105
+	 * @param string $file
106
+	 */
103 107
 	public static function download($url, $file, $referer = '') {
104 108
 		global $globalDebug, $globalProxy, $globalForceIPv4;
105 109
 		$fp = fopen($file, 'w');
@@ -124,6 +128,9 @@  discard block
 block discarded – undo
124 128
 		fclose($fp);
125 129
 	}
126 130
 
131
+	/**
132
+	 * @param string $in_file
133
+	 */
127 134
 	public static function gunzip($in_file,$out_file_name = '') {
128 135
 		//echo $in_file.' -> '.$out_file_name."\n";
129 136
 		$buffer_size = 4096; // read 4kb at a time
@@ -285,7 +292,7 @@  discard block
 block discarded – undo
285 292
 	* Check is distance realistic
286 293
 	* @param int $timeDifference the time between the reception of both messages
287 294
 	* @param float $distance distance covered
288
-	* @return whether distance is realistic
295
+	* @return boolean distance is realistic
289 296
 	*/
290 297
 	public function withinThreshold ($timeDifference, $distance) {
291 298
 		$x = abs($timeDifference);
@@ -309,6 +316,9 @@  discard block
 block discarded – undo
309 316
 	}
310 317
 
311 318
 
319
+	/**
320
+	 * @param string $latlong
321
+	 */
312 322
 	public function convertDec($dms,$latlong) {
313 323
 		if ($latlong == 'latitude') {
314 324
 			$deg = substr($dms, 0, 2);
@@ -343,6 +353,9 @@  discard block
 block discarded – undo
343 353
 		return array('latitude' => round($latitude,5),'longitude' => round($longitude,5));
344 354
 	}
345 355
 	
356
+	/**
357
+	 * @param string $latlong
358
+	 */
346 359
 	public function convertDM($coord,$latlong) {
347 360
 		if ($latlong == 'latitude') {
348 361
 			if ($coord < 0) $NSEW = 'S';
@@ -480,7 +493,7 @@  discard block
 block discarded – undo
480 493
 	/**
481 494
 	* Returns list of available locales
482 495
 	*
483
-	* @return array
496
+	* @return string[]
484 497
 	 */
485 498
 	public function listLocaleDir()
486 499
 	{
Please login to merge, or discard this 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.
require/class.Connection.php 2 patches
Doc Comments   +20 added lines patch added patch discarded remove patch
@@ -6,6 +6,9 @@  discard block
 block discarded – undo
6 6
 	public $dbs = array();
7 7
 	public $latest_schema = 52;
8 8
 
9
+	/**
10
+	 * @param string $dbname
11
+	 */
9 12
 	public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) {
10 13
 		global $globalNoDB;
11 14
 		if (isset($globalNoDB) && $globalNoDB === TRUE) {
@@ -142,6 +145,9 @@  discard block
 block discarded – undo
142 145
 		return true;
143 146
 	}
144 147
 
148
+	/**
149
+	 * @param string $table
150
+	 */
145 151
 	public function tableExists($table)
146 152
 	{
147 153
 		global $globalDBdriver, $globalDBname;
@@ -192,6 +198,11 @@  discard block
 block discarded – undo
192 198
 	/*
193 199
 	* Check if index exist
194 200
 	*/
201
+
202
+	/**
203
+	 * @param string $table
204
+	 * @param string $index
205
+	 */
195 206
 	public function indexExists($table,$index)
196 207
 	{
197 208
 		global $globalDBdriver, $globalDBname;
@@ -234,6 +245,10 @@  discard block
 block discarded – undo
234 245
 		return $columns;
235 246
 	}
236 247
 
248
+	/**
249
+	 * @param string $table
250
+	 * @param string $column
251
+	 */
237 252
 	public function getColumnType($table,$column) {
238 253
 		$select = $this->db->query('SELECT '.$column.' FROM '.$table);
239 254
 		$tomet = $select->getColumnMeta(0);
@@ -244,6 +259,11 @@  discard block
 block discarded – undo
244 259
 	* Check if a column name exist in a table
245 260
 	* @return Boolean column exist or not
246 261
 	*/
262
+
263
+	/**
264
+	 * @param string $table
265
+	 * @param string $name
266
+	 */
247 267
 	public function checkColumnName($table,$name)
248 268
 	{
249 269
 		global $globalDBdriver, $globalDBname;
Please login to merge, or discard this 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.Marine.php 4 patches
Doc Comments   +3 added lines, -21 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 	/**
15 15
 	* Get SQL query part for filter used
16 16
 	* @param Array $filter the filter
17
-	* @return Array the SQL part
17
+	* @return string the SQL part
18 18
 	*/
19 19
 	
20 20
 	public function getFilter($filter = array(),$where = false,$and = false) {
@@ -694,25 +694,6 @@  discard block
 block discarded – undo
694 694
 	*
695 695
 	* @param String $fammarine_id the ID
696 696
 	* @param String $ident the marine ident
697
-	* @param String $departure_airport_icao the departure airport
698
-	* @param String $arrival_airport_icao the arrival airport
699
-	* @param String $latitude latitude of flight
700
-	* @param String $longitude latitude of flight
701
-	* @param String $waypoints waypoints of flight
702
-	* @param String $heading heading of flight
703
-	* @param String $groundspeed speed of flight
704
-	* @param String $date date of flight
705
-	* @param String $departure_airport_time departure time of flight
706
-	* @param String $arrival_airport_time arrival time of flight
707
-	* @param String $squawk squawk code of flight
708
-	* @param String $route_stop route stop of flight
709
-	* @param String $highlight highlight or not
710
-	* @param String $ModeS ModesS code of flight
711
-	* @param String $registration registration code of flight
712
-	* @param String $pilot_id pilot id of flight (for virtual airlines)
713
-	* @param String $pilot_name pilot name of flight (for virtual airlines)
714
-	* @param String $verticalrate vertival rate of flight
715
-	* @return String success or false
716 697
 	*/
717 698
 	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 699
 	{
@@ -1310,6 +1291,7 @@  discard block
 block discarded – undo
1310 1291
 	/**
1311 1292
 	* Counts all hours
1312 1293
 	*
1294
+	* @param string $orderby
1313 1295
 	* @return Array the hour list
1314 1296
 	*
1315 1297
 	*/
@@ -1661,7 +1643,7 @@  discard block
 block discarded – undo
1661 1643
 	/**
1662 1644
 	* Parses the direction degrees to working
1663 1645
 	*
1664
-	* @param Float $direction the direction in degrees
1646
+	* @param integer $direction the direction in degrees
1665 1647
 	* @return Array the direction information
1666 1648
 	*
1667 1649
 	*/
Please login to merge, or discard this patch.
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@  discard block
 block discarded – undo
12 12
 	}
13 13
 
14 14
 	/**
15
-	* Get SQL query part for filter used
16
-	* @param Array $filter the filter
17
-	* @return Array the SQL part
18
-	*/
15
+	 * Get SQL query part for filter used
16
+	 * @param Array $filter the filter
17
+	 * @return Array the SQL part
18
+	 */
19 19
 	
20 20
 	public function getFilter($filter = array(),$where = false,$and = false) {
21 21
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
@@ -88,14 +88,14 @@  discard block
 block discarded – undo
88 88
 	}
89 89
 
90 90
 	/**
91
-	* Executes the SQL statements to get the spotter information
92
-	*
93
-	* @param String $query the SQL query
94
-	* @param Array $params parameter of the query
95
-	* @param String $limitQuery the limit query
96
-	* @return Array the spotter information
97
-	*
98
-	*/
91
+	 * Executes the SQL statements to get the spotter information
92
+	 *
93
+	 * @param String $query the SQL query
94
+	 * @param Array $params parameter of the query
95
+	 * @param String $limitQuery the limit query
96
+	 * @return Array the spotter information
97
+	 *
98
+	 */
99 99
 	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false)
100 100
 	{
101 101
 		date_default_timezone_set('UTC');
@@ -230,11 +230,11 @@  discard block
 block discarded – undo
230 230
 	
231 231
 	
232 232
 	/**
233
-	* Gets all the spotter information based on the latest data entry
234
-	*
235
-	* @return Array the spotter information
236
-	*
237
-	*/
233
+	 * Gets all the spotter information based on the latest data entry
234
+	 *
235
+	 * @return Array the spotter information
236
+	 *
237
+	 */
238 238
 	public function getLatestMarineData($limit = '', $sort = '', $filter = array())
239 239
 	{
240 240
 		global $global_query;
@@ -283,11 +283,11 @@  discard block
 block discarded – undo
283 283
 	}
284 284
 
285 285
 	/**
286
-	* Gets all the spotter information based on the callsign
287
-	*
288
-	* @return Array the spotter information
289
-	*
290
-	*/
286
+	 * Gets all the spotter information based on the callsign
287
+	 *
288
+	 * @return Array the spotter information
289
+	 *
290
+	 */
291 291
 	public function getMarineDataByIdent($ident = '', $limit = '', $sort = '', $filter = array())
292 292
 	{
293 293
 		global $global_query;
@@ -339,11 +339,11 @@  discard block
 block discarded – undo
339 339
 	}
340 340
 
341 341
 	/**
342
-	* Gets all the marine information based on the type
343
-	*
344
-	* @return Array the marine information
345
-	*
346
-	*/
342
+	 * Gets all the marine information based on the type
343
+	 *
344
+	 * @return Array the marine information
345
+	 *
346
+	 */
347 347
 	public function getMarineDataByType($type = '', $limit = '', $sort = '', $filter = array())
348 348
 	{
349 349
 		global $global_query;
@@ -451,12 +451,12 @@  discard block
 block discarded – undo
451 451
 
452 452
 
453 453
 	/**
454
-	* Gets all source name
455
-	*
456
-	* @param String type format of source
457
-	* @return Array list of source name
458
-	*
459
-	*/
454
+	 * Gets all source name
455
+	 *
456
+	 * @param String type format of source
457
+	 * @return Array list of source name
458
+	 *
459
+	 */
460 460
 	public function getAllSourceName($type = '',$filters = array())
461 461
 	{
462 462
 		$filter_query = $this->getFilter($filters,true,true);
@@ -486,11 +486,11 @@  discard block
 block discarded – undo
486 486
 
487 487
 
488 488
 	/**
489
-	* Gets a list of all idents/callsigns
490
-	*
491
-	* @return Array list of ident/callsign names
492
-	*
493
-	*/
489
+	 * Gets a list of all idents/callsigns
490
+	 *
491
+	 * @return Array list of ident/callsign names
492
+	 *
493
+	 */
494 494
 	public function getAllIdents($filters = array())
495 495
 	{
496 496
 		$filter_query = $this->getFilter($filters,true,true);
@@ -514,11 +514,11 @@  discard block
 block discarded – undo
514 514
 	}
515 515
 
516 516
 	/**
517
-	* Gets all info from a mmsi
518
-	*
519
-	* @return Array ident
520
-	*
521
-	*/
517
+	 * Gets all info from a mmsi
518
+	 *
519
+	 * @return Array ident
520
+	 *
521
+	 */
522 522
 	public function getIdentity($mmsi)
523 523
 	{
524 524
 		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
@@ -531,9 +531,9 @@  discard block
 block discarded – undo
531 531
 	}
532 532
 
533 533
 	/**
534
-	* Add identity
535
-	*
536
-	*/
534
+	 * Add identity
535
+	 *
536
+	 */
537 537
 	public function addIdentity($mmsi,$imo,$ident,$callsign,$type)
538 538
 	{
539 539
 		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
@@ -599,13 +599,13 @@  discard block
 block discarded – undo
599 599
 	}
600 600
 
601 601
 	/**
602
-	* Update ident tracker data
603
-	*
604
-	* @param String $fammarine_id the ID
605
-	* @param String $ident the marine ident
606
-	* @return String success or false
607
-	*
608
-	*/
602
+	 * Update ident tracker data
603
+	 *
604
+	 * @param String $fammarine_id the ID
605
+	 * @param String $ident the marine ident
606
+	 * @return String success or false
607
+	 *
608
+	 */
609 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';
@@ -620,13 +620,13 @@  discard block
 block discarded – undo
620 620
 	}
621 621
 
622 622
 	/**
623
-	* Update arrival marine data
624
-	*
625
-	* @param String $fammarine_id the ID
626
-	* @param String $arrival_code the marine ident
627
-	* @return String success or false
628
-	*
629
-	*/
623
+	 * Update arrival marine data
624
+	 *
625
+	 * @param String $fammarine_id the ID
626
+	 * @param String $arrival_code the marine ident
627
+	 * @return String success or false
628
+	 *
629
+	 */
630 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';
@@ -641,19 +641,19 @@  discard block
 block discarded – undo
641 641
 	}
642 642
 
643 643
 	/**
644
-	* Update Status data
645
-	*
646
-	* @param String $fammarine_id the ID
647
-	* @param String $status_id the marine status id
648
-	* @param String $status the marine status
649
-	* @return String success or false
650
-	*
651
-	*/
644
+	 * Update Status data
645
+	 *
646
+	 * @param String $fammarine_id the ID
647
+	 * @param String $status_id the marine status id
648
+	 * @param String $status the marine status
649
+	 * @return String success or false
650
+	 *
651
+	 */
652 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);
@@ -666,17 +666,17 @@  discard block
 block discarded – undo
666 666
 
667 667
 	}
668 668
 	/**
669
-	* Update latest marine data
670
-	*
671
-	* @param String $fammarine_id the ID
672
-	* @param String $ident the marine ident
673
-	* @return String success or false
674
-	*
675
-	*/	
669
+	 * Update latest marine data
670
+	 *
671
+	 * @param String $fammarine_id the ID
672
+	 * @param String $ident the marine ident
673
+	 * @return String success or false
674
+	 *
675
+	 */	
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);
@@ -690,30 +690,30 @@  discard block
 block discarded – undo
690 690
 	}
691 691
 
692 692
 	/**
693
-	* Adds a new spotter data
694
-	*
695
-	* @param String $fammarine_id the ID
696
-	* @param String $ident the marine ident
697
-	* @param String $departure_airport_icao the departure airport
698
-	* @param String $arrival_airport_icao the arrival airport
699
-	* @param String $latitude latitude of flight
700
-	* @param String $longitude latitude of flight
701
-	* @param String $waypoints waypoints of flight
702
-	* @param String $heading heading of flight
703
-	* @param String $groundspeed speed of flight
704
-	* @param String $date date of flight
705
-	* @param String $departure_airport_time departure time of flight
706
-	* @param String $arrival_airport_time arrival time of flight
707
-	* @param String $squawk squawk code of flight
708
-	* @param String $route_stop route stop of flight
709
-	* @param String $highlight highlight or not
710
-	* @param String $ModeS ModesS code of flight
711
-	* @param String $registration registration code of flight
712
-	* @param String $pilot_id pilot id of flight (for virtual airlines)
713
-	* @param String $pilot_name pilot name of flight (for virtual airlines)
714
-	* @param String $verticalrate vertival rate of flight
715
-	* @return String success or false
716
-	*/
693
+	 * Adds a new spotter data
694
+	 *
695
+	 * @param String $fammarine_id the ID
696
+	 * @param String $ident the marine ident
697
+	 * @param String $departure_airport_icao the departure airport
698
+	 * @param String $arrival_airport_icao the arrival airport
699
+	 * @param String $latitude latitude of flight
700
+	 * @param String $longitude latitude of flight
701
+	 * @param String $waypoints waypoints of flight
702
+	 * @param String $heading heading of flight
703
+	 * @param String $groundspeed speed of flight
704
+	 * @param String $date date of flight
705
+	 * @param String $departure_airport_time departure time of flight
706
+	 * @param String $arrival_airport_time arrival time of flight
707
+	 * @param String $squawk squawk code of flight
708
+	 * @param String $route_stop route stop of flight
709
+	 * @param String $highlight highlight or not
710
+	 * @param String $ModeS ModesS code of flight
711
+	 * @param String $registration registration code of flight
712
+	 * @param String $pilot_id pilot id of flight (for virtual airlines)
713
+	 * @param String $pilot_name pilot name of flight (for virtual airlines)
714
+	 * @param String $verticalrate vertival rate of flight
715
+	 * @return String success or false
716
+	 */
717 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;
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
 			$sth->execute($query_values);
833 833
 			$this->db = null;
834 834
 		} catch (PDOException $e) {
835
-		    return "error : ".$e->getMessage();
835
+			return "error : ".$e->getMessage();
836 836
 		}
837 837
 		
838 838
 		return "success";
@@ -841,11 +841,11 @@  discard block
 block discarded – undo
841 841
 	
842 842
   
843 843
 	/**
844
-	* Gets the aircraft ident within the last hour
845
-	*
846
-	* @return String the ident
847
-	*
848
-	*/
844
+	 * Gets the aircraft ident within the last hour
845
+	 *
846
+	 * @return String the ident
847
+	 *
848
+	 */
849 849
 	public function getIdentFromLastHour($ident)
850 850
 	{
851 851
 		global $globalDBdriver, $globalTimezone;
@@ -861,11 +861,11 @@  discard block
 block discarded – undo
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'";
863 863
 			$query_data = array(':ident' => $ident);
864
-    		}
864
+			}
865 865
 		
866 866
 		$sth = $this->db->prepare($query);
867 867
 		$sth->execute($query_data);
868
-    		$ident_result='';
868
+			$ident_result='';
869 869
 		while($row = $sth->fetch(PDO::FETCH_ASSOC))
870 870
 		{
871 871
 			$ident_result = $row['ident'];
@@ -876,11 +876,11 @@  discard block
 block discarded – undo
876 876
 	
877 877
 	
878 878
 	/**
879
-	* Gets the aircraft data from the last 20 seconds
880
-	*
881
-	* @return Array the spotter data
882
-	*
883
-	*/
879
+	 * Gets the aircraft data from the last 20 seconds
880
+	 *
881
+	 * @return Array the spotter data
882
+	 *
883
+	 */
884 884
 	public function getRealTimeData($q = '')
885 885
 	{
886 886
 		global $globalDBdriver;
@@ -918,11 +918,11 @@  discard block
 block discarded – undo
918 918
 	
919 919
 
920 920
 	/**
921
-	* Gets all number of flight over countries
922
-	*
923
-	* @return Array the airline country list
924
-	*
925
-	*/
921
+	 * Gets all number of flight over countries
922
+	 *
923
+	 * @return Array the airline country list
924
+	 *
925
+	 */
926 926
 
927 927
 	public function countAllMarineOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array())
928 928
 	{
@@ -995,11 +995,11 @@  discard block
 block discarded – undo
995 995
 	
996 996
 	
997 997
 	/**
998
-	* Gets all callsigns that have flown over
999
-	*
1000
-	* @return Array the callsign list
1001
-	*
1002
-	*/
998
+	 * Gets all callsigns that have flown over
999
+	 *
1000
+	 * @return Array the callsign list
1001
+	 *
1002
+	 */
1003 1003
 	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
1004 1004
 	{
1005 1005
 		global $globalDBdriver;
@@ -1066,11 +1066,11 @@  discard block
 block discarded – undo
1066 1066
 
1067 1067
 
1068 1068
 	/**
1069
-	* Counts all dates
1070
-	*
1071
-	* @return Array the date list
1072
-	*
1073
-	*/
1069
+	 * Counts all dates
1070
+	 *
1071
+	 * @return Array the date list
1072
+	 *
1073
+	 */
1074 1074
 	public function countAllDates($filters = array())
1075 1075
 	{
1076 1076
 		global $globalTimezone, $globalDBdriver;
@@ -1116,11 +1116,11 @@  discard block
 block discarded – undo
1116 1116
 	
1117 1117
 	
1118 1118
 	/**
1119
-	* Counts all dates during the last 7 days
1120
-	*
1121
-	* @return Array the date list
1122
-	*
1123
-	*/
1119
+	 * Counts all dates during the last 7 days
1120
+	 *
1121
+	 * @return Array the date list
1122
+	 *
1123
+	 */
1124 1124
 	public function countAllDatesLast7Days($filters = array())
1125 1125
 	{
1126 1126
 		global $globalTimezone, $globalDBdriver;
@@ -1142,7 +1142,7 @@  discard block
 block discarded – undo
1142 1142
 			$query .= " GROUP BY date_name 
1143 1143
 								ORDER BY date_name ASC";
1144 1144
 			$query_data = array(':offset' => $offset);
1145
-    		}
1145
+			}
1146 1146
 		
1147 1147
 		$sth = $this->db->prepare($query);
1148 1148
 		$sth->execute($query_data);
@@ -1162,11 +1162,11 @@  discard block
 block discarded – undo
1162 1162
 	}
1163 1163
 
1164 1164
 	/**
1165
-	* Counts all dates during the last month
1166
-	*
1167
-	* @return Array the date list
1168
-	*
1169
-	*/
1165
+	 * Counts all dates during the last month
1166
+	 *
1167
+	 * @return Array the date list
1168
+	 *
1169
+	 */
1170 1170
 	public function countAllDatesLastMonth($filters = array())
1171 1171
 	{
1172 1172
 		global $globalTimezone, $globalDBdriver;
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
 			$query .= " GROUP BY date_name 
1189 1189
 								ORDER BY date_name ASC";
1190 1190
 			$query_data = array(':offset' => $offset);
1191
-    		}
1191
+			}
1192 1192
 		
1193 1193
 		$sth = $this->db->prepare($query);
1194 1194
 		$sth->execute($query_data);
@@ -1210,11 +1210,11 @@  discard block
 block discarded – undo
1210 1210
 
1211 1211
 
1212 1212
 	/**
1213
-	* Counts all month
1214
-	*
1215
-	* @return Array the month list
1216
-	*
1217
-	*/
1213
+	 * Counts all month
1214
+	 *
1215
+	 * @return Array the month list
1216
+	 *
1217
+	 */
1218 1218
 	public function countAllMonths($filters = array())
1219 1219
 	{
1220 1220
 		global $globalTimezone, $globalDBdriver;
@@ -1259,11 +1259,11 @@  discard block
 block discarded – undo
1259 1259
 	
1260 1260
 
1261 1261
 	/**
1262
-	* Counts all dates during the last year
1263
-	*
1264
-	* @return Array the date list
1265
-	*
1266
-	*/
1262
+	 * Counts all dates during the last year
1263
+	 *
1264
+	 * @return Array the date list
1265
+	 *
1266
+	 */
1267 1267
 	public function countAllMonthsLastYear($filters)
1268 1268
 	{
1269 1269
 		global $globalTimezone, $globalDBdriver;
@@ -1285,7 +1285,7 @@  discard block
 block discarded – undo
1285 1285
 			$query .= " GROUP BY year_name, month_name
1286 1286
 								ORDER BY year_name, month_name ASC";
1287 1287
 			$query_data = array(':offset' => $offset);
1288
-    		}
1288
+			}
1289 1289
 		
1290 1290
 		$sth = $this->db->prepare($query);
1291 1291
 		$sth->execute($query_data);
@@ -1308,11 +1308,11 @@  discard block
 block discarded – undo
1308 1308
 	
1309 1309
 	
1310 1310
 	/**
1311
-	* Counts all hours
1312
-	*
1313
-	* @return Array the hour list
1314
-	*
1315
-	*/
1311
+	 * Counts all hours
1312
+	 *
1313
+	 * @return Array the hour list
1314
+	 *
1315
+	 */
1316 1316
 	public function countAllHours($orderby,$filters = array())
1317 1317
 	{
1318 1318
 		global $globalTimezone, $globalDBdriver;
@@ -1375,11 +1375,11 @@  discard block
 block discarded – undo
1375 1375
 	
1376 1376
 	
1377 1377
 	/**
1378
-	* Counts all hours by date
1379
-	*
1380
-	* @return Array the hour list
1381
-	*
1382
-	*/
1378
+	 * Counts all hours by date
1379
+	 *
1380
+	 * @return Array the hour list
1381
+	 *
1382
+	 */
1383 1383
 	public function countAllHoursByDate($date, $filters = array())
1384 1384
 	{
1385 1385
 		global $globalTimezone, $globalDBdriver;
@@ -1423,11 +1423,11 @@  discard block
 block discarded – undo
1423 1423
 	
1424 1424
 	
1425 1425
 	/**
1426
-	* Counts all hours by a ident/callsign
1427
-	*
1428
-	* @return Array the hour list
1429
-	*
1430
-	*/
1426
+	 * Counts all hours by a ident/callsign
1427
+	 *
1428
+	 * @return Array the hour list
1429
+	 *
1430
+	 */
1431 1431
 	public function countAllHoursByIdent($ident, $filters = array())
1432 1432
 	{
1433 1433
 		global $globalTimezone, $globalDBdriver;
@@ -1472,11 +1472,11 @@  discard block
 block discarded – undo
1472 1472
 	
1473 1473
 	
1474 1474
 	/**
1475
-	* Counts all vessels
1476
-	*
1477
-	* @return Integer the number of vessels
1478
-	*
1479
-	*/
1475
+	 * Counts all vessels
1476
+	 *
1477
+	 * @return Integer the number of vessels
1478
+	 *
1479
+	 */
1480 1480
 	public function countOverallMarine($filters = array(),$year = '',$month = '')
1481 1481
 	{
1482 1482
 		global $globalDBdriver;
@@ -1511,11 +1511,11 @@  discard block
 block discarded – undo
1511 1511
 	}
1512 1512
 	
1513 1513
 	/**
1514
-	* Counts all vessel type
1515
-	*
1516
-	* @return Integer the number of vessels
1517
-	*
1518
-	*/
1514
+	 * Counts all vessel type
1515
+	 *
1516
+	 * @return Integer the number of vessels
1517
+	 *
1518
+	 */
1519 1519
 	public function countOverallMarineTypes($filters = array(),$year = '',$month = '')
1520 1520
 	{
1521 1521
 		global $globalDBdriver;
@@ -1550,11 +1550,11 @@  discard block
 block discarded – undo
1550 1550
 	
1551 1551
   
1552 1552
 	/**
1553
-	* Counts all hours of today
1554
-	*
1555
-	* @return Array the hour list
1556
-	*
1557
-	*/
1553
+	 * Counts all hours of today
1554
+	 *
1555
+	 * @return Array the hour list
1556
+	 *
1557
+	 */
1558 1558
 	public function countAllHoursFromToday($filters = array())
1559 1559
 	{
1560 1560
 		global $globalTimezone, $globalDBdriver;
@@ -1594,12 +1594,12 @@  discard block
 block discarded – undo
1594 1594
 	}
1595 1595
     
1596 1596
     
1597
-     /**
1598
-	* Gets the Barrie Spotter ID based on the FlightAware ID
1599
-	*
1600
-	* @return Integer the Barrie Spotter ID
1597
+	 /**
1598
+	  * Gets the Barrie Spotter ID based on the FlightAware ID
1599
+	  *
1600
+	  * @return Integer the Barrie Spotter ID
1601 1601
 q	*
1602
-	*/
1602
+	  */
1603 1603
 	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1604 1604
 	{
1605 1605
 		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
@@ -1620,13 +1620,13 @@  discard block
 block discarded – undo
1620 1620
   
1621 1621
  
1622 1622
 	/**
1623
-	* Parses a date string
1624
-	*
1625
-	* @param String $dateString the date string
1626
-	* @param String $timezone the timezone of a user
1627
-	* @return Array the time information
1628
-	*
1629
-	*/
1623
+	 * Parses a date string
1624
+	 *
1625
+	 * @param String $dateString the date string
1626
+	 * @param String $timezone the timezone of a user
1627
+	 * @return Array the time information
1628
+	 *
1629
+	 */
1630 1630
 	public function parseDateString($dateString, $timezone = '')
1631 1631
 	{
1632 1632
 		$time_array = array();
@@ -1659,12 +1659,12 @@  discard block
 block discarded – undo
1659 1659
 	}
1660 1660
 	
1661 1661
 	/**
1662
-	* Parses the direction degrees to working
1663
-	*
1664
-	* @param Float $direction the direction in degrees
1665
-	* @return Array the direction information
1666
-	*
1667
-	*/
1662
+	 * Parses the direction degrees to working
1663
+	 *
1664
+	 * @param Float $direction the direction in degrees
1665
+	 * @return Array the direction information
1666
+	 *
1667
+	 */
1668 1668
 	public function parseDirection($direction = 0)
1669 1669
 	{
1670 1670
 		if ($direction == '') $direction = 0;
@@ -1743,12 +1743,12 @@  discard block
 block discarded – undo
1743 1743
 	
1744 1744
 	
1745 1745
 	/**
1746
-	* Gets Country from latitude/longitude
1747
-	*
1748
-	* @param Float $latitude latitute of the flight
1749
-	* @param Float $longitude longitute of the flight
1750
-	* @return String the countrie
1751
-	*/
1746
+	 * Gets Country from latitude/longitude
1747
+	 *
1748
+	 * @param Float $latitude latitute of the flight
1749
+	 * @param Float $longitude longitute of the flight
1750
+	 * @return String the countrie
1751
+	 */
1752 1752
 	public function getCountryFromLatitudeLongitude($latitude,$longitude)
1753 1753
 	{
1754 1754
 		global $globalDBdriver, $globalDebug;
@@ -1785,11 +1785,11 @@  discard block
 block discarded – undo
1785 1785
 	}
1786 1786
 
1787 1787
 	/**
1788
-	* Gets Country from iso2
1789
-	*
1790
-	* @param String $iso2 ISO2 country code
1791
-	* @return String the countrie
1792
-	*/
1788
+	 * Gets Country from iso2
1789
+	 *
1790
+	 * @param String $iso2 ISO2 country code
1791
+	 * @return String the countrie
1792
+	 */
1793 1793
 	public function getCountryFromISO2($iso2)
1794 1794
 	{
1795 1795
 		global $globalDBdriver, $globalDebug;
@@ -1818,12 +1818,12 @@  discard block
 block discarded – undo
1818 1818
 
1819 1819
 	
1820 1820
 	/**
1821
-	* Gets the short url from bit.ly
1822
-	*
1823
-	* @param String $url the full url
1824
-	* @return String the bit.ly url
1825
-	*
1826
-	*/
1821
+	 * Gets the short url from bit.ly
1822
+	 *
1823
+	 * @param String $url the full url
1824
+	 * @return String the bit.ly url
1825
+	 *
1826
+	 */
1827 1827
 	public function getBitlyURL($url)
1828 1828
 	{
1829 1829
 		global $globalBitlyAccessToken;
@@ -1850,11 +1850,11 @@  discard block
 block discarded – undo
1850 1850
 
1851 1851
 	
1852 1852
 	/**
1853
-	* Gets all vessels types that have flown over
1854
-	*
1855
-	* @return Array the vessel type list
1856
-	*
1857
-	*/
1853
+	 * Gets all vessels types that have flown over
1854
+	 *
1855
+	 * @return Array the vessel type list
1856
+	 *
1857
+	 */
1858 1858
 	public function countAllMarineTypes($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array(),$year = '',$month = '',$day = '')
1859 1859
 	{
1860 1860
 		global $globalDBdriver;
@@ -1920,11 +1920,11 @@  discard block
 block discarded – undo
1920 1920
 	}
1921 1921
 
1922 1922
 	/**
1923
-	* Gets all the tracker information
1924
-	*
1925
-	* @return Array the tracker information
1926
-	*
1927
-	*/
1923
+	 * Gets all the tracker information
1924
+	 *
1925
+	 * @return Array the tracker information
1926
+	 *
1927
+	 */
1928 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;
Please login to merge, or discard this 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.
Braces   +218 added lines, -77 removed lines patch added patch discarded remove patch
@@ -8,7 +8,9 @@  discard block
 block discarded – undo
8 8
 	public function __construct($dbc = null) {
9 9
 		$Connection = new Connection($dbc);
10 10
 		$this->db = $Connection->db();
11
-		if ($this->db === null) die('Error: No DB connection. (Marine)');
11
+		if ($this->db === null) {
12
+			die('Error: No DB connection. (Marine)');
13
+		}
12 14
 	}
13 15
 
14 16
 	/**
@@ -30,7 +32,9 @@  discard block
 block discarded – undo
30 32
 		if (isset($filter[0]['source'])) {
31 33
 			$filters = array_merge($filters,$filter);
32 34
 		}
33
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
35
+		if (is_array($globalFilter)) {
36
+			$filter = array_merge($filter,$globalFilter);
37
+		}
34 38
 		$filter_query_join = '';
35 39
 		$filter_query_where = '';
36 40
 		foreach($filters as $flt) {
@@ -78,8 +82,11 @@  discard block
 block discarded – undo
78 82
 				$filter_query_where .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'";
79 83
 			}
80 84
 		}
81
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
82
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
85
+		if ($filter_query_where == '' && $where) {
86
+			$filter_query_where = ' WHERE';
87
+		} elseif ($filter_query_where != '' && $and) {
88
+			$filter_query_where .= ' AND';
89
+		}
83 90
 		if ($filter_query_where != '') {
84 91
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
85 92
 		}
@@ -133,39 +140,75 @@  discard block
 block discarded – undo
133 140
 				$temp_array['spotter_id'] = $row['spotter_archive_id'];
134 141
 			} elseif (isset($row['spotter_archive_output_id'])) {
135 142
 				$temp_array['spotter_id'] = $row['spotter_archive_output_id'];
136
-			*/} 
137
-			elseif (isset($row['marineid'])) {
143
+			*/} elseif (isset($row['marineid'])) {
138 144
 				$temp_array['marine_id'] = $row['marineid'];
139 145
 			} else {
140 146
 				$temp_array['marine_id'] = '';
141 147
 			}
142
-			if (isset($row['fammarine_id'])) $temp_array['fammarine_id'] = $row['fammarine_id'];
143
-			if (isset($row['mmsi'])) $temp_array['mmsi'] = $row['mmsi'];
144
-			if (isset($row['type'])) $temp_array['type'] = $row['type'];
145
-			if (isset($row['type_id'])) $temp_array['type_id'] = $row['type_id'];
146
-			if (isset($row['status'])) $temp_array['status'] = $row['status'];
147
-			if (isset($row['status_id'])) $temp_array['status_id'] = $row['status_id'];
148
-			if (isset($row['captain_id'])) $temp_array['captain_id'] = $row['captain_id'];
149
-			if (isset($row['captain_name'])) $temp_array['captain_name'] = $row['captain_name'];
150
-			if (isset($row['race_id'])) $temp_array['race_id'] = $row['race_id'];
151
-			if (isset($row['race_name'])) $temp_array['race_name'] = $row['race_name'];
152
-			if (isset($row['ident'])) $temp_array['ident'] = $row['ident'];
153
-			if (isset($row['arrival_port_name'])) $temp_array['arrival_port_name'] = $row['arrival_port_name'];
154
-			if (isset($row['latitude'])) $temp_array['latitude'] = $row['latitude'];
155
-			if (isset($row['longitude'])) $temp_array['longitude'] = $row['longitude'];
156
-			if (isset($row['format_source'])) $temp_array['format_source'] = $row['format_source'];
148
+			if (isset($row['fammarine_id'])) {
149
+				$temp_array['fammarine_id'] = $row['fammarine_id'];
150
+			}
151
+			if (isset($row['mmsi'])) {
152
+				$temp_array['mmsi'] = $row['mmsi'];
153
+			}
154
+			if (isset($row['type'])) {
155
+				$temp_array['type'] = $row['type'];
156
+			}
157
+			if (isset($row['type_id'])) {
158
+				$temp_array['type_id'] = $row['type_id'];
159
+			}
160
+			if (isset($row['status'])) {
161
+				$temp_array['status'] = $row['status'];
162
+			}
163
+			if (isset($row['status_id'])) {
164
+				$temp_array['status_id'] = $row['status_id'];
165
+			}
166
+			if (isset($row['captain_id'])) {
167
+				$temp_array['captain_id'] = $row['captain_id'];
168
+			}
169
+			if (isset($row['captain_name'])) {
170
+				$temp_array['captain_name'] = $row['captain_name'];
171
+			}
172
+			if (isset($row['race_id'])) {
173
+				$temp_array['race_id'] = $row['race_id'];
174
+			}
175
+			if (isset($row['race_name'])) {
176
+				$temp_array['race_name'] = $row['race_name'];
177
+			}
178
+			if (isset($row['ident'])) {
179
+				$temp_array['ident'] = $row['ident'];
180
+			}
181
+			if (isset($row['arrival_port_name'])) {
182
+				$temp_array['arrival_port_name'] = $row['arrival_port_name'];
183
+			}
184
+			if (isset($row['latitude'])) {
185
+				$temp_array['latitude'] = $row['latitude'];
186
+			}
187
+			if (isset($row['longitude'])) {
188
+				$temp_array['longitude'] = $row['longitude'];
189
+			}
190
+			if (isset($row['format_source'])) {
191
+				$temp_array['format_source'] = $row['format_source'];
192
+			}
157 193
 			if (isset($row['heading'])) {
158 194
 				$temp_array['heading'] = $row['heading'];
159 195
 				$heading_direction = $this->parseDirection($row['heading']);
160
-				if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
196
+				if (isset($heading_direction[0]['direction_fullname'])) {
197
+					$temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
198
+				}
199
+			}
200
+			if (isset($row['ground_speed'])) {
201
+				$temp_array['ground_speed'] = $row['ground_speed'];
161 202
 			}
162
-			if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed'];
163 203
 
164 204
 			if(isset($temp_array['mmsi']) && $temp_array['mmsi'] != "")
165 205
 			{
166 206
 				$Image = new Image($this->db);
167
-				if (isset($temp_array['ident']) && $temp_array['ident'] != '') $image_array = $Image->getMarineImage($temp_array['mmsi'],'',$temp_array['ident']);
168
-				else $image_array = $Image->getMarineImage($temp_array['mmsi']);
207
+				if (isset($temp_array['ident']) && $temp_array['ident'] != '') {
208
+					$image_array = $Image->getMarineImage($temp_array['mmsi'],'',$temp_array['ident']);
209
+				} else {
210
+					$image_array = $Image->getMarineImage($temp_array['mmsi']);
211
+				}
169 212
 				unset($Image);
170 213
 				if (count($image_array) > 0) {
171 214
 					$temp_array['image'] = $image_array[0]['image'];
@@ -217,13 +260,21 @@  discard block
 block discarded – undo
217 260
 			}
218 261
 			
219 262
 			$fromsource = NULL;
220
-			if (isset($row['source_name']) && $row['source_name'] != '') $temp_array['source_name'] = $row['source_name'];
221
-			if (isset($row['over_country']) && $row['over_country'] != '') $temp_array['over_country'] = $row['over_country'];
222
-			if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance'];
263
+			if (isset($row['source_name']) && $row['source_name'] != '') {
264
+				$temp_array['source_name'] = $row['source_name'];
265
+			}
266
+			if (isset($row['over_country']) && $row['over_country'] != '') {
267
+				$temp_array['over_country'] = $row['over_country'];
268
+			}
269
+			if (isset($row['distance']) && $row['distance'] != '') {
270
+				$temp_array['distance'] = $row['distance'];
271
+			}
223 272
 			$temp_array['query_number_rows'] = $num_rows;
224 273
 			$spotter_array[] = $temp_array;
225 274
 		}
226
-		if ($num_rows == 0) return array();
275
+		if ($num_rows == 0) {
276
+			return array();
277
+		}
227 278
 		$spotter_array[0]['query_number_rows'] = $num_rows;
228 279
 		return $spotter_array;
229 280
 	}	
@@ -249,8 +300,12 @@  discard block
 block discarded – undo
249 300
 			{
250 301
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
251 302
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
252
-			} else $limit_query = "";
253
-		} else $limit_query = "";
303
+			} else {
304
+				$limit_query = "";
305
+			}
306
+		} else {
307
+			$limit_query = "";
308
+		}
254 309
 		if ($sort != "")
255 310
 		{
256 311
 			$search_orderby_array = $this->getOrderBy();
@@ -274,7 +329,9 @@  discard block
 block discarded – undo
274 329
 		global $global_query;
275 330
 		
276 331
 		date_default_timezone_set('UTC');
277
-		if ($id == '') return array();
332
+		if ($id == '') {
333
+			return array();
334
+		}
278 335
 		$additional_query = "marine_output.fammarine_id = :id";
279 336
 		$query_values = array(':id' => $id);
280 337
 		$query  = $global_query." WHERE ".$additional_query." ";
@@ -470,8 +527,11 @@  discard block
 block discarded – undo
470 527
 		$query .= " ORDER BY marine_output.source_name ASC";
471 528
 
472 529
 		$sth = $this->db->prepare($query);
473
-		if (!empty($query_values)) $sth->execute($query_values);
474
-		else $sth->execute();
530
+		if (!empty($query_values)) {
531
+			$sth->execute($query_values);
532
+		} else {
533
+			$sth->execute();
534
+		}
475 535
 
476 536
 		$source_array = array();
477 537
 		$temp_array = array();
@@ -526,8 +586,11 @@  discard block
 block discarded – undo
526 586
 		$sth = $this->db->prepare($query);
527 587
 		$sth->execute(array(':mmsi' => $mmsi));
528 588
 		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
529
-		if (isset($result[0])) return $result[0];
530
-		else return array();
589
+		if (isset($result[0])) {
590
+			return $result[0];
591
+		} else {
592
+			return array();
593
+		}
531 594
 	}
532 595
 
533 596
 	/**
@@ -568,7 +631,9 @@  discard block
 block discarded – undo
568 631
 			date_default_timezone_set($globalTimezone);
569 632
 			$datetime = new DateTime();
570 633
 			$offset = $datetime->format('P');
571
-		} else $offset = '+00:00';
634
+		} else {
635
+			$offset = '+00:00';
636
+		}
572 637
 
573 638
 		if ($globalDBdriver == 'mysql') {
574 639
 			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
@@ -818,11 +883,21 @@  discard block
 block discarded – undo
818 883
 			$latitude = 0;
819 884
 			$longitude = 0;
820 885
 		}
821
-		if ($type_id == '') $type_id = NULL;
822
-		if ($status_id == '') $status_id = NULL;
823
-		if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
824
-		if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
825
-		if ($arrival_date == '') $arrival_date = NULL;
886
+		if ($type_id == '') {
887
+			$type_id = NULL;
888
+		}
889
+		if ($status_id == '') {
890
+			$status_id = NULL;
891
+		}
892
+		if ($heading == '' || $Common->isInteger($heading) === false) {
893
+			$heading = 0;
894
+		}
895
+		if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) {
896
+			$groundspeed = 0;
897
+		}
898
+		if ($arrival_date == '') {
899
+			$arrival_date = NULL;
900
+		}
826 901
 		$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 902
 		    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 903
 
@@ -929,7 +1004,9 @@  discard block
 block discarded – undo
929 1004
 		global $globalDBdriver, $globalArchive;
930 1005
 		//$filter_query = $this->getFilter($filters,true,true);
931 1006
 		$Connection= new Connection($this->db);
932
-		if (!$Connection->tableExists('countries')) return array();
1007
+		if (!$Connection->tableExists('countries')) {
1008
+			return array();
1009
+		}
933 1010
 		require_once('class.SpotterLive.php');
934 1011
 		if (!isset($globalArchive) || $globalArchive !== TRUE) {
935 1012
 			$MarineLive = new MarineLive($this->db);
@@ -973,7 +1050,9 @@  discard block
 block discarded – undo
973 1050
 			$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb FROM countries c INNER JOIN (SELECT DISTINCT fammarine_id,over_country FROM marine_archive".$filter_query.") l ON c.iso2 = l.over_country ";
974 1051
 		}
975 1052
 		$query .= "GROUP BY c.name,c.iso3,c.iso2 ORDER BY nb DESC";
976
-		if ($limit) $query .= " LIMIT 10 OFFSET 0";
1053
+		if ($limit) {
1054
+			$query .= " LIMIT 10 OFFSET 0";
1055
+		}
977 1056
 
978 1057
 		$sth = $this->db->prepare($query);
979 1058
 		$sth->execute();
@@ -1007,12 +1086,18 @@  discard block
 block discarded – undo
1007 1086
 		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
1008 1087
                     FROM marine_output".$filter_query." marine_output.ident <> ''";
1009 1088
 		 if ($olderthanmonths > 0) {
1010
-			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
1011
-			else $query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
1089
+			if ($globalDBdriver == 'mysql') {
1090
+				$query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
1091
+			} else {
1092
+				$query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
1093
+			}
1012 1094
 		}
1013 1095
 		if ($sincedate != '') {
1014
-			if ($globalDBdriver == 'mysql') $query .= " AND marine_output.date > '".$sincedate."'";
1015
-			else $query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
1096
+			if ($globalDBdriver == 'mysql') {
1097
+				$query .= " AND marine_output.date > '".$sincedate."'";
1098
+			} else {
1099
+				$query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
1100
+			}
1016 1101
 		}
1017 1102
 		$query_values = array();
1018 1103
 		if ($year != '') {
@@ -1043,7 +1128,9 @@  discard block
 block discarded – undo
1043 1128
 			}
1044 1129
 		}
1045 1130
 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
1046
-		if ($limit) $query .= " LIMIT 10 OFFSET 0";
1131
+		if ($limit) {
1132
+			$query .= " LIMIT 10 OFFSET 0";
1133
+		}
1047 1134
       		
1048 1135
 		$sth = $this->db->prepare($query);
1049 1136
 		$sth->execute($query_values);
@@ -1078,7 +1165,9 @@  discard block
 block discarded – undo
1078 1165
 			date_default_timezone_set($globalTimezone);
1079 1166
 			$datetime = new DateTime();
1080 1167
 			$offset = $datetime->format('P');
1081
-		} else $offset = '+00:00';
1168
+		} else {
1169
+			$offset = '+00:00';
1170
+		}
1082 1171
 
1083 1172
 		if ($globalDBdriver == 'mysql') {
1084 1173
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -1128,7 +1217,9 @@  discard block
 block discarded – undo
1128 1217
 			date_default_timezone_set($globalTimezone);
1129 1218
 			$datetime = new DateTime();
1130 1219
 			$offset = $datetime->format('P');
1131
-		} else $offset = '+00:00';
1220
+		} else {
1221
+			$offset = '+00:00';
1222
+		}
1132 1223
 		$filter_query = $this->getFilter($filters,true,true);
1133 1224
 		if ($globalDBdriver == 'mysql') {
1134 1225
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -1174,7 +1265,9 @@  discard block
 block discarded – undo
1174 1265
 			date_default_timezone_set($globalTimezone);
1175 1266
 			$datetime = new DateTime();
1176 1267
 			$offset = $datetime->format('P');
1177
-		} else $offset = '+00:00';
1268
+		} else {
1269
+			$offset = '+00:00';
1270
+		}
1178 1271
 		$filter_query = $this->getFilter($filters,true,true);
1179 1272
 		if ($globalDBdriver == 'mysql') {
1180 1273
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -1222,7 +1315,9 @@  discard block
 block discarded – undo
1222 1315
 			date_default_timezone_set($globalTimezone);
1223 1316
 			$datetime = new DateTime();
1224 1317
 			$offset = $datetime->format('P');
1225
-		} else $offset = '+00:00';
1318
+		} else {
1319
+			$offset = '+00:00';
1320
+		}
1226 1321
 
1227 1322
 		if ($globalDBdriver == 'mysql') {
1228 1323
 			$query  = "SELECT YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count
@@ -1271,7 +1366,9 @@  discard block
 block discarded – undo
1271 1366
 			date_default_timezone_set($globalTimezone);
1272 1367
 			$datetime = new DateTime();
1273 1368
 			$offset = $datetime->format('P');
1274
-		} else $offset = '+00:00';
1369
+		} else {
1370
+			$offset = '+00:00';
1371
+		}
1275 1372
 		$filter_query = $this->getFilter($filters,true,true);
1276 1373
 		if ($globalDBdriver == 'mysql') {
1277 1374
 			$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
@@ -1320,7 +1417,9 @@  discard block
 block discarded – undo
1320 1417
 			date_default_timezone_set($globalTimezone);
1321 1418
 			$datetime = new DateTime();
1322 1419
 			$offset = $datetime->format('P');
1323
-		} else $offset = '+00:00';
1420
+		} else {
1421
+			$offset = '+00:00';
1422
+		}
1324 1423
 
1325 1424
 		$orderby_sql = '';
1326 1425
 		if ($orderby == "hour")
@@ -1389,7 +1488,9 @@  discard block
 block discarded – undo
1389 1488
 			date_default_timezone_set($globalTimezone);
1390 1489
 			$datetime = new DateTime($date);
1391 1490
 			$offset = $datetime->format('P');
1392
-		} else $offset = '+00:00';
1491
+		} else {
1492
+			$offset = '+00:00';
1493
+		}
1393 1494
 
1394 1495
 		if ($globalDBdriver == 'mysql') {
1395 1496
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1437,7 +1538,9 @@  discard block
 block discarded – undo
1437 1538
 			date_default_timezone_set($globalTimezone);
1438 1539
 			$datetime = new DateTime();
1439 1540
 			$offset = $datetime->format('P');
1440
-		} else $offset = '+00:00';
1541
+		} else {
1542
+			$offset = '+00:00';
1543
+		}
1441 1544
 
1442 1545
 		if ($globalDBdriver == 'mysql') {
1443 1546
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1502,8 +1605,11 @@  discard block
 block discarded – undo
1502 1605
 				$query_values = array_merge($query_values,array(':month' => $month));
1503 1606
 			}
1504 1607
 		}
1505
-		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1506
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1608
+		if (empty($query_values)) {
1609
+			$queryi .= $this->getFilter($filters);
1610
+		} else {
1611
+			$queryi .= $this->getFilter($filters,true,true).substr($query,4);
1612
+		}
1507 1613
 		
1508 1614
 		$sth = $this->db->prepare($queryi);
1509 1615
 		$sth->execute($query_values);
@@ -1540,8 +1646,11 @@  discard block
 block discarded – undo
1540 1646
 				$query_values = array_merge($query_values,array(':month' => $month));
1541 1647
 			}
1542 1648
 		}
1543
-		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1544
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1649
+		if (empty($query_values)) {
1650
+			$queryi .= $this->getFilter($filters);
1651
+		} else {
1652
+			$queryi .= $this->getFilter($filters,true,true).substr($query,4);
1653
+		}
1545 1654
 		
1546 1655
 		$sth = $this->db->prepare($queryi);
1547 1656
 		$sth->execute($query_values);
@@ -1563,7 +1672,9 @@  discard block
 block discarded – undo
1563 1672
 			date_default_timezone_set($globalTimezone);
1564 1673
 			$datetime = new DateTime();
1565 1674
 			$offset = $datetime->format('P');
1566
-		} else $offset = '+00:00';
1675
+		} else {
1676
+			$offset = '+00:00';
1677
+		}
1567 1678
 
1568 1679
 		if ($globalDBdriver == 'mysql') {
1569 1680
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1667,7 +1778,9 @@  discard block
 block discarded – undo
1667 1778
 	*/
1668 1779
 	public function parseDirection($direction = 0)
1669 1780
 	{
1670
-		if ($direction == '') $direction = 0;
1781
+		if ($direction == '') {
1782
+			$direction = 0;
1783
+		}
1671 1784
 		$direction_array = array();
1672 1785
 		$temp_array = array();
1673 1786
 
@@ -1756,7 +1869,9 @@  discard block
 block discarded – undo
1756 1869
 		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1757 1870
 	
1758 1871
 		$Connection = new Connection($this->db);
1759
-		if (!$Connection->tableExists('countries')) return '';
1872
+		if (!$Connection->tableExists('countries')) {
1873
+			return '';
1874
+		}
1760 1875
 	
1761 1876
 		try {
1762 1877
 			/*
@@ -1776,9 +1891,13 @@  discard block
 block discarded – undo
1776 1891
 			$sth->closeCursor();
1777 1892
 			if (count($row) > 0) {
1778 1893
 				return $row;
1779
-			} else return '';
1894
+			} else {
1895
+				return '';
1896
+			}
1780 1897
 		} catch (PDOException $e) {
1781
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
1898
+			if (isset($globalDebug) && $globalDebug) {
1899
+				echo 'Error : '.$e->getMessage()."\n";
1900
+			}
1782 1901
 			return '';
1783 1902
 		}
1784 1903
 	
@@ -1796,7 +1915,9 @@  discard block
 block discarded – undo
1796 1915
 		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
1797 1916
 	
1798 1917
 		$Connection = new Connection($this->db);
1799
-		if (!$Connection->tableExists('countries')) return '';
1918
+		if (!$Connection->tableExists('countries')) {
1919
+			return '';
1920
+		}
1800 1921
 	
1801 1922
 		try {
1802 1923
 			$query = "SELECT name,iso2,iso3 FROM countries WHERE iso2 = :iso2 LIMIT 1";
@@ -1808,9 +1929,13 @@  discard block
 block discarded – undo
1808 1929
 			$sth->closeCursor();
1809 1930
 			if (count($row) > 0) {
1810 1931
 				return $row;
1811
-			} else return '';
1932
+			} else {
1933
+				return '';
1934
+			}
1812 1935
 		} catch (PDOException $e) {
1813
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
1936
+			if (isset($globalDebug) && $globalDebug) {
1937
+				echo 'Error : '.$e->getMessage()."\n";
1938
+			}
1814 1939
 			return '';
1815 1940
 		}
1816 1941
 	
@@ -1828,7 +1953,9 @@  discard block
 block discarded – undo
1828 1953
 	{
1829 1954
 		global $globalBitlyAccessToken;
1830 1955
 		
1831
-		if ($globalBitlyAccessToken == '') return $url;
1956
+		if ($globalBitlyAccessToken == '') {
1957
+			return $url;
1958
+		}
1832 1959
         
1833 1960
 		$google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url;
1834 1961
 		
@@ -1904,7 +2031,9 @@  discard block
 block discarded – undo
1904 2031
 			}
1905 2032
 		}
1906 2033
 		$query .= " GROUP BY marine_output.type, marine_output.type_id ORDER BY marine_type_count DESC";
1907
-		if ($limit) $query .= " LIMIT 10 OFFSET 0";
2034
+		if ($limit) {
2035
+			$query .= " LIMIT 10 OFFSET 0";
2036
+		}
1908 2037
 		$sth = $this->db->prepare($query);
1909 2038
 		$sth->execute($query_values);
1910 2039
 		$marine_array = array();
@@ -1942,9 +2071,15 @@  discard block
 block discarded – undo
1942 2071
 				foreach ($q_array as $q_item){
1943 2072
 					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
1944 2073
 					$additional_query .= " AND (";
1945
-					if (is_int($q_item)) $additional_query .= "(marine_output.marine_id = '".$q_item."') OR ";
1946
-					if (is_int($q_item)) $additional_query .= "(marine_output.mmsi = '".$q_item."') OR ";
1947
-					if (is_int($q_item)) $additional_query .= "(marine_output.imo = '".$q_item."') OR ";
2074
+					if (is_int($q_item)) {
2075
+						$additional_query .= "(marine_output.marine_id = '".$q_item."') OR ";
2076
+					}
2077
+					if (is_int($q_item)) {
2078
+						$additional_query .= "(marine_output.mmsi = '".$q_item."') OR ";
2079
+					}
2080
+					if (is_int($q_item)) {
2081
+						$additional_query .= "(marine_output.imo = '".$q_item."') OR ";
2082
+					}
1948 2083
 					$additional_query .= "(marine_output.ident like '%".$q_item."%') OR ";
1949 2084
 					$additional_query .= ")";
1950 2085
 				}
@@ -1992,7 +2127,9 @@  discard block
 block discarded – undo
1992 2127
 				date_default_timezone_set($globalTimezone);
1993 2128
 				$datetime = new DateTime();
1994 2129
 				$offset = $datetime->format('P');
1995
-			} else $offset = '+00:00';
2130
+			} else {
2131
+				$offset = '+00:00';
2132
+			}
1996 2133
 			if ($date_array[1] != "")
1997 2134
 			{
1998 2135
 				$date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0]));
@@ -2019,8 +2156,12 @@  discard block
 block discarded – undo
2019 2156
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
2020 2157
 			{
2021 2158
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
2022
-			} else $limit_query = "";
2023
-		} else $limit_query = "";
2159
+			} else {
2160
+				$limit_query = "";
2161
+			}
2162
+		} else {
2163
+			$limit_query = "";
2164
+		}
2024 2165
 		if ($sort != "")
2025 2166
 		{
2026 2167
 			$search_orderby_array = $this->getOrderBy();
Please login to merge, or discard this patch.
require/class.MarineLive.php 4 patches
Doc Comments   +1 added lines, -5 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	/**
16 16
 	* Get SQL query part for filter used
17 17
 	* @param Array $filter the filter
18
-	* @return Array the SQL part
18
+	* @return string the SQL part
19 19
 	*/
20 20
 	public function getFilter($filter = array(),$where = false,$and = false) {
21 21
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
@@ -915,10 +915,6 @@  discard block
 block discarded – undo
915 915
 	*
916 916
 	* @param String $fammarine_id the ID from flightaware
917 917
 	* @param String $ident the flight ident
918
-	* @param String $aircraft_icao the aircraft type
919
-	* @param String $departure_airport_icao the departure airport
920
-	* @param String $arrival_airport_icao the arrival airport
921
-	* @return String success or false
922 918
 	*
923 919
 	*/
924 920
 	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 = '')
Please login to merge, or discard this patch.
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@  discard block
 block discarded – undo
13 13
 
14 14
 
15 15
 	/**
16
-	* Get SQL query part for filter used
17
-	* @param Array $filter the filter
18
-	* @return Array the SQL part
19
-	*/
16
+	 * Get SQL query part for filter used
17
+	 * @param Array $filter the filter
18
+	 * @return Array the SQL part
19
+	 */
20 20
 	public function getFilter($filter = array(),$where = false,$and = false) {
21 21
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
22 22
 		$filters = array();
@@ -96,11 +96,11 @@  discard block
 block discarded – undo
96 96
 	}
97 97
 
98 98
 	/**
99
-	* Gets all the spotter information based on the latest data entry
100
-	*
101
-	* @return Array the spotter information
102
-	*
103
-	*/
99
+	 * Gets all the spotter information based on the latest data entry
100
+	 *
101
+	 * @return Array the spotter information
102
+	 *
103
+	 */
104 104
 	public function getLiveMarineData($limit = '', $sort = '', $filter = array())
105 105
 	{
106 106
 		global $globalDBdriver, $globalLiveInterval;
@@ -143,11 +143,11 @@  discard block
 block discarded – undo
143 143
 	}
144 144
 
145 145
 	/**
146
-	* Gets Minimal Live Spotter data
147
-	*
148
-	* @return Array the spotter information
149
-	*
150
-	*/
146
+	 * Gets Minimal Live Spotter data
147
+	 *
148
+	 * @return Array the spotter information
149
+	 *
150
+	 */
151 151
 	public function getMinLiveMarineData($filter = array())
152 152
 	{
153 153
 		global $globalDBdriver, $globalLiveInterval;
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
 	}
178 178
 
179 179
 	/**
180
-	* Gets Minimal Live Spotter data since xx seconds
181
-	*
182
-	* @return Array the spotter information
183
-	*
184
-	*/
180
+	 * Gets Minimal Live Spotter data since xx seconds
181
+	 *
182
+	 * @return Array the spotter information
183
+	 *
184
+	 */
185 185
 	public function getMinLastLiveMarineData($coord = array(),$filter = array(), $limit = false)
186 186
 	{
187 187
 		global $globalDBdriver, $globalLiveInterval, $globalMap3DMarinesLimit, $globalArchive;
@@ -252,11 +252,11 @@  discard block
 block discarded – undo
252 252
 	}
253 253
 
254 254
 	/**
255
-	* Gets number of latest data entry
256
-	*
257
-	* @return String number of entry
258
-	*
259
-	*/
255
+	 * Gets number of latest data entry
256
+	 *
257
+	 * @return String number of entry
258
+	 *
259
+	 */
260 260
 	public function getLiveMarineCount($filter = array())
261 261
 	{
262 262
 		global $globalDBdriver, $globalLiveInterval;
@@ -281,11 +281,11 @@  discard block
 block discarded – undo
281 281
 	}
282 282
 
283 283
 	/**
284
-	* Gets all the spotter information based on the latest data entry and coord
285
-	*
286
-	* @return Array the spotter information
287
-	*
288
-	*/
284
+	 * Gets all the spotter information based on the latest data entry and coord
285
+	 *
286
+	 * @return Array the spotter information
287
+	 *
288
+	 */
289 289
 	public function getLiveMarineDatabyCoord($coord, $filter = array())
290 290
 	{
291 291
 		global $globalDBdriver, $globalLiveInterval;
@@ -309,11 +309,11 @@  discard block
 block discarded – undo
309 309
 	}
310 310
 
311 311
 	/**
312
-	* Gets all the spotter information based on the latest data entry and coord
313
-	*
314
-	* @return Array the spotter information
315
-	*
316
-	*/
312
+	 * Gets all the spotter information based on the latest data entry and coord
313
+	 *
314
+	 * @return Array the spotter information
315
+	 *
316
+	 */
317 317
 	public function getMinLiveMarineDatabyCoord($coord, $filter = array())
318 318
 	{
319 319
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
 	}
383 383
 
384 384
 	/**
385
-	* Gets all the spotter information based on a user's latitude and longitude
386
-	*
387
-	* @return Array the spotter information
388
-	*
389
-	*/
385
+	 * Gets all the spotter information based on a user's latitude and longitude
386
+	 *
387
+	 * @return Array the spotter information
388
+	 *
389
+	 */
390 390
 	public function getLatestMarineForLayar($lat, $lng, $radius, $interval)
391 391
 	{
392 392
 		$Marine = new Marine($this->db);
@@ -399,75 +399,75 @@  discard block
 block discarded – undo
399 399
 		if ($lng != '')
400 400
 		{
401 401
 			if (!is_numeric($lng))
402
-                        {
403
-                                return false;
404
-                        }
405
-                }
406
-
407
-                if ($radius != '')
408
-                {
409
-                        if (!is_numeric($radius))
410
-                        {
411
-                                return false;
412
-                        }
413
-                }
402
+						{
403
+								return false;
404
+						}
405
+				}
406
+
407
+				if ($radius != '')
408
+				{
409
+						if (!is_numeric($radius))
410
+						{
411
+								return false;
412
+						}
413
+				}
414 414
 		$additional_query = '';
415 415
 		if ($interval != '')
416
-                {
417
-                        if (!is_string($interval))
418
-                        {
419
-                                //$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
420
-			        return false;
421
-                        } else {
422
-                if ($interval == '1m')
423
-                {
424
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
425
-                } else if ($interval == '15m'){
426
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
427
-                } 
428
-            }
429
-                } else {
430
-         $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';   
431
-        }
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 
416
+				{
417
+						if (!is_string($interval))
418
+						{
419
+								//$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
420
+					return false;
421
+						} else {
422
+				if ($interval == '1m')
423
+				{
424
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
425
+				} else if ($interval == '15m'){
426
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
427
+				} 
428
+			}
429
+				} else {
430
+		 $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';   
431
+		}
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 
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
-                return $spotter_array;
443
-        }
442
+				return $spotter_array;
443
+		}
444 444
 
445 445
     
446
-        /**
447
-	* Gets all the spotter information based on a particular callsign
448
-	*
449
-	* @return Array the spotter information
450
-	*
451
-	*/
446
+		/**
447
+		 * Gets all the spotter information based on a particular callsign
448
+		 *
449
+		 * @return Array the spotter information
450
+		 *
451
+		 */
452 452
 	public function getLastLiveMarineDataByIdent($ident)
453 453
 	{
454 454
 		$Marine = new Marine($this->db);
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 460
 		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident),'',true);
461 461
 
462 462
 		return $spotter_array;
463 463
 	}
464 464
 
465
-        /**
466
-	* Gets all the spotter information based on a particular callsign
467
-	*
468
-	* @return Array the spotter information
469
-	*
470
-	*/
465
+		/**
466
+		 * Gets all the spotter information based on a particular callsign
467
+		 *
468
+		 * @return Array the spotter information
469
+		 *
470
+		 */
471 471
 	public function getDateLiveMarineDataByIdent($ident,$date)
472 472
 	{
473 473
 		$Marine = new Marine($this->db);
@@ -480,11 +480,11 @@  discard block
 block discarded – undo
480 480
 	}
481 481
 
482 482
 	/**
483
-	* Gets all the spotter information based on a particular MMSI
484
-	*
485
-	* @return Array the spotter information
486
-	*
487
-	*/
483
+	 * Gets all the spotter information based on a particular MMSI
484
+	 *
485
+	 * @return Array the spotter information
486
+	 *
487
+	 */
488 488
 	public function getDateLiveMarineDataByMMSI($mmsi,$date)
489 489
 	{
490 490
 		$Marine = new Marine($this->db);
@@ -496,51 +496,51 @@  discard block
 block discarded – undo
496 496
 		return $spotter_array;
497 497
 	}
498 498
 
499
-        /**
500
-	* Gets last spotter information based on a particular callsign
501
-	*
502
-	* @return Array the spotter information
503
-	*
504
-	*/
499
+		/**
500
+		 * Gets last spotter information based on a particular callsign
501
+		 *
502
+		 * @return Array the spotter information
503
+		 *
504
+		 */
505 505
 	public function getLastLiveMarineDataById($id)
506 506
 	{
507 507
 		$Marine = new Marine($this->db);
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 513
 		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id),'',true);
514 514
 
515 515
 		return $spotter_array;
516 516
 	}
517 517
 
518
-        /**
519
-	* Gets last spotter information based on a particular callsign
520
-	*
521
-	* @return Array the spotter information
522
-	*
523
-	*/
518
+		/**
519
+		 * Gets last spotter information based on a particular callsign
520
+		 *
521
+		 * @return Array the spotter information
522
+		 *
523
+		 */
524 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);
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 532
 		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
533 533
 
534 534
 		return $spotter_array;
535 535
 	}
536 536
 
537 537
 
538
-        /**
539
-	* Gets all the spotter information based on a particular id
540
-	*
541
-	* @return Array the spotter information
542
-	*
543
-	*/
538
+		/**
539
+		 * Gets all the spotter information based on a particular id
540
+		 *
541
+		 * @return Array the spotter information
542
+		 *
543
+		 */
544 544
 	public function getAllLiveMarineDataById($id,$liveinterval = false)
545 545
 	{
546 546
 		global $globalDBdriver, $globalLiveInterval;
@@ -568,18 +568,18 @@  discard block
 block discarded – undo
568 568
 		return $spotter_array;
569 569
 	}
570 570
 
571
-        /**
572
-	* Gets all the spotter information based on a particular ident
573
-	*
574
-	* @return Array the spotter information
575
-	*
576
-	*/
571
+		/**
572
+		 * Gets all the spotter information based on a particular ident
573
+		 *
574
+		 * @return Array the spotter information
575
+		 *
576
+		 */
577 577
 	public function getAllLiveMarineDataByIdent($ident)
578 578
 	{
579 579
 		date_default_timezone_set('UTC');
580 580
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
581 581
 		$query  = self::$global_query.' WHERE marine_live.ident = :ident';
582
-    		try {
582
+			try {
583 583
 			
584 584
 			$sth = $this->db->prepare($query);
585 585
 			$sth->execute(array(':ident' => $ident));
@@ -593,23 +593,23 @@  discard block
 block discarded – undo
593 593
 
594 594
 
595 595
 	/**
596
-	* Deletes all info in the table
597
-	*
598
-	* @return String success or false
599
-	*
600
-	*/
596
+	 * Deletes all info in the table
597
+	 *
598
+	 * @return String success or false
599
+	 *
600
+	 */
601 601
 	public function deleteLiveMarineData()
602 602
 	{
603 603
 		global $globalDBdriver;
604 604
 		if ($globalDBdriver == 'mysql') {
605 605
 			//$query  = "DELETE FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= marine_live.date";
606 606
 			$query  = 'DELETE FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= marine_live.date';
607
-            		//$query  = "DELETE FROM marine_live WHERE marine_live.id IN (SELECT marine_live.id FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= marine_live.date)";
607
+					//$query  = "DELETE FROM marine_live WHERE marine_live.id IN (SELECT marine_live.id FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= marine_live.date)";
608 608
 		} else {
609 609
 			$query  = "DELETE FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= marine_live.date";
610 610
 		}
611 611
         
612
-    		try {
612
+			try {
613 613
 			
614 614
 			$sth = $this->db->prepare($query);
615 615
 			$sth->execute();
@@ -621,18 +621,18 @@  discard block
 block discarded – undo
621 621
 	}
622 622
 
623 623
 	/**
624
-	* Deletes all info in the table for aircraft not seen since 2 HOUR
625
-	*
626
-	* @return String success or false
627
-	*
628
-	*/
624
+	 * Deletes all info in the table for aircraft not seen since 2 HOUR
625
+	 *
626
+	 * @return String success or false
627
+	 *
628
+	 */
629 629
 	public function deleteLiveMarineDataNotUpdated()
630 630
 	{
631 631
 		global $globalDBdriver, $globalDebug;
632 632
 		if ($globalDBdriver == 'mysql') {
633 633
 			//$query = 'SELECT fammarine_id FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= marine_live.date AND marine_live.fammarine_id NOT IN (SELECT fammarine_id FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < marine_live.date) LIMIT 800 OFFSET 0';
634
-    			$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
635
-    			try {
634
+				$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
635
+				try {
636 636
 				
637 637
 				$sth = $this->db->prepare($query);
638 638
 				$sth->execute();
@@ -640,8 +640,8 @@  discard block
 block discarded – undo
640 640
 				return "error";
641 641
 			}
642 642
 			$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
643
-                        $i = 0;
644
-                        $j =0;
643
+						$i = 0;
644
+						$j =0;
645 645
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
646 646
 			foreach($all as $row)
647 647
 			{
@@ -649,20 +649,20 @@  discard block
 block discarded – undo
649 649
 				$j++;
650 650
 				if ($j == 30) {
651 651
 					if ($globalDebug) echo ".";
652
-				    	try {
652
+						try {
653 653
 						
654 654
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
655 655
 						$sth->execute();
656 656
 					} catch(PDOException $e) {
657 657
 						return "error";
658 658
 					}
659
-                                	$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
660
-                                	$j = 0;
659
+									$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
660
+									$j = 0;
661 661
 				}
662 662
 				$query_delete .= "'".$row['fammarine_id']."',";
663 663
 			}
664 664
 			if ($i > 0) {
665
-    				try {
665
+					try {
666 666
 					
667 667
 					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
668 668
 					$sth->execute();
@@ -673,9 +673,9 @@  discard block
 block discarded – undo
673 673
 			return "success";
674 674
 		} elseif ($globalDBdriver == 'pgsql') {
675 675
 			//$query = "SELECT fammarine_id FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= marine_live.date AND marine_live.fammarine_id NOT IN (SELECT fammarine_id FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < marine_live.date) LIMIT 800 OFFSET 0";
676
-    			//$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
677
-    			$query = "DELETE FROM marine_live WHERE fammarine_id IN (SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
678
-    			try {
676
+				//$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
677
+				$query = "DELETE FROM marine_live WHERE fammarine_id IN (SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
678
+				try {
679 679
 				
680 680
 				$sth = $this->db->prepare($query);
681 681
 				$sth->execute();
@@ -719,17 +719,17 @@  discard block
 block discarded – undo
719 719
 	}
720 720
 
721 721
 	/**
722
-	* Deletes all info in the table for an ident
723
-	*
724
-	* @return String success or false
725
-	*
726
-	*/
722
+	 * Deletes all info in the table for an ident
723
+	 *
724
+	 * @return String success or false
725
+	 *
726
+	 */
727 727
 	public function deleteLiveMarineDataByIdent($ident)
728 728
 	{
729 729
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
730 730
 		$query  = 'DELETE FROM marine_live WHERE ident = :ident';
731 731
         
732
-    		try {
732
+			try {
733 733
 			
734 734
 			$sth = $this->db->prepare($query);
735 735
 			$sth->execute(array(':ident' => $ident));
@@ -741,17 +741,17 @@  discard block
 block discarded – undo
741 741
 	}
742 742
 
743 743
 	/**
744
-	* Deletes all info in the table for an id
745
-	*
746
-	* @return String success or false
747
-	*
748
-	*/
744
+	 * Deletes all info in the table for an id
745
+	 *
746
+	 * @return String success or false
747
+	 *
748
+	 */
749 749
 	public function deleteLiveMarineDataById($id)
750 750
 	{
751 751
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
752 752
 		$query  = 'DELETE FROM marine_live WHERE fammarine_id = :id';
753 753
         
754
-    		try {
754
+			try {
755 755
 			
756 756
 			$sth = $this->db->prepare($query);
757 757
 			$sth->execute(array(':id' => $id));
@@ -764,11 +764,11 @@  discard block
 block discarded – undo
764 764
 
765 765
 
766 766
 	/**
767
-	* Gets the marine race
768
-	*
769
-	* @return String the ident
770
-	*
771
-	*/
767
+	 * Gets the marine race
768
+	 *
769
+	 * @return String the ident
770
+	 *
771
+	 */
772 772
 	public function getAllRaces()
773 773
 	{
774 774
 		$query  = 'SELECT DISTINCT marine_live.race_id, marine_live.race_name FROM marine_live ORDER BY marine_live.race_name';
@@ -779,11 +779,11 @@  discard block
 block discarded – undo
779 779
 	}
780 780
 
781 781
 	/**
782
-	* Gets the aircraft ident within the last hour
783
-	*
784
-	* @return String the ident
785
-	*
786
-	*/
782
+	 * Gets the aircraft ident within the last hour
783
+	 *
784
+	 * @return String the ident
785
+	 *
786
+	 */
787 787
 	public function getIdentFromLastHour($ident)
788 788
 	{
789 789
 		global $globalDBdriver, $globalTimezone;
@@ -809,14 +809,14 @@  discard block
 block discarded – undo
809 809
 			$ident_result = $row['ident'];
810 810
 		}
811 811
 		return $ident_result;
812
-        }
812
+		}
813 813
 
814 814
 	/**
815
-	* Check recent aircraft
816
-	*
817
-	* @return String the ident
818
-	*
819
-	*/
815
+	 * Check recent aircraft
816
+	 *
817
+	 * @return String the ident
818
+	 *
819
+	 */
820 820
 	public function checkIdentRecent($ident)
821 821
 	{
822 822
 		global $globalDBdriver, $globalTimezone;
@@ -842,14 +842,14 @@  discard block
 block discarded – undo
842 842
 			$ident_result = $row['fammarine_id'];
843 843
 		}
844 844
 		return $ident_result;
845
-        }
845
+		}
846 846
 
847 847
 	/**
848
-	* Check recent aircraft by id
849
-	*
850
-	* @return String the ident
851
-	*
852
-	*/
848
+	 * Check recent aircraft by id
849
+	 *
850
+	 * @return String the ident
851
+	 *
852
+	 */
853 853
 	public function checkIdRecent($id)
854 854
 	{
855 855
 		global $globalDBdriver, $globalTimezone;
@@ -875,14 +875,14 @@  discard block
 block discarded – undo
875 875
 			$ident_result = $row['fammarine_id'];
876 876
 		}
877 877
 		return $ident_result;
878
-        }
878
+		}
879 879
 
880 880
 	/**
881
-	* Check recent aircraft by mmsi
882
-	*
883
-	* @return String the ident
884
-	*
885
-	*/
881
+	 * Check recent aircraft by mmsi
882
+	 *
883
+	 * @return String the ident
884
+	 *
885
+	 */
886 886
 	public function checkMMSIRecent($mmsi)
887 887
 	{
888 888
 		global $globalDBdriver, $globalTimezone;
@@ -908,19 +908,19 @@  discard block
 block discarded – undo
908 908
 			$ident_result = $row['fammarine_id'];
909 909
 		}
910 910
 		return $ident_result;
911
-        }
911
+		}
912 912
 
913 913
 	/**
914
-	* Adds a new spotter data
915
-	*
916
-	* @param String $fammarine_id the ID from flightaware
917
-	* @param String $ident the flight ident
918
-	* @param String $aircraft_icao the aircraft type
919
-	* @param String $departure_airport_icao the departure airport
920
-	* @param String $arrival_airport_icao the arrival airport
921
-	* @return String success or false
922
-	*
923
-	*/
914
+	 * Adds a new spotter data
915
+	 *
916
+	 * @param String $fammarine_id the ID from flightaware
917
+	 * @param String $ident the flight ident
918
+	 * @param String $aircraft_icao the aircraft type
919
+	 * @param String $departure_airport_icao the departure airport
920
+	 * @param String $arrival_airport_icao the arrival airport
921
+	 * @return String success or false
922
+	 *
923
+	 */
924 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;
@@ -998,10 +998,10 @@  discard block
 block discarded – undo
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;
1003
-            	if ($arrival_date == '') $arrival_date = NULL;
1004
-            	$query = '';
1001
+				if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1002
+				if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1003
+				if ($arrival_date == '') $arrival_date = NULL;
1004
+				$query = '';
1005 1005
 		if ($globalArchive) {
1006 1006
 			if ($globalDebug) echo '-- Delete previous data -- ';
1007 1007
 			$query .= 'DELETE FROM marine_live WHERE fammarine_id = :fammarine_id;';
Please login to merge, or discard this 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.
Braces   +119 added lines, -40 removed lines patch added patch discarded remove patch
@@ -8,7 +8,9 @@  discard block
 block discarded – undo
8 8
 	public function __construct($dbc = null) {
9 9
 		$Connection = new Connection($dbc);
10 10
 		$this->db = $Connection->db();
11
-		if ($this->db === null) die('Error: No DB connection. (MarineLive)');
11
+		if ($this->db === null) {
12
+			die('Error: No DB connection. (MarineLive)');
13
+		}
12 14
 	}
13 15
 
14 16
 
@@ -30,7 +32,9 @@  discard block
 block discarded – undo
30 32
 		if (isset($filter[0]['source'])) {
31 33
 			$filters = array_merge($filters,$filter);
32 34
 		}
33
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
35
+		if (is_array($globalFilter)) {
36
+			$filter = array_merge($filter,$globalFilter);
37
+		}
34 38
 		$filter_query_join = '';
35 39
 		$filter_query_where = '';
36 40
 		foreach($filters as $flt) {
@@ -86,8 +90,11 @@  discard block
 block discarded – undo
86 90
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
87 91
 			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
88 92
 		}
89
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
90
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
93
+		if ($filter_query_where == '' && $where) {
94
+			$filter_query_where = ' WHERE';
95
+		} elseif ($filter_query_where != '' && $and) {
96
+			$filter_query_where .= ' AND';
97
+		}
91 98
 		if ($filter_query_where != '') {
92 99
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
93 100
 		}
@@ -128,9 +135,13 @@  discard block
 block discarded – undo
128 135
 				$orderby_query = ' '.$search_orderby_array[$sort]['sql'];
129 136
 			}
130 137
 		}
131
-		if ($orderby_query == '') $orderby_query= ' ORDER BY date DESC';
138
+		if ($orderby_query == '') {
139
+			$orderby_query= ' ORDER BY date DESC';
140
+		}
132 141
 
133
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
142
+		if (!isset($globalLiveInterval)) {
143
+			$globalLiveInterval = '200';
144
+		}
134 145
 		if ($globalDBdriver == 'mysql') {
135 146
 			//$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 30 SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate";
136 147
 			$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'.$filter_query.$orderby_query;
@@ -155,7 +166,9 @@  discard block
 block discarded – undo
155 166
 
156 167
 		$filter_query = $this->getFilter($filter,true,true);
157 168
 
158
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
169
+		if (!isset($globalLiveInterval)) {
170
+			$globalLiveInterval = '200';
171
+		}
159 172
 		if ($globalDBdriver == 'mysql') {
160 173
 			$query  = 'SELECT marine_live.mmsi, marine_live.ident, marine_live.type,marine_live.fammarine_id, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name 
161 174
 			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'.$filter_query." marine_live.latitude <> 0 AND marine_live.longitude <> 0";
@@ -196,48 +209,72 @@  discard block
 block discarded – undo
196 209
 		}
197 210
 		$filter_query = $this->getFilter($filter,true,true);
198 211
 
199
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
200
-		if (!isset($globalMap3DMarinesLimit) || $globalMap3DMarinesLimit == '') $globalMap3DMarinesLimit = '300';
212
+		if (!isset($globalLiveInterval)) {
213
+			$globalLiveInterval = '200';
214
+		}
215
+		if (!isset($globalMap3DMarinesLimit) || $globalMap3DMarinesLimit == '') {
216
+			$globalMap3DMarinesLimit = '300';
217
+		}
201 218
 		if ($globalDBdriver == 'mysql') {
202 219
 			if (isset($globalArchive) && $globalArchive === TRUE) {
203 220
 				$query  = 'SELECT * FROM (SELECT marine_archive.ident, marine_archive.fammarine_id,marine_archive.type, marine_archive.latitude, marine_archive.longitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.date, marine_archive.format_source, marine_live.captain_name 
204 221
 				    FROM marine_archive INNER JOIN (SELECT fammarine_id FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date) l ON l.fammarine_id = marine_archive.fammarine_id ";
205
-				if ($usecoord) $query .= "AND marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
222
+				if ($usecoord) {
223
+					$query .= "AND marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
224
+				}
206 225
 				$query .= "UNION
207 226
 				    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 
208 227
 				    FROM marine_live".$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date";
209
-				if ($usecoord) $query .= " AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong;
228
+				if ($usecoord) {
229
+					$query .= " AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong;
230
+				}
210 231
 				$query .= ") AS marine 
211 232
 				    WHERE latitude <> '0' AND longitude <> '0' 
212 233
 				    ORDER BY fammarine_id, date";
213
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
234
+				if ($limit) {
235
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
236
+				}
214 237
 			} else {
215 238
 				$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 
216 239
 				    FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date ";
217
-				if ($usecoord) $query .= "AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
240
+				if ($usecoord) {
241
+					$query .= "AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
242
+				}
218 243
 				$query .= "AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
219 244
 				ORDER BY marine_live.fammarine_id, marine_live.date";
220
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
245
+				if ($limit) {
246
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
247
+				}
221 248
 			}
222 249
 		} else {
223 250
 			if (isset($globalArchive) && $globalArchive === TRUE) {
224 251
 				$query  = "SELECT * FROM (SELECT marine_archive.ident, marine_archive.fammarine_id, marine_archive.type,marine_archive.latitude, marine_archive.longitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.date, marine_archive.format_source, marine_live.captain_name 
225 252
 				    FROM marine_archive INNER JOIN (SELECT fammarine_id FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date) l ON l.fammarine_id = marine_archive.fammarine_id ";
226
-				if ($usecoord) $query .= "AND marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
253
+				if ($usecoord) {
254
+					$query .= "AND marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
255
+				}
227 256
 				$query .= "UNION
228 257
 				    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 
229 258
 				    FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date";
230
-				if ($usecoord) $query .= " AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong;
259
+				if ($usecoord) {
260
+					$query .= " AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong;
261
+				}
231 262
 				$query .= ") AS marine WHERE latitude <> '0' AND longitude <> '0' ";
232 263
 				$query .= "ORDER BY fammarine_id, date";
233
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
264
+				if ($limit) {
265
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
266
+				}
234 267
 			} else {
235 268
 				$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 
236 269
 				    FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date ";
237
-				if ($usecoord) $query .= "AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
270
+				if ($usecoord) {
271
+					$query .= "AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
272
+				}
238 273
 				$query .= "AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
239 274
 				ORDER BY marine_live.fammarine_id, marine_live.date";
240
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
275
+				if ($limit) {
276
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
277
+				}
241 278
 			}
242 279
 		}
243 280
 		try {
@@ -262,7 +299,9 @@  discard block
 block discarded – undo
262 299
 		global $globalDBdriver, $globalLiveInterval;
263 300
 		$filter_query = $this->getFilter($filter,true,true);
264 301
 
265
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
302
+		if (!isset($globalLiveInterval)) {
303
+			$globalLiveInterval = '200';
304
+		}
266 305
 		if ($globalDBdriver == 'mysql') {
267 306
 			$query = 'SELECT COUNT(DISTINCT marine_live.fammarine_id) as nb FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
268 307
 		} else {
@@ -290,7 +329,9 @@  discard block
 block discarded – undo
290 329
 	{
291 330
 		global $globalDBdriver, $globalLiveInterval;
292 331
 		$Marine = new Marine($this->db);
293
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
332
+		if (!isset($globalLiveInterval)) {
333
+			$globalLiveInterval = '200';
334
+		}
294 335
 		$filter_query = $this->getFilter($filter);
295 336
 
296 337
 		if (is_array($coord)) {
@@ -298,7 +339,9 @@  discard block
 block discarded – undo
298 339
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
299 340
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
300 341
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
301
-		} else return array();
342
+		} else {
343
+			return array();
344
+		}
302 345
 		if ($globalDBdriver == 'mysql') {
303 346
 			$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;
304 347
 		} else {
@@ -318,7 +361,9 @@  discard block
 block discarded – undo
318 361
 	{
319 362
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
320 363
 		$Marine = new Marine($this->db);
321
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
364
+		if (!isset($globalLiveInterval)) {
365
+			$globalLiveInterval = '200';
366
+		}
322 367
 		$filter_query = $this->getFilter($filter,true,true);
323 368
 
324 369
 		if (is_array($coord)) {
@@ -326,7 +371,9 @@  discard block
 block discarded – undo
326 371
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
327 372
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
328 373
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
329
-		} else return array();
374
+		} else {
375
+			return array();
376
+		}
330 377
 		/*
331 378
 		if ($globalDBdriver == 'mysql') {
332 379
 			$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 
@@ -549,11 +596,15 @@  discard block
 block discarded – undo
549 596
 		//$query  = self::$global_query.' WHERE marine_live.fammarine_id = :id ORDER BY date';
550 597
 		if ($globalDBdriver == 'mysql') {
551 598
 			$query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id';
552
-			if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
599
+			if ($liveinterval) {
600
+				$query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
601
+			}
553 602
 			$query .= ' ORDER BY date';
554 603
 		} else {
555 604
 			$query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id';
556
-			if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
605
+			if ($liveinterval) {
606
+				$query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
607
+			}
557 608
 			$query .= ' ORDER BY date';
558 609
 		}
559 610
 
@@ -648,7 +699,9 @@  discard block
 block discarded – undo
648 699
 				$i++;
649 700
 				$j++;
650 701
 				if ($j == 30) {
651
-					if ($globalDebug) echo ".";
702
+					if ($globalDebug) {
703
+						echo ".";
704
+					}
652 705
 				    	try {
653 706
 						
654 707
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
@@ -943,7 +996,9 @@  discard block
 block discarded – undo
943 996
 			{
944 997
 				return false;
945 998
 			}
946
-		} else return '';
999
+		} else {
1000
+			return '';
1001
+		}
947 1002
 
948 1003
 		if ($longitude != '')
949 1004
 		{
@@ -951,7 +1006,9 @@  discard block
 block discarded – undo
951 1006
 			{
952 1007
 				return false;
953 1008
 			}
954
-		} else return '';
1009
+		} else {
1010
+			return '';
1011
+		}
955 1012
 
956 1013
 
957 1014
 		if ($heading != '')
@@ -960,7 +1017,9 @@  discard block
 block discarded – undo
960 1017
 			{
961 1018
 				return false;
962 1019
 			}
963
-		} else $heading = 0;
1020
+		} else {
1021
+			$heading = 0;
1022
+		}
964 1023
 
965 1024
 		if ($groundspeed != '')
966 1025
 		{
@@ -968,9 +1027,13 @@  discard block
 block discarded – undo
968 1027
 			{
969 1028
 				return false;
970 1029
 			}
971
-		} else $groundspeed = 0;
1030
+		} else {
1031
+			$groundspeed = 0;
1032
+		}
972 1033
 		date_default_timezone_set('UTC');
973
-		if ($date == '') $date = date("Y-m-d H:i:s", time());
1034
+		if ($date == '') {
1035
+			$date = date("Y-m-d H:i:s", time());
1036
+		}
974 1037
 
975 1038
         
976 1039
 		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
@@ -995,15 +1058,27 @@  discard block
 block discarded – undo
995 1058
 		$captain_name = filter_var($captain_name,FILTER_SANITIZE_STRING);
996 1059
 		$race_id = filter_var($race_id,FILTER_SANITIZE_STRING);
997 1060
 		$race_name = filter_var($race_name,FILTER_SANITIZE_STRING);
998
-		if ($typeid == '') $typeid = NULL;
999
-		if ($statusid == '') $statusid = NULL;
1061
+		if ($typeid == '') {
1062
+			$typeid = NULL;
1063
+		}
1064
+		if ($statusid == '') {
1065
+			$statusid = NULL;
1066
+		}
1000 1067
 
1001
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1002
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1003
-            	if ($arrival_date == '') $arrival_date = NULL;
1068
+            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) {
1069
+            		$groundspeed = 0;
1070
+            	}
1071
+            	if ($heading == '' || $Common->isInteger($heading) === false ) {
1072
+            		$heading = 0;
1073
+            	}
1074
+            	if ($arrival_date == '') {
1075
+            		$arrival_date = NULL;
1076
+            	}
1004 1077
             	$query = '';
1005 1078
 		if ($globalArchive) {
1006
-			if ($globalDebug) echo '-- Delete previous data -- ';
1079
+			if ($globalDebug) {
1080
+				echo '-- Delete previous data -- ';
1081
+			}
1007 1082
 			$query .= 'DELETE FROM marine_live WHERE fammarine_id = :fammarine_id;';
1008 1083
 		}
1009 1084
 		$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) 
@@ -1018,10 +1093,14 @@  discard block
 block discarded – undo
1018 1093
 		}
1019 1094
 		
1020 1095
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
1021
-			if ($globalDebug) echo '(Add to Marine archive : ';
1096
+			if ($globalDebug) {
1097
+				echo '(Add to Marine archive : ';
1098
+			}
1022 1099
 			$MarineArchive = new MarineArchive($this->db);
1023 1100
 			$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
-			if ($globalDebug) echo $result.')';
1101
+			if ($globalDebug) {
1102
+				echo $result.')';
1103
+			}
1025 1104
 		}
1026 1105
 		return "success";
1027 1106
 	}
Please login to merge, or discard this patch.
js/map-marine.2d.js.php 1 patch
Braces   +36 added lines, -9 removed lines patch added patch discarded remove patch
@@ -5,11 +5,18 @@  discard block
 block discarded – undo
5 5
 setcookie("MapFormat",'2d');
6 6
 
7 7
 // Compressed GeoJson is used if true
8
-if (!isset($globalJsonCompress)) $compress = true;
9
-else $compress = $globalJsonCompress;
10
-if (isset($_COOKIE['MarineIconColor'])) $MarineIconColor = $_COOKIE['MarineIconColor'];
11
-elseif (isset($globalMarineIconColor)) $MarineIconColor = $globalMarineIconColor;
12
-else $MarineIconColor = '1a3151';
8
+if (!isset($globalJsonCompress)) {
9
+	$compress = true;
10
+} else {
11
+	$compress = $globalJsonCompress;
12
+}
13
+if (isset($_COOKIE['MarineIconColor'])) {
14
+	$MarineIconColor = $_COOKIE['MarineIconColor'];
15
+} elseif (isset($globalMarineIconColor)) {
16
+	$MarineIconColor = $globalMarineIconColor;
17
+} else {
18
+	$MarineIconColor = '1a3151';
19
+}
13 20
 
14 21
 ?>
15 22
 
@@ -181,7 +188,12 @@  discard block
 block discarded – undo
181 188
 <?php
182 189
 		} else {
183 190
 ?>
184
-		    var movingtime = Math.round(<?php if (isset($archiveupdatetime)) print $archiveupdatetime*1000; else print $globalMapRefresh*1000+20000; ?>+feature.properties.sqt*1000);
191
+		    var movingtime = Math.round(<?php if (isset($archiveupdatetime)) {
192
+	print $archiveupdatetime*1000;
193
+} else {
194
+	print $globalMapRefresh*1000+20000;
195
+}
196
+?>+feature.properties.sqt*1000);
185 197
 		    return new L.Marker.movingMarker([latLng, feature.properties.nextlatlon],[movingtime],{
186 198
 <?php
187 199
 		}
@@ -238,7 +250,12 @@  discard block
 block discarded – undo
238 250
 <?php
239 251
 		} else {
240 252
 ?>
241
-			    var movingtime = Math.round(<?php if (isset($archiveupdatetime)) print $archiveupdatetime*1000; else print $globalMapRefresh*1000+20000; ?>+feature.properties.sqt*1000);
253
+			    var movingtime = Math.round(<?php if (isset($archiveupdatetime)) {
254
+	print $archiveupdatetime*1000;
255
+} else {
256
+	print $globalMapRefresh*1000+20000;
257
+}
258
+?>+feature.properties.sqt*1000);
242 259
 			    return new L.Marker.movingMarker([latLng, feature.properties.nextlatlon],[movingtime],{
243 260
 <?php
244 261
 		}
@@ -294,7 +311,12 @@  discard block
 block discarded – undo
294 311
 <?php
295 312
 		} else {
296 313
 ?>
297
-			    var movingtime = Math.round(<?php if (isset($archiveupdatetime)) print $archiveupdatetime*1000; else print $globalMapRefresh*1000+20000; ?>+feature.properties.sqt*1000);
314
+			    var movingtime = Math.round(<?php if (isset($archiveupdatetime)) {
315
+	print $archiveupdatetime*1000;
316
+} else {
317
+	print $globalMapRefresh*1000+20000;
318
+}
319
+?>+feature.properties.sqt*1000);
298 320
 			    return new L.Marker.movingMarker([latLng, feature.properties.nextlatlon],[movingtime],{
299 321
 <?php
300 322
 		}
@@ -702,7 +724,12 @@  discard block
 block discarded – undo
702 724
 } else {
703 725
 	//then load it again every 30 seconds
704 726
 	reloadMarinePage = setInterval(
705
-	function(){if (noTimeout) getLiveMarineData(0)},<?php if (isset($globalMapRefresh)) print $globalMapRefresh*1000; else print '30000'; ?>);
727
+	function(){if (noTimeout) getLiveMarineData(0)},<?php if (isset($globalMapRefresh)) {
728
+	print $globalMapRefresh*1000;
729
+} else {
730
+	print '30000';
731
+}
732
+?>);
706 733
 }
707 734
 
708 735
 if (getCookie('openseamap') == 'true') loadOpenSeaMap(getCookie('openseamap'));
Please login to merge, or discard this patch.
js/map.2d.js.php 1 patch
Braces   +134 added lines, -30 removed lines patch added patch discarded remove patch
@@ -4,10 +4,15 @@  discard block
 block discarded – undo
4 4
 
5 5
 setcookie("MapFormat",'2d');
6 6
 
7
-if (!isset($globalOpenWeatherMapKey)) $globalOpenWeatherMapKey = '';
7
+if (!isset($globalOpenWeatherMapKey)) {
8
+	$globalOpenWeatherMapKey = '';
9
+}
8 10
 // Compressed GeoJson is used if true
9
-if (!isset($globalJsonCompress)) $compress = true;
10
-else $compress = $globalJsonCompress;
11
+if (!isset($globalJsonCompress)) {
12
+	$compress = true;
13
+} else {
14
+	$compress = $globalJsonCompress;
15
+}
11 16
 
12 17
 /*
13 18
 if (isset($_COOKIE['archive_begin']) && $_COOKIE['archive_begin'] != '') {
@@ -119,7 +124,17 @@  discard block
 block discarded – undo
119 124
 	}
120 125
 
121 126
 	//create the map
122
-	map = L.map('archive-map', { zoomControl:false }).setView([<?php if (isset($latitude)) print $latitude; else print $globalCenterLatitude; ?>,<?php if (isset($longitude)) print $longitude; else print $globalCenterLongitude; ?>], zoom);
127
+	map = L.map('archive-map', { zoomControl:false }).setView([<?php if (isset($latitude)) {
128
+	print $latitude;
129
+} else {
130
+	print $globalCenterLatitude;
131
+}
132
+?>,<?php if (isset($longitude)) {
133
+	print $longitude;
134
+} else {
135
+	print $globalCenterLongitude;
136
+}
137
+?>], zoom);
123 138
 <?php
124 139
 	} else {
125 140
 		if ((isset($globalCenterLatitude) && $globalCenterLatitude != '' && isset($globalCenterLongitude) && $globalCenterLongitude != '') || isset($_COOKIE['lastcentercoord'])) {
@@ -145,9 +160,21 @@  discard block
 block discarded – undo
145 160
 	     || navigator.userAgent.match(/BlackBerry/i)
146 161
 	     || navigator.userAgent.match(/Windows Phone/i))
147 162
 	{
148
-		var zoom = <?php if (isset($viewzoom) && $viewzoom == $globalLiveZoom) print $viewzoom-1; elseif (isset($viewzoom)) print $viewzoom; else print '8'; ?>;
163
+		var zoom = <?php if (isset($viewzoom) && $viewzoom == $globalLiveZoom) {
164
+	print $viewzoom-1;
165
+} elseif (isset($viewzoom)) {
166
+	print $viewzoom;
167
+} else {
168
+	print '8';
169
+}
170
+?>;
149 171
 	} else {
150
-		var zoom = <?php if (isset($viewzoom)) print $viewzoom; else print '9'; ?>;
172
+		var zoom = <?php if (isset($viewzoom)) {
173
+	print $viewzoom;
174
+} else {
175
+	print '9';
176
+}
177
+?>;
151 178
 	}
152 179
 
153 180
 	//create the map
@@ -173,16 +200,27 @@  discard block
 block discarded – undo
173 200
 	bounds = L.latLngBounds(southWest,northEast);
174 201
 	//a few title layers
175 202
 <?php
176
-	if (isset($_COOKIE['MapType'])) $MapType = $_COOKIE['MapType'];
177
-	else $MapType = $globalMapProvider;
203
+	if (isset($_COOKIE['MapType'])) {
204
+		$MapType = $_COOKIE['MapType'];
205
+	} else {
206
+		$MapType = $globalMapProvider;
207
+	}
178 208
 
179 209
 	if ($MapType == 'Mapbox') {
180
-		if ($_COOKIE['MapTypeId'] == 'default') $MapBoxId = $globalMapboxId;
181
-		else $MapBoxId = $_COOKIE['MapTypeId'];
182
-?>
210
+		if ($_COOKIE['MapTypeId'] == 'default') {
211
+			$MapBoxId = $globalMapboxId;
212
+		} else {
213
+			$MapBoxId = $_COOKIE['MapTypeId'];
214
+		}
215
+		?>
183 216
 	L.tileLayer('https://{s}.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={token}', {
184 217
 	    maxZoom: 18,
185
-	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) print 'false'; else print 'true'; ?>,
218
+	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) {
219
+	print 'false';
220
+} else {
221
+	print 'true';
222
+}
223
+?>,
186 224
 	    attribution: '© <a href="https://www.mapbox.com/about/maps/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> <strong><a href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a></strong>',
187 225
 	    id: '<?php print $MapBoxId; ?>',
188 226
 	    token: '<?php print $globalMapboxToken; ?>'
@@ -201,7 +239,12 @@  discard block
 block discarded – undo
201 239
 ?>
202 240
 	L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
203 241
 	    maxZoom: 18,
204
-	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) print 'false'; else print 'true'; ?>,
242
+	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) {
243
+	print 'false';
244
+} else {
245
+	print 'true';
246
+}
247
+?>,
205 248
 	    attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
206 249
 	      '<a href="www.openstreetmap.org/copyright">Open Database Licence</a>'
207 250
 	}).addTo(map);
@@ -210,7 +253,12 @@  discard block
 block discarded – undo
210 253
 ?>
211 254
 	L.tileLayer('https://tiles.openseamap.org/seamark/{z}/{x}/{y}.png', {
212 255
 	    maxZoom: 18,
213
-	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) print 'false'; else print 'true'; ?>,
256
+	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) {
257
+	print 'false';
258
+} else {
259
+	print 'true';
260
+}
261
+?>,
214 262
 	    attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
215 263
 		'&copy; <a href="http://openseamap.org">OpenSeaMap</a> contributors, ' +
216 264
 	      '<a href="www.openstreetmap.org/copyright">Open Database Licence</a>'
@@ -220,7 +268,12 @@  discard block
 block discarded – undo
220 268
 ?>
221 269
 	L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}', {
222 270
 	    maxZoom: 18,
223
-	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) print 'false'; else print 'true'; ?>,
271
+	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) {
272
+	print 'false';
273
+} else {
274
+	print 'true';
275
+}
276
+?>,
224 277
 	    attribution: 'Tiles &copy; Esri &mdash; Sources: Esri, DeLorme, NAVTEQ, USGS, Intermap, iPC, NRCAN, Esri Japan, METI, Esri China (Hong Kong), Esri (Thailand), TomTom, 2012'
225 278
 	}).addTo(map);
226 279
 <?php
@@ -228,7 +281,12 @@  discard block
 block discarded – undo
228 281
 ?>
229 282
 	L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
230 283
 	    maxZoom: 18,
231
-	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) print 'false'; else print 'true'; ?>,
284
+	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) {
285
+	print 'false';
286
+} else {
287
+	print 'true';
288
+}
289
+?>,
232 290
 	    attribution: 'Tiles &copy; Esri &mdash; Sources: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
233 291
 	}).addTo(map);
234 292
 <?php
@@ -236,7 +294,12 @@  discard block
 block discarded – undo
236 294
 ?>
237 295
 	L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer/tile/{z}/{y}/{x}', {
238 296
 	    maxZoom: 18,
239
-	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) print 'false'; else print 'true'; ?>,
297
+	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) {
298
+	print 'false';
299
+} else {
300
+	print 'true';
301
+}
302
+?>,
240 303
 	    attribution: 'Tiles &copy; Esri &mdash; Sources: GEBCO, NOAA, CHS, OSU, UNH, CSUMB, National Geographic, DeLorme, NAVTEQ, and Esri'
241 304
 	}).addTo(map);
242 305
 <?php
@@ -244,7 +307,12 @@  discard block
 block discarded – undo
244 307
 ?>
245 308
 	L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{z}/{y}/{x}', {
246 309
 	    maxZoom: 18,
247
-	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) print 'false'; else print 'true'; ?>,
310
+	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) {
311
+	print 'false';
312
+} else {
313
+	print 'true';
314
+}
315
+?>,
248 316
 	    attribution: 'Tiles &copy; Esri &mdash; Sources: National Geographic, Esri, DeLorme, NAVTEQ, UNEP-WCMC, USGS, NASA, ESA, METI, NRCAN, GEBCO, NOAA, iPC'
249 317
 	}).addTo(map);
250 318
 <?php
@@ -289,20 +357,26 @@  discard block
 block discarded – undo
289 357
 	map.addLayer(yandexLayer);
290 358
 <?php
291 359
 	} elseif ($MapType == 'Bing-Aerial') {
292
-		if (!isset($globalBingMapKey) || $globalBingMapKey == '') setcookie('MapType','OpenStreetMap');
293
-?>
360
+		if (!isset($globalBingMapKey) || $globalBingMapKey == '') {
361
+			setcookie('MapType','OpenStreetMap');
362
+		}
363
+		?>
294 364
 	var bingLayer = new L.tileLayer.bing({bingMapsKey: '<?php print $globalBingMapKey; ?>',imagerySet: 'Aerial'});
295 365
 	map.addLayer(bingLayer);
296 366
 <?php
297 367
 	} elseif ($MapType == 'Bing-Hybrid') {
298
-		if (!isset($globalBingMapKey) || $globalBingMapKey == '') setcookie('MapType','OpenStreetMap');
299
-?>
368
+		if (!isset($globalBingMapKey) || $globalBingMapKey == '') {
369
+			setcookie('MapType','OpenStreetMap');
370
+		}
371
+		?>
300 372
 	var bingLayer = new L.tileLayer.bing({bingMapsKey: '<?php print $globalBingMapKey; ?>',imagerySet: 'AerialWithLabels'});
301 373
 	map.addLayer(bingLayer);
302 374
 <?php
303 375
 	} elseif ($MapType == 'Bing-Road') {
304
-		if (!isset($globalBingMapKey) || $globalBingMapKey == '') setcookie('MapType','OpenStreetMap');
305
-?>
376
+		if (!isset($globalBingMapKey) || $globalBingMapKey == '') {
377
+			setcookie('MapType','OpenStreetMap');
378
+		}
379
+		?>
306 380
 	var bingLayer = new L.tileLayer.bing({bingMapsKey: '<?php print $globalBingMapKey; ?>',imagerySet: 'Road'});
307 381
 	map.addLayer(bingLayer);
308 382
 <?php
@@ -331,7 +405,12 @@  discard block
 block discarded – undo
331 405
 	    maxZoom: 5,
332 406
 	    tms : true,
333 407
 	    zindex : 3,
334
-	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) print 'false'; else print 'true'; ?>,
408
+	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) {
409
+	print 'false';
410
+} else {
411
+	print 'true';
412
+}
413
+?>,
335 414
 	    attribution: 'Natural Earth'
336 415
 	}).addTo(map);
337 416
 <?php
@@ -339,9 +418,24 @@  discard block
 block discarded – undo
339 418
 		$customid = $MapType;
340 419
 ?>
341 420
 	L.tileLayer('<?php print $globalMapCustomLayer[$customid]['url']; ?>/{z}/{x}/{y}.png', {
342
-	    maxZoom: <?php if (isset($globalMapCustomLayer[$customid]['maxZoom'])) print $globalMapCustomLayer[$customid]['maxZoom']; else print '18'; ?>,
343
-	    minZoom: <?php if (isset($globalMapCustomLayer[$customid]['minZoom'])) print $globalMapCustomLayer[$customid]['minZoom']; else print '0'; ?>,
344
-	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) print 'false'; else print 'true'; ?>,
421
+	    maxZoom: <?php if (isset($globalMapCustomLayer[$customid]['maxZoom'])) {
422
+	print $globalMapCustomLayer[$customid]['maxZoom'];
423
+} else {
424
+	print '18';
425
+}
426
+?>,
427
+	    minZoom: <?php if (isset($globalMapCustomLayer[$customid]['minZoom'])) {
428
+	print $globalMapCustomLayer[$customid]['minZoom'];
429
+} else {
430
+	print '0';
431
+}
432
+?>,
433
+	    noWrap: <?php if (isset($globalMapWrap) && !$globalMapWrap) {
434
+	print 'false';
435
+} else {
436
+	print 'true';
437
+}
438
+?>,
345 439
 	    attribution: '<?php print $globalMapCustomLayer[$customid]['attribution']; ?>'
346 440
 	}).addTo(map);
347 441
 
@@ -381,7 +475,12 @@  discard block
 block discarded – undo
381 475
 		}
382 476
 	} elseif ($globalBounding == 'circle') {
383 477
 ?>
384
-	var circle = L.circle([<?php print $globalCenterLatitude; ?>, <?php print $globalCenterLongitude; ?>],<?php if (isset($globalBoundingCircleSize)) print $globalBoundingCircleSize; else print '70000'; ?>,{
478
+	var circle = L.circle([<?php print $globalCenterLatitude; ?>, <?php print $globalCenterLongitude; ?>],<?php if (isset($globalBoundingCircleSize)) {
479
+	print $globalBoundingCircleSize;
480
+} else {
481
+	print '70000';
482
+}
483
+?>,{
385 484
 	    color: '#92C7D1',
386 485
 	    fillColor: '#92C7D1',
387 486
 	    fillOpacity: 0.3,
@@ -471,7 +570,12 @@  discard block
 block discarded – undo
471 570
 	});
472 571
 	if (archive === false) {
473 572
 		update_locationsLayer();
474
-		setInterval(function(){if (noTimeout) { map.removeLayer(locationsLayer); update_locationsLayer();} },<?php if (isset($globalMapRefresh)) print $globalMapRefresh*1000*2; else print '60000'; ?>);
573
+		setInterval(function(){if (noTimeout) { map.removeLayer(locationsLayer); update_locationsLayer();} },<?php if (isset($globalMapRefresh)) {
574
+	print $globalMapRefresh*1000*2;
575
+} else {
576
+	print '60000';
577
+}
578
+?>);
475 579
 	}
476 580
 <?php
477 581
     // Add support for custom json via $globalMapJson
Please login to merge, or discard this patch.
scripts/daemon-spotter.php 3 patches
Indentation   +1103 added lines, -1103 removed lines patch added patch discarded remove patch
@@ -16,8 +16,8 @@  discard block
 block discarded – undo
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17 17
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18 18
 if (isset($globalMarine) && $globalMarine) {
19
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
20
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
19
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
20
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21 21
 }
22 22
 
23 23
 if (!isset($globalDebug)) $globalDebug = FALSE;
@@ -25,46 +25,46 @@  discard block
 block discarded – undo
25 25
 // Check if schema is at latest version
26 26
 $Connection = new Connection();
27 27
 if ($Connection->connectionExists() === false) {
28
-    echo "Can't connect to your database. Check DB is running, user/password and database logs.";
29
-    exit();
28
+	echo "Can't connect to your database. Check DB is running, user/password and database logs.";
29
+	exit();
30 30
 }
31 31
 if ($Connection->latest() === false) {
32
-    echo "You MUST update to latest schema. Run install/index.php";
33
-    exit();
32
+	echo "You MUST update to latest schema. Run install/index.php";
33
+	exit();
34 34
 }
35 35
 if (PHP_SAPI != 'cli') {
36
-    echo "This script MUST be called from console, not a web browser.";
36
+	echo "This script MUST be called from console, not a web browser.";
37 37
 //    exit();
38 38
 }
39 39
 
40 40
 // This is to be compatible with old version of settings.php
41 41
 if (!isset($globalSources)) {
42
-    if (isset($globalSBS1Hosts)) {
43
-        //$hosts = $globalSBS1Hosts;
44
-        foreach ($globalSBS1Hosts as $host) {
45
-	    $globalSources[] = array('host' => $host);
46
-    	}
47
-    } else {
48
-        if (!isset($globalSBS1Host)) {
49
-	    echo '$globalSources MUST be defined !';
50
-	    die;
42
+	if (isset($globalSBS1Hosts)) {
43
+		//$hosts = $globalSBS1Hosts;
44
+		foreach ($globalSBS1Hosts as $host) {
45
+		$globalSources[] = array('host' => $host);
46
+		}
47
+	} else {
48
+		if (!isset($globalSBS1Host)) {
49
+		echo '$globalSources MUST be defined !';
50
+		die;
51 51
 	}
52 52
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
53 53
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
54
-    }
54
+	}
55 55
 }
56 56
 
57 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
-    $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['s']);
61
+	$globalSources = array();
62
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
+	else $globalSources[] = array('host' => $options['s']);
64 64
 } elseif (isset($options['source'])) {
65
-    $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
-    else $globalSources[] = array('host' => $options['source']);
65
+	$globalSources = array();
66
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
+	else $globalSources[] = array('host' => $options['source']);
68 68
 }
69 69
 if (isset($options['aprsserverhost'])) {
70 70
 	$globalServerAPRS = TRUE;
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 if (isset($options['idsource'])) $id_source = $options['idsource'];
104 104
 else $id_source = 1;
105 105
 if (isset($globalServer) && $globalServer) {
106
-    if ($globalDebug) echo "Using Server Mode\n";
107
-    $SI=new SpotterServer();
106
+	if ($globalDebug) echo "Using Server Mode\n";
107
+	$SI=new SpotterServer();
108 108
 /*
109 109
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 110
     $SI = new adsb2aprs();
@@ -114,14 +114,14 @@  discard block
 block discarded – undo
114 114
 
115 115
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
116 116
 if (isset($globalMarine) && $globalMarine) {
117
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
118
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
117
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
118
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
119 119
 }
120 120
 
121 121
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
122 122
 if (isset($globalMarine) && $globalMarine) {
123
-    $AIS = new AIS();
124
-    $MI = new MarineImport($Connection->db);
123
+	$AIS = new AIS();
124
+	$MI = new MarineImport($Connection->db);
125 125
 }
126 126
 //$APRS=new APRS($Connection->db);
127 127
 $SBS=new SBS();
@@ -134,12 +134,12 @@  discard block
 block discarded – undo
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() {
138
-        global $sockets;
139
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
140
-        die("Bye!\n");
141
-    });
142
-    pcntl_signal_dispatch();
137
+	pcntl_signal(SIGINT,  function() {
138
+		global $sockets;
139
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
140
+		die("Bye!\n");
141
+	});
142
+	pcntl_signal_dispatch();
143 143
 }
144 144
 
145 145
 // let's try and connect
@@ -149,46 +149,46 @@  discard block
 block discarded – undo
149 149
 $reset = 0;
150 150
 
151 151
 function connect_all($hosts) {
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;
154
-    $reset++;
155
-    if ($globalDebug) echo 'Connect to all...'."\n";
156
-    foreach ($hosts as $id => $value) {
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;
154
+	$reset++;
155
+	if ($globalDebug) echo 'Connect to all...'."\n";
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 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
-        	//$formats[$id] = 'deltadbtxt';
163
-        	$globalSources[$id]['format'] = 'deltadbtxt';
164
-        	//$last_exec['deltadbtxt'] = 0;
165
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
166
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
167
-        	//$formats[$id] = 'vatsimtxt';
168
-        	$globalSources[$id]['format'] = 'vatsimtxt';
169
-        	//$last_exec['vatsimtxt'] = 0;
170
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
171
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
172
-        	//$formats[$id] = 'aircraftlistjson';
173
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
174
-        	//$last_exec['aircraftlistjson'] = 0;
175
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
176
-    	    } else if (preg_match('/aircraft.json$/i',$host)) {
177
-        	//$formats[$id] = 'aircraftjson';
178
-        	$globalSources[$id]['format'] = 'aircraftjson';
179
-        	//$last_exec['aircraftlistjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
181
-    	    } else if (preg_match('/aircraft$/i',$host)) {
182
-        	//$formats[$id] = 'planefinderclient';
183
-        	$globalSources[$id]['format'] = 'planefinderclient';
184
-        	//$last_exec['aircraftlistjson'] = 0;
185
-        	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
186
-    	    } else if (preg_match('/opensky/i',$host)) {
187
-        	//$formats[$id] = 'aircraftlistjson';
188
-        	$globalSources[$id]['format'] = 'opensky';
189
-        	//$last_exec['aircraftlistjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
191
-    	    /*
161
+			if (preg_match('/deltadb.txt$/i',$host)) {
162
+			//$formats[$id] = 'deltadbtxt';
163
+			$globalSources[$id]['format'] = 'deltadbtxt';
164
+			//$last_exec['deltadbtxt'] = 0;
165
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
166
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
167
+			//$formats[$id] = 'vatsimtxt';
168
+			$globalSources[$id]['format'] = 'vatsimtxt';
169
+			//$last_exec['vatsimtxt'] = 0;
170
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
171
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
172
+			//$formats[$id] = 'aircraftlistjson';
173
+			$globalSources[$id]['format'] = 'aircraftlistjson';
174
+			//$last_exec['aircraftlistjson'] = 0;
175
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
176
+			} else if (preg_match('/aircraft.json$/i',$host)) {
177
+			//$formats[$id] = 'aircraftjson';
178
+			$globalSources[$id]['format'] = 'aircraftjson';
179
+			//$last_exec['aircraftlistjson'] = 0;
180
+			if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
181
+			} else if (preg_match('/aircraft$/i',$host)) {
182
+			//$formats[$id] = 'planefinderclient';
183
+			$globalSources[$id]['format'] = 'planefinderclient';
184
+			//$last_exec['aircraftlistjson'] = 0;
185
+			if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
186
+			} else if (preg_match('/opensky/i',$host)) {
187
+			//$formats[$id] = 'aircraftlistjson';
188
+			$globalSources[$id]['format'] = 'opensky';
189
+			//$last_exec['aircraftlistjson'] = 0;
190
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
191
+			/*
192 192
     	    // Disabled for now, site change source format
193 193
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
194 194
         	//$formats[$id] = 'radarvirtueljson';
@@ -200,128 +200,128 @@  discard block
 block discarded – undo
200 200
         	    exit(0);
201 201
         	}
202 202
     	    */
203
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
204
-        	//$formats[$id] = 'planeupdatefaa';
205
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
206
-        	//$last_exec['planeupdatefaa'] = 0;
207
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
208
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
209
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
210
-        	    exit(0);
211
-        	}
212
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
213
-        	//$formats[$id] = 'phpvmacars';
214
-        	$globalSources[$id]['format'] = 'phpvmacars';
215
-        	//$last_exec['phpvmacars'] = 0;
216
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
217
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
218
-        	//$formats[$id] = 'phpvmacars';
219
-        	$globalSources[$id]['format'] = 'vaos';
220
-        	//$last_exec['phpvmacars'] = 0;
221
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
222
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
223
-        	//$formats[$id] = 'phpvmacars';
224
-        	$globalSources[$id]['format'] = 'vam';
225
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
226
-            } else if (preg_match('/whazzup/i',$host)) {
227
-        	//$formats[$id] = 'whazzup';
228
-        	$globalSources[$id]['format'] = 'whazzup';
229
-        	//$last_exec['whazzup'] = 0;
230
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
231
-            } else if (preg_match('/blitzortung/i',$host)) {
232
-        	$globalSources[$id]['format'] = 'blitzortung';
233
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
234
-            } else if (preg_match('/airwhere/i',$host)) {
235
-        	$globalSources[$id]['format'] = 'airwhere';
236
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
237
-            } else if (preg_match('/recentpireps/i',$host)) {
238
-        	//$formats[$id] = 'pirepsjson';
239
-        	$globalSources[$id]['format'] = 'pirepsjson';
240
-        	//$last_exec['pirepsjson'] = 0;
241
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
242
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
243
-        	//$formats[$id] = 'fr24json';
244
-        	$globalSources[$id]['format'] = 'fr24json';
245
-        	//$last_exec['fr24json'] = 0;
246
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
247
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
248
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
249
-        	    exit(0);
250
-        	}
251
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
252
-        	//$formats[$id] = 'fr24json';
253
-        	$globalSources[$id]['format'] = 'myshiptracking';
254
-        	//$last_exec['fr24json'] = 0;
255
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
256
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
257
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
258
-        	    exit(0);
259
-        	}
260
-            //} else if (preg_match('/10001/',$host)) {
261
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
262
-        	//$formats[$id] = 'tsv';
263
-        	$globalSources[$id]['format'] = 'tsv';
264
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
265
-            }
266
-        } elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway')) {
267
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
268
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
269
-    		    if ($idf !== false) {
270
-    			$httpfeeds[$id] = $idf;
271
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
272
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
273
-    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
274
-    		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
275
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
276
-	    $hostport = explode(':',$host);
277
-	    if (isset($hostport[1])) {
203
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
204
+			//$formats[$id] = 'planeupdatefaa';
205
+			$globalSources[$id]['format'] = 'planeupdatefaa';
206
+			//$last_exec['planeupdatefaa'] = 0;
207
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
208
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
209
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
210
+				exit(0);
211
+			}
212
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
213
+			//$formats[$id] = 'phpvmacars';
214
+			$globalSources[$id]['format'] = 'phpvmacars';
215
+			//$last_exec['phpvmacars'] = 0;
216
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
217
+			} else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
218
+			//$formats[$id] = 'phpvmacars';
219
+			$globalSources[$id]['format'] = 'vaos';
220
+			//$last_exec['phpvmacars'] = 0;
221
+			if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
222
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
223
+			//$formats[$id] = 'phpvmacars';
224
+			$globalSources[$id]['format'] = 'vam';
225
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
226
+			} else if (preg_match('/whazzup/i',$host)) {
227
+			//$formats[$id] = 'whazzup';
228
+			$globalSources[$id]['format'] = 'whazzup';
229
+			//$last_exec['whazzup'] = 0;
230
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
231
+			} else if (preg_match('/blitzortung/i',$host)) {
232
+			$globalSources[$id]['format'] = 'blitzortung';
233
+			if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
234
+			} else if (preg_match('/airwhere/i',$host)) {
235
+			$globalSources[$id]['format'] = 'airwhere';
236
+			if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
237
+			} else if (preg_match('/recentpireps/i',$host)) {
238
+			//$formats[$id] = 'pirepsjson';
239
+			$globalSources[$id]['format'] = 'pirepsjson';
240
+			//$last_exec['pirepsjson'] = 0;
241
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
242
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
243
+			//$formats[$id] = 'fr24json';
244
+			$globalSources[$id]['format'] = 'fr24json';
245
+			//$last_exec['fr24json'] = 0;
246
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
247
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
248
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
249
+				exit(0);
250
+			}
251
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
252
+			//$formats[$id] = 'fr24json';
253
+			$globalSources[$id]['format'] = 'myshiptracking';
254
+			//$last_exec['fr24json'] = 0;
255
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
256
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
257
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
258
+				exit(0);
259
+			}
260
+			//} else if (preg_match('/10001/',$host)) {
261
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
262
+			//$formats[$id] = 'tsv';
263
+			$globalSources[$id]['format'] = 'tsv';
264
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
265
+			}
266
+		} elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway')) {
267
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
268
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
269
+				if ($idf !== false) {
270
+				$httpfeeds[$id] = $idf;
271
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
272
+				} elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
273
+			} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
274
+			elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
275
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
276
+		$hostport = explode(':',$host);
277
+		if (isset($hostport[1])) {
278 278
 		$port = $hostport[1];
279 279
 		$hostn = $hostport[0];
280
-	    } else {
280
+		} else {
281 281
 		$port = $globalSources[$id]['port'];
282 282
 		$hostn = $globalSources[$id]['host'];
283
-	    }
284
-	    $Common = new Common();
285
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
286
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
287
-    	    } else {
288
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
289
-	    }
290
-	    if ($s) {
291
-    	        $sockets[$id] = $s;
292
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
293
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
283
+		}
284
+		$Common = new Common();
285
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
286
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
287
+			} else {
288
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
289
+		}
290
+		if ($s) {
291
+				$sockets[$id] = $s;
292
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
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
-    		    } elseif ($port == '10001') {
301
-        		//$formats[$id] = 'tsv';
302
-        		$globalSources[$id]['format'] = 'tsv';
303
-		    } elseif ($port == '30002') {
304
-        		//$formats[$id] = 'raw';
305
-        		$globalSources[$id]['format'] = 'raw';
306
-		    } elseif ($port == '5001') {
307
-        		//$formats[$id] = 'raw';
308
-        		$globalSources[$id]['format'] = 'flightgearmp';
309
-		    } elseif ($port == '30005') {
300
+				} elseif ($port == '10001') {
301
+				//$formats[$id] = 'tsv';
302
+				$globalSources[$id]['format'] = 'tsv';
303
+			} elseif ($port == '30002') {
304
+				//$formats[$id] = 'raw';
305
+				$globalSources[$id]['format'] = 'raw';
306
+			} elseif ($port == '5001') {
307
+				//$formats[$id] = 'raw';
308
+				$globalSources[$id]['format'] = 'flightgearmp';
309
+			} elseif ($port == '30005') {
310 310
 			// Not yet supported
311
-        		//$formats[$id] = 'beast';
312
-        		$globalSources[$id]['format'] = 'beast';
313
-		    //} else $formats[$id] = 'sbs';
314
-		    } else $globalSources[$id]['format'] = 'sbs';
315
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
311
+				//$formats[$id] = 'beast';
312
+				$globalSources[$id]['format'] = 'beast';
313
+			//} else $formats[$id] = 'sbs';
314
+			} else $globalSources[$id]['format'] = 'sbs';
315
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
316 316
 		}
317 317
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
318
-            } else {
318
+			} else {
319 319
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
320 320
 		sleep(10);
321 321
 		connect_all($hosts);
322
-    	    }
323
-        }
324
-    }
322
+			}
323
+		}
324
+	}
325 325
 }
326 326
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
327 327
 
@@ -344,9 +344,9 @@  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
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
349
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
350 350
 }
351 351
 
352 352
 // APRS Configuration
@@ -355,21 +355,21 @@  discard block
 block discarded – undo
355 355
 	die;
356 356
 }
357 357
 foreach ($globalSources as $key => $source) {
358
-    if (!isset($source['format'])) {
359
-        $globalSources[$key]['format'] = 'auto';
360
-    }
361
-    if (isset($source['callback']) && $source['callback'] === TRUE) {
362
-        unset($globalSources[$key]);
363
-    }
358
+	if (!isset($source['format'])) {
359
+		$globalSources[$key]['format'] = 'auto';
360
+	}
361
+	if (isset($source['callback']) && $source['callback'] === TRUE) {
362
+		unset($globalSources[$key]);
363
+	}
364 364
 }
365 365
 connect_all($globalSources);
366 366
 foreach ($globalSources as $key => $source) {
367
-    if (isset($source['format']) && $source['format'] == 'aprs') {
367
+	if (isset($source['format']) && $source['format'] == 'aprs') {
368 368
 	$aprs_connect = 0;
369 369
 	$use_aprs = true;
370 370
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
371 371
 	break;
372
-    }
372
+	}
373 373
 }
374 374
 
375 375
 if ($use_aprs) {
@@ -410,133 +410,133 @@  discard block
 block discarded – undo
410 410
 
411 411
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
412 412
 while ($i > 0) {
413
-    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
413
+	if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
414 414
 
415
-    if (!$globalDaemon) $i = $endtime-time();
416
-    // Delete old ATC
417
-    if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
415
+	if (!$globalDaemon) $i = $endtime-time();
416
+	// Delete old ATC
417
+	if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
418 418
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
419
-        $ATC->deleteOldATC();
420
-    }
419
+		$ATC->deleteOldATC();
420
+	}
421 421
     
422
-    if (count($last_exec) == count($globalSources)) {
422
+	if (count($last_exec) == count($globalSources)) {
423 423
 	$max = $globalMinFetch;
424 424
 	foreach ($last_exec as $last) {
425
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
425
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
426 426
 	}
427 427
 	if ($max < $globalMinFetch) {
428
-	    if ($globalDebug) echo 'Sleeping...'."\n";
429
-	    sleep($globalMinFetch-$max+2);
428
+		if ($globalDebug) echo 'Sleeping...'."\n";
429
+		sleep($globalMinFetch-$max+2);
430
+	}
430 431
 	}
431
-    }
432 432
 
433 433
     
434
-    //foreach ($formats as $id => $value) {
435
-    foreach ($globalSources as $id => $value) {
434
+	//foreach ($formats as $id => $value) {
435
+	foreach ($globalSources as $id => $value) {
436 436
 	date_default_timezone_set('UTC');
437 437
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
438 438
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
439 439
 	if ($value['format'] === 'deltadbtxt' && 
440
-	    (
440
+		(
441 441
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
442 442
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
443
-	    )
443
+		)
444 444
 	) {
445
-	    //$buffer = $Common->getData($hosts[$id]);
446
-	    $buffer = $Common->getData($value['host']);
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);
450
-	    foreach ($buffer as $line) {
451
-    		if ($line != '' && count($line) > 7) {
452
-    		    $line = explode(',', $line);
453
-	            $data = array();
454
-	            $data['hex'] = $line[1]; // hex
455
-	            $data['ident'] = $line[2]; // ident
456
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
457
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
458
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
459
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
460
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
461
-	            $data['verticalrate'] = ''; // vertical rate
462
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
463
-	            $data['emergency'] = ''; // emergency
464
-		    $data['datetime'] = date('Y-m-d H:i:s');
465
-		    $data['format_source'] = 'deltadbtxt';
466
-    		    $data['id_source'] = $id_source;
467
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
468
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
469
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
470
-    		    $SI->add($data);
471
-		    unset($data);
472
-    		}
473
-    	    }
474
-    	    $last_exec[$id]['last'] = time();
445
+		//$buffer = $Common->getData($hosts[$id]);
446
+		$buffer = $Common->getData($value['host']);
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);
450
+		foreach ($buffer as $line) {
451
+			if ($line != '' && count($line) > 7) {
452
+				$line = explode(',', $line);
453
+				$data = array();
454
+				$data['hex'] = $line[1]; // hex
455
+				$data['ident'] = $line[2]; // ident
456
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
457
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
458
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
459
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
460
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
461
+				$data['verticalrate'] = ''; // vertical rate
462
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
463
+				$data['emergency'] = ''; // emergency
464
+			$data['datetime'] = date('Y-m-d H:i:s');
465
+			$data['format_source'] = 'deltadbtxt';
466
+				$data['id_source'] = $id_source;
467
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
468
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
469
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
470
+				$SI->add($data);
471
+			unset($data);
472
+			}
473
+			}
474
+			$last_exec[$id]['last'] = time();
475 475
 	} elseif ($value['format'] === 'aisnmeatxt' && 
476
-	    (
476
+		(
477 477
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
478 478
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
479
-	    )
479
+		)
480 480
 	) {
481
-	    date_default_timezone_set('CET');
482
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
483
-	    date_default_timezone_set('UTC');
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);
487
-	    foreach ($buffer as $line) {
481
+		date_default_timezone_set('CET');
482
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
483
+		date_default_timezone_set('UTC');
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);
487
+		foreach ($buffer as $line) {
488 488
 		if ($line != '') {
489
-		    //echo "'".$line."'\n";
490
-		    $add = false;
491
-		    $ais_data = $AIS->parse_line(trim($line));
492
-		    $data = array();
493
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
494
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
495
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
496
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
497
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
498
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
499
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
500
-		    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
501
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
502
-		    if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
503
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
504
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
505
-		    if (isset($ais_data['timestamp'])) {
489
+			//echo "'".$line."'\n";
490
+			$add = false;
491
+			$ais_data = $AIS->parse_line(trim($line));
492
+			$data = array();
493
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
494
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
495
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
496
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
497
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
498
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
499
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
500
+			if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
501
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
502
+			if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
503
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
504
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
505
+			if (isset($ais_data['timestamp'])) {
506 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
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
509
-			    $add = true;
508
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
509
+				$add = true;
510 510
 			}
511
-		    } else {
511
+			} else {
512 512
 			$data['datetime'] = date('Y-m-d H:i:s');
513 513
 			$add = true;
514
-		    }
515
-		    $data['format_source'] = 'aisnmeatxt';
516
-    		    $data['id_source'] = $id_source;
517
-		    //print_r($data);
518
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
519
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
520
-		    unset($data);
514
+			}
515
+			$data['format_source'] = 'aisnmeatxt';
516
+				$data['id_source'] = $id_source;
517
+			//print_r($data);
518
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
519
+			if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
520
+			unset($data);
521 521
 		}
522
-    	    }
523
-    	    $last_exec[$id]['last'] = time();
522
+			}
523
+			$last_exec[$id]['last'] = time();
524 524
 	} elseif ($value['format'] === 'aisnmeahttp') {
525
-	    $arr = $httpfeeds;
526
-	    $w = $e = null;
525
+		$arr = $httpfeeds;
526
+		$w = $e = null;
527 527
 	    
528
-	    if (isset($arr[$id])) {
528
+		if (isset($arr[$id])) {
529 529
 		$nn = stream_select($arr,$w,$e,$timeout);
530 530
 		if ($nn > 0) {
531
-		    foreach ($httpfeeds as $feed) {
531
+			foreach ($httpfeeds as $feed) {
532 532
 			$buffer = stream_get_line($feed,2000,"\n");
533 533
 			if ($buffer === FALSE) {
534
-			    connect_all($globalSources);
534
+				connect_all($globalSources);
535 535
 			}
536 536
 			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537 537
 			$buffer = explode('\n',$buffer);
538 538
 			foreach ($buffer as $line) {
539
-			    if ($line != '') {
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'];
@@ -554,117 +554,117 @@  discard block
 block discarded – undo
554 554
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
555 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
-				    $data['datetime'] = date('Y-m-d H:i:s');
559
+					$data['datetime'] = date('Y-m-d H:i:s');
560 560
 				}
561 561
 				$data['format_source'] = 'aisnmeahttp';
562 562
 				$data['id_source'] = $id_source;
563 563
 				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
564 564
 				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
565 565
 				unset($data);
566
-			    }
566
+				}
567
+			}
567 568
 			}
568
-		    }
569 569
 		} else {
570
-		    $format = $value['format'];
571
-		    if (isset($tt[$format])) $tt[$format]++;
572
-		    else $tt[$format] = 0;
573
-		    if ($tt[$format] > 30) {
570
+			$format = $value['format'];
571
+			if (isset($tt[$format])) $tt[$format]++;
572
+			else $tt[$format] = 0;
573
+			if ($tt[$format] > 30) {
574 574
 			if ($globalDebug) echo 'Reconnect...'."\n";
575 575
 			sleep(2);
576 576
 			//$sourceeen[] = $value;
577 577
 			//connect_all($sourceeen);
578 578
 			//$sourceeen = array();
579 579
 			connect_all($globalSources);
580
-		    }
580
+			}
581
+		}
581 582
 		}
582
-	    }
583 583
 	} elseif ($value['format'] === 'myshiptracking' && 
584
-	    (
584
+		(
585 585
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
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');
590
-	    if ($buffer != '') {
589
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
590
+		if ($buffer != '') {
591 591
 		//echo $buffer;
592 592
 		$all_data = json_decode($buffer,true);
593 593
 		//print_r($all_data);
594 594
 		if (isset($all_data[0]['DATA'])) {
595
-		    foreach ($all_data[0]['DATA'] as $line) {
595
+			foreach ($all_data[0]['DATA'] as $line) {
596 596
 			if ($line != '') {
597
-			    $data = array();
598
-			    $data['ident'] = $line['NAME'];
599
-			    $data['mmsi'] = $line['MMSI'];
600
-			    if (strlen($data['mmsi']) > 9) {
597
+				$data = array();
598
+				$data['ident'] = $line['NAME'];
599
+				$data['mmsi'] = $line['MMSI'];
600
+				if (strlen($data['mmsi']) > 9) {
601 601
 				$data['mmsi'] = substr($data['mmsi'],-9);
602
-			    }
603
-			    $data['speed'] = $line['SOG'];
604
-			    $data['heading'] = $line['COG'];
605
-			    $data['latitude'] = $line['LAT'];
606
-			    $data['longitude'] = $line['LNG'];
607
-			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
608
-			    //$data['type_id'] = $line['TYPE'];
609
-			    $data['imo'] = $line['IMO'];
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']);
613
-			    $data['format_source'] = 'myshiptracking';
614
-			    $data['id_source'] = $id_source;
615
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
616
-			    $MI->add($data);
617
-			    unset($data);
602
+				}
603
+				$data['speed'] = $line['SOG'];
604
+				$data['heading'] = $line['COG'];
605
+				$data['latitude'] = $line['LAT'];
606
+				$data['longitude'] = $line['LNG'];
607
+				//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
608
+				//$data['type_id'] = $line['TYPE'];
609
+				$data['imo'] = $line['IMO'];
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']);
613
+				$data['format_source'] = 'myshiptracking';
614
+				$data['id_source'] = $id_source;
615
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
616
+				$MI->add($data);
617
+				unset($data);
618
+			}
618 619
 			}
619
-		    }
620 620
 		}
621
-	    }
622
-	    $last_exec[$id]['last'] = time();
621
+		}
622
+		$last_exec[$id]['last'] = time();
623 623
 	} elseif ($value['format'] === 'boatbeaconapp' && 
624
-	    (
624
+		(
625 625
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
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']));
630
-	    if ($buffer != '') {
629
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
630
+		if ($buffer != '') {
631 631
 		$all_data = json_decode($buffer,true);
632 632
 		if (isset($all_data[0]['mmsi'])) {
633
-		    foreach ($all_data as $line) {
633
+			foreach ($all_data as $line) {
634 634
 			if ($line != '') {
635
-			    $data = array();
636
-			    $data['ident'] = $line['shipname'];
637
-			    $data['callsign'] = $line['callsign'];
638
-			    $data['mmsi'] = substr($line['mmsi'],-9);
639
-			    $data['speed'] = $line['sog'];
640
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
641
-			    $data['latitude'] = $line['latitude'];
642
-			    $data['longitude'] = $line['longitude'];
643
-			    $data['type_id'] = $line['shiptype'];
644
-			    $data['arrival_code'] = $line['destination'];
645
-			    $data['datetime'] = $line['time'];
646
-			    $data['format_source'] = 'boatbeaconapp';
647
-			    $data['id_source'] = $id_source;
648
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
649
-			    $MI->add($data);
650
-			    unset($data);
635
+				$data = array();
636
+				$data['ident'] = $line['shipname'];
637
+				$data['callsign'] = $line['callsign'];
638
+				$data['mmsi'] = substr($line['mmsi'],-9);
639
+				$data['speed'] = $line['sog'];
640
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
641
+				$data['latitude'] = $line['latitude'];
642
+				$data['longitude'] = $line['longitude'];
643
+				$data['type_id'] = $line['shiptype'];
644
+				$data['arrival_code'] = $line['destination'];
645
+				$data['datetime'] = $line['time'];
646
+				$data['format_source'] = 'boatbeaconapp';
647
+				$data['id_source'] = $id_source;
648
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
649
+				$MI->add($data);
650
+				unset($data);
651
+			}
651 652
 			}
652
-		    }
653 653
 		}
654 654
 		
655
-	    }
656
-    	    $last_exec[$id]['last'] = time();
655
+		}
656
+			$last_exec[$id]['last'] = time();
657 657
 	} elseif ($value['format'] === 'boatnerd' && 
658
-	    (
658
+		(
659 659
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
660 660
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
661
-	    )
661
+		)
662 662
 	) {
663
-	    $buffer = $Common->getData($value['host']);
664
-	    if ($buffer != '') {
663
+		$buffer = $Common->getData($value['host']);
664
+		if ($buffer != '') {
665 665
 		$all_data = json_decode($buffer,true);
666 666
 		if (isset($all_data['features'][0]['id'])) {
667
-		    foreach ($all_data['features'] as $line) {
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'];
@@ -684,66 +684,66 @@  discard block
 block discarded – undo
684 684
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
685 685
 			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
686 686
 			unset($data);
687
-		    }
687
+			}
688 688
 		}
689 689
 		
690
-	    }
691
-    	    $last_exec[$id]['last'] = time();
690
+		}
691
+			$last_exec[$id]['last'] = time();
692 692
 	} elseif ($value['format'] === 'shipplotter' && 
693
-	    (
693
+		(
694 694
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
695 695
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
696
-	    )
696
+		)
697 697
 	) {
698
-	    if ($globalDebug) echo 'download...';
699
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
700
-	    if ($globalDebug) echo 'done !'."\n";
701
-	    // FIXME: Need more work
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);
705
-	    foreach ($buffer as $line) {
698
+		if ($globalDebug) echo 'download...';
699
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
700
+		if ($globalDebug) echo 'done !'."\n";
701
+		// FIXME: Need more work
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);
705
+		foreach ($buffer as $line) {
706 706
 		if ($line != '') {
707
-		    $data = array();
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));
716
-		    //$data['course'] = substr($line,57,5);
717
-		    $data['heading'] = round(substr($line,63,3));
718
-		    //$data['draft'] = substr($line,67,4);
719
-		    //$data['length'] = substr($line,72,3);
720
-		    //$data['beam'] = substr($line,76,2);
721
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
722
-		    //$data['callsign'] = trim(substr($line,100,7);
723
-		    $data['arrival_code'] = substr($line,108,20);
724
-		    //$data['etaDate'] = substr($line,129,5);
725
-		    //$data['etaTime'] = substr($line,135,5);
726
-		    $data['format_source'] = 'shipplotter';
727
-    		    $data['id_source'] = $id_source;
728
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
729
-		    //print_r($data);
730
-		    //echo 'Add...'."\n";
731
-		    $MI->add($data);
732
-		    unset($data);
707
+			$data = array();
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));
716
+			//$data['course'] = substr($line,57,5);
717
+			$data['heading'] = round(substr($line,63,3));
718
+			//$data['draft'] = substr($line,67,4);
719
+			//$data['length'] = substr($line,72,3);
720
+			//$data['beam'] = substr($line,76,2);
721
+			$data['ident'] = trim(utf8_encode(substr($line,78,20)));
722
+			//$data['callsign'] = trim(substr($line,100,7);
723
+			$data['arrival_code'] = substr($line,108,20);
724
+			//$data['etaDate'] = substr($line,129,5);
725
+			//$data['etaTime'] = substr($line,135,5);
726
+			$data['format_source'] = 'shipplotter';
727
+				$data['id_source'] = $id_source;
728
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
729
+			//print_r($data);
730
+			//echo 'Add...'."\n";
731
+			$MI->add($data);
732
+			unset($data);
733 733
 		}
734
-    	    }
735
-    	    $last_exec[$id]['last'] = time();
734
+			}
735
+			$last_exec[$id]['last'] = time();
736 736
 	} elseif ($value['format'] === 'sailaway' && 
737
-	    (
737
+		(
738 738
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
739 739
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
740
-	    )
740
+		)
741 741
 	) {
742
-	    if ($globalDebug) echo 'download...';
743
-	    for ($i =0; $i <= 1; $i++) {
744
-	    $buffer = $Common->getData('https://sailaway.world/cgi-bin/sailaway/GetMissions.pl?race=1&tutorial=0&hist=1&racetype='.$i);
745
-	    if ($globalDebug) echo 'done'."\n";
746
-	    if ($buffer != '') {
742
+		if ($globalDebug) echo 'download...';
743
+		for ($i =0; $i <= 1; $i++) {
744
+		$buffer = $Common->getData('https://sailaway.world/cgi-bin/sailaway/GetMissions.pl?race=1&tutorial=0&hist=1&racetype='.$i);
745
+		if ($globalDebug) echo 'done'."\n";
746
+		if ($buffer != '') {
747 747
 		$all_data = json_decode($buffer,true);
748 748
 		if (isset($all_data['missions'])) {
749 749
 			foreach ($all_data['missions'] as $mission) {
@@ -791,34 +791,34 @@  discard block
 block discarded – undo
791 791
 				}
792 792
 			}
793 793
 		}
794
-	    }
795
-	    }
796
-    	    $last_exec[$id]['last'] = time();
794
+		}
795
+		}
796
+			$last_exec[$id]['last'] = time();
797 797
 	//} elseif (($value === 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value === 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
798 798
 	} elseif (
799
-	    (
799
+		(
800 800
 		$value['format'] === 'whazzup' && 
801 801
 		(
802
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
803
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
802
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
803
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
804 804
 		)
805
-	    ) || (
805
+		) || (
806 806
 		$value['format'] === 'vatsimtxt' && 
807 807
 		(
808
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
809
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
808
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
809
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
810
+		)
810 811
 		)
811
-	    )
812 812
 	) {
813
-	    //$buffer = $Common->getData($hosts[$id]);
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);
817
-	    $reset = 0;
818
-	    foreach ($buffer as $line) {
819
-    		if ($line != '') {
820
-    		    $line = explode(':', $line);
821
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
813
+		//$buffer = $Common->getData($hosts[$id]);
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);
817
+		$reset = 0;
818
+		foreach ($buffer as $line) {
819
+			if ($line != '') {
820
+				$line = explode(':', $line);
821
+				if (count($line) > 30 && $line[0] != 'callsign') {
822 822
 			$data = array();
823 823
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
824 824
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -831,37 +831,37 @@  discard block
 block discarded – undo
831 831
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
832 832
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
833 833
 			$data['latitude'] = $line[5]; // lat
834
-	        	$data['longitude'] = $line[6]; // long
835
-	        	$data['verticalrate'] = ''; // vertical rate
836
-	        	$data['squawk'] = ''; // squawk
837
-	        	$data['emergency'] = ''; // emergency
838
-	        	$data['waypoints'] = $line[30];
834
+				$data['longitude'] = $line[6]; // long
835
+				$data['verticalrate'] = ''; // vertical rate
836
+				$data['squawk'] = ''; // squawk
837
+				$data['emergency'] = ''; // emergency
838
+				$data['waypoints'] = $line[30];
839 839
 			$data['datetime'] = date('Y-m-d H:i:s');
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
-		        $data['departure_airport_icao'] = $line[11];
843
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
844
-		        $data['arrival_airport_icao'] = $line[13];
842
+				$data['departure_airport_icao'] = $line[11];
843
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
844
+				$data['arrival_airport_icao'] = $line[13];
845 845
 			$data['frequency'] = $line[4];
846 846
 			$data['type'] = $line[18];
847 847
 			$data['range'] = $line[19];
848 848
 			if (isset($line[35])) $data['info'] = $line[35];
849
-    			$data['id_source'] = $id_source;
850
-	    		//$data['arrival_airport_time'] = ;
851
-	    		if ($line[9] != '') {
852
-	    		    $aircraft_data = explode('/',$line[9]);
853
-	    		    if (isset($aircraft_data[1])) {
854
-	    			$data['aircraft_icao'] = $aircraft_data[1];
855
-	    		    }
856
-        		}
857
-	    		/*
849
+				$data['id_source'] = $id_source;
850
+				//$data['arrival_airport_time'] = ;
851
+				if ($line[9] != '') {
852
+					$aircraft_data = explode('/',$line[9]);
853
+					if (isset($aircraft_data[1])) {
854
+					$data['aircraft_icao'] = $aircraft_data[1];
855
+					}
856
+				}
857
+				/*
858 858
 	    		if ($value === 'whazzup') $data['format_source'] = 'whazzup';
859 859
 	    		elseif ($value === 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
860 860
 	    		*/
861
-	    		$data['format_source'] = $value['format'];
861
+				$data['format_source'] = $value['format'];
862 862
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
863 863
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
864
-    			if ($line[3] === 'PILOT') $SI->add($data);
864
+				if ($line[3] === 'PILOT') $SI->add($data);
865 865
 			elseif ($line[3] === 'ATC') {
866 866
 				//print_r($data);
867 867
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -882,21 +882,21 @@  discard block
 block discarded – undo
882 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
-    			unset($data);
886
-    		    }
887
-    		}
888
-    	    }
889
-    	    //if ($value === 'whazzup') $last_exec['whazzup'] = time();
890
-    	    //elseif ($value === 'vatsimtxt') $last_exec['vatsimtxt'] = time();
891
-    	    $last_exec[$id]['last'] = time();
892
-    	} elseif ($value['format'] === 'airwhere' && 
893
-    	    (
894
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
895
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
896
-    	    )
897
-    	) {
898
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
899
-	    if ($buffer != '') {
885
+				unset($data);
886
+				}
887
+			}
888
+			}
889
+			//if ($value === 'whazzup') $last_exec['whazzup'] = time();
890
+			//elseif ($value === 'vatsimtxt') $last_exec['vatsimtxt'] = time();
891
+			$last_exec[$id]['last'] = time();
892
+		} elseif ($value['format'] === 'airwhere' && 
893
+			(
894
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
895
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
896
+			)
897
+		) {
898
+		$buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
899
+		if ($buffer != '') {
900 900
 		$all_data = simplexml_load_string($buffer);
901 901
 		foreach($all_data->children() as $childdata) {
902 902
 			$data = array();
@@ -918,10 +918,10 @@  discard block
 block discarded – undo
918 918
 			$SI->add($data);
919 919
 			unset($data);
920 920
 		}
921
-	    }
922
-	    $Source->deleteOldLocationByType('gs');
923
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
924
-	    if ($buffer != '') {
921
+		}
922
+		$Source->deleteOldLocationByType('gs');
923
+		$buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
924
+		if ($buffer != '') {
925 925
 		$all_data = simplexml_load_string($buffer);
926 926
 		foreach($all_data->children() as $childdata) {
927 927
 			$data = array();
@@ -939,8 +939,8 @@  discard block
 block discarded – undo
939 939
 			}
940 940
 			unset($data);
941 941
 		}
942
-	    }
943
-	    $last_exec[$id]['last'] = time();
942
+		}
943
+		$last_exec[$id]['last'] = time();
944 944
 	/*
945 945
 	} if ($value['format'] === 'aircraftlistjson') {
946 946
 	    print_r($globalSources);
@@ -948,17 +948,17 @@  discard block
 block discarded – undo
948 948
 	    echo $globalMinFetch;
949 949
 	*/
950 950
 	} elseif ($value['format'] === 'aircraftlistjson' && 
951
-	    (
951
+		(
952 952
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
953 953
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
954
-	    )
954
+		)
955 955
 	) {
956
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
957
-	    if ($buffer != '') {
958
-	        $all_data = json_decode($buffer,true);
956
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
957
+		if ($buffer != '') {
958
+			$all_data = json_decode($buffer,true);
959 959
 		if (isset($all_data['acList'])) {
960
-		    $reset = 0;
961
-		    foreach ($all_data['acList'] as $line) {
960
+			$reset = 0;
961
+			foreach ($all_data['acList'] as $line) {
962 962
 			$data = array();
963 963
 			$data['hex'] = $line['Icao']; // hex
964 964
 			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -981,10 +981,10 @@  discard block
 block discarded – undo
981 981
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
982 982
 			if (isset($data['latitude'])) $SI->add($data);
983 983
 			unset($data);
984
-		    }
984
+			}
985 985
 		} elseif (is_array($all_data)) {
986
-		    $reset = 0;
987
-		    foreach ($all_data as $line) {
986
+			$reset = 0;
987
+			foreach ($all_data as $line) {
988 988
 			$data = array();
989 989
 			$data['hex'] = $line['hex']; // hex
990 990
 			$data['ident'] = $line['flight']; // ident
@@ -1004,291 +1004,291 @@  discard block
 block discarded – undo
1004 1004
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1005 1005
 			$SI->add($data);
1006 1006
 			unset($data);
1007
-		    }
1007
+			}
1008 1008
 		}
1009
-	    } elseif ($globalDebug) echo 'No data'."\n";
1010
-    	    //$last_exec['aircraftlistjson'] = time();
1011
-    	    $last_exec[$id]['last'] = time();
1012
-    	//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
1013
-    	} elseif ($value['format'] === 'planeupdatefaa' && 
1014
-    	    (
1015
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1016
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1017
-    	    )
1018
-    	) {
1019
-	    $buffer = $Common->getData($value['host']);
1020
-	    $all_data = json_decode($buffer,true);
1021
-	    if (isset($all_data['planes'])) {
1009
+		} elseif ($globalDebug) echo 'No data'."\n";
1010
+			//$last_exec['aircraftlistjson'] = time();
1011
+			$last_exec[$id]['last'] = time();
1012
+		//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
1013
+		} elseif ($value['format'] === 'planeupdatefaa' && 
1014
+			(
1015
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1016
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1017
+			)
1018
+		) {
1019
+		$buffer = $Common->getData($value['host']);
1020
+		$all_data = json_decode($buffer,true);
1021
+		if (isset($all_data['planes'])) {
1022 1022
 		$reset = 0;
1023 1023
 		foreach ($all_data['planes'] as $key => $line) {
1024
-		    $data = array();
1025
-		    $data['hex'] = $key; // hex
1026
-		    $data['ident'] = $line[3]; // ident
1027
-		    $data['altitude'] = $line[6]; // altitude
1028
-		    $data['speed'] = $line[8]; // speed
1029
-		    $data['heading'] = $line[7]; // heading
1030
-		    $data['latitude'] = $line[4]; // lat
1031
-		    $data['longitude'] = $line[5]; // long
1032
-		    //$data['verticalrate'] = $line[]; // verticale rate
1033
-		    $data['squawk'] = $line[10]; // squawk
1034
-		    $data['emergency'] = ''; // emergency
1035
-		    $data['registration'] = $line[2];
1036
-		    $data['aircraft_icao'] = $line[0];
1037
-		    $deparr = explode('-',$line[1]);
1038
-		    if (count($deparr) === 2) {
1024
+			$data = array();
1025
+			$data['hex'] = $key; // hex
1026
+			$data['ident'] = $line[3]; // ident
1027
+			$data['altitude'] = $line[6]; // altitude
1028
+			$data['speed'] = $line[8]; // speed
1029
+			$data['heading'] = $line[7]; // heading
1030
+			$data['latitude'] = $line[4]; // lat
1031
+			$data['longitude'] = $line[5]; // long
1032
+			//$data['verticalrate'] = $line[]; // verticale rate
1033
+			$data['squawk'] = $line[10]; // squawk
1034
+			$data['emergency'] = ''; // emergency
1035
+			$data['registration'] = $line[2];
1036
+			$data['aircraft_icao'] = $line[0];
1037
+			$deparr = explode('-',$line[1]);
1038
+			if (count($deparr) === 2) {
1039 1039
 			$data['departure_airport_icao'] = $deparr[0];
1040 1040
 			$data['arrival_airport_icao'] = $deparr[1];
1041
-		    }
1042
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1043
-	    	    $data['format_source'] = 'planeupdatefaa';
1044
-    		    $data['id_source'] = $id_source;
1045
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1046
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1047
-		    $SI->add($data);
1048
-		    unset($data);
1041
+			}
1042
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1043
+				$data['format_source'] = 'planeupdatefaa';
1044
+				$data['id_source'] = $id_source;
1045
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1046
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1047
+			$SI->add($data);
1048
+			unset($data);
1049 1049
 		}
1050
-	    }
1051
-	    //$last_exec['planeupdatefaa'] = time();
1052
-	    $last_exec[$id]['last'] = time();
1050
+		}
1051
+		//$last_exec['planeupdatefaa'] = time();
1052
+		$last_exec[$id]['last'] = time();
1053 1053
 	} elseif ($value['format'] === 'opensky' && 
1054
-	    (
1054
+		(
1055 1055
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1056 1056
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1057
-	    )
1057
+		)
1058 1058
 	) {
1059
-	    $buffer = $Common->getData($value['host']);
1060
-	    $all_data = json_decode($buffer,true);
1061
-	    if (isset($all_data['states'])) {
1059
+		$buffer = $Common->getData($value['host']);
1060
+		$all_data = json_decode($buffer,true);
1061
+		if (isset($all_data['states'])) {
1062 1062
 		$reset = 0;
1063 1063
 		foreach ($all_data['states'] as $key => $line) {
1064
-		    $data = array();
1065
-		    $data['hex'] = $line[0]; // hex
1066
-		    $data['ident'] = trim($line[1]); // ident
1067
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
1068
-		    $data['speed'] = round($line[9]*1.94384); // speed
1069
-		    $data['heading'] = round($line[10]); // heading
1070
-		    $data['latitude'] = $line[6]; // lat
1071
-		    $data['longitude'] = $line[5]; // long
1072
-		    $data['verticalrate'] = $line[11]; // verticale rate
1073
-		    //$data['squawk'] = $line[10]; // squawk
1074
-		    //$data['emergency'] = ''; // emergency
1075
-		    //$data['registration'] = $line[2];
1076
-		    //$data['aircraft_icao'] = $line[0];
1077
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1078
-		    $data['format_source'] = 'opensky';
1079
-		    $data['id_source'] = $id_source;
1080
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1081
-		    $SI->add($data);
1082
-		    unset($data);
1064
+			$data = array();
1065
+			$data['hex'] = $line[0]; // hex
1066
+			$data['ident'] = trim($line[1]); // ident
1067
+			$data['altitude'] = round($line[7]*3.28084); // altitude
1068
+			$data['speed'] = round($line[9]*1.94384); // speed
1069
+			$data['heading'] = round($line[10]); // heading
1070
+			$data['latitude'] = $line[6]; // lat
1071
+			$data['longitude'] = $line[5]; // long
1072
+			$data['verticalrate'] = $line[11]; // verticale rate
1073
+			//$data['squawk'] = $line[10]; // squawk
1074
+			//$data['emergency'] = ''; // emergency
1075
+			//$data['registration'] = $line[2];
1076
+			//$data['aircraft_icao'] = $line[0];
1077
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1078
+			$data['format_source'] = 'opensky';
1079
+			$data['id_source'] = $id_source;
1080
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1081
+			$SI->add($data);
1082
+			unset($data);
1083
+		}
1083 1084
 		}
1084
-	    }
1085
-	    //$last_exec['planeupdatefaa'] = time();
1086
-	    $last_exec[$id]['last'] = time();
1085
+		//$last_exec['planeupdatefaa'] = time();
1086
+		$last_exec[$id]['last'] = time();
1087 1087
 	} elseif ($value['format'] === 'aircraftjson' && 
1088
-	    (
1088
+		(
1089 1089
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1090 1090
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1091
-	    )
1091
+		)
1092 1092
 	) {
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) {
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) {
1096 1096
 		$reset = 0;
1097 1097
 		foreach ($all_data['aircraft'] as $key => $line) {
1098
-		    $data = array();
1099
-		    // add support for ground vehicule with ~ in front of hex
1100
-		    if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1101
-		    if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1102
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1103
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1104
-		    if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1105
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1106
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1107
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1108
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1109
-		    //$data['emergency'] = ''; // emergency
1110
-		    //$data['registration'] = $line[2];
1111
-		    //$data['aircraft_icao'] = $line[0];
1112
-		    $data['datetime'] = date('Y-m-d H:i:s');
1113
-		    $data['format_source'] = 'aircraftjson';
1114
-		    $data['id_source'] = $id_source;
1115
-		    if (isset($value['name']) && $value['name'] != '') {
1116
-			    if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1117
-			    else $data['source_name'] = $value['name'];
1118
-		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1119
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1120
-		    $SI->add($data);
1121
-		    unset($data);
1098
+			$data = array();
1099
+			// add support for ground vehicule with ~ in front of hex
1100
+			if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1101
+			if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1102
+			if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1103
+			if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1104
+			if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1105
+			if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1106
+			if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1107
+			if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1108
+			if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1109
+			//$data['emergency'] = ''; // emergency
1110
+			//$data['registration'] = $line[2];
1111
+			//$data['aircraft_icao'] = $line[0];
1112
+			$data['datetime'] = date('Y-m-d H:i:s');
1113
+			$data['format_source'] = 'aircraftjson';
1114
+			$data['id_source'] = $id_source;
1115
+			if (isset($value['name']) && $value['name'] != '') {
1116
+				if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1117
+				else $data['source_name'] = $value['name'];
1118
+			} elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1119
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1120
+			$SI->add($data);
1121
+			unset($data);
1122 1122
 		}
1123
-	    }
1124
-	    //$last_exec['planeupdatefaa'] = time();
1125
-	    $last_exec[$id]['last'] = time();
1123
+		}
1124
+		//$last_exec['planeupdatefaa'] = time();
1125
+		$last_exec[$id]['last'] = time();
1126 1126
 	} elseif ($value['format'] === 'planefinderclient' && 
1127
-	    (
1127
+		(
1128 1128
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1129 1129
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1130
-	    )
1130
+		)
1131 1131
 	) {
1132
-	    $buffer = $Common->getData($value['host']);
1133
-	    $all_data = json_decode($buffer,true);
1134
-	    if (isset($all_data['aircraft'])) {
1132
+		$buffer = $Common->getData($value['host']);
1133
+		$all_data = json_decode($buffer,true);
1134
+		if (isset($all_data['aircraft'])) {
1135 1135
 		$reset = 0;
1136 1136
 		foreach ($all_data['aircraft'] as $key => $line) {
1137
-		    $data = array();
1138
-		    $data['hex'] = $key; // hex
1139
-		    if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1140
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1141
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1142
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1143
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1144
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1145
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1146
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1147
-		    //$data['emergency'] = ''; // emergency
1148
-		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1149
-		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1150
-		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1151
-		    $data['format_source'] = 'planefinderclient';
1152
-		    $data['id_source'] = $id_source;
1153
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1154
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1155
-		    $SI->add($data);
1156
-		    unset($data);
1137
+			$data = array();
1138
+			$data['hex'] = $key; // hex
1139
+			if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1140
+			if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1141
+			if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1142
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1143
+			if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1144
+			if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1145
+			if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1146
+			if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1147
+			//$data['emergency'] = ''; // emergency
1148
+			if (isset($line['reg'])) $data['registration'] = $line['reg'];
1149
+			if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1150
+			$data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1151
+			$data['format_source'] = 'planefinderclient';
1152
+			$data['id_source'] = $id_source;
1153
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1154
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1155
+			$SI->add($data);
1156
+			unset($data);
1157
+		}
1157 1158
 		}
1158
-	    }
1159
-	    $last_exec[$id]['last'] = time();
1159
+		$last_exec[$id]['last'] = time();
1160 1160
 	//} elseif ($value === 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
1161 1161
 	} elseif ($value['format'] === 'fr24json' && 
1162
-	    (
1162
+		(
1163 1163
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1164 1164
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1165
-	    )
1165
+		)
1166 1166
 	) {
1167
-	    //$buffer = $Common->getData($hosts[$id]);
1168
-	    $buffer = $Common->getData($value['host']);
1169
-	    $all_data = json_decode($buffer,true);
1170
-	    if (!empty($all_data)) $reset = 0;
1171
-	    foreach ($all_data as $key => $line) {
1167
+		//$buffer = $Common->getData($hosts[$id]);
1168
+		$buffer = $Common->getData($value['host']);
1169
+		$all_data = json_decode($buffer,true);
1170
+		if (!empty($all_data)) $reset = 0;
1171
+		foreach ($all_data as $key => $line) {
1172 1172
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1173
-		    $data = array();
1174
-		    $data['hex'] = $line[0];
1175
-		    $data['ident'] = $line[16]; //$line[13]
1176
-	    	    $data['altitude'] = $line[4]; // altitude
1177
-	    	    $data['speed'] = $line[5]; // speed
1178
-	    	    $data['heading'] = $line[3]; // heading
1179
-	    	    $data['latitude'] = $line[1]; // lat
1180
-	    	    $data['longitude'] = $line[2]; // long
1181
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
1182
-	    	    $data['squawk'] = $line[6]; // squawk
1183
-	    	    $data['aircraft_icao'] = $line[8];
1184
-	    	    $data['registration'] = $line[9];
1185
-		    $data['departure_airport_iata'] = $line[11];
1186
-		    $data['arrival_airport_iata'] = $line[12];
1187
-	    	    $data['emergency'] = ''; // emergency
1188
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1189
-	    	    $data['format_source'] = 'fr24json';
1190
-    		    $data['id_source'] = $id_source;
1191
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1192
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1193
-		    $SI->add($data);
1194
-		    unset($data);
1173
+			$data = array();
1174
+			$data['hex'] = $line[0];
1175
+			$data['ident'] = $line[16]; //$line[13]
1176
+				$data['altitude'] = $line[4]; // altitude
1177
+				$data['speed'] = $line[5]; // speed
1178
+				$data['heading'] = $line[3]; // heading
1179
+				$data['latitude'] = $line[1]; // lat
1180
+				$data['longitude'] = $line[2]; // long
1181
+				$data['verticalrate'] = $line[15]; // verticale rate
1182
+				$data['squawk'] = $line[6]; // squawk
1183
+				$data['aircraft_icao'] = $line[8];
1184
+				$data['registration'] = $line[9];
1185
+			$data['departure_airport_iata'] = $line[11];
1186
+			$data['arrival_airport_iata'] = $line[12];
1187
+				$data['emergency'] = ''; // emergency
1188
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1189
+				$data['format_source'] = 'fr24json';
1190
+				$data['id_source'] = $id_source;
1191
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1192
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1193
+			$SI->add($data);
1194
+			unset($data);
1195 1195
 		}
1196
-	    }
1197
-	    //$last_exec['fr24json'] = time();
1198
-	    $last_exec[$id]['last'] = time();
1196
+		}
1197
+		//$last_exec['fr24json'] = time();
1198
+		$last_exec[$id]['last'] = time();
1199 1199
 	//} elseif ($value === 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
1200 1200
 	} elseif ($value['format'] === 'radarvirtueljson' && 
1201
-	    (
1201
+		(
1202 1202
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1203 1203
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1204
-	    )
1204
+		)
1205 1205
 	) {
1206
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1207
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1208
-	    //echo $buffer;
1209
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1210
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1211
-	    $all_data = json_decode($buffer,true);
1212
-	    if (json_last_error() != JSON_ERROR_NONE) {
1206
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1207
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
1208
+		//echo $buffer;
1209
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
1210
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1211
+		$all_data = json_decode($buffer,true);
1212
+		if (json_last_error() != JSON_ERROR_NONE) {
1213 1213
 		die(json_last_error_msg());
1214
-	    }
1215
-	    if (isset($all_data['mrkrs'])) {
1214
+		}
1215
+		if (isset($all_data['mrkrs'])) {
1216 1216
 		$reset = 0;
1217 1217
 		foreach ($all_data['mrkrs'] as $key => $line) {
1218
-		    if (isset($line['inf'])) {
1218
+			if (isset($line['inf'])) {
1219 1219
 			$data = array();
1220 1220
 			$data['hex'] = $line['inf']['ia'];
1221 1221
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1222
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1223
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1224
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1225
-	    		$data['latitude'] = $line['pt'][0]; // lat
1226
-	    		$data['longitude'] = $line['pt'][1]; // long
1227
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1228
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1229
-	    		//$data['aircraft_icao'] = $line[8];
1230
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1222
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1223
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1224
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1225
+				$data['latitude'] = $line['pt'][0]; // lat
1226
+				$data['longitude'] = $line['pt'][1]; // long
1227
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1228
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1229
+				//$data['aircraft_icao'] = $line[8];
1230
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1231 1231
 			//$data['departure_airport_iata'] = $line[11];
1232 1232
 			//$data['arrival_airport_iata'] = $line[12];
1233
-	    		//$data['emergency'] = ''; // emergency
1233
+				//$data['emergency'] = ''; // emergency
1234 1234
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1235
-	    		$data['format_source'] = 'radarvirtueljson';
1236
-    			$data['id_source'] = $id_source;
1235
+				$data['format_source'] = 'radarvirtueljson';
1236
+				$data['id_source'] = $id_source;
1237 1237
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1238 1238
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1239 1239
 			$SI->add($data);
1240 1240
 			unset($data);
1241
-		    }
1241
+			}
1242
+		}
1242 1243
 		}
1243
-	    }
1244
-	    //$last_exec['radarvirtueljson'] = time();
1245
-	    $last_exec[$id]['last'] = time();
1244
+		//$last_exec['radarvirtueljson'] = time();
1245
+		$last_exec[$id]['last'] = time();
1246 1246
 	//} elseif ($value === 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
1247 1247
 	} elseif ($value['format'] === 'pirepsjson' && 
1248
-	    (
1248
+		(
1249 1249
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1250 1250
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1251
-	    )
1251
+		)
1252 1252
 	) {
1253
-	    //$buffer = $Common->getData($hosts[$id]);
1254
-	    $buffer = $Common->getData($value['host'].'?'.time());
1255
-	    $all_data = json_decode(utf8_encode($buffer),true);
1253
+		//$buffer = $Common->getData($hosts[$id]);
1254
+		$buffer = $Common->getData($value['host'].'?'.time());
1255
+		$all_data = json_decode(utf8_encode($buffer),true);
1256 1256
 	    
1257
-	    if (isset($all_data['pireps'])) {
1257
+		if (isset($all_data['pireps'])) {
1258 1258
 		$reset = 0;
1259
-	        foreach ($all_data['pireps'] as $line) {
1260
-		    $data = array();
1261
-		    $data['id'] = $line['id'];
1262
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1263
-		    $data['ident'] = $line['callsign']; // ident
1264
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1265
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1266
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1267
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1268
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1269
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1270
-		    $data['latitude'] = $line['lat']; // lat
1271
-		    $data['longitude'] = $line['lon']; // long
1272
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1273
-		    //$data['squawk'] = $line['squawk']; // squawk
1274
-		    //$data['emergency'] = ''; // emergency
1275
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1276
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1277
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1278
-		    //$data['arrival_airport_time'] = $line['arrtime'];
1279
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1280
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1281
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1282
-		    else $data['info'] = '';
1283
-		    $data['format_source'] = 'pireps';
1284
-    		    $data['id_source'] = $id_source;
1285
-		    $data['datetime'] = date('Y-m-d H:i:s');
1286
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1287
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1288
-		    if ($line['icon'] === 'plane') {
1259
+			foreach ($all_data['pireps'] as $line) {
1260
+			$data = array();
1261
+			$data['id'] = $line['id'];
1262
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1263
+			$data['ident'] = $line['callsign']; // ident
1264
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1265
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1266
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1267
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1268
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1269
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1270
+			$data['latitude'] = $line['lat']; // lat
1271
+			$data['longitude'] = $line['lon']; // long
1272
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
1273
+			//$data['squawk'] = $line['squawk']; // squawk
1274
+			//$data['emergency'] = ''; // emergency
1275
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1276
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1277
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1278
+			//$data['arrival_airport_time'] = $line['arrtime'];
1279
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1280
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1281
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
1282
+			else $data['info'] = '';
1283
+			$data['format_source'] = 'pireps';
1284
+				$data['id_source'] = $id_source;
1285
+			$data['datetime'] = date('Y-m-d H:i:s');
1286
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1287
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1288
+			if ($line['icon'] === 'plane') {
1289 1289
 			$SI->add($data);
1290
-		    //    print_r($data);
1291
-    		    } elseif ($line['icon'] === 'ct') {
1290
+			//    print_r($data);
1291
+				} elseif ($line['icon'] === 'ct') {
1292 1292
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1293 1293
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1294 1294
 			$typec = substr($data['ident'],-3);
@@ -1303,209 +1303,209 @@  discard block
 block discarded – undo
1303 1303
 			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1304 1304
 			else $data['type'] = 'Observer';
1305 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
-		    }
1307
-		    unset($data);
1306
+			}
1307
+			unset($data);
1308
+		}
1308 1309
 		}
1309
-	    }
1310
-	    //$last_exec['pirepsjson'] = time();
1311
-	    $last_exec[$id]['last'] = time();
1310
+		//$last_exec['pirepsjson'] = time();
1311
+		$last_exec[$id]['last'] = time();
1312 1312
 	//} elseif ($value === 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1313 1313
 	} elseif ($value['format'] === 'phpvmacars' && 
1314
-	    (
1314
+		(
1315 1315
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1316 1316
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1317
-	    )
1317
+		)
1318 1318
 	) {
1319
-	    //$buffer = $Common->getData($hosts[$id]);
1320
-	    if ($globalDebug) echo 'Get Data...'."\n";
1321
-	    $buffer = $Common->getData($value['host']);
1322
-	    $all_data = json_decode($buffer,true);
1323
-	    if ($buffer != '' && is_array($all_data)) {
1319
+		//$buffer = $Common->getData($hosts[$id]);
1320
+		if ($globalDebug) echo 'Get Data...'."\n";
1321
+		$buffer = $Common->getData($value['host']);
1322
+		$all_data = json_decode($buffer,true);
1323
+		if ($buffer != '' && is_array($all_data)) {
1324 1324
 		$reset = 0;
1325 1325
 		foreach ($all_data as $line) {
1326
-	    	    $data = array();
1327
-	    	    //$data['id'] = $line['id']; // id not usable
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
1330
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1331
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1332
-	    	    $data['ident'] = $line['flightnum']; // ident
1333
-	    	    $data['altitude'] = $line['alt']; // altitude
1334
-	    	    $data['speed'] = $line['gs']; // speed
1335
-	    	    $data['heading'] = $line['heading']; // heading
1336
-	    	    $data['latitude'] = $line['lat']; // lat
1337
-	    	    $data['longitude'] = $line['lng']; // long
1338
-	    	    $data['verticalrate'] = ''; // verticale rate
1339
-	    	    $data['squawk'] = ''; // squawk
1340
-	    	    $data['emergency'] = ''; // emergency
1341
-	    	    //$data['datetime'] = $line['lastupdate'];
1342
-	    	    //$data['last_update'] = $line['lastupdate'];
1343
-	    	    if (isset($value['timezone'])) {
1344
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1345
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1346
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1347
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1348
-	    	    $data['departure_airport_icao'] = $line['depicao'];
1349
-	    	    $data['departure_airport_time'] = $line['deptime'];
1350
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
1351
-    		    $data['arrival_airport_time'] = $line['arrtime'];
1352
-    		    if (isset($line['registration'])) {
1353
-    			$data['registration'] = $line['registration'];
1354
-    			//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1355
-    		    } else $data['registration'] = $line['aircraft'];
1356
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1357
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1358
-		    if (isset($line['aircraftname'])) {
1326
+				$data = array();
1327
+				//$data['id'] = $line['id']; // id not usable
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
1330
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1331
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1332
+				$data['ident'] = $line['flightnum']; // ident
1333
+				$data['altitude'] = $line['alt']; // altitude
1334
+				$data['speed'] = $line['gs']; // speed
1335
+				$data['heading'] = $line['heading']; // heading
1336
+				$data['latitude'] = $line['lat']; // lat
1337
+				$data['longitude'] = $line['lng']; // long
1338
+				$data['verticalrate'] = ''; // verticale rate
1339
+				$data['squawk'] = ''; // squawk
1340
+				$data['emergency'] = ''; // emergency
1341
+				//$data['datetime'] = $line['lastupdate'];
1342
+				//$data['last_update'] = $line['lastupdate'];
1343
+				if (isset($value['timezone'])) {
1344
+				$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1345
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1346
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1347
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1348
+				$data['departure_airport_icao'] = $line['depicao'];
1349
+				$data['departure_airport_time'] = $line['deptime'];
1350
+				$data['arrival_airport_icao'] = $line['arricao'];
1351
+				$data['arrival_airport_time'] = $line['arrtime'];
1352
+				if (isset($line['registration'])) {
1353
+				$data['registration'] = $line['registration'];
1354
+				//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1355
+				} else $data['registration'] = $line['aircraft'];
1356
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1357
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1358
+			if (isset($line['aircraftname'])) {
1359 1359
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1360 1360
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1361
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1362
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1363
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
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']);
1368
-	    		}
1369
-	    	    }
1370
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1371
-    		    $data['id_source'] = $id_source;
1372
-	    	    $data['format_source'] = 'phpvmacars';
1373
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1374
-		    $SI->add($data);
1375
-		    unset($data);
1361
+				$aircraft_data = explode('-',$line['aircraftname']);
1362
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1363
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
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']);
1368
+				}
1369
+				}
1370
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
1371
+				$data['id_source'] = $id_source;
1372
+				$data['format_source'] = 'phpvmacars';
1373
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1374
+			$SI->add($data);
1375
+			unset($data);
1376 1376
 		}
1377 1377
 		if ($globalDebug) echo 'No more data...'."\n";
1378 1378
 		unset($buffer);
1379 1379
 		unset($all_data);
1380
-	    }
1381
-	    //$last_exec['phpvmacars'] = time();
1382
-	    $last_exec[$id]['last'] = time();
1380
+		}
1381
+		//$last_exec['phpvmacars'] = time();
1382
+		$last_exec[$id]['last'] = time();
1383 1383
 	} elseif ($value['format'] === 'vaos' && 
1384
-	    (
1384
+		(
1385 1385
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1386 1386
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1387
-	    )
1387
+		)
1388 1388
 	) {
1389
-	    //$buffer = $Common->getData($hosts[$id]);
1390
-	    if ($globalDebug) echo 'Get Data...'."\n";
1391
-	    $buffer = $Common->getData($value['host']);
1392
-	    $all_data = json_decode($buffer,true);
1393
-	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1389
+		//$buffer = $Common->getData($hosts[$id]);
1390
+		if ($globalDebug) echo 'Get Data...'."\n";
1391
+		$buffer = $Common->getData($value['host']);
1392
+		$all_data = json_decode($buffer,true);
1393
+		if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1394 1394
 		$reset = 0;
1395 1395
 		foreach ($all_data['ACARSData'] as $line) {
1396
-		    //print_r($line);
1397
-	    	    $data = array();
1398
-	    	    //$data['id'] = $line['id']; // id not usable
1399
-	    	    $data['id'] = $line['id'];
1400
-	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1401
-	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1402
-	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1403
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1404
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1405
-	    	    $data['altitude'] = $line['altitude']; // altitude
1406
-	    	    $data['speed'] = $line['groundspeed']; // speed
1407
-	    	    $data['heading'] = $line['heading']; // heading
1408
-	    	    $data['latitude'] = $line['lat']; // lat
1409
-	    	    $data['longitude'] = $line['lon']; // long
1410
-	    	    //$data['verticalrate'] = ''; // verticale rate
1411
-	    	    //$data['squawk'] = ''; // squawk
1412
-	    	    //$data['emergency'] = ''; // emergency
1413
-	    	    if (isset($value['timezone'])) {
1414
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1415
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1416
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1417
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1396
+			//print_r($line);
1397
+				$data = array();
1398
+				//$data['id'] = $line['id']; // id not usable
1399
+				$data['id'] = $line['id'];
1400
+				//$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1401
+				if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1402
+				if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1403
+				$data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1404
+				if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1405
+				$data['altitude'] = $line['altitude']; // altitude
1406
+				$data['speed'] = $line['groundspeed']; // speed
1407
+				$data['heading'] = $line['heading']; // heading
1408
+				$data['latitude'] = $line['lat']; // lat
1409
+				$data['longitude'] = $line['lon']; // long
1410
+				//$data['verticalrate'] = ''; // verticale rate
1411
+				//$data['squawk'] = ''; // squawk
1412
+				//$data['emergency'] = ''; // emergency
1413
+				if (isset($value['timezone'])) {
1414
+				$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1415
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1416
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1417
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1418 1418
 	    	    
1419
-	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1420
-	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
1421
-	    	    $data['arrival_airport_icao'] = $line['bid']['arrapt']['icao'];
1422
-		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1423
-		    $data['registration'] = $line['bid']['aircraft']['registration'];
1419
+				$data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1420
+				$data['departure_airport_time'] = $line['bid']['deptime'];
1421
+				$data['arrival_airport_icao'] = $line['bid']['arrapt']['icao'];
1422
+			$data['arrival_airport_time'] = $line['bid']['arrtime'];
1423
+			$data['registration'] = $line['bid']['aircraft']['registration'];
1424 1424
 
1425
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1426
-		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1427
-	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1425
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1426
+			if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1427
+				$data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1428 1428
 
1429
-    		    $data['id_source'] = $id_source;
1430
-	    	    $data['format_source'] = 'vaos';
1431
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1432
-		    $SI->add($data);
1433
-		    unset($data);
1429
+				$data['id_source'] = $id_source;
1430
+				$data['format_source'] = 'vaos';
1431
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1432
+			$SI->add($data);
1433
+			unset($data);
1434 1434
 		}
1435 1435
 		if ($globalDebug) echo 'No more data...'."\n";
1436 1436
 		unset($buffer);
1437 1437
 		unset($all_data);
1438
-	    }
1439
-	    //$last_exec['phpvmacars'] = time();
1440
-	    $last_exec[$id]['last'] = time();
1438
+		}
1439
+		//$last_exec['phpvmacars'] = time();
1440
+		$last_exec[$id]['last'] = time();
1441 1441
 	} elseif ($value['format'] === 'vam' && 
1442
-	    (
1442
+		(
1443 1443
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1444 1444
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1445
-	    )
1445
+		)
1446 1446
 	) {
1447
-	    //$buffer = $Common->getData($hosts[$id]);
1448
-	    if ($globalDebug) echo 'Get Data...'."\n";
1449
-	    $buffer = $Common->getData($value['host']);
1450
-	    $all_data = json_decode($buffer,true);
1451
-	    if ($buffer != '' && is_array($all_data)) {
1447
+		//$buffer = $Common->getData($hosts[$id]);
1448
+		if ($globalDebug) echo 'Get Data...'."\n";
1449
+		$buffer = $Common->getData($value['host']);
1450
+		$all_data = json_decode($buffer,true);
1451
+		if ($buffer != '' && is_array($all_data)) {
1452 1452
 		$reset = 0;
1453 1453
 		foreach ($all_data as $line) {
1454
-	    	    $data = array();
1455
-	    	    //$data['id'] = $line['id']; // id not usable
1456
-	    	    $data['id'] = trim($line['flight_id']);
1457
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1458
-	    	    $data['pilot_name'] = $line['pilot_name'];
1459
-	    	    $data['pilot_id'] = $line['pilot_id'];
1460
-	    	    $data['ident'] = trim($line['callsign']); // ident
1461
-	    	    $data['altitude'] = $line['altitude']; // altitude
1462
-	    	    $data['speed'] = $line['gs']; // speed
1463
-	    	    $data['heading'] = $line['heading']; // heading
1464
-	    	    $data['latitude'] = $line['latitude']; // lat
1465
-	    	    $data['longitude'] = $line['longitude']; // long
1466
-	    	    $data['verticalrate'] = ''; // verticale rate
1467
-	    	    $data['squawk'] = ''; // squawk
1468
-	    	    $data['emergency'] = ''; // emergency
1469
-	    	    //$data['datetime'] = $line['lastupdate'];
1470
-	    	    $data['last_update'] = $line['last_update'];
1471
-		    $data['datetime'] = date('Y-m-d H:i:s');
1472
-	    	    $data['departure_airport_icao'] = $line['departure'];
1473
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
1474
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
1475
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
1476
-    		    //$data['registration'] = $line['aircraft'];
1477
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1478
-	    	    $data['aircraft_icao'] = $line['plane_type'];
1479
-    		    $data['id_source'] = $id_source;
1480
-	    	    $data['format_source'] = 'vam';
1481
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1482
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1483
-		    $SI->add($data);
1484
-		    unset($data);
1454
+				$data = array();
1455
+				//$data['id'] = $line['id']; // id not usable
1456
+				$data['id'] = trim($line['flight_id']);
1457
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1458
+				$data['pilot_name'] = $line['pilot_name'];
1459
+				$data['pilot_id'] = $line['pilot_id'];
1460
+				$data['ident'] = trim($line['callsign']); // ident
1461
+				$data['altitude'] = $line['altitude']; // altitude
1462
+				$data['speed'] = $line['gs']; // speed
1463
+				$data['heading'] = $line['heading']; // heading
1464
+				$data['latitude'] = $line['latitude']; // lat
1465
+				$data['longitude'] = $line['longitude']; // long
1466
+				$data['verticalrate'] = ''; // verticale rate
1467
+				$data['squawk'] = ''; // squawk
1468
+				$data['emergency'] = ''; // emergency
1469
+				//$data['datetime'] = $line['lastupdate'];
1470
+				$data['last_update'] = $line['last_update'];
1471
+			$data['datetime'] = date('Y-m-d H:i:s');
1472
+				$data['departure_airport_icao'] = $line['departure'];
1473
+				//$data['departure_airport_time'] = $line['departure_time'];
1474
+				$data['arrival_airport_icao'] = $line['arrival'];
1475
+				//$data['arrival_airport_time'] = $line['arrival_time'];
1476
+				//$data['registration'] = $line['aircraft'];
1477
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1478
+				$data['aircraft_icao'] = $line['plane_type'];
1479
+				$data['id_source'] = $id_source;
1480
+				$data['format_source'] = 'vam';
1481
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1482
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1483
+			$SI->add($data);
1484
+			unset($data);
1485 1485
 		}
1486 1486
 		if ($globalDebug) echo 'No more data...'."\n";
1487 1487
 		unset($buffer);
1488 1488
 		unset($all_data);
1489
-	    }
1490
-	    //$last_exec['phpvmacars'] = time();
1491
-	    $last_exec[$id]['last'] = time();
1489
+		}
1490
+		//$last_exec['phpvmacars'] = time();
1491
+		$last_exec[$id]['last'] = time();
1492 1492
 	} elseif ($value['format'] === 'blitzortung' && 
1493
-	    (
1493
+		(
1494 1494
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1495 1495
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1496
-	    )
1496
+		)
1497 1497
 	) {
1498
-	    //$buffer = $Common->getData($hosts[$id]);
1499
-	    if ($globalDebug) echo 'Get Data...'."\n";
1500
-	    $buffer = $Common->getData($value['host']);
1501
-	    $all_data = json_decode($buffer,true);
1502
-	    if ($buffer != '') {
1498
+		//$buffer = $Common->getData($hosts[$id]);
1499
+		if ($globalDebug) echo 'Get Data...'."\n";
1500
+		$buffer = $Common->getData($value['host']);
1501
+		$all_data = json_decode($buffer,true);
1502
+		if ($buffer != '') {
1503 1503
 		$Source->deleteLocationBySource('blitzortung');
1504 1504
 		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1505 1505
 		$buffer = explode('\n',$buffer);
1506 1506
 		foreach ($buffer as $buffer_line) {
1507
-		    $line = json_decode($buffer_line,true);
1508
-		    if (isset($line['time'])) {
1507
+			$line = json_decode($buffer_line,true);
1508
+			if (isset($line['time'])) {
1509 1509
 			$data = array();
1510 1510
 			$data['altitude'] = $line['alt']; // altitude
1511 1511
 			$data['latitude'] = $line['lat']; // lat
@@ -1517,94 +1517,94 @@  discard block
 block discarded – undo
1517 1517
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1518 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
 		}
1522 1522
 		if ($globalDebug) echo 'No more data...'."\n";
1523 1523
 		unset($buffer);
1524
-	    }
1525
-	    $last_exec[$id]['last'] = time();
1524
+		}
1525
+		$last_exec[$id]['last'] = time();
1526 1526
 	//} elseif ($value === 'sbs' || $value === 'tsv' || $value === 'raw' || $value === 'aprs' || $value === 'beast') {
1527 1527
 	} elseif ($value['format'] === 'sbs' || $value['format'] === 'tsv' || $value['format'] === 'raw' || $value['format'] === 'aprs' || $value['format'] === 'famaprs' || $value['format'] === 'beast' || $value['format'] === 'flightgearmp' || $value['format'] === 'flightgearsp' || $value['format'] === 'acars' || $value['format'] === 'acarssbs3' || $value['format'] === 'ais' || $value['format'] === 'vrstcp') {
1528
-	    //$last_exec[$id]['last'] = time();
1529
-	    //$read = array( $sockets[$id] );
1530
-	    $read = $sockets;
1531
-	    $write = NULL;
1532
-	    $e = NULL;
1533
-	    $n = socket_select($read, $write, $e, $timeout);
1534
-	    if ($e != NULL) var_dump($e);
1535
-	    if ($n > 0) {
1528
+		//$last_exec[$id]['last'] = time();
1529
+		//$read = array( $sockets[$id] );
1530
+		$read = $sockets;
1531
+		$write = NULL;
1532
+		$e = NULL;
1533
+		$n = socket_select($read, $write, $e, $timeout);
1534
+		if ($e != NULL) var_dump($e);
1535
+		if ($n > 0) {
1536 1536
 		$reset = 0;
1537 1537
 		foreach ($read as $nb => $r) {
1538
-		    //$value = $formats[$nb];
1539
-		    $format = $globalSources[$nb]['format'];
1540
-		    if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1538
+			//$value = $formats[$nb];
1539
+			$format = $globalSources[$nb]['format'];
1540
+			if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1541 1541
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1542
-		    } elseif ($format === 'vrstcp') {
1542
+			} elseif ($format === 'vrstcp') {
1543 1543
 			$buffer = @socket_read($r, 6000);
1544
-		    } else {
1544
+			} else {
1545 1545
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1546
-		    }
1547
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1548
-		    //echo $buffer."\n";
1549
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1550
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1551
-		    $error = false;
1552
-		    //$SI::del();
1553
-		    if ($buffer !== FALSE) {
1546
+			}
1547
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1548
+			//echo $buffer."\n";
1549
+			// lets play nice and handle signals such as ctrl-c/kill properly
1550
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1551
+			$error = false;
1552
+			//$SI::del();
1553
+			if ($buffer !== FALSE) {
1554 1554
 			if ($format === 'vrstcp') {
1555
-			    $buffer = explode('},{',$buffer);
1555
+				$buffer = explode('},{',$buffer);
1556 1556
 			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1557
-		    }
1558
-		    // SBS format is CSV format
1559
-		    if ($buffer !== FALSE && $buffer !== '') {
1557
+			}
1558
+			// SBS format is CSV format
1559
+			if ($buffer !== FALSE && $buffer !== '') {
1560 1560
 			$tt[$format] = 0;
1561 1561
 			if ($format === 'acarssbs3') {
1562
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1563
-			    $ACARS->add(trim($buffer));
1564
-			    $ACARS->deleteLiveAcarsData();
1562
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1563
+				$ACARS->add(trim($buffer));
1564
+				$ACARS->deleteLiveAcarsData();
1565 1565
 			} elseif ($format === 'raw') {
1566
-			    // AVR format
1567
-			    $data = $SBS->parse($buffer);
1568
-			    if (is_array($data)) {
1566
+				// AVR format
1567
+				$data = $SBS->parse($buffer);
1568
+				if (is_array($data)) {
1569 1569
 				$data['datetime'] = date('Y-m-d H:i:s');
1570 1570
 				$data['format_source'] = 'raw';
1571 1571
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1572 1572
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1573 1573
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1574 1574
 				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1575
-			    }
1575
+				}
1576 1576
 			} elseif ($format === 'ais') {
1577
-			    $ais_data = $AIS->parse_line(trim($buffer));
1578
-			    $data = array();
1579
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1580
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1581
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1582
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1583
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1584
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1585
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1586
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1587
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1588
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1589
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
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']);
1592
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1593
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1594
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1577
+				$ais_data = $AIS->parse_line(trim($buffer));
1578
+				$data = array();
1579
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1580
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1581
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1582
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1583
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1584
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1585
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1586
+				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1587
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1588
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1589
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
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']);
1592
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1593
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1594
+				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1595 1595
 
1596
-			    if (isset($ais_data['timestamp'])) {
1596
+				if (isset($ais_data['timestamp'])) {
1597 1597
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1598
-			    } else {
1598
+				} else {
1599 1599
 				$data['datetime'] = date('Y-m-d H:i:s');
1600
-			    }
1601
-			    $data['format_source'] = 'aisnmea';
1602
-    			    $data['id_source'] = $id_source;
1603
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
1604
-			    unset($data);
1605
-                        } elseif ($format === 'flightgearsp') {
1606
-                    	    //echo $buffer."\n";
1607
-                    	    if (strlen($buffer) > 5) {
1600
+				}
1601
+				$data['format_source'] = 'aisnmea';
1602
+					$data['id_source'] = $id_source;
1603
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
1604
+				unset($data);
1605
+						} elseif ($format === 'flightgearsp') {
1606
+							//echo $buffer."\n";
1607
+							if (strlen($buffer) > 5) {
1608 1608
 				$line = explode(',',$buffer);
1609 1609
 				$data = array();
1610 1610
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1621,38 +1621,38 @@  discard block
 block discarded – undo
1621 1621
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1622 1622
 				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1623 1623
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1624
-			    }
1625
-                        } elseif ($format === 'acars') {
1626
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1627
-			    $ACARS->add(trim($buffer));
1628
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1629
-			    $ACARS->deleteLiveAcarsData();
1624
+				}
1625
+						} elseif ($format === 'acars') {
1626
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1627
+				$ACARS->add(trim($buffer));
1628
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
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 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
1638
-				    $data['ident'] = $userserver[0];
1639
-				    $data['registration'] = $userserver[0];
1640
-				    $data['latitude'] = $line[4];
1641
-				    $data['longitude'] = $line[5];
1642
-				    $data['altitude'] = $line[6];
1643
-				    $data['datetime'] = date('Y-m-d H:i:s');
1644
-				    $aircraft_type = $line[10];
1645
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1646
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1647
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1648
-				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1636
+					$userserver = explode('@',$line[0]);
1637
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1638
+					$data['ident'] = $userserver[0];
1639
+					$data['registration'] = $userserver[0];
1640
+					$data['latitude'] = $line[4];
1641
+					$data['longitude'] = $line[5];
1642
+					$data['altitude'] = $line[6];
1643
+					$data['datetime'] = date('Y-m-d H:i:s');
1644
+					$aircraft_type = $line[10];
1645
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1646
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1647
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1648
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1649
+				}
1649 1650
 				}
1650
-			    }
1651 1651
 			} elseif ($format === 'beast') {
1652
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1653
-			    die;
1652
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1653
+				die;
1654 1654
 			} elseif ($format === 'vrstcp') {
1655
-			    foreach($buffer as $all_data) {
1655
+				foreach($buffer as $all_data) {
1656 1656
 				$line = json_decode('{'.$all_data.'}',true);
1657 1657
 				$data = array();
1658 1658
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1672,158 +1672,158 @@  discard block
 block discarded – undo
1672 1672
 				*/
1673 1673
 				$data['datetime'] = date('Y-m-d H:i:s');
1674 1674
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1675
-		    		$data['format_source'] = 'vrstcp';
1675
+					$data['format_source'] = 'vrstcp';
1676 1676
 				$data['id_source'] = $id_source;
1677 1677
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1678 1678
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1679 1679
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1680 1680
 				unset($data);
1681
-			    }
1681
+				}
1682 1682
 			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
1683
-			    $line = explode("\t", $buffer);
1684
-			    for($k = 0; $k < count($line); $k=$k+2) {
1683
+				$line = explode("\t", $buffer);
1684
+				for($k = 0; $k < count($line); $k=$k+2) {
1685 1685
 				$key = $line[$k];
1686
-			        $lined[$key] = $line[$k+1];
1687
-			    }
1688
-    			    if (count($lined) > 3) {
1689
-    				$data['hex'] = $lined['hexid'];
1690
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1691
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1692
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1693
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1694
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1695
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1696
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1697
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1698
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1699
-    				$data['id_source'] = $id_source;
1700
-    				$data['format_source'] = 'tsv';
1701
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1702
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1686
+					$lined[$key] = $line[$k+1];
1687
+				}
1688
+					if (count($lined) > 3) {
1689
+					$data['hex'] = $lined['hexid'];
1690
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1691
+					$data['datetime'] = date('Y-m-d H:i:s');;
1692
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1693
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1694
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1695
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1696
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1697
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1698
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1699
+					$data['id_source'] = $id_source;
1700
+					$data['format_source'] = 'tsv';
1701
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1702
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1703 1703
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1704
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1705
-    				unset($lined);
1706
-    				unset($data);
1707
-    			    } else $error = true;
1704
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1705
+					unset($lined);
1706
+					unset($data);
1707
+					} else $error = true;
1708 1708
 			} elseif ($format === 'aprs' && $use_aprs) {
1709
-			    if ($aprs_connect === 0) {
1709
+				if ($aprs_connect === 0) {
1710 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 1717
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1718
-			    }
1718
+				}
1719 1719
 			    
1720
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1721
-			    //echo 'APRS data : '.$buffer."\n";
1722
-			    $buffer = str_replace('APRS <- ','',$buffer);
1723
-			    $buffer = str_replace('APRS -> ','',$buffer);
1724
-			    //echo $buffer."\n";
1725
-			    date_default_timezone_set('UTC');
1726
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1720
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1721
+				//echo 'APRS data : '.$buffer."\n";
1722
+				$buffer = str_replace('APRS <- ','',$buffer);
1723
+				$buffer = str_replace('APRS -> ','',$buffer);
1724
+				//echo $buffer."\n";
1725
+				date_default_timezone_set('UTC');
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']))) {
1730
-				    $aprs_last_tx = time();
1731
-				    $data = array();
1732
-				    //print_r($line);
1733
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1734
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1735
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1736
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1737
-				    if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1738
-				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1739
-				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
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']);
1742
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1743
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1744
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1745
-				    $data['latitude'] = $line['latitude'];
1746
-				    $data['longitude'] = $line['longitude'];
1747
-				    //$data['verticalrate'] = $line[16];
1748
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1749
-				    //else $data['speed'] = 0;
1750
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1751
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1752
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1753
-				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1730
+					$aprs_last_tx = time();
1731
+					$data = array();
1732
+					//print_r($line);
1733
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1734
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1735
+					if (isset($line['imo'])) $data['imo'] = $line['imo'];
1736
+					if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1737
+					if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1738
+					if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1739
+					if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
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']);
1742
+					else $data['datetime'] = date('Y-m-d H:i:s');
1743
+					//$data['datetime'] = date('Y-m-d H:i:s');
1744
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1745
+					$data['latitude'] = $line['latitude'];
1746
+					$data['longitude'] = $line['longitude'];
1747
+					//$data['verticalrate'] = $line[16];
1748
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1749
+					//else $data['speed'] = 0;
1750
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1751
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1752
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1753
+					//if (isset($line['heading'])) $data['heading'] = $line['heading'];
1754 1754
 				    
1755
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1756
-				    //else echo 'No heading...'."\n";
1757
-				    //else $data['heading'] = 0;
1758
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1759
-				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1760
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1761
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1762
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1763
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1764
-    				    $data['id_source'] = $id_source;
1765
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1766
-				    else $data['format_source'] = 'aprs';
1767
-				    $data['source_name'] = $line['source'];
1768
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1769
-				    else $data['source_type'] = 'flarm';
1770
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1771
-				    $currentdate = date('Y-m-d H:i:s');
1772
-				    $aprsdate = strtotime($data['datetime']);
1773
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1774
-				    // Accept data if time <= system time + 20s
1775
-				    //if (($data['source_type'] === 'modes') || isset($line['stealth']) && ($line['stealth'] === 0 || $line['stealth'] === '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1776
-				    if (
1755
+					if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1756
+					//else echo 'No heading...'."\n";
1757
+					//else $data['heading'] = 0;
1758
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1759
+					//if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1760
+					if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1761
+					elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1762
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1763
+					elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1764
+						$data['id_source'] = $id_source;
1765
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1766
+					else $data['format_source'] = 'aprs';
1767
+					$data['source_name'] = $line['source'];
1768
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1769
+					else $data['source_type'] = 'flarm';
1770
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1771
+					$currentdate = date('Y-m-d H:i:s');
1772
+					$aprsdate = strtotime($data['datetime']);
1773
+					if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1774
+					// Accept data if time <= system time + 20s
1775
+					//if (($data['source_type'] === 'modes') || isset($line['stealth']) && ($line['stealth'] === 0 || $line['stealth'] === '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1776
+					if (
1777 1777
 					($data['source_type'] === 'modes') || 
1778 1778
 					isset($line['stealth']) && 
1779 1779
 					(!isset($data['hex']) || $data['hex'] != 'FFFFFF') && 
1780 1780
 					 ($line['stealth'] === 0 || $line['stealth'] == '') && 
1781 1781
 					 (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1782 1782
 					$send = $SI->add($data);
1783
-				    } elseif ($data['source_type'] === 'ais') {
1783
+					} elseif ($data['source_type'] === 'ais') {
1784 1784
 					$data['type'] = '';
1785 1785
 					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
1786
-				    } elseif (isset($line['stealth']) && $line['stealth'] != 0) {
1786
+					} elseif (isset($line['stealth']) && $line['stealth'] != 0) {
1787 1787
 					 echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1788
-				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1789
-					    //$line['symbol'] === 'Balloon' ||
1790
-					    $line['symbol'] === 'Glider' || 
1791
-					    $line['symbol'] === 'No. Plane' || 
1792
-					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
1793
-					    if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
1794
-					    if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1795
-					    $send = $SI->add($data);
1796
-				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1797
-					    $line['symbol'] === 'Yacht (Sail)' || 
1798
-					    $line['symbol'] === 'Ship (Power Boat)')) {
1799
-					    $send = $MI->add($data);
1800
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1801
-					    $line['symbol'] === 'Car' || 
1802
-					    $line['symbol'] === 'Ambulance' || 
1803
-					    $line['symbol'] === 'Van' || 
1804
-					    $line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || 
1805
-					    $line['symbol'] === 'Motorcycle' || 
1806
-					    $line['symbol'] === 'Tractor' || 
1807
-					    $line['symbol'] === 'Police' || 
1808
-					    $line['symbol'] === 'Bike' || 
1809
-					    $line['symbol'] === 'Jogger' || 
1810
-					    $line['symbol'] === 'Horse' || 
1811
-					    $line['symbol'] === 'Bus' || 
1812
-					    $line['symbol'] === 'Jeep' || 
1813
-					    $line['symbol'] === 'Recreational Vehicle' || 
1814
-					    $line['symbol'] === 'Yacht (Sail)' || 
1815
-					    $line['symbol'] === 'Ship (Power Boat)' || 
1816
-					    $line['symbol'] === 'Firetruck' || 
1817
-					    $line['symbol'] === 'Balloon' || $line['symbol'] === 'Glider' || 
1818
-					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter' || 
1819
-					    $line['symbol'] === 'SUV' ||
1820
-					    $line['symbol'] === 'Snowmobile' ||
1821
-					    $line['symbol'] === 'Mobile Satellite Station')) {
1822
-				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1788
+					} elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1789
+						//$line['symbol'] === 'Balloon' ||
1790
+						$line['symbol'] === 'Glider' || 
1791
+						$line['symbol'] === 'No. Plane' || 
1792
+						$line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
1793
+						if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
1794
+						if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1795
+						$send = $SI->add($data);
1796
+					} elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1797
+						$line['symbol'] === 'Yacht (Sail)' || 
1798
+						$line['symbol'] === 'Ship (Power Boat)')) {
1799
+						$send = $MI->add($data);
1800
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1801
+						$line['symbol'] === 'Car' || 
1802
+						$line['symbol'] === 'Ambulance' || 
1803
+						$line['symbol'] === 'Van' || 
1804
+						$line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || 
1805
+						$line['symbol'] === 'Motorcycle' || 
1806
+						$line['symbol'] === 'Tractor' || 
1807
+						$line['symbol'] === 'Police' || 
1808
+						$line['symbol'] === 'Bike' || 
1809
+						$line['symbol'] === 'Jogger' || 
1810
+						$line['symbol'] === 'Horse' || 
1811
+						$line['symbol'] === 'Bus' || 
1812
+						$line['symbol'] === 'Jeep' || 
1813
+						$line['symbol'] === 'Recreational Vehicle' || 
1814
+						$line['symbol'] === 'Yacht (Sail)' || 
1815
+						$line['symbol'] === 'Ship (Power Boat)' || 
1816
+						$line['symbol'] === 'Firetruck' || 
1817
+						$line['symbol'] === 'Balloon' || $line['symbol'] === 'Glider' || 
1818
+						$line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter' || 
1819
+						$line['symbol'] === 'SUV' ||
1820
+						$line['symbol'] === 'Snowmobile' ||
1821
+						$line['symbol'] === 'Mobile Satellite Station')) {
1822
+					//} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1823 1823
 				//    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1824 1824
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1825 1825
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1826
-				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
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 1829
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
@@ -1831,7 +1831,7 @@  discard block
 block discarded – undo
1831 1831
 					} else {
1832 1832
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1833 1833
 					}
1834
-				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
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');
@@ -1841,7 +1841,7 @@  discard block
 block discarded – undo
1841 1841
 					} else {
1842 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
-				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
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');
@@ -1850,11 +1850,11 @@  discard block
 block discarded – undo
1850 1850
 					} else {
1851 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
-				    } elseif ($globalDebug) {
1854
-				    	echo '/!\ Not added: '.$buffer."\n";
1855
-				    	print_r($line);
1856
-				    }
1857
-				    unset($data);
1853
+					} elseif ($globalDebug) {
1854
+						echo '/!\ Not added: '.$buffer."\n";
1855
+						print_r($line);
1856
+					}
1857
+					unset($data);
1858 1858
 				}
1859 1859
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1860 1860
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
@@ -1873,12 +1873,12 @@  discard block
 block discarded – undo
1873 1873
 				} elseif (!isset($globalSources[$nb]['last_weather_clean'])) {
1874 1874
 					$globalSources[$nb]['last_weather_clean'] = time();
1875 1875
 				}
1876
-			    }
1876
+				}
1877 1877
 			} else {
1878
-			    $line = explode(',', $buffer);
1879
-    			    if (count($line) > 20) {
1880
-    			    	$data['hex'] = $line[4];
1881
-    				/*
1878
+				$line = explode(',', $buffer);
1879
+					if (count($line) > 20) {
1880
+						$data['hex'] = $line[4];
1881
+					/*
1882 1882
     				$data['datetime'] = $line[6].' '.$line[7];
1883 1883
     					date_default_timezone_set($globalTimezone);
1884 1884
     					$datetime = new DateTime($data['datetime']);
@@ -1886,31 +1886,31 @@  discard block
 block discarded – undo
1886 1886
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1887 1887
     					date_default_timezone_set('UTC');
1888 1888
     				*/
1889
-    				// Force datetime to current UTC datetime
1890
-    				date_default_timezone_set('UTC');
1891
-    				$data['datetime'] = date('Y-m-d H:i:s');
1892
-    				$data['ident'] = trim($line[10]);
1893
-    				$data['latitude'] = $line[14];
1894
-    				$data['longitude'] = $line[15];
1895
-    				$data['verticalrate'] = $line[16];
1896
-    				$data['emergency'] = $line[20];
1897
-    				$data['speed'] = $line[12];
1898
-    				$data['squawk'] = $line[17];
1899
-    				$data['altitude'] = $line[11];
1900
-    				$data['heading'] = $line[13];
1901
-    				$data['ground'] = $line[21];
1902
-    				$data['emergency'] = $line[19];
1903
-    				$data['format_source'] = 'sbs';
1889
+					// Force datetime to current UTC datetime
1890
+					date_default_timezone_set('UTC');
1891
+					$data['datetime'] = date('Y-m-d H:i:s');
1892
+					$data['ident'] = trim($line[10]);
1893
+					$data['latitude'] = $line[14];
1894
+					$data['longitude'] = $line[15];
1895
+					$data['verticalrate'] = $line[16];
1896
+					$data['emergency'] = $line[20];
1897
+					$data['speed'] = $line[12];
1898
+					$data['squawk'] = $line[17];
1899
+					$data['altitude'] = $line[11];
1900
+					$data['heading'] = $line[13];
1901
+					$data['ground'] = $line[21];
1902
+					$data['emergency'] = $line[19];
1903
+					$data['format_source'] = 'sbs';
1904 1904
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1905 1905
 				elseif ($line[0] == 'MLAT') $data['source_name'] = 'MLAT';
1906
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1906
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1907 1907
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1908
-    				$data['id_source'] = $id_source;
1909
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1910
-    				else $error = true;
1911
-    				unset($data);
1912
-    			    } else $error = true;
1913
-			    if ($error) {
1908
+					$data['id_source'] = $id_source;
1909
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1910
+					else $error = true;
1911
+					unset($data);
1912
+					} else $error = true;
1913
+				if ($error) {
1914 1914
 				if (count($line) > 1 && ($line[0] === 'STA' || $line[0] === 'AIR' || $line[0] === 'SEL' || $line[0] === 'ID' || $line[0] === 'CLK')) { 
1915 1915
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1916 1916
 				} else {
@@ -1926,13 +1926,13 @@  discard block
 block discarded – undo
1926 1926
 					connect_all($sourceer);
1927 1927
 					$sourceer = array();
1928 1928
 				}
1929
-			    }
1929
+				}
1930 1930
 			}
1931 1931
 			// Sleep for xxx microseconds
1932 1932
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1933
-		    } else {
1933
+			} else {
1934 1934
 			if ($format === 'flightgearmp') {
1935
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1935
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1936 1936
 				//@socket_close($r);
1937 1937
 				sleep($globalMinFetch);
1938 1938
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1941,9 +1941,9 @@  discard block
 block discarded – undo
1941 1941
 				break;
1942 1942
 				
1943 1943
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1944
-			    if (isset($tt[$format])) $tt[$format]++;
1945
-			    else $tt[$format] = 0;
1946
-			    if ($tt[$format] > 30 || $buffer === FALSE) {
1944
+				if (isset($tt[$format])) $tt[$format]++;
1945
+				else $tt[$format] = 0;
1946
+				if ($tt[$format] > 30 || $buffer === FALSE) {
1947 1947
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1948 1948
 				//@socket_close($r);
1949 1949
 				sleep(2);
@@ -1954,24 +1954,24 @@  discard block
 block discarded – undo
1954 1954
 				//connect_all($globalSources);
1955 1955
 				$tt[$format]=0;
1956 1956
 				break;
1957
-			    } 
1958
-			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
1957
+				} 
1958
+				//else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
1959
+			}
1959 1960
 			}
1960
-		    }
1961 1961
 		}
1962
-	    } else {
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 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
-			    if ($globalDebug) echo "Shutdown all sockets...";
1969
+				if ($globalDebug) echo "Shutdown all sockets...";
1970 1970
 			    
1971
-			    foreach ($sockets as $sock) {
1971
+				foreach ($sockets as $sock) {
1972 1972
 				@socket_shutdown($sock,2);
1973 1973
 				@socket_close($sock);
1974
-			    }
1974
+				}
1975 1975
 			    
1976 1976
 			}
1977 1977
 			if ($globalDebug) echo "Waiting...";
@@ -1986,15 +1986,15 @@  discard block
 block discarded – undo
1986 1986
 			if ($globalDebug) echo "Restart all connections...";
1987 1987
 			connect_all($globalSources);
1988 1988
 		}
1989
-	    }
1989
+		}
1990 1990
 	}
1991 1991
 	if ($globalDaemon === false) {
1992
-	    if ($globalDebug) echo 'Check all...'."\n";
1993
-	    if (isset($SI)) $SI->checkAll();
1994
-	    if (isset($TI)) $TI->checkAll();
1995
-	    if (isset($MI)) $MI->checkAll();
1992
+		if ($globalDebug) echo 'Check all...'."\n";
1993
+		if (isset($SI)) $SI->checkAll();
1994
+		if (isset($TI)) $TI->checkAll();
1995
+		if (isset($MI)) $MI->checkAll();
1996
+	}
1996 1997
 	}
1997
-    }
1998 1998
 }
1999 1999
 
2000 2000
 ?>
Please login to merge, or discard this 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.
Braces   +1207 added lines, -405 removed lines patch added patch discarded remove patch
@@ -14,13 +14,17 @@  discard block
 block discarded – undo
14 14
 require_once(dirname(__FILE__).'/../require/class.Source.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17
+if (isset($globalTracker) && $globalTracker) {
18
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
19
+}
18 20
 if (isset($globalMarine) && $globalMarine) {
19 21
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
20 22
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21 23
 }
22 24
 
23
-if (!isset($globalDebug)) $globalDebug = FALSE;
25
+if (!isset($globalDebug)) {
26
+	$globalDebug = FALSE;
27
+}
24 28
 
25 29
 // Check if schema is at latest version
26 30
 $Connection = new Connection();
@@ -59,66 +63,107 @@  discard block
 block discarded – undo
59 63
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 64
 if (isset($options['s'])) {
61 65
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['s']);
64
-} elseif (isset($options['source'])) {
66
+    if (isset($options['format'])) {
67
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
68
+    } else {
69
+    	$globalSources[] = array('host' => $options['s']);
70
+    }
71
+    } elseif (isset($options['source'])) {
65 72
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
-    else $globalSources[] = array('host' => $options['source']);
68
-}
73
+    if (isset($options['format'])) {
74
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
75
+    } else {
76
+    	$globalSources[] = array('host' => $options['source']);
77
+    }
78
+    }
69 79
 if (isset($options['aprsserverhost'])) {
70 80
 	$globalServerAPRS = TRUE;
71 81
 	$globalServerAPRShost = $options['aprsserverhost'];
72 82
 }
73
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
74
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
75
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
76
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
83
+if (isset($options['aprsserverport'])) {
84
+	$globalServerAPRSport = $options['aprsserverport'];
85
+}
86
+if (isset($options['aprsserverssid'])) {
87
+	$globalServerAPRSssid = $options['aprsserverssid'];
88
+}
89
+if (isset($options['aprsserverpass'])) {
90
+	$globalServerAPRSpass = $options['aprsserverpass'];
91
+}
92
+if (isset($options['noaprsserver'])) {
93
+	$globalServerAPRS = FALSE;
94
+}
77 95
 if (isset($options['enable-aircraft'])) {
78
-	if ($globalDebug) echo 'Enable Aircraft mode'."\n";
96
+	if ($globalDebug) {
97
+		echo 'Enable Aircraft mode'."\n";
98
+	}
79 99
 	$globalAircraft = TRUE; 
80 100
 }
81 101
 if (isset($options['disable-aircraft'])) {
82
-	if ($globalDebug) echo 'Disable Aircraft mode'."\n";
102
+	if ($globalDebug) {
103
+		echo 'Disable Aircraft mode'."\n";
104
+	}
83 105
 	$globalAircraft = FALSE;
84 106
 }
85 107
 if (isset($options['enable-tracker'])) {
86
-	if ($globalDebug) echo 'Enable Tracker mode'."\n";
108
+	if ($globalDebug) {
109
+		echo 'Enable Tracker mode'."\n";
110
+	}
87 111
 	$globalTracker = TRUE; 
88 112
 }
89 113
 if (isset($options['disable-tracker'])) {
90
-	if ($globalDebug) echo 'Disable Tracker mode'."\n";
114
+	if ($globalDebug) {
115
+		echo 'Disable Tracker mode'."\n";
116
+	}
91 117
 	$globalTracker = FALSE;
92 118
 }
93 119
 if (isset($options['enable-marine'])) {
94
-	if ($globalDebug) echo 'Enable Marine mode'."\n";
120
+	if ($globalDebug) {
121
+		echo 'Enable Marine mode'."\n";
122
+	}
95 123
 	$globalMarine = TRUE;
96 124
 }
97 125
 if (isset($options['disable-marine'])) {
98
-	if ($globalDebug) echo 'Disable Marine mode'."\n";
126
+	if ($globalDebug) {
127
+		echo 'Disable Marine mode'."\n";
128
+	}
99 129
 	$globalMarine = FALSE;
100 130
 }
101
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
102
-if (isset($options['server'])) $globalServer = TRUE;
103
-if (isset($options['idsource'])) $id_source = $options['idsource'];
104
-else $id_source = 1;
131
+if (isset($options['nodaemon'])) {
132
+	$globalDaemon = FALSE;
133
+}
134
+if (isset($options['server'])) {
135
+	$globalServer = TRUE;
136
+}
137
+if (isset($options['idsource'])) {
138
+	$id_source = $options['idsource'];
139
+} else {
140
+	$id_source = 1;
141
+}
105 142
 if (isset($globalServer) && $globalServer) {
106
-    if ($globalDebug) echo "Using Server Mode\n";
143
+    if ($globalDebug) {
144
+    	echo "Using Server Mode\n";
145
+    }
107 146
     $SI=new SpotterServer();
108 147
 /*
109 148
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 149
     $SI = new adsb2aprs();
111 150
     $SI->connect();
112 151
 */
113
-} else $SI=new SpotterImport($Connection->db);
152
+} else {
153
+	$SI=new SpotterImport($Connection->db);
154
+}
114 155
 
115
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
156
+if (isset($globalTracker) && $globalTracker) {
157
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
158
+}
116 159
 if (isset($globalMarine) && $globalMarine) {
117 160
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
118 161
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
119 162
 }
120 163
 
121
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
164
+if (isset($globalTracker) && $globalTracker) {
165
+	$TI = new TrackerImport($Connection->db);
166
+}
122 167
 if (isset($globalMarine) && $globalMarine) {
123 168
     $AIS = new AIS();
124 169
     $MI = new MarineImport($Connection->db);
@@ -143,7 +188,9 @@  discard block
 block discarded – undo
143 188
 }
144 189
 
145 190
 // let's try and connect
146
-if ($globalDebug) echo "Connecting...\n";
191
+if ($globalDebug) {
192
+	echo "Connecting...\n";
193
+}
147 194
 $use_aprs = false;
148 195
 $aprs_full = false;
149 196
 $reset = 0;
@@ -152,7 +199,9 @@  discard block
 block discarded – undo
152 199
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153 200
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
154 201
     $reset++;
155
-    if ($globalDebug) echo 'Connect to all...'."\n";
202
+    if ($globalDebug) {
203
+    	echo 'Connect to all...'."\n";
204
+    }
156 205
     foreach ($hosts as $id => $value) {
157 206
 	$host = $value['host'];
158 207
 	$globalSources[$id]['last_exec'] = 0;
@@ -162,32 +211,44 @@  discard block
 block discarded – undo
162 211
         	//$formats[$id] = 'deltadbtxt';
163 212
         	$globalSources[$id]['format'] = 'deltadbtxt';
164 213
         	//$last_exec['deltadbtxt'] = 0;
165
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
214
+        	if ($globalDebug) {
215
+        		echo "Connect to deltadb source (".$host.")...\n";
216
+        	}
166 217
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
167 218
         	//$formats[$id] = 'vatsimtxt';
168 219
         	$globalSources[$id]['format'] = 'vatsimtxt';
169 220
         	//$last_exec['vatsimtxt'] = 0;
170
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
221
+        	if ($globalDebug) {
222
+        		echo "Connect to vatsim source (".$host.")...\n";
223
+        	}
171 224
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
172 225
         	//$formats[$id] = 'aircraftlistjson';
173 226
         	$globalSources[$id]['format'] = 'aircraftlistjson';
174 227
         	//$last_exec['aircraftlistjson'] = 0;
175
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
228
+        	if ($globalDebug) {
229
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
230
+        	}
176 231
     	    } else if (preg_match('/aircraft.json$/i',$host)) {
177 232
         	//$formats[$id] = 'aircraftjson';
178 233
         	$globalSources[$id]['format'] = 'aircraftjson';
179 234
         	//$last_exec['aircraftlistjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
235
+        	if ($globalDebug) {
236
+        		echo "Connect to aircraft.json source (".$host.")...\n";
237
+        	}
181 238
     	    } else if (preg_match('/aircraft$/i',$host)) {
182 239
         	//$formats[$id] = 'planefinderclient';
183 240
         	$globalSources[$id]['format'] = 'planefinderclient';
184 241
         	//$last_exec['aircraftlistjson'] = 0;
185
-        	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
242
+        	if ($globalDebug) {
243
+        		echo "Connect to planefinderclient source (".$host.")...\n";
244
+        	}
186 245
     	    } else if (preg_match('/opensky/i',$host)) {
187 246
         	//$formats[$id] = 'aircraftlistjson';
188 247
         	$globalSources[$id]['format'] = 'opensky';
189 248
         	//$last_exec['aircraftlistjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
249
+        	if ($globalDebug) {
250
+        		echo "Connect to opensky source (".$host.")...\n";
251
+        	}
191 252
     	    /*
192 253
     	    // Disabled for now, site change source format
193 254
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
@@ -204,7 +265,9 @@  discard block
 block discarded – undo
204 265
         	//$formats[$id] = 'planeupdatefaa';
205 266
         	$globalSources[$id]['format'] = 'planeupdatefaa';
206 267
         	//$last_exec['planeupdatefaa'] = 0;
207
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
268
+        	if ($globalDebug) {
269
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
270
+        	}
208 271
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
209 272
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
210 273
         	    exit(0);
@@ -213,37 +276,53 @@  discard block
 block discarded – undo
213 276
         	//$formats[$id] = 'phpvmacars';
214 277
         	$globalSources[$id]['format'] = 'phpvmacars';
215 278
         	//$last_exec['phpvmacars'] = 0;
216
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
279
+        	if ($globalDebug) {
280
+        		echo "Connect to phpvmacars source (".$host.")...\n";
281
+        	}
217 282
             } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
218 283
         	//$formats[$id] = 'phpvmacars';
219 284
         	$globalSources[$id]['format'] = 'vaos';
220 285
         	//$last_exec['phpvmacars'] = 0;
221
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
286
+        	if ($globalDebug) {
287
+        		echo "Connect to vaos source (".$host.")...\n";
288
+        	}
222 289
             } else if (preg_match('/VAM-json.php$/i',$host)) {
223 290
         	//$formats[$id] = 'phpvmacars';
224 291
         	$globalSources[$id]['format'] = 'vam';
225
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
292
+        	if ($globalDebug) {
293
+        		echo "Connect to Vam source (".$host.")...\n";
294
+        	}
226 295
             } else if (preg_match('/whazzup/i',$host)) {
227 296
         	//$formats[$id] = 'whazzup';
228 297
         	$globalSources[$id]['format'] = 'whazzup';
229 298
         	//$last_exec['whazzup'] = 0;
230
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
299
+        	if ($globalDebug) {
300
+        		echo "Connect to whazzup source (".$host.")...\n";
301
+        	}
231 302
             } else if (preg_match('/blitzortung/i',$host)) {
232 303
         	$globalSources[$id]['format'] = 'blitzortung';
233
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
304
+        	if ($globalDebug) {
305
+        		echo "Connect to blitzortung source (".$host.")...\n";
306
+        	}
234 307
             } else if (preg_match('/airwhere/i',$host)) {
235 308
         	$globalSources[$id]['format'] = 'airwhere';
236
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
309
+        	if ($globalDebug) {
310
+        		echo "Connect to airwhere source (".$host.")...\n";
311
+        	}
237 312
             } else if (preg_match('/recentpireps/i',$host)) {
238 313
         	//$formats[$id] = 'pirepsjson';
239 314
         	$globalSources[$id]['format'] = 'pirepsjson';
240 315
         	//$last_exec['pirepsjson'] = 0;
241
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
316
+        	if ($globalDebug) {
317
+        		echo "Connect to pirepsjson source (".$host.")...\n";
318
+        	}
242 319
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
243 320
         	//$formats[$id] = 'fr24json';
244 321
         	$globalSources[$id]['format'] = 'fr24json';
245 322
         	//$last_exec['fr24json'] = 0;
246
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
323
+        	if ($globalDebug) {
324
+        		echo "Connect to fr24 source (".$host.")...\n";
325
+        	}
247 326
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
248 327
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
249 328
         	    exit(0);
@@ -252,7 +331,9 @@  discard block
 block discarded – undo
252 331
         	//$formats[$id] = 'fr24json';
253 332
         	$globalSources[$id]['format'] = 'myshiptracking';
254 333
         	//$last_exec['fr24json'] = 0;
255
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
334
+        	if ($globalDebug) {
335
+        		echo "Connect to myshiptracking source (".$host.")...\n";
336
+        	}
256 337
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
257 338
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
258 339
         	    exit(0);
@@ -261,17 +342,26 @@  discard block
 block discarded – undo
261 342
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
262 343
         	//$formats[$id] = 'tsv';
263 344
         	$globalSources[$id]['format'] = 'tsv';
264
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
345
+        	if ($globalDebug) {
346
+        		echo "Connect to tsv source (".$host.")...\n";
347
+        	}
265 348
             }
266 349
         } elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway')) {
267 350
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
268 351
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
269 352
     		    if ($idf !== false) {
270 353
     			$httpfeeds[$id] = $idf;
271
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
272
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
273
-    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
274
-    		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
354
+        		if ($globalDebug) {
355
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
356
+        		}
357
+    		    } elseif ($globalDebug) {
358
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
359
+    		    }
360
+    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') {
361
+    			echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
362
+    		} elseif ($globalDebug) {
363
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
364
+    		}
275 365
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
276 366
 	    $hostport = explode(':',$host);
277 367
 	    if (isset($hostport[1])) {
@@ -311,19 +401,27 @@  discard block
 block discarded – undo
311 401
         		//$formats[$id] = 'beast';
312 402
         		$globalSources[$id]['format'] = 'beast';
313 403
 		    //} else $formats[$id] = 'sbs';
314
-		    } else $globalSources[$id]['format'] = 'sbs';
404
+		    } else {
405
+		    	$globalSources[$id]['format'] = 'sbs';
406
+		    }
315 407
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
316 408
 		}
317
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
409
+		if ($globalDebug) {
410
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
411
+		}
318 412
             } else {
319
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
413
+		if ($globalDebug) {
414
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
415
+		}
320 416
 		sleep(10);
321 417
 		connect_all($hosts);
322 418
     	    }
323 419
         }
324 420
     }
325 421
 }
326
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
422
+if (!isset($globalMinFetch)) {
423
+	$globalMinFetch = 15;
424
+}
327 425
 
328 426
 // Initialize all
329 427
 $status = array();
@@ -332,13 +430,19 @@  discard block
 block discarded – undo
332 430
 $formats = array();
333 431
 $last_exec = array();
334 432
 $time = time();
335
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
336
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
337
-else $timeout = 20;
433
+if (isset($globalSourcesTimeout)) {
434
+	$timeout = $globalSourcesTimeOut;
435
+} else if (isset($globalSBS1TimeOut)) {
436
+	$timeout = $globalSBS1TimeOut;
437
+} else {
438
+	$timeout = 20;
439
+}
338 440
 $errno = '';
339 441
 $errstr='';
340 442
 
341
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
443
+if (!isset($globalDaemon)) {
444
+	$globalDaemon = TRUE;
445
+}
342 446
 /* Initiate connections to all the hosts simultaneously */
343 447
 //connect_all($hosts);
344 448
 //connect_all($globalSources);
@@ -367,7 +471,9 @@  discard block
 block discarded – undo
367 471
     if (isset($source['format']) && $source['format'] == 'aprs') {
368 472
 	$aprs_connect = 0;
369 473
 	$use_aprs = true;
370
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
474
+	if (isset($source['port']) && $source['port'] == '10152') {
475
+		$aprs_full = true;
476
+	}
371 477
 	break;
372 478
     }
373 479
 }
@@ -378,25 +484,46 @@  discard block
 block discarded – undo
378 484
 	$aprs_connect = 0;
379 485
 	$aprs_keep = 120;
380 486
 	$aprs_last_tx = time();
381
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
382
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
383
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
384
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
385
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
386
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
387
-	if ($aprs_full) $aprs_filter = '';
388
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
389
-	else $aprs_pass = '-1';
487
+	if (isset($globalAPRSversion)) {
488
+		$aprs_version = $globalAPRSversion;
489
+	} else {
490
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
491
+	}
492
+	if (isset($globalAPRSssid)) {
493
+		$aprs_ssid = $globalAPRSssid;
494
+	} else {
495
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
496
+	}
497
+	if (isset($globalAPRSfilter)) {
498
+		$aprs_filter = $globalAPRSfilter;
499
+	} else {
500
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
501
+	}
502
+	if ($aprs_full) {
503
+		$aprs_filter = '';
504
+	}
505
+	if (isset($globalAPRSpass)) {
506
+		$aprs_pass = $globalAPRSpass;
507
+	} else {
508
+		$aprs_pass = '-1';
509
+	}
390 510
 
391
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
392
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
393
-}
511
+	if ($aprs_filter != '') {
512
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
513
+	} else {
514
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
515
+	}
516
+	}
394 517
 
395 518
 // connected - lets do some work
396 519
 //if ($globalDebug) echo "Connected!\n";
397 520
 sleep(1);
398
-if ($globalDebug) echo "SCAN MODE \n\n";
399
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
521
+if ($globalDebug) {
522
+	echo "SCAN MODE \n\n";
523
+}
524
+if (!isset($globalCronEnd)) {
525
+	$globalCronEnd = 60;
526
+}
400 527
 $endtime = time()+$globalCronEnd;
401 528
 $i = 1;
402 529
 $tt = array();
@@ -410,22 +537,32 @@  discard block
 block discarded – undo
410 537
 
411 538
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
412 539
 while ($i > 0) {
413
-    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
540
+    if (function_exists('pcntl_fork')) {
541
+    	pcntl_signal_dispatch();
542
+    }
414 543
 
415
-    if (!$globalDaemon) $i = $endtime-time();
544
+    if (!$globalDaemon) {
545
+    	$i = $endtime-time();
546
+    }
416 547
     // Delete old ATC
417 548
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
418
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
549
+	if ($globalDebug) {
550
+		echo 'Delete old ATC...'."\n";
551
+	}
419 552
         $ATC->deleteOldATC();
420 553
     }
421 554
     
422 555
     if (count($last_exec) == count($globalSources)) {
423 556
 	$max = $globalMinFetch;
424 557
 	foreach ($last_exec as $last) {
425
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
558
+	    if ((time() - $last['last']) < $max) {
559
+	    	$max = time() - $last['last'];
560
+	    }
426 561
 	}
427 562
 	if ($max < $globalMinFetch) {
428
-	    if ($globalDebug) echo 'Sleeping...'."\n";
563
+	    if ($globalDebug) {
564
+	    	echo 'Sleeping...'."\n";
565
+	    }
429 566
 	    sleep($globalMinFetch-$max+2);
430 567
 	}
431 568
     }
@@ -435,7 +572,9 @@  discard block
 block discarded – undo
435 572
     foreach ($globalSources as $id => $value) {
436 573
 	date_default_timezone_set('UTC');
437 574
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
438
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
575
+	if (!isset($last_exec[$id]['last'])) {
576
+		$last_exec[$id]['last'] = 0;
577
+	}
439 578
 	if ($value['format'] === 'deltadbtxt' && 
440 579
 	    (
441 580
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
@@ -444,7 +583,9 @@  discard block
 block discarded – undo
444 583
 	) {
445 584
 	    //$buffer = $Common->getData($hosts[$id]);
446 585
 	    $buffer = $Common->getData($value['host']);
447
-	    if ($buffer != '') $reset = 0;
586
+	    if ($buffer != '') {
587
+	    	$reset = 0;
588
+	    }
448 589
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
449 590
 	    $buffer = explode('\n',$buffer);
450 591
 	    foreach ($buffer as $line) {
@@ -453,20 +594,41 @@  discard block
 block discarded – undo
453 594
 	            $data = array();
454 595
 	            $data['hex'] = $line[1]; // hex
455 596
 	            $data['ident'] = $line[2]; // ident
456
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
457
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
458
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
459
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
460
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
597
+	            if (isset($line[3])) {
598
+	            	$data['altitude'] = $line[3];
599
+	            }
600
+	            // altitude
601
+	            if (isset($line[4])) {
602
+	            	$data['speed'] = $line[4];
603
+	            }
604
+	            // speed
605
+	            if (isset($line[5])) {
606
+	            	$data['heading'] = $line[5];
607
+	            }
608
+	            // heading
609
+	            if (isset($line[6])) {
610
+	            	$data['latitude'] = $line[6];
611
+	            }
612
+	            // lat
613
+	            if (isset($line[7])) {
614
+	            	$data['longitude'] = $line[7];
615
+	            }
616
+	            // long
461 617
 	            $data['verticalrate'] = ''; // vertical rate
462 618
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
463 619
 	            $data['emergency'] = ''; // emergency
464 620
 		    $data['datetime'] = date('Y-m-d H:i:s');
465 621
 		    $data['format_source'] = 'deltadbtxt';
466 622
     		    $data['id_source'] = $id_source;
467
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
468
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
469
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
623
+		    if (isset($value['name']) && $value['name'] != '') {
624
+		    	$data['source_name'] = $value['name'];
625
+		    }
626
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
627
+		    	$data['noarchive'] = true;
628
+		    }
629
+		    if (isset($value['sourcestats'])) {
630
+		    	$data['sourcestats'] = $value['sourcestats'];
631
+		    }
470 632
     		    $SI->add($data);
471 633
 		    unset($data);
472 634
     		}
@@ -481,7 +643,9 @@  discard block
 block discarded – undo
481 643
 	    date_default_timezone_set('CET');
482 644
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
483 645
 	    date_default_timezone_set('UTC');
484
-	    if ($buffer != '') $reset = 0;
646
+	    if ($buffer != '') {
647
+	    	$reset = 0;
648
+	    }
485 649
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
486 650
 	    $buffer = explode('\n',$buffer);
487 651
 	    foreach ($buffer as $line) {
@@ -490,18 +654,42 @@  discard block
 block discarded – undo
490 654
 		    $add = false;
491 655
 		    $ais_data = $AIS->parse_line(trim($line));
492 656
 		    $data = array();
493
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
494
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
495
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
496
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
497
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
498
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
499
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
500
-		    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
501
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
502
-		    if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
503
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
504
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
657
+		    if (isset($ais_data['ident'])) {
658
+		    	$data['ident'] = $ais_data['ident'];
659
+		    }
660
+		    if (isset($ais_data['mmsi'])) {
661
+		    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
662
+		    }
663
+		    if (isset($ais_data['speed'])) {
664
+		    	$data['speed'] = $ais_data['speed'];
665
+		    }
666
+		    if (isset($ais_data['heading'])) {
667
+		    	$data['heading'] = $ais_data['heading'];
668
+		    }
669
+		    if (isset($ais_data['latitude'])) {
670
+		    	$data['latitude'] = $ais_data['latitude'];
671
+		    }
672
+		    if (isset($ais_data['longitude'])) {
673
+		    	$data['longitude'] = $ais_data['longitude'];
674
+		    }
675
+		    if (isset($ais_data['status'])) {
676
+		    	$data['status'] = $ais_data['status'];
677
+		    }
678
+		    if (isset($ais_data['statusid'])) {
679
+		    	$data['status_id'] = $ais_data['statusid'];
680
+		    }
681
+		    if (isset($ais_data['type'])) {
682
+		    	$data['type'] = $ais_data['type'];
683
+		    }
684
+		    if (isset($ais_data['typeid'])) {
685
+		    	$data['type_id'] = $ais_data['typeid'];
686
+		    }
687
+		    if (isset($ais_data['imo'])) {
688
+		    	$data['imo'] = $ais_data['imo'];
689
+		    }
690
+		    if (isset($ais_data['callsign'])) {
691
+		    	$data['callsign'] = $ais_data['callsign'];
692
+		    }
505 693
 		    if (isset($ais_data['timestamp'])) {
506 694
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
507 695
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -515,8 +703,12 @@  discard block
 block discarded – undo
515 703
 		    $data['format_source'] = 'aisnmeatxt';
516 704
     		    $data['id_source'] = $id_source;
517 705
 		    //print_r($data);
518
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
519
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
706
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
707
+		    	$data['noarchive'] = true;
708
+		    }
709
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
710
+		    	$MI->add($data);
711
+		    }
520 712
 		    unset($data);
521 713
 		}
522 714
     	    }
@@ -539,20 +731,48 @@  discard block
 block discarded – undo
539 731
 			    if ($line != '') {
540 732
 				$ais_data = $AIS->parse_line(trim($line));
541 733
 				$data = array();
542
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
543
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
544
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
545
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
546
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
547
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
548
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
549
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
550
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
551
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
552
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
553
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
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']);
734
+				if (isset($ais_data['ident'])) {
735
+					$data['ident'] = $ais_data['ident'];
736
+				}
737
+				if (isset($ais_data['mmsi'])) {
738
+					$data['mmsi'] = substr($ais_data['mmsi'],-9);
739
+				}
740
+				if (isset($ais_data['speed'])) {
741
+					$data['speed'] = $ais_data['speed'];
742
+				}
743
+				if (isset($ais_data['heading'])) {
744
+					$data['heading'] = $ais_data['heading'];
745
+				}
746
+				if (isset($ais_data['latitude'])) {
747
+					$data['latitude'] = $ais_data['latitude'];
748
+				}
749
+				if (isset($ais_data['longitude'])) {
750
+					$data['longitude'] = $ais_data['longitude'];
751
+				}
752
+				if (isset($ais_data['status'])) {
753
+					$data['status'] = $ais_data['status'];
754
+				}
755
+				if (isset($ais_data['statusid'])) {
756
+					$data['status_id'] = $ais_data['statusid'];
757
+				}
758
+				if (isset($ais_data['type'])) {
759
+					$data['type'] = $ais_data['type'];
760
+				}
761
+				if (isset($ais_data['typeid'])) {
762
+					$data['type_id'] = $ais_data['typeid'];
763
+				}
764
+				if (isset($ais_data['imo'])) {
765
+					$data['imo'] = $ais_data['imo'];
766
+				}
767
+				if (isset($ais_data['callsign'])) {
768
+					$data['callsign'] = $ais_data['callsign'];
769
+				}
770
+				if (isset($ais_data['destination'])) {
771
+					$data['arrival_code'] = $ais_data['destination'];
772
+				}
773
+				if (isset($ais_data['eta_ts'])) {
774
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
775
+				}
556 776
 				if (isset($ais_data['timestamp'])) {
557 777
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
558 778
 				} else {
@@ -560,18 +780,27 @@  discard block
 block discarded – undo
560 780
 				}
561 781
 				$data['format_source'] = 'aisnmeahttp';
562 782
 				$data['id_source'] = $id_source;
563
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
564
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
783
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
784
+					$data['noarchive'] = true;
785
+				}
786
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
787
+					$MI->add($data);
788
+				}
565 789
 				unset($data);
566 790
 			    }
567 791
 			}
568 792
 		    }
569 793
 		} else {
570 794
 		    $format = $value['format'];
571
-		    if (isset($tt[$format])) $tt[$format]++;
572
-		    else $tt[$format] = 0;
795
+		    if (isset($tt[$format])) {
796
+		    	$tt[$format]++;
797
+		    } else {
798
+		    	$tt[$format] = 0;
799
+		    }
573 800
 		    if ($tt[$format] > 30) {
574
-			if ($globalDebug) echo 'Reconnect...'."\n";
801
+			if ($globalDebug) {
802
+				echo 'Reconnect...'."\n";
803
+			}
575 804
 			sleep(2);
576 805
 			//$sourceeen[] = $value;
577 806
 			//connect_all($sourceeen);
@@ -607,12 +836,18 @@  discard block
 block discarded – undo
607 836
 			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
608 837
 			    //$data['type_id'] = $line['TYPE'];
609 838
 			    $data['imo'] = $line['IMO'];
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']));
839
+			    if ($line['DEST'] != '') {
840
+			    	$data['arrival_code'] = $line['DEST'];
841
+			    }
842
+			    if ($line['ARV'] != '') {
843
+			    	$data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
844
+			    }
612 845
 			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
613 846
 			    $data['format_source'] = 'myshiptracking';
614 847
 			    $data['id_source'] = $id_source;
615
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
848
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
849
+			    	$data['noarchive'] = true;
850
+			    }
616 851
 			    $MI->add($data);
617 852
 			    unset($data);
618 853
 			}
@@ -637,7 +872,9 @@  discard block
 block discarded – undo
637 872
 			    $data['callsign'] = $line['callsign'];
638 873
 			    $data['mmsi'] = substr($line['mmsi'],-9);
639 874
 			    $data['speed'] = $line['sog'];
640
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
875
+			    if ($line['heading'] != '511') {
876
+			    	$data['heading'] = $line['heading'];
877
+			    }
641 878
 			    $data['latitude'] = $line['latitude'];
642 879
 			    $data['longitude'] = $line['longitude'];
643 880
 			    $data['type_id'] = $line['shiptype'];
@@ -645,7 +882,9 @@  discard block
 block discarded – undo
645 882
 			    $data['datetime'] = $line['time'];
646 883
 			    $data['format_source'] = 'boatbeaconapp';
647 884
 			    $data['id_source'] = $id_source;
648
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
885
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
886
+			    	$data['noarchive'] = true;
887
+			    }
649 888
 			    $MI->add($data);
650 889
 			    unset($data);
651 890
 			}
@@ -667,22 +906,44 @@  discard block
 block discarded – undo
667 906
 		    foreach ($all_data['features'] as $line) {
668 907
 			print_r($line);
669 908
 			$data = array();
670
-			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
671
-			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
672
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
673
-			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
674
-			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
675
-			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
909
+			if (isset($line['properties']['name'])) {
910
+				$data['ident'] = $line['properties']['name'];
911
+			}
912
+			if (isset($line['properties']['callsign'])) {
913
+				$data['callsign'] = $line['properties']['callsign'];
914
+			}
915
+			if (isset($line['properties']['mmsi'])) {
916
+				$data['mmsi'] = substr($line['properties']['mmsi'],-9);
917
+			}
918
+			if (isset($line['properties']['imo'])) {
919
+				$data['imo'] = $line['properties']['imo'];
920
+			}
921
+			if (isset($line['properties']['speed'])) {
922
+				$data['speed'] = $line['properties']['speed'];
923
+			}
924
+			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) {
925
+				$data['heading'] = $line['properties']['heading'];
926
+			}
676 927
 			$data['latitude'] = $line['geometry']['coordinates'][1];
677 928
 			$data['longitude'] = $line['geometry']['coordinates'][0];
678
-			if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType'];
679
-			if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination'];
680
-			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta'];
929
+			if (isset($line['properties']['vesselType'])) {
930
+				$data['type'] = $line['properties']['vesselType'];
931
+			}
932
+			if (isset($line['properties']['destination'])) {
933
+				$data['arrival_code'] = $line['properties']['destination'];
934
+			}
935
+			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') {
936
+				$data['arrival_date'] = $line['properties']['eta'];
937
+			}
681 938
 			$data['format_source'] = 'boatnerd';
682 939
 			$data['id_source'] = $id_source;
683 940
 			$data['datetime'] = date('Y-m-d H:i:s');
684
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
685
-			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
941
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
942
+				$data['noarchive'] = true;
943
+			}
944
+			if ($line['properties']['vesselType'] != 'Navigation Aid') {
945
+				$MI->add($data);
946
+			}
686 947
 			unset($data);
687 948
 		    }
688 949
 		}
@@ -695,11 +956,17 @@  discard block
 block discarded – undo
695 956
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
696 957
 	    )
697 958
 	) {
698
-	    if ($globalDebug) echo 'download...';
959
+	    if ($globalDebug) {
960
+	    	echo 'download...';
961
+	    }
699 962
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
700
-	    if ($globalDebug) echo 'done !'."\n";
963
+	    if ($globalDebug) {
964
+	    	echo 'done !'."\n";
965
+	    }
701 966
 	    // FIXME: Need more work
702
-	    if ($buffer != '') $reset = 0;
967
+	    if ($buffer != '') {
968
+	    	$reset = 0;
969
+	    }
703 970
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
704 971
 	    $buffer = explode('\n',$buffer);
705 972
 	    foreach ($buffer as $line) {
@@ -725,7 +992,9 @@  discard block
 block discarded – undo
725 992
 		    //$data['etaTime'] = substr($line,135,5);
726 993
 		    $data['format_source'] = 'shipplotter';
727 994
     		    $data['id_source'] = $id_source;
728
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
995
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
996
+		    	$data['noarchive'] = true;
997
+		    }
729 998
 		    //print_r($data);
730 999
 		    //echo 'Add...'."\n";
731 1000
 		    $MI->add($data);
@@ -739,10 +1008,14 @@  discard block
 block discarded – undo
739 1008
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
740 1009
 	    )
741 1010
 	) {
742
-	    if ($globalDebug) echo 'download...';
1011
+	    if ($globalDebug) {
1012
+	    	echo 'download...';
1013
+	    }
743 1014
 	    for ($i =0; $i <= 1; $i++) {
744 1015
 	    $buffer = $Common->getData('https://sailaway.world/cgi-bin/sailaway/GetMissions.pl?race=1&tutorial=0&hist=1&racetype='.$i);
745
-	    if ($globalDebug) echo 'done'."\n";
1016
+	    if ($globalDebug) {
1017
+	    	echo 'done'."\n";
1018
+	    }
746 1019
 	    if ($buffer != '') {
747 1020
 		$all_data = json_decode($buffer,true);
748 1021
 		if (isset($all_data['missions'])) {
@@ -751,7 +1024,9 @@  discard block
 block discarded – undo
751 1024
 				$mission_name = $mission['mistitle'];
752 1025
 				if (!isset($globalFilter['sailway']['race']) || (isset($globalFilter['sailway']['race']) && in_array($mission['misnr'],$globalFilter['sailway']['race']))) {
753 1026
 					$bufferm = $Common->getData('https://sailaway.world/cgi-bin/sailaway/GetLeaderboard.pl?misnr='.$mission['misnr']);
754
-				} else $bufferm = '';
1027
+				} else {
1028
+					$bufferm = '';
1029
+				}
755 1030
 				if ($bufferm != '') {
756 1031
 					$mission_data = json_decode($bufferm,true);
757 1032
 					if (isset($mission_data['leaderboard'][0]['results'])) {
@@ -779,7 +1054,9 @@  discard block
 block discarded – undo
779 1054
 								//$data['callsign'] = trim(substr($line,100,7);
780 1055
 								$data['format_source'] = 'sailaway';
781 1056
 								$data['id_source'] = $id_source;
782
-								if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1057
+								if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1058
+									$data['noarchive'] = true;
1059
+								}
783 1060
 								//print_r($data);
784 1061
 								//echo 'Add...'."\n";
785 1062
 								$MI->add($data);
@@ -820,16 +1097,28 @@  discard block
 block discarded – undo
820 1097
     		    $line = explode(':', $line);
821 1098
     		    if (count($line) > 30 && $line[0] != 'callsign') {
822 1099
 			$data = array();
823
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
824
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1100
+			if (isset($line[37]) && $line[37] != '') {
1101
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
1102
+			} else {
1103
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1104
+			}
825 1105
 			$data['pilot_id'] = $line[1];
826 1106
 			$data['pilot_name'] = $line[2];
827 1107
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
828 1108
 			$data['ident'] = $line[0]; // ident
829
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
1109
+			if ($line[7] != '' && $line[7] != 0) {
1110
+				$data['altitude'] = $line[7];
1111
+			}
1112
+			// altitude
830 1113
 			$data['speed'] = $line[8]; // speed
831
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
832
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
1114
+			if (isset($line[45])) {
1115
+				$data['heading'] = $line[45];
1116
+			}
1117
+			// heading
1118
+			elseif (isset($line[38])) {
1119
+				$data['heading'] = $line[38];
1120
+			}
1121
+			// heading
833 1122
 			$data['latitude'] = $line[5]; // lat
834 1123
 	        	$data['longitude'] = $line[6]; // long
835 1124
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -845,7 +1134,9 @@  discard block
 block discarded – undo
845 1134
 			$data['frequency'] = $line[4];
846 1135
 			$data['type'] = $line[18];
847 1136
 			$data['range'] = $line[19];
848
-			if (isset($line[35])) $data['info'] = $line[35];
1137
+			if (isset($line[35])) {
1138
+				$data['info'] = $line[35];
1139
+			}
849 1140
     			$data['id_source'] = $id_source;
850 1141
 	    		//$data['arrival_airport_time'] = ;
851 1142
 	    		if ($line[9] != '') {
@@ -859,27 +1150,47 @@  discard block
 block discarded – undo
859 1150
 	    		elseif ($value === 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
860 1151
 	    		*/
861 1152
 	    		$data['format_source'] = $value['format'];
862
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
863
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
864
-    			if ($line[3] === 'PILOT') $SI->add($data);
865
-			elseif ($line[3] === 'ATC') {
1153
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1154
+				$data['noarchive'] = true;
1155
+			}
1156
+			if (isset($value['name']) && $value['name'] != '') {
1157
+				$data['source_name'] = $value['name'];
1158
+			}
1159
+    			if ($line[3] === 'PILOT') {
1160
+    				$SI->add($data);
1161
+    			} elseif ($line[3] === 'ATC') {
866 1162
 				//print_r($data);
867 1163
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
868 1164
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
869 1165
 				$typec = substr($data['ident'],-3);
870
-				if ($typec === 'APP') $data['type'] = 'Approach';
871
-				elseif ($typec === 'TWR') $data['type'] = 'Tower';
872
-				elseif ($typec === 'OBS') $data['type'] = 'Observer';
873
-				elseif ($typec === 'GND') $data['type'] = 'Ground';
874
-				elseif ($typec === 'DEL') $data['type'] = 'Delivery';
875
-				elseif ($typec === 'DEP') $data['type'] = 'Departure';
876
-				elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
877
-				elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
878
-				elseif ($data['type'] === '') $data['type'] = 'Observer';
879
-				if (!isset($data['source_name'])) $data['source_name'] = '';
1166
+				if ($typec === 'APP') {
1167
+					$data['type'] = 'Approach';
1168
+				} elseif ($typec === 'TWR') {
1169
+					$data['type'] = 'Tower';
1170
+				} elseif ($typec === 'OBS') {
1171
+					$data['type'] = 'Observer';
1172
+				} elseif ($typec === 'GND') {
1173
+					$data['type'] = 'Ground';
1174
+				} elseif ($typec === 'DEL') {
1175
+					$data['type'] = 'Delivery';
1176
+				} elseif ($typec === 'DEP') {
1177
+					$data['type'] = 'Departure';
1178
+				} elseif ($typec === 'FSS') {
1179
+					$data['type'] = 'Flight Service Station';
1180
+				} elseif ($typec === 'CTR') {
1181
+					$data['type'] = 'Control Radar or Centre';
1182
+				} elseif ($data['type'] === '') {
1183
+					$data['type'] = 'Observer';
1184
+				}
1185
+				if (!isset($data['source_name'])) {
1186
+					$data['source_name'] = '';
1187
+				}
880 1188
 				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']);
1189
+					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) {
1190
+						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']);
1191
+					} else {
1192
+						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']);
1193
+					}
883 1194
 				}
884 1195
 			}
885 1196
     			unset($data);
@@ -906,14 +1217,20 @@  discard block
 block discarded – undo
906 1217
 			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
907 1218
 			$data['latitude'] = (float)$line['pktLatitude'];
908 1219
 			$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'];
1220
+			if ((float)$line['pktTrack'] != 0) {
1221
+				$data['heading'] = (float)$line['pktTrack'];
1222
+			}
1223
+			if ((int)$line['pktSpeed'] != 0) {
1224
+				$data['speed'] = (int)$line['pktSpeed'];
1225
+			}
911 1226
 			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
912 1227
 			$data['altitude_relative'] = 'AMSL';
913 1228
 			$data['pilot_id'] = (int)$line['pktPilotID'];
914 1229
 			$data['aircraft_icao'] = 'PARAGLIDER';
915 1230
 			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
916
-			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1231
+			if (isset($pilot_data[4])) {
1232
+				$data['pilot_name'] = $pilot_data[4];
1233
+			}
917 1234
 			$data['format_source'] = $value['format'];
918 1235
 			$SI->add($data);
919 1236
 			unset($data);
@@ -961,25 +1278,59 @@  discard block
 block discarded – undo
961 1278
 		    foreach ($all_data['acList'] as $line) {
962 1279
 			$data = array();
963 1280
 			$data['hex'] = $line['Icao']; // hex
964
-			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
965
-			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
966
-			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
967
-			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
968
-			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
969
-			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1281
+			if (isset($line['Call'])) {
1282
+				$data['ident'] = $line['Call'];
1283
+			}
1284
+			// ident
1285
+			if (isset($line['Alt'])) {
1286
+				$data['altitude'] = $line['Alt'];
1287
+			}
1288
+			// altitude
1289
+			if (isset($line['Spd'])) {
1290
+				$data['speed'] = $line['Spd'];
1291
+			}
1292
+			// speed
1293
+			if (isset($line['Trak'])) {
1294
+				$data['heading'] = $line['Trak'];
1295
+			}
1296
+			// heading
1297
+			if (isset($line['Lat'])) {
1298
+				$data['latitude'] = $line['Lat'];
1299
+			}
1300
+			// lat
1301
+			if (isset($line['Long'])) {
1302
+				$data['longitude'] = $line['Long'];
1303
+			}
1304
+			// long
970 1305
 			//$data['verticalrate'] = $line['']; // verticale rate
971
-			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1306
+			if (isset($line['Sqk'])) {
1307
+				$data['squawk'] = $line['Sqk'];
1308
+			}
1309
+			// squawk
972 1310
 			$data['emergency'] = ''; // emergency
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));
975
-			else $data['datetime'] = date('Y-m-d H:i:s');
1311
+			if (isset($line['Reg'])) {
1312
+				$data['registration'] = $line['Reg'];
1313
+			}
1314
+			if (isset($line['PosTime'])) {
1315
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1316
+			} else {
1317
+				$data['datetime'] = date('Y-m-d H:i:s');
1318
+			}
976 1319
 			//$data['datetime'] = date('Y-m-d H:i:s');
977
-			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1320
+			if (isset($line['Type'])) {
1321
+				$data['aircraft_icao'] = $line['Type'];
1322
+			}
978 1323
 			$data['format_source'] = 'aircraftlistjson';
979 1324
 			$data['id_source'] = $id_source;
980
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
981
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
982
-			if (isset($data['latitude'])) $SI->add($data);
1325
+			if (isset($value['name']) && $value['name'] != '') {
1326
+				$data['source_name'] = $value['name'];
1327
+			}
1328
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1329
+				$data['noarchive'] = true;
1330
+			}
1331
+			if (isset($data['latitude'])) {
1332
+				$SI->add($data);
1333
+			}
983 1334
 			unset($data);
984 1335
 		    }
985 1336
 		} elseif (is_array($all_data)) {
@@ -996,17 +1347,26 @@  discard block
 block discarded – undo
996 1347
 			$data['verticalrate'] = $line['vrt']; // verticale rate
997 1348
 			$data['squawk'] = $line['squawk']; // squawk
998 1349
 			$data['emergency'] = ''; // emergency
999
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1000
-			else $data['datetime'] = date('Y-m-d H:i:s');
1350
+			if (isset($line['PosTime'])) {
1351
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1352
+			} else {
1353
+				$data['datetime'] = date('Y-m-d H:i:s');
1354
+			}
1001 1355
 			$data['format_source'] = 'aircraftlistjson';
1002 1356
 			$data['id_source'] = $id_source;
1003
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1004
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1357
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1358
+				$data['noarchive'] = true;
1359
+			}
1360
+			if (isset($value['name']) && $value['name'] != '') {
1361
+				$data['source_name'] = $value['name'];
1362
+			}
1005 1363
 			$SI->add($data);
1006 1364
 			unset($data);
1007 1365
 		    }
1008 1366
 		}
1009
-	    } elseif ($globalDebug) echo 'No data'."\n";
1367
+	    } elseif ($globalDebug) {
1368
+	    	echo 'No data'."\n";
1369
+	    }
1010 1370
     	    //$last_exec['aircraftlistjson'] = time();
1011 1371
     	    $last_exec[$id]['last'] = time();
1012 1372
     	//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
@@ -1042,8 +1402,12 @@  discard block
 block discarded – undo
1042 1402
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1043 1403
 	    	    $data['format_source'] = 'planeupdatefaa';
1044 1404
     		    $data['id_source'] = $id_source;
1045
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1046
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1405
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1406
+		    	$data['noarchive'] = true;
1407
+		    }
1408
+		    if (isset($value['name']) && $value['name'] != '') {
1409
+		    	$data['source_name'] = $value['name'];
1410
+		    }
1047 1411
 		    $SI->add($data);
1048 1412
 		    unset($data);
1049 1413
 		}
@@ -1077,7 +1441,9 @@  discard block
 block discarded – undo
1077 1441
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1078 1442
 		    $data['format_source'] = 'opensky';
1079 1443
 		    $data['id_source'] = $id_source;
1080
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1444
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1445
+		    	$data['noarchive'] = true;
1446
+		    }
1081 1447
 		    $SI->add($data);
1082 1448
 		    unset($data);
1083 1449
 		}
@@ -1097,15 +1463,42 @@  discard block
 block discarded – undo
1097 1463
 		foreach ($all_data['aircraft'] as $key => $line) {
1098 1464
 		    $data = array();
1099 1465
 		    // add support for ground vehicule with ~ in front of hex
1100
-		    if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1101
-		    if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1102
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1103
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1104
-		    if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1105
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1106
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1107
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1108
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1466
+		    if (isset($line['hex'])) {
1467
+		    	$data['hex'] = $line['hex'];
1468
+		    }
1469
+		    // hex
1470
+		    if (isset($line['flight'])) {
1471
+		    	$data['ident'] = trim($line['flight']);
1472
+		    }
1473
+		    // ident
1474
+		    if (isset($line['altitude'])) {
1475
+		    	$data['altitude'] = $line['altitude'];
1476
+		    }
1477
+		    // altitude
1478
+		    if (isset($line['speed'])) {
1479
+		    	$data['speed'] = $line['speed'];
1480
+		    }
1481
+		    // speed
1482
+		    if (isset($line['track'])) {
1483
+		    	$data['heading'] = $line['track'];
1484
+		    }
1485
+		    // heading
1486
+		    if (isset($line['lat'])) {
1487
+		    	$data['latitude'] = $line['lat'];
1488
+		    }
1489
+		    // lat
1490
+		    if (isset($line['lon'])) {
1491
+		    	$data['longitude'] = $line['lon'];
1492
+		    }
1493
+		    // long
1494
+		    if (isset($line['vert_rate'])) {
1495
+		    	$data['verticalrate'] = $line['vert_rate'];
1496
+		    }
1497
+		    // verticale rate
1498
+		    if (isset($line['squawk'])) {
1499
+		    	$data['squawk'] = $line['squawk'];
1500
+		    }
1501
+		    // squawk
1109 1502
 		    //$data['emergency'] = ''; // emergency
1110 1503
 		    //$data['registration'] = $line[2];
1111 1504
 		    //$data['aircraft_icao'] = $line[0];
@@ -1113,10 +1506,17 @@  discard block
 block discarded – undo
1113 1506
 		    $data['format_source'] = 'aircraftjson';
1114 1507
 		    $data['id_source'] = $id_source;
1115 1508
 		    if (isset($value['name']) && $value['name'] != '') {
1116
-			    if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1117
-			    else $data['source_name'] = $value['name'];
1118
-		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1119
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1509
+			    if (isset($line['mlat']) && !empty($line['mlat'])) {
1510
+			    	$data['source_name'] = $value['name'].'_MLAT';
1511
+			    } else {
1512
+			    	$data['source_name'] = $value['name'];
1513
+			    }
1514
+		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) {
1515
+		    	$data['source_name'] = 'MLAT';
1516
+		    }
1517
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1518
+		    	$data['noarchive'] = true;
1519
+		    }
1120 1520
 		    $SI->add($data);
1121 1521
 		    unset($data);
1122 1522
 		}
@@ -1136,22 +1536,54 @@  discard block
 block discarded – undo
1136 1536
 		foreach ($all_data['aircraft'] as $key => $line) {
1137 1537
 		    $data = array();
1138 1538
 		    $data['hex'] = $key; // hex
1139
-		    if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1140
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1141
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1142
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1143
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1144
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1145
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1146
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1539
+		    if (isset($line['callsign'])) {
1540
+		    	$data['ident'] = trim($line['callsign']);
1541
+		    }
1542
+		    // ident
1543
+		    if (isset($line['altitude'])) {
1544
+		    	$data['altitude'] = $line['altitude'];
1545
+		    }
1546
+		    // altitude
1547
+		    if (isset($line['speed'])) {
1548
+		    	$data['speed'] = $line['speed'];
1549
+		    }
1550
+		    // speed
1551
+		    if (isset($line['heading'])) {
1552
+		    	$data['heading'] = $line['heading'];
1553
+		    }
1554
+		    // heading
1555
+		    if (isset($line['lat'])) {
1556
+		    	$data['latitude'] = $line['lat'];
1557
+		    }
1558
+		    // lat
1559
+		    if (isset($line['lon'])) {
1560
+		    	$data['longitude'] = $line['lon'];
1561
+		    }
1562
+		    // long
1563
+		    if (isset($line['vert_rate'])) {
1564
+		    	$data['verticalrate'] = $line['vert_rate'];
1565
+		    }
1566
+		    // verticale rate
1567
+		    if (isset($line['squawk'])) {
1568
+		    	$data['squawk'] = $line['squawk'];
1569
+		    }
1570
+		    // squawk
1147 1571
 		    //$data['emergency'] = ''; // emergency
1148
-		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1149
-		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1572
+		    if (isset($line['reg'])) {
1573
+		    	$data['registration'] = $line['reg'];
1574
+		    }
1575
+		    if (isset($line['type'])) {
1576
+		    	$data['aircraft_icao'] = $line['type'];
1577
+		    }
1150 1578
 		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1151 1579
 		    $data['format_source'] = 'planefinderclient';
1152 1580
 		    $data['id_source'] = $id_source;
1153
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1154
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1581
+		    if (isset($value['name']) && $value['name'] != '') {
1582
+		    	$data['source_name'] = $value['name'];
1583
+		    }
1584
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1585
+		    	$data['noarchive'] = true;
1586
+		    }
1155 1587
 		    $SI->add($data);
1156 1588
 		    unset($data);
1157 1589
 		}
@@ -1167,7 +1599,9 @@  discard block
 block discarded – undo
1167 1599
 	    //$buffer = $Common->getData($hosts[$id]);
1168 1600
 	    $buffer = $Common->getData($value['host']);
1169 1601
 	    $all_data = json_decode($buffer,true);
1170
-	    if (!empty($all_data)) $reset = 0;
1602
+	    if (!empty($all_data)) {
1603
+	    	$reset = 0;
1604
+	    }
1171 1605
 	    foreach ($all_data as $key => $line) {
1172 1606
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1173 1607
 		    $data = array();
@@ -1188,8 +1622,12 @@  discard block
 block discarded – undo
1188 1622
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1189 1623
 	    	    $data['format_source'] = 'fr24json';
1190 1624
     		    $data['id_source'] = $id_source;
1191
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1192
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1625
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1626
+		    	$data['noarchive'] = true;
1627
+		    }
1628
+		    if (isset($value['name']) && $value['name'] != '') {
1629
+		    	$data['source_name'] = $value['name'];
1630
+		    }
1193 1631
 		    $SI->add($data);
1194 1632
 		    unset($data);
1195 1633
 		}
@@ -1218,24 +1656,42 @@  discard block
 block discarded – undo
1218 1656
 		    if (isset($line['inf'])) {
1219 1657
 			$data = array();
1220 1658
 			$data['hex'] = $line['inf']['ia'];
1221
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1659
+			if (isset($line['inf']['cs'])) {
1660
+				$data['ident'] = $line['inf']['cs'];
1661
+			}
1662
+			//$line[13]
1222 1663
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1223
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1224
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1664
+	    		if (isset($line['inf']['gs'])) {
1665
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1666
+	    		}
1667
+	    		// speed
1668
+	    		if (isset($line['inf']['tr'])) {
1669
+	    			$data['heading'] = $line['inf']['tr'];
1670
+	    		}
1671
+	    		// heading
1225 1672
 	    		$data['latitude'] = $line['pt'][0]; // lat
1226 1673
 	    		$data['longitude'] = $line['pt'][1]; // long
1227 1674
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1228
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1675
+	    		if (isset($line['inf']['sq'])) {
1676
+	    			$data['squawk'] = $line['inf']['sq'];
1677
+	    		}
1678
+	    		// squawk
1229 1679
 	    		//$data['aircraft_icao'] = $line[8];
1230
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1680
+	    		if (isset($line['inf']['rc'])) {
1681
+	    			$data['registration'] = $line['inf']['rc'];
1682
+	    		}
1231 1683
 			//$data['departure_airport_iata'] = $line[11];
1232 1684
 			//$data['arrival_airport_iata'] = $line[12];
1233 1685
 	    		//$data['emergency'] = ''; // emergency
1234 1686
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1235 1687
 	    		$data['format_source'] = 'radarvirtueljson';
1236 1688
     			$data['id_source'] = $id_source;
1237
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1238
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1689
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1690
+				$data['noarchive'] = true;
1691
+			}
1692
+			if (isset($value['name']) && $value['name'] != '') {
1693
+				$data['source_name'] = $value['name'];
1694
+			}
1239 1695
 			$SI->add($data);
1240 1696
 			unset($data);
1241 1697
 		    }
@@ -1261,30 +1717,65 @@  discard block
 block discarded – undo
1261 1717
 		    $data['id'] = $line['id'];
1262 1718
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1263 1719
 		    $data['ident'] = $line['callsign']; // ident
1264
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1265
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1266
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1267
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1268
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1269
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1720
+		    if (isset($line['pilotid'])) {
1721
+		    	$data['pilot_id'] = $line['pilotid'];
1722
+		    }
1723
+		    // pilot id
1724
+		    if (isset($line['name'])) {
1725
+		    	$data['pilot_name'] = $line['name'];
1726
+		    }
1727
+		    // pilot name
1728
+		    if (isset($line['alt'])) {
1729
+		    	$data['altitude'] = $line['alt'];
1730
+		    }
1731
+		    // altitude
1732
+		    if (isset($line['gs'])) {
1733
+		    	$data['speed'] = $line['gs'];
1734
+		    }
1735
+		    // speed
1736
+		    if (isset($line['heading'])) {
1737
+		    	$data['heading'] = $line['heading'];
1738
+		    }
1739
+		    // heading
1740
+		    if (isset($line['route'])) {
1741
+		    	$data['waypoints'] = $line['route'];
1742
+		    }
1743
+		    // route
1270 1744
 		    $data['latitude'] = $line['lat']; // lat
1271 1745
 		    $data['longitude'] = $line['lon']; // long
1272 1746
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1273 1747
 		    //$data['squawk'] = $line['squawk']; // squawk
1274 1748
 		    //$data['emergency'] = ''; // emergency
1275
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1276
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1277
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1749
+		    if (isset($line['depicao'])) {
1750
+		    	$data['departure_airport_icao'] = $line['depicao'];
1751
+		    }
1752
+		    if (isset($line['deptime'])) {
1753
+		    	$data['departure_airport_time'] = $line['deptime'];
1754
+		    }
1755
+		    if (isset($line['arricao'])) {
1756
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1757
+		    }
1278 1758
 		    //$data['arrival_airport_time'] = $line['arrtime'];
1279
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1280
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1281
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1282
-		    else $data['info'] = '';
1759
+		    if (isset($line['aircraft'])) {
1760
+		    	$data['aircraft_icao'] = $line['aircraft'];
1761
+		    }
1762
+		    if (isset($line['transponder'])) {
1763
+		    	$data['squawk'] = $line['transponder'];
1764
+		    }
1765
+		    if (isset($line['atis'])) {
1766
+		    	$data['info'] = $line['atis'];
1767
+		    } else {
1768
+		    	$data['info'] = '';
1769
+		    }
1283 1770
 		    $data['format_source'] = 'pireps';
1284 1771
     		    $data['id_source'] = $id_source;
1285 1772
 		    $data['datetime'] = date('Y-m-d H:i:s');
1286
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1287
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1773
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1774
+		    	$data['noarchive'] = true;
1775
+		    }
1776
+		    if (isset($value['name']) && $value['name'] != '') {
1777
+		    	$data['source_name'] = $value['name'];
1778
+		    }
1288 1779
 		    if ($line['icon'] === 'plane') {
1289 1780
 			$SI->add($data);
1290 1781
 		    //    print_r($data);
@@ -1293,16 +1784,28 @@  discard block
 block discarded – undo
1293 1784
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1294 1785
 			$typec = substr($data['ident'],-3);
1295 1786
 			$data['type'] = '';
1296
-			if ($typec === 'APP') $data['type'] = 'Approach';
1297
-			elseif ($typec === 'TWR') $data['type'] = 'Tower';
1298
-			elseif ($typec === 'OBS') $data['type'] = 'Observer';
1299
-			elseif ($typec === 'GND') $data['type'] = 'Ground';
1300
-			elseif ($typec === 'DEL') $data['type'] = 'Delivery';
1301
-			elseif ($typec === 'DEP') $data['type'] = 'Departure';
1302
-			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1303
-			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
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']);
1787
+			if ($typec === 'APP') {
1788
+				$data['type'] = 'Approach';
1789
+			} elseif ($typec === 'TWR') {
1790
+				$data['type'] = 'Tower';
1791
+			} elseif ($typec === 'OBS') {
1792
+				$data['type'] = 'Observer';
1793
+			} elseif ($typec === 'GND') {
1794
+				$data['type'] = 'Ground';
1795
+			} elseif ($typec === 'DEL') {
1796
+				$data['type'] = 'Delivery';
1797
+			} elseif ($typec === 'DEP') {
1798
+				$data['type'] = 'Departure';
1799
+			} elseif ($typec === 'FSS') {
1800
+				$data['type'] = 'Flight Service Station';
1801
+			} elseif ($typec === 'CTR') {
1802
+				$data['type'] = 'Control Radar or Centre';
1803
+			} else {
1804
+				$data['type'] = 'Observer';
1805
+			}
1806
+			if (isset($ATC)) {
1807
+				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']);
1808
+			}
1306 1809
 		    }
1307 1810
 		    unset($data);
1308 1811
 		}
@@ -1317,7 +1820,9 @@  discard block
 block discarded – undo
1317 1820
 	    )
1318 1821
 	) {
1319 1822
 	    //$buffer = $Common->getData($hosts[$id]);
1320
-	    if ($globalDebug) echo 'Get Data...'."\n";
1823
+	    if ($globalDebug) {
1824
+	    	echo 'Get Data...'."\n";
1825
+	    }
1321 1826
 	    $buffer = $Common->getData($value['host']);
1322 1827
 	    $all_data = json_decode($buffer,true);
1323 1828
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1325,10 +1830,16 @@  discard block
 block discarded – undo
1325 1830
 		foreach ($all_data as $line) {
1326 1831
 	    	    $data = array();
1327 1832
 	    	    //$data['id'] = $line['id']; // id not usable
1328
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1833
+	    	    if (isset($line['pilotid'])) {
1834
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1835
+	    	    }
1329 1836
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1330
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1331
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1837
+	    	    if (isset($line['pilotname'])) {
1838
+	    	    	$data['pilot_name'] = $line['pilotname'];
1839
+	    	    }
1840
+	    	    if (isset($line['pilotid'])) {
1841
+	    	    	$data['pilot_id'] = $line['pilotid'];
1842
+	    	    }
1332 1843
 	    	    $data['ident'] = $line['flightnum']; // ident
1333 1844
 	    	    $data['altitude'] = $line['alt']; // altitude
1334 1845
 	    	    $data['speed'] = $line['gs']; // speed
@@ -1344,7 +1855,9 @@  discard block
 block discarded – undo
1344 1855
 	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1345 1856
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1346 1857
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1347
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1858
+	    	    } else {
1859
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1860
+	    	    }
1348 1861
 	    	    $data['departure_airport_icao'] = $line['depicao'];
1349 1862
 	    	    $data['departure_airport_time'] = $line['deptime'];
1350 1863
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
@@ -1352,29 +1865,47 @@  discard block
 block discarded – undo
1352 1865
     		    if (isset($line['registration'])) {
1353 1866
     			$data['registration'] = $line['registration'];
1354 1867
     			//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1355
-    		    } else $data['registration'] = $line['aircraft'];
1356
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1357
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1868
+    		    } else {
1869
+    		    	$data['registration'] = $line['aircraft'];
1870
+    		    }
1871
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1872
+		    	$data['noarchive'] = true;
1873
+		    }
1874
+		    if (isset($line['route'])) {
1875
+		    	$data['waypoints'] = $line['route'];
1876
+		    }
1877
+		    // route
1358 1878
 		    if (isset($line['aircraftname'])) {
1359 1879
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1360 1880
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1361 1881
 	    		$aircraft_data = explode('-',$line['aircraftname']);
1362
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1363
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1364
-	    		else {
1882
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1883
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1884
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1885
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1886
+	    		} else {
1365 1887
 	    		    $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']);
1888
+	    		    if (isset($aircraft_data[1])) {
1889
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1890
+	    		    } else {
1891
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1892
+	    		    }
1368 1893
 	    		}
1369 1894
 	    	    }
1370
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1895
+    		    if (isset($line['route'])) {
1896
+    		    	$data['waypoints'] = $line['route'];
1897
+    		    }
1371 1898
     		    $data['id_source'] = $id_source;
1372 1899
 	    	    $data['format_source'] = 'phpvmacars';
1373
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1900
+		    if (isset($value['name']) && $value['name'] != '') {
1901
+		    	$data['source_name'] = $value['name'];
1902
+		    }
1374 1903
 		    $SI->add($data);
1375 1904
 		    unset($data);
1376 1905
 		}
1377
-		if ($globalDebug) echo 'No more data...'."\n";
1906
+		if ($globalDebug) {
1907
+			echo 'No more data...'."\n";
1908
+		}
1378 1909
 		unset($buffer);
1379 1910
 		unset($all_data);
1380 1911
 	    }
@@ -1387,7 +1918,9 @@  discard block
 block discarded – undo
1387 1918
 	    )
1388 1919
 	) {
1389 1920
 	    //$buffer = $Common->getData($hosts[$id]);
1390
-	    if ($globalDebug) echo 'Get Data...'."\n";
1921
+	    if ($globalDebug) {
1922
+	    	echo 'Get Data...'."\n";
1923
+	    }
1391 1924
 	    $buffer = $Common->getData($value['host']);
1392 1925
 	    $all_data = json_decode($buffer,true);
1393 1926
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
@@ -1398,10 +1931,16 @@  discard block
 block discarded – undo
1398 1931
 	    	    //$data['id'] = $line['id']; // id not usable
1399 1932
 	    	    $data['id'] = $line['id'];
1400 1933
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1401
-	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1402
-	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1934
+	    	    if (isset($line['user']['username'])) {
1935
+	    	    	$data['pilot_name'] = $line['user']['username'];
1936
+	    	    }
1937
+	    	    if (isset($line['user_id'])) {
1938
+	    	    	$data['pilot_id'] = $line['user_id'];
1939
+	    	    }
1403 1940
 	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1404
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1941
+	    	    if (is_numeric($data['ident'])) {
1942
+	    	    	$data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1943
+	    	    }
1405 1944
 	    	    $data['altitude'] = $line['altitude']; // altitude
1406 1945
 	    	    $data['speed'] = $line['groundspeed']; // speed
1407 1946
 	    	    $data['heading'] = $line['heading']; // heading
@@ -1414,7 +1953,9 @@  discard block
 block discarded – undo
1414 1953
 	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1415 1954
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1416 1955
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1417
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1956
+	    	    } else {
1957
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1958
+	    	    }
1418 1959
 	    	    
1419 1960
 	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1420 1961
 	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
@@ -1422,17 +1963,26 @@  discard block
 block discarded – undo
1422 1963
 		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1423 1964
 		    $data['registration'] = $line['bid']['aircraft']['registration'];
1424 1965
 
1425
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1426
-		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1966
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1967
+		    	$data['noarchive'] = true;
1968
+		    }
1969
+		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') {
1970
+		    	$data['waypoints'] = $line['bid']['route'];
1971
+		    }
1972
+		    // route
1427 1973
 	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1428 1974
 
1429 1975
     		    $data['id_source'] = $id_source;
1430 1976
 	    	    $data['format_source'] = 'vaos';
1431
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1977
+		    if (isset($value['name']) && $value['name'] != '') {
1978
+		    	$data['source_name'] = $value['name'];
1979
+		    }
1432 1980
 		    $SI->add($data);
1433 1981
 		    unset($data);
1434 1982
 		}
1435
-		if ($globalDebug) echo 'No more data...'."\n";
1983
+		if ($globalDebug) {
1984
+			echo 'No more data...'."\n";
1985
+		}
1436 1986
 		unset($buffer);
1437 1987
 		unset($all_data);
1438 1988
 	    }
@@ -1445,7 +1995,9 @@  discard block
 block discarded – undo
1445 1995
 	    )
1446 1996
 	) {
1447 1997
 	    //$buffer = $Common->getData($hosts[$id]);
1448
-	    if ($globalDebug) echo 'Get Data...'."\n";
1998
+	    if ($globalDebug) {
1999
+	    	echo 'Get Data...'."\n";
2000
+	    }
1449 2001
 	    $buffer = $Common->getData($value['host']);
1450 2002
 	    $all_data = json_decode($buffer,true);
1451 2003
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1474,16 +2026,25 @@  discard block
 block discarded – undo
1474 2026
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1475 2027
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1476 2028
     		    //$data['registration'] = $line['aircraft'];
1477
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
2029
+		    if (isset($line['route'])) {
2030
+		    	$data['waypoints'] = $line['route'];
2031
+		    }
2032
+		    // route
1478 2033
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1479 2034
     		    $data['id_source'] = $id_source;
1480 2035
 	    	    $data['format_source'] = 'vam';
1481
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1482
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
2036
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
2037
+		    	$data['noarchive'] = true;
2038
+		    }
2039
+		    if (isset($value['name']) && $value['name'] != '') {
2040
+		    	$data['source_name'] = $value['name'];
2041
+		    }
1483 2042
 		    $SI->add($data);
1484 2043
 		    unset($data);
1485 2044
 		}
1486
-		if ($globalDebug) echo 'No more data...'."\n";
2045
+		if ($globalDebug) {
2046
+			echo 'No more data...'."\n";
2047
+		}
1487 2048
 		unset($buffer);
1488 2049
 		unset($all_data);
1489 2050
 	    }
@@ -1496,7 +2057,9 @@  discard block
 block discarded – undo
1496 2057
 	    )
1497 2058
 	) {
1498 2059
 	    //$buffer = $Common->getData($hosts[$id]);
1499
-	    if ($globalDebug) echo 'Get Data...'."\n";
2060
+	    if ($globalDebug) {
2061
+	    	echo 'Get Data...'."\n";
2062
+	    }
1500 2063
 	    $buffer = $Common->getData($value['host']);
1501 2064
 	    $all_data = json_decode($buffer,true);
1502 2065
 	    if ($buffer != '') {
@@ -1514,12 +2077,16 @@  discard block
 block discarded – undo
1514 2077
 			$data['id_source'] = $id_source;
1515 2078
 			$data['format_source'] = 'blitzortung';
1516 2079
 			$SI->add($data);
1517
-			if ($globalDebug) echo '☈ Lightning added'."\n";
2080
+			if ($globalDebug) {
2081
+				echo '☈ Lightning added'."\n";
2082
+			}
1518 2083
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1519 2084
 			unset($data);
1520 2085
 		    }
1521 2086
 		}
1522
-		if ($globalDebug) echo 'No more data...'."\n";
2087
+		if ($globalDebug) {
2088
+			echo 'No more data...'."\n";
2089
+		}
1523 2090
 		unset($buffer);
1524 2091
 	    }
1525 2092
 	    $last_exec[$id]['last'] = time();
@@ -1531,7 +2098,9 @@  discard block
 block discarded – undo
1531 2098
 	    $write = NULL;
1532 2099
 	    $e = NULL;
1533 2100
 	    $n = socket_select($read, $write, $e, $timeout);
1534
-	    if ($e != NULL) var_dump($e);
2101
+	    if ($e != NULL) {
2102
+	    	var_dump($e);
2103
+	    }
1535 2104
 	    if ($n > 0) {
1536 2105
 		$reset = 0;
1537 2106
 		foreach ($read as $nb => $r) {
@@ -1553,13 +2122,17 @@  discard block
 block discarded – undo
1553 2122
 		    if ($buffer !== FALSE) {
1554 2123
 			if ($format === 'vrstcp') {
1555 2124
 			    $buffer = explode('},{',$buffer);
1556
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
2125
+			} else {
2126
+				$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
2127
+			}
1557 2128
 		    }
1558 2129
 		    // SBS format is CSV format
1559 2130
 		    if ($buffer !== FALSE && $buffer !== '') {
1560 2131
 			$tt[$format] = 0;
1561 2132
 			if ($format === 'acarssbs3') {
1562
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2133
+			    if ($globalDebug) {
2134
+			    	echo 'ACARS : '.$buffer."\n";
2135
+			    }
1563 2136
 			    $ACARS->add(trim($buffer));
1564 2137
 			    $ACARS->deleteLiveAcarsData();
1565 2138
 			} elseif ($format === 'raw') {
@@ -1568,30 +2141,70 @@  discard block
 block discarded – undo
1568 2141
 			    if (is_array($data)) {
1569 2142
 				$data['datetime'] = date('Y-m-d H:i:s');
1570 2143
 				$data['format_source'] = 'raw';
1571
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1572
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1573
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1574
-				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2144
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2145
+					$data['source_name'] = $globalSources[$nb]['name'];
2146
+				}
2147
+				if (isset($globalSources[$nb]['sourcestats'])) {
2148
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2149
+				}
2150
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2151
+					$data['noarchive'] = true;
2152
+				}
2153
+				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2154
+					$SI->add($data);
2155
+				}
1575 2156
 			    }
1576 2157
 			} elseif ($format === 'ais') {
1577 2158
 			    $ais_data = $AIS->parse_line(trim($buffer));
1578 2159
 			    $data = array();
1579
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1580
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1581
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1582
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1583
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1584
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1585
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1586
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1587
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1588
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1589
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
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']);
1592
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1593
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1594
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2160
+			    if (isset($ais_data['ident'])) {
2161
+			    	$data['ident'] = $ais_data['ident'];
2162
+			    }
2163
+			    if (isset($ais_data['mmsi'])) {
2164
+			    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
2165
+			    }
2166
+			    if (isset($ais_data['speed'])) {
2167
+			    	$data['speed'] = $ais_data['speed'];
2168
+			    }
2169
+			    if (isset($ais_data['heading'])) {
2170
+			    	$data['heading'] = $ais_data['heading'];
2171
+			    }
2172
+			    if (isset($ais_data['latitude'])) {
2173
+			    	$data['latitude'] = $ais_data['latitude'];
2174
+			    }
2175
+			    if (isset($ais_data['longitude'])) {
2176
+			    	$data['longitude'] = $ais_data['longitude'];
2177
+			    }
2178
+			    if (isset($ais_data['status'])) {
2179
+			    	$data['status'] = $ais_data['status'];
2180
+			    }
2181
+			    if (isset($ais_data['statusid'])) {
2182
+			    	$data['status_id'] = $ais_data['statusid'];
2183
+			    }
2184
+			    if (isset($ais_data['type'])) {
2185
+			    	$data['type'] = $ais_data['type'];
2186
+			    }
2187
+			    if (isset($ais_data['imo'])) {
2188
+			    	$data['imo'] = $ais_data['imo'];
2189
+			    }
2190
+			    if (isset($ais_data['callsign'])) {
2191
+			    	$data['callsign'] = $ais_data['callsign'];
2192
+			    }
2193
+			    if (isset($ais_data['destination'])) {
2194
+			    	$data['arrival_code'] = $ais_data['destination'];
2195
+			    }
2196
+			    if (isset($ais_data['eta_ts'])) {
2197
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
2198
+			    }
2199
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2200
+			    	$data['noarchive'] = true;
2201
+			    }
2202
+			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2203
+			    	$data['source_name'] = $globalSources[$nb]['name'];
2204
+			    }
2205
+			    if (isset($globalSources[$nb]['sourcestats'])) {
2206
+			    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2207
+			    }
1595 2208
 
1596 2209
 			    if (isset($ais_data['timestamp'])) {
1597 2210
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1600,7 +2213,9 @@  discard block
 block discarded – undo
1600 2213
 			    }
1601 2214
 			    $data['format_source'] = 'aisnmea';
1602 2215
     			    $data['id_source'] = $id_source;
1603
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
2216
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
2217
+			    	$MI->add($data);
2218
+			    }
1604 2219
 			    unset($data);
1605 2220
                         } elseif ($format === 'flightgearsp') {
1606 2221
                     	    //echo $buffer."\n";
@@ -1618,12 +2233,18 @@  discard block
 block discarded – undo
1618 2233
 				$data['speed'] = round($line[5]*1.94384);
1619 2234
 				$data['datetime'] = date('Y-m-d H:i:s');
1620 2235
 				$data['format_source'] = 'flightgearsp';
1621
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1622
-				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2236
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2237
+					$data['noarchive'] = true;
2238
+				}
2239
+				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2240
+					$SI->add($data);
2241
+				}
1623 2242
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1624 2243
 			    }
1625 2244
                         } elseif ($format === 'acars') {
1626
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2245
+                    	    if ($globalDebug) {
2246
+                    	    	echo 'ACARS : '.$buffer."\n";
2247
+                    	    }
1627 2248
 			    $ACARS->add(trim($buffer));
1628 2249
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1629 2250
 			    $ACARS->deleteLiveAcarsData();
@@ -1644,8 +2265,12 @@  discard block
 block discarded – undo
1644 2265
 				    $aircraft_type = $line[10];
1645 2266
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1646 2267
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1647
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1648
-				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2268
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2269
+				    	$data['noarchive'] = true;
2270
+				    }
2271
+				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2272
+				    	$SI->add($data);
2273
+				    }
1649 2274
 				}
1650 2275
 			    }
1651 2276
 			} elseif ($format === 'beast') {
@@ -1655,28 +2280,62 @@  discard block
 block discarded – undo
1655 2280
 			    foreach($buffer as $all_data) {
1656 2281
 				$line = json_decode('{'.$all_data.'}',true);
1657 2282
 				$data = array();
1658
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1659
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1660
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1661
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1662
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1663
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1664
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
2283
+				if (isset($line['Icao'])) {
2284
+					$data['hex'] = $line['Icao'];
2285
+				}
2286
+				// hex
2287
+				if (isset($line['Call'])) {
2288
+					$data['ident'] = $line['Call'];
2289
+				}
2290
+				// ident
2291
+				if (isset($line['Alt'])) {
2292
+					$data['altitude'] = $line['Alt'];
2293
+				}
2294
+				// altitude
2295
+				if (isset($line['Spd'])) {
2296
+					$data['speed'] = $line['Spd'];
2297
+				}
2298
+				// speed
2299
+				if (isset($line['Trak'])) {
2300
+					$data['heading'] = $line['Trak'];
2301
+				}
2302
+				// heading
2303
+				if (isset($line['Lat'])) {
2304
+					$data['latitude'] = $line['Lat'];
2305
+				}
2306
+				// lat
2307
+				if (isset($line['Long'])) {
2308
+					$data['longitude'] = $line['Long'];
2309
+				}
2310
+				// long
1665 2311
 				//$data['verticalrate'] = $line['']; // verticale rate
1666
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
2312
+				if (isset($line['Sqk'])) {
2313
+					$data['squawk'] = $line['Sqk'];
2314
+				}
2315
+				// squawk
1667 2316
 				$data['emergency'] = ''; // emergency
1668
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
2317
+				if (isset($line['Reg'])) {
2318
+					$data['registration'] = $line['Reg'];
2319
+				}
1669 2320
 				/*
1670 2321
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1671 2322
 				else $data['datetime'] = date('Y-m-d H:i:s');
1672 2323
 				*/
1673 2324
 				$data['datetime'] = date('Y-m-d H:i:s');
1674
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
2325
+				if (isset($line['Type'])) {
2326
+					$data['aircraft_icao'] = $line['Type'];
2327
+				}
1675 2328
 		    		$data['format_source'] = 'vrstcp';
1676 2329
 				$data['id_source'] = $id_source;
1677
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1678
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1679
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
2330
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2331
+					$data['noarchive'] = true;
2332
+				}
2333
+				if (isset($value['name']) && $value['name'] != '') {
2334
+					$data['source_name'] = $value['name'];
2335
+				}
2336
+				if (isset($data['latitude']) && isset($data['hex'])) {
2337
+					$SI->add($data);
2338
+				}
1680 2339
 				unset($data);
1681 2340
 			    }
1682 2341
 			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
@@ -1689,22 +2348,46 @@  discard block
 block discarded – undo
1689 2348
     				$data['hex'] = $lined['hexid'];
1690 2349
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1691 2350
     				$data['datetime'] = date('Y-m-d H:i:s');;
1692
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1693
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1694
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1695
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1696
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1697
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1698
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
2351
+    				if (isset($lined['ident'])) {
2352
+    					$data['ident'] = $lined['ident'];
2353
+    				}
2354
+    				if (isset($lined['lat'])) {
2355
+    					$data['latitude'] = $lined['lat'];
2356
+    				}
2357
+    				if (isset($lined['lon'])) {
2358
+    					$data['longitude'] = $lined['lon'];
2359
+    				}
2360
+    				if (isset($lined['speed'])) {
2361
+    					$data['speed'] = $lined['speed'];
2362
+    				}
2363
+    				if (isset($lined['squawk'])) {
2364
+    					$data['squawk'] = $lined['squawk'];
2365
+    				}
2366
+    				if (isset($lined['alt'])) {
2367
+    					$data['altitude'] = $lined['alt'];
2368
+    				}
2369
+    				if (isset($lined['heading'])) {
2370
+    					$data['heading'] = $lined['heading'];
2371
+    				}
1699 2372
     				$data['id_source'] = $id_source;
1700 2373
     				$data['format_source'] = 'tsv';
1701
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1702
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1703
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1704
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2374
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2375
+    					$data['source_name'] = $globalSources[$nb]['name'];
2376
+    				}
2377
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2378
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2379
+    				}
2380
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2381
+					$data['noarchive'] = true;
2382
+				}
2383
+    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2384
+    					$SI->add($data);
2385
+    				}
1705 2386
     				unset($lined);
1706 2387
     				unset($data);
1707
-    			    } else $error = true;
2388
+    			    } else {
2389
+    			    	$error = true;
2390
+    			    }
1708 2391
 			} elseif ($format === 'aprs' && $use_aprs) {
1709 2392
 			    if ($aprs_connect === 0) {
1710 2393
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1730,47 +2413,96 @@  discard block
 block discarded – undo
1730 2413
 				    $aprs_last_tx = time();
1731 2414
 				    $data = array();
1732 2415
 				    //print_r($line);
1733
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1734
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1735
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1736
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1737
-				    if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1738
-				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1739
-				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
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']);
1742
-				    else $data['datetime'] = date('Y-m-d H:i:s');
2416
+				    if (isset($line['address'])) {
2417
+				    	$data['hex'] = $line['address'];
2418
+				    }
2419
+				    if (isset($line['mmsi'])) {
2420
+				    	$data['mmsi'] = $line['mmsi'];
2421
+				    }
2422
+				    if (isset($line['imo'])) {
2423
+				    	$data['imo'] = $line['imo'];
2424
+				    }
2425
+				    if (isset($line['squawk'])) {
2426
+				    	$data['squawk'] = $line['squawk'];
2427
+				    }
2428
+				    if (isset($line['arrival_code'])) {
2429
+				    	$data['arrival_code'] = $line['arrival_code'];
2430
+				    }
2431
+				    if (isset($line['arrival_date'])) {
2432
+				    	$data['arrival_date'] = $line['arrival_date'];
2433
+				    }
2434
+				    if (isset($line['typeid'])) {
2435
+				    	$data['type_id'] = $line['typeid'];
2436
+				    }
2437
+				    if (isset($line['statusid'])) {
2438
+				    	$data['status_id'] = $line['statusid'];
2439
+				    }
2440
+				    if (isset($line['timestamp'])) {
2441
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
2442
+				    } else {
2443
+				    	$data['datetime'] = date('Y-m-d H:i:s');
2444
+				    }
1743 2445
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1744
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
2446
+				    if (isset($line['ident'])) {
2447
+				    	$data['ident'] = $line['ident'];
2448
+				    }
1745 2449
 				    $data['latitude'] = $line['latitude'];
1746 2450
 				    $data['longitude'] = $line['longitude'];
1747 2451
 				    //$data['verticalrate'] = $line[16];
1748
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
2452
+				    if (isset($line['speed'])) {
2453
+				    	$data['speed'] = $line['speed'];
2454
+				    }
1749 2455
 				    //else $data['speed'] = 0;
1750
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1751
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1752
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
2456
+				    if (isset($line['altitude'])) {
2457
+				    	$data['altitude'] = $line['altitude'];
2458
+				    }
2459
+				    if (isset($line['comment'])) {
2460
+				    	$data['comment'] = $line['comment'];
2461
+				    }
2462
+				    if (isset($line['symbol'])) {
2463
+				    	$data['type'] = $line['symbol'];
2464
+				    }
1753 2465
 				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1754 2466
 				    
1755
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
2467
+				    if (isset($line['heading']) && isset($line['format_source'])) {
2468
+				    	$data['heading'] = $line['heading'];
2469
+				    }
1756 2470
 				    //else echo 'No heading...'."\n";
1757 2471
 				    //else $data['heading'] = 0;
1758
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
2472
+				    if (isset($line['stealth'])) {
2473
+				    	$data['aircraft_type'] = $line['stealth'];
2474
+				    }
1759 2475
 				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1760
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1761
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1762
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1763
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
2476
+				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) {
2477
+				    	$data['noarchive'] = true;
2478
+				    } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) {
2479
+				    	$data['noarchive'] = false;
2480
+				    }
2481
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2482
+				    	$data['noarchive'] = true;
2483
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
2484
+				    	$data['noarchive'] = false;
2485
+				    }
1764 2486
     				    $data['id_source'] = $id_source;
1765
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1766
-				    else $data['format_source'] = 'aprs';
2487
+    				    if (isset($line['format_source'])) {
2488
+    				    	$data['format_source'] = $line['format_source'];
2489
+    				    } else {
2490
+				    	$data['format_source'] = 'aprs';
2491
+				    }
1767 2492
 				    $data['source_name'] = $line['source'];
1768
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1769
-				    else $data['source_type'] = 'flarm';
1770
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2493
+				    if (isset($line['source_type'])) {
2494
+				    	$data['source_type'] = $line['source_type'];
2495
+				    } else {
2496
+				    	$data['source_type'] = 'flarm';
2497
+				    }
2498
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
2499
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2500
+    				    }
1771 2501
 				    $currentdate = date('Y-m-d H:i:s');
1772 2502
 				    $aprsdate = strtotime($data['datetime']);
1773
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
2503
+				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') {
2504
+				    	$data['altitude_relative'] = 'AMSL';
2505
+				    }
1774 2506
 				    // Accept data if time <= system time + 20s
1775 2507
 				    //if (($data['source_type'] === 'modes') || isset($line['stealth']) && ($line['stealth'] === 0 || $line['stealth'] === '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1776 2508
 				    if (
@@ -1782,7 +2514,9 @@  discard block
 block discarded – undo
1782 2514
 					$send = $SI->add($data);
1783 2515
 				    } elseif ($data['source_type'] === 'ais') {
1784 2516
 					$data['type'] = '';
1785
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
2517
+					if (isset($globalMarine) && $globalMarine) {
2518
+						$send = $MI->add($data);
2519
+					}
1786 2520
 				    } elseif (isset($line['stealth']) && $line['stealth'] != 0) {
1787 2521
 					 echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1788 2522
 				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
@@ -1790,8 +2524,12 @@  discard block
 block discarded – undo
1790 2524
 					    $line['symbol'] === 'Glider' || 
1791 2525
 					    $line['symbol'] === 'No. Plane' || 
1792 2526
 					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
1793
-					    if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
1794
-					    if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2527
+					    if ($line['symbol'] === 'Ballon') {
2528
+					    	$data['aircraft_icao'] = 'BALL';
2529
+					    }
2530
+					    if ($line['symbol'] === 'Glider') {
2531
+					    	$data['aircraft_icao'] = 'PARAGLIDER';
2532
+					    }
1795 2533
 					    $send = $SI->add($data);
1796 2534
 				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1797 2535
 					    $line['symbol'] === 'Yacht (Sail)' || 
@@ -1822,9 +2560,13 @@  discard block
 block discarded – undo
1822 2560
 				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1823 2561
 				//    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1824 2562
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1825
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2563
+					if (isset($globalTracker) && $globalTracker) {
2564
+						$send = $TI->add($data);
2565
+					}
1826 2566
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1827
-					if (!isset($data['altitude'])) $data['altitude'] = 0;
2567
+					if (!isset($data['altitude'])) {
2568
+						$data['altitude'] = 0;
2569
+					}
1828 2570
 					$Source->deleteOldLocationByType('gs');
1829 2571
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1830 2572
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
@@ -1833,7 +2575,9 @@  discard block
 block discarded – undo
1833 2575
 					}
1834 2576
 				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
1835 2577
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1836
-					if ($globalDebug) echo '# Weather Station added'."\n";
2578
+					if ($globalDebug) {
2579
+						echo '# Weather Station added'."\n";
2580
+					}
1837 2581
 					$Source->deleteOldLocationByType('wx');
1838 2582
 					$weather_data = json_encode($line);
1839 2583
 					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
@@ -1843,7 +2587,9 @@  discard block
 block discarded – undo
1843 2587
 					}
1844 2588
 				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
1845 2589
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1846
-					if ($globalDebug) echo '☈ Lightning added'."\n";
2590
+					if ($globalDebug) {
2591
+						echo '☈ Lightning added'."\n";
2592
+					}
1847 2593
 					$Source->deleteOldLocationByType('lightning');
1848 2594
 					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1849 2595
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
@@ -1855,8 +2601,7 @@  discard block
 block discarded – undo
1855 2601
 				    	print_r($line);
1856 2602
 				    }
1857 2603
 				    unset($data);
1858
-				}
1859
-				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2604
+				} elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1860 2605
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1861 2606
 				}
1862 2607
 				/*
@@ -1865,7 +2610,9 @@  discard block
 block discarded – undo
1865 2610
 				}
1866 2611
 				*/
1867 2612
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1868
-				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2613
+				elseif ($line === true && $globalDebug) {
2614
+					echo '!! Failed : '.$buffer."!!\n";
2615
+				}
1869 2616
 				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1870 2617
 					$Source->deleteOldLocationByType('lightning');
1871 2618
 					$Source->deleteOldLocationByType('wx');
@@ -1901,27 +2648,47 @@  discard block
 block discarded – undo
1901 2648
     				$data['ground'] = $line[21];
1902 2649
     				$data['emergency'] = $line[19];
1903 2650
     				$data['format_source'] = 'sbs';
1904
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1905
-				elseif ($line[0] == 'MLAT') $data['source_name'] = 'MLAT';
1906
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1907
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2651
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2652
+					$data['source_name'] = $globalSources[$nb]['name'];
2653
+				} elseif ($line[0] == 'MLAT') {
2654
+					$data['source_name'] = 'MLAT';
2655
+				}
2656
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2657
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2658
+    				}
2659
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2660
+					$data['noarchive'] = true;
2661
+				}
1908 2662
     				$data['id_source'] = $id_source;
1909
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1910
-    				else $error = true;
2663
+    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2664
+    					$send = $SI->add($data);
2665
+    				} else {
2666
+    					$error = true;
2667
+    				}
1911 2668
     				unset($data);
1912
-    			    } else $error = true;
2669
+    			    } else {
2670
+    			    	$error = true;
2671
+    			    }
1913 2672
 			    if ($error) {
1914 2673
 				if (count($line) > 1 && ($line[0] === 'STA' || $line[0] === 'AIR' || $line[0] === 'SEL' || $line[0] === 'ID' || $line[0] === 'CLK')) { 
1915
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
2674
+					if ($globalDebug) {
2675
+						echo "Not a message. Ignoring... \n";
2676
+					}
1916 2677
 				} else {
1917
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
2678
+					if ($globalDebug) {
2679
+						echo "Wrong line format. Ignoring... \n";
2680
+					}
1918 2681
 					if ($globalDebug) {
1919 2682
 						echo $buffer;
1920 2683
 						//print_r($line);
1921 2684
 					}
1922 2685
 					//socket_close($r);
1923
-					if ($globalDebug) echo "Reconnect after an error...\n";
1924
-					if ($format === 'aprs') $aprs_connect = 0;
2686
+					if ($globalDebug) {
2687
+						echo "Reconnect after an error...\n";
2688
+					}
2689
+					if ($format === 'aprs') {
2690
+						$aprs_connect = 0;
2691
+					}
1925 2692
 					$sourceer[$nb] = $globalSources[$nb];
1926 2693
 					connect_all($sourceer);
1927 2694
 					$sourceer = array();
@@ -1929,10 +2696,14 @@  discard block
 block discarded – undo
1929 2696
 			    }
1930 2697
 			}
1931 2698
 			// Sleep for xxx microseconds
1932
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2699
+			if (isset($globalSBSSleep)) {
2700
+				usleep($globalSBSSleep);
2701
+			}
1933 2702
 		    } else {
1934 2703
 			if ($format === 'flightgearmp') {
1935
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2704
+			    	if ($globalDebug) {
2705
+			    		echo "Reconnect FlightGear MP...";
2706
+			    	}
1936 2707
 				//@socket_close($r);
1937 2708
 				sleep($globalMinFetch);
1938 2709
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1941,10 +2712,15 @@  discard block
 block discarded – undo
1941 2712
 				break;
1942 2713
 				
1943 2714
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1944
-			    if (isset($tt[$format])) $tt[$format]++;
1945
-			    else $tt[$format] = 0;
2715
+			    if (isset($tt[$format])) {
2716
+			    	$tt[$format]++;
2717
+			    } else {
2718
+			    	$tt[$format] = 0;
2719
+			    }
1946 2720
 			    if ($tt[$format] > 30 || $buffer === FALSE) {
1947
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2721
+				if ($globalDebug) {
2722
+					echo "ERROR : Reconnect ".$format."...";
2723
+				}
1948 2724
 				//@socket_close($r);
1949 2725
 				sleep(2);
1950 2726
 				$aprs_connect = 0;
@@ -1962,11 +2738,17 @@  discard block
 block discarded – undo
1962 2738
 	    } else {
1963 2739
 		$error = socket_strerror(socket_last_error());
1964 2740
 		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";
1966
-			if (isset($globalDebug)) echo "Restarting...\n";
2741
+			if ($globalDebug) {
2742
+				echo "ERROR : socket_select give this error ".$error . "\n";
2743
+			}
2744
+			if (isset($globalDebug)) {
2745
+				echo "Restarting...\n";
2746
+			}
1967 2747
 			// Restart the script if possible
1968 2748
 			if (is_array($sockets)) {
1969
-			    if ($globalDebug) echo "Shutdown all sockets...";
2749
+			    if ($globalDebug) {
2750
+			    	echo "Shutdown all sockets...";
2751
+			    }
1970 2752
 			    
1971 2753
 			    foreach ($sockets as $sock) {
1972 2754
 				@socket_shutdown($sock,2);
@@ -1974,25 +2756,45 @@  discard block
 block discarded – undo
1974 2756
 			    }
1975 2757
 			    
1976 2758
 			}
1977
-			if ($globalDebug) echo "Waiting...";
2759
+			if ($globalDebug) {
2760
+				echo "Waiting...";
2761
+			}
1978 2762
 			sleep(2);
1979 2763
 			$time = time();
1980 2764
 			//connect_all($hosts);
1981 2765
 			$aprs_connect = 0;
1982
-			if ($reset%5 === 0) sleep(20);
1983
-			if ($reset%10 === 0) sleep(100);
1984
-			if ($reset%20 === 0) sleep(200);
1985
-			if ($reset > 100) exit('Too many attempts...');
1986
-			if ($globalDebug) echo "Restart all connections...";
2766
+			if ($reset%5 === 0) {
2767
+				sleep(20);
2768
+			}
2769
+			if ($reset%10 === 0) {
2770
+				sleep(100);
2771
+			}
2772
+			if ($reset%20 === 0) {
2773
+				sleep(200);
2774
+			}
2775
+			if ($reset > 100) {
2776
+				exit('Too many attempts...');
2777
+			}
2778
+			if ($globalDebug) {
2779
+				echo "Restart all connections...";
2780
+			}
1987 2781
 			connect_all($globalSources);
1988 2782
 		}
1989 2783
 	    }
1990 2784
 	}
1991 2785
 	if ($globalDaemon === false) {
1992
-	    if ($globalDebug) echo 'Check all...'."\n";
1993
-	    if (isset($SI)) $SI->checkAll();
1994
-	    if (isset($TI)) $TI->checkAll();
1995
-	    if (isset($MI)) $MI->checkAll();
2786
+	    if ($globalDebug) {
2787
+	    	echo 'Check all...'."\n";
2788
+	    }
2789
+	    if (isset($SI)) {
2790
+	    	$SI->checkAll();
2791
+	    }
2792
+	    if (isset($TI)) {
2793
+	    	$TI->checkAll();
2794
+	    }
2795
+	    if (isset($MI)) {
2796
+	    	$MI->checkAll();
2797
+	    }
1996 2798
 	}
1997 2799
     }
1998 2800
 }
Please login to merge, or discard this patch.
require/class.MarineImport.php 3 patches
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -9,25 +9,25 @@  discard block
 block discarded – undo
9 9
 require_once(dirname(__FILE__).'/class.Stats.php');
10 10
 require_once(dirname(__FILE__).'/class.Source.php');
11 11
 if (isset($globalServerAPRS) && $globalServerAPRS) {
12
-    require_once(dirname(__FILE__).'/class.APRS.php');
12
+	require_once(dirname(__FILE__).'/class.APRS.php');
13 13
 }
14 14
 
15 15
 class MarineImport {
16
-    private $all_tracked = array();
17
-    private $last_delete_hourly = 0;
18
-    private $last_delete = 0;
19
-    private $stats = array();
20
-    private $tmd = 0;
21
-    private $source_location = array();
22
-    public $db = null;
23
-    public $nb = 0;
16
+	private $all_tracked = array();
17
+	private $last_delete_hourly = 0;
18
+	private $last_delete = 0;
19
+	private $stats = array();
20
+	private $tmd = 0;
21
+	private $source_location = array();
22
+	public $db = null;
23
+	public $nb = 0;
24 24
 
25
-    public function __construct($dbc = null) {
25
+	public function __construct($dbc = null) {
26 26
 	global $globalBeta, $globalServerAPRS, $APRSMarine, $globalNoDB;
27 27
 	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
28
-	    $Connection = new Connection($dbc);
29
-	    $this->db = $Connection->db();
30
-	    date_default_timezone_set('UTC');
28
+		$Connection = new Connection($dbc);
29
+		$this->db = $Connection->db();
30
+		date_default_timezone_set('UTC');
31 31
 	}
32 32
 	// Get previous source stats
33 33
 	/*
@@ -46,57 +46,57 @@  discard block
 block discarded – undo
46 46
 	}
47 47
 	*/
48 48
 	if (isset($globalServerAPRS) && $globalServerAPRS) {
49
-	    $APRSMarine = new APRSMarine();
50
-	    //$APRSSpotter->connect();
49
+		$APRSMarine = new APRSMarine();
50
+		//$APRSSpotter->connect();
51
+	}
51 52
 	}
52
-    }
53 53
 
54
-    public function checkAll() {
54
+	public function checkAll() {
55 55
 	global $globalDebug, $globalNoDB;
56 56
 	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
57
-	    if ($globalDebug) echo "Update last seen tracked data...\n";
58
-	    foreach ($this->all_tracked as $key => $flight) {
57
+		if ($globalDebug) echo "Update last seen tracked data...\n";
58
+		foreach ($this->all_tracked as $key => $flight) {
59 59
 		if (isset($this->all_tracked[$key]['id'])) {
60
-		    //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
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']);
60
+			//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
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']);
63
+		}
63 64
 		}
64
-	    }
65 65
 	}
66
-    }
66
+	}
67 67
 
68
-    public function del() {
68
+	public function del() {
69 69
 	global $globalDebug, $globalNoDB, $globalNoImport;
70 70
 	// Delete old infos
71 71
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
72 72
 	foreach ($this->all_tracked as $key => $flight) {
73
-    	    if (isset($flight['lastupdate'])) {
74
-        	if ($flight['lastupdate'] < (time()-3000)) {
75
-            	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
76
-            		if (isset($this->all_tracked[$key]['id'])) {
77
-            		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
78
-			    /*
73
+			if (isset($flight['lastupdate'])) {
74
+			if ($flight['lastupdate'] < (time()-3000)) {
75
+					if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
76
+					if (isset($this->all_tracked[$key]['id'])) {
77
+						if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
78
+				/*
79 79
 			    $MarineLive = new MarineLive();
80 80
             		    $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
81 81
 			    $MarineLive->db = null;
82 82
 			    */
83
-            		    //$real_arrival = $this->arrival($key);
84
-            		    $Marine = new Marine($this->db);
85
-            		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
83
+						//$real_arrival = $this->arrival($key);
84
+						$Marine = new Marine($this->db);
85
+						if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
86 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
-			    }
89
-			    // Put in archive
88
+				}
89
+				// Put in archive
90 90
 //				$Marine->db = null;
91 91
 			}
92
-            	    }
93
-            	    unset($this->all_tracked[$key]);
94
-    	        }
95
-	    }
96
-        }
97
-    }
92
+					}
93
+					unset($this->all_tracked[$key]);
94
+				}
95
+		}
96
+		}
97
+	}
98 98
 
99
-    public function add($line) {
99
+	public function add($line) {
100 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');
@@ -105,104 +105,104 @@  discard block
 block discarded – undo
105 105
 	
106 106
 	// SBS format is CSV format
107 107
 	if(is_array($line) && (isset($line['mmsi']) || isset($line['id']))) {
108
-	    //print_r($line);
109
-  	    if (isset($line['mmsi']) || isset($line['id'])) {
108
+		//print_r($line);
109
+  		if (isset($line['mmsi']) || isset($line['id'])) {
110 110
 
111 111
 		
112 112
 		// Increment message number
113 113
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
114
-		    $current_date = date('Y-m-d');
115
-		    if (isset($line['source_name'])) $source = $line['source_name'];
116
-		    else $source = '';
117
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
118
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
119
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
120
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
121
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
114
+			$current_date = date('Y-m-d');
115
+			if (isset($line['source_name'])) $source = $line['source_name'];
116
+			else $source = '';
117
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
118
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
119
+				$this->stats[$current_date][$source]['msg']['date'] = time();
120
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
121
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
122 122
 		}
123 123
 		
124 124
 		
125 125
 		$Common = new Common();
126 126
 		$AIS = new AIS();
127
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
128
-	        else $id = trim($line['id']);
127
+			if (!isset($line['id'])) $id = trim($line['mmsi']);
128
+			else $id = trim($line['id']);
129 129
 		
130 130
 		if (!isset($this->all_tracked[$id])) {
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()));
135
-		    if (!isset($line['id'])) {
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()));
135
+			if (!isset($line['id'])) {
136 136
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
137 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
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
138
+			 } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
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']));
144
-		    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
143
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
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
-			    $this->all_tracked[$id]['ident'] = $identity['ship_name'];
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'])));
148
+				$this->all_tracked[$id]['ident'] = $identity['ship_name'];
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'])));
151 151
 			}
152 152
 			//print_r($identity);
153 153
 			unset($Marine);
154 154
 			//$dataFound = true;
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']));
170
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
169
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
170
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
171 171
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
172
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
172
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
173 173
 				$Marine = new Marine($this->db);
174 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 178
 			}
178
-		    }
179 179
 		}
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
-		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
192
+			if (!isset($this->all_tracked[$id]['arrival_code'])) {
193 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
-			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
196
+				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
197 197
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
198
-				    $Marine = new Marine($this->db);
199
-				    $fromsource = NULL;
200
-				    $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource);
201
-				    $Marine->db = null;
198
+					$Marine = new Marine($this->db);
199
+					$fromsource = NULL;
200
+					$Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource);
201
+					$Marine->db = null;
202
+				}
202 203
 				}
203
-			    }
204 204
 			}
205
-		    } elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) {
205
+			} elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) {
206 206
 			$this->all_tracked[$id]['arrival_code'] = $line['arrival_code'];
207 207
 			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
208 208
 			if (!isset($line['id'])) {
@@ -210,38 +210,38 @@  discard block
 block discarded – undo
210 210
 				$this->all_tracked[$id]['forcenew'] = 1;
211 211
 				$this->all_tracked[$id]['addedMarine'] = 0;
212 212
 			}
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'])) {
232 232
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
233
-		    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
233
+			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
234 234
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
235
-			    $timeelapsed = microtime(true);
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']);
238
-			    $Marine->db = null;
235
+				$timeelapsed = microtime(true);
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']);
238
+				$Marine->db = null;
239
+			}
239 240
 			}
240
-		    }
241
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
242
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
241
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
242
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
243 243
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
244
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
244
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
245 245
 				$timeelapsed = microtime(true);
246 246
 				$Marine = new Marine($this->db);
247 247
 				$fromsource = NULL;
@@ -249,20 +249,20 @@  discard block
 block discarded – undo
249 249
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
250 250
 				$Marine->db = null;
251 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 258
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
259
-		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
259
+			if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
260 260
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
261
-		    } else {
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 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 '';
@@ -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');
286
-		    if ($distance > 1000 && $distance < 10000) {
285
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
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 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
-	        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']);
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')))) {
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']);
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')))) {
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;
@@ -304,192 +304,192 @@  discard block
 block discarded – undo
304 304
 				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
305 305
 				$timeelapsed = microtime(true);
306 306
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
307
-				    $Marine = new Marine($this->db);
308
-				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
309
-				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
310
-				    $Marine->db = null;
311
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
307
+					$Marine = new Marine($this->db);
308
+					$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
309
+					if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
310
+					$Marine->db = null;
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";
315
-			    }
315
+				}
316 316
 			}
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 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
-				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
322
-				    $dataFound = true;
323
-				    $this->all_tracked[$id]['time_last_coord'] = time();
321
+					$this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
322
+					$dataFound = true;
323
+					$this->all_tracked[$id]['time_last_coord'] = time();
324 324
 				}
325 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
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
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 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
-				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
332
-				    $dataFound = true;
333
-				    $this->all_tracked[$id]['time_last_coord'] = time();
331
+					$this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
332
+					$dataFound = true;
333
+					$this->all_tracked[$id]['time_last_coord'] = time();
334 334
 				}
335 335
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
336 336
 			}
337 337
 
338
-		    } else if ($globalDebug && $timediff > 20) {
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 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 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
-		    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']));
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']));
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));
364
-		    //$dataFound = 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
+			//$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;
369
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
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
+  			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;
372 372
 
373 373
 
374 374
 
375 375
 		if ($dataFound === true && (isset($this->all_tracked[$id]['mmsi']) || isset($this->all_tracked[$id]['id']))) {
376
-		    $this->all_tracked[$id]['lastupdate'] = time();
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'])) {
379
-			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
376
+			$this->all_tracked[$id]['lastupdate'] = time();
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'])) {
379
+				if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
380 380
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
381
-				    if ($globalDebug) echo "Check if vessel is already in DB...";
382
-				    $timeelapsed = microtime(true);
383
-				    $MarineLive = new MarineLive($this->db);
384
-				    if (isset($line['id'])) {
381
+					if ($globalDebug) echo "Check if vessel is already in DB...";
382
+					$timeelapsed = microtime(true);
383
+					$MarineLive = new MarineLive($this->db);
384
+					if (isset($line['id'])) {
385 385
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
386 386
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
387
-				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
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 389
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
390
-				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
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 392
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
393
-				    } else $recent_ident = '';
394
-				    $MarineLive->db=null;
395
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
396
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
393
+					} else $recent_ident = '';
394
+					$MarineLive->db=null;
395
+					if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
396
+					elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
397 397
 				} else $recent_ident = '';
398
-			    } else {
398
+				} else {
399 399
 				$recent_ident = '';
400 400
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
401
-			    }
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'] != '')
404
-			    {
401
+				}
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'] != '')
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
-				    $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')));
409
-				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
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')));
409
+					if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
410 410
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
411
-					    $timeelapsed = microtime(true);
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']);
414
-					    $Marine->db = null;
415
-					    if ($globalDebug && isset($result)) echo $result."\n";
416
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
411
+						$timeelapsed = microtime(true);
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']);
414
+						$Marine->db = null;
415
+						if ($globalDebug && isset($result)) echo $result."\n";
416
+						if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
417
+					}
417 418
 					}
418
-				    }
419
-				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
419
+					if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
420 420
 					// Add source stat in DB
421 421
 					$Stats = new Stats($this->db);
422 422
 					if (!empty($this->stats)) {
423
-					    if ($globalDebug) echo 'Add source stats : ';
424
-				    	    foreach($this->stats as $date => $data) {
423
+						if ($globalDebug) echo 'Add source stats : ';
424
+							foreach($this->stats as $date => $data) {
425 425
 						foreach($data as $source => $sourced) {
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);
429
-				    		    if (isset($sourced['msg'])) {
430
-				    			if (time() - $sourced['msg']['date'] > 10) {
431
-				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
432
-				    		    	    echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
433
-			    			    	    unset($this->stats[$date][$source]['msg']);
434
-			    				}
435
-			    			    }
436
-			    			}
437
-			    			if ($date != date('Y-m-d')) {
438
-			    			    unset($this->stats[$date]);
439
-			    			}
440
-				    	    }
441
-				    	    if ($globalDebug) echo 'Done'."\n";
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);
429
+								if (isset($sourced['msg'])) {
430
+								if (time() - $sourced['msg']['date'] > 10) {
431
+										$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
432
+										echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
433
+										unset($this->stats[$date][$source]['msg']);
434
+								}
435
+								}
436
+							}
437
+							if ($date != date('Y-m-d')) {
438
+								unset($this->stats[$date]);
439
+							}
440
+							}
441
+							if ($globalDebug) echo 'Done'."\n";
442 442
 					}
443 443
 					$Stats->db = null;
444
-				    }
444
+					}
445 445
 				    
446
-				    $this->del();
446
+					$this->del();
447 447
 				//$ignoreImport = false;
448 448
 				$this->all_tracked[$id]['addedMarine'] = 1;
449 449
 				//print_r($this->all_tracked[$id]);
450 450
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
451
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
452
-				    //MarineLive->deleteLiveMarineDataNotUpdated();
453
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
451
+					if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
452
+					//MarineLive->deleteLiveMarineDataNotUpdated();
453
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
454 454
 					$MarineLive = new MarineLive($this->db);
455 455
 					$MarineLive->deleteLiveMarineData();
456 456
 					$MarineLive->db=null;
457 457
 					if ($globalDebug) echo " Done\n";
458
-				    }
459
-				    $this->last_delete = time();
458
+					}
459
+					$this->last_delete = time();
460 460
 				}
461
-			    } elseif ($recent_ident != '') {
461
+				} elseif ($recent_ident != '') {
462 462
 				$this->all_tracked[$id]['id'] = $recent_ident;
463 463
 				$this->all_tracked[$id]['addedMarine'] = 1;
464 464
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
465
-				    if (isset($globalDaemon) && !$globalDaemon) {
465
+					if (isset($globalDaemon) && !$globalDaemon) {
466 466
 					$Marine = new Marine($this->db);
467 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
 				}
471 471
 				
472
-			    }
472
+				}
473 473
 			}
474
-		    }
475
-		    //adds the spotter LIVE data
476
-		    if ($globalDebug) {
474
+			}
475
+			//adds the spotter LIVE data
476
+			if ($globalDebug) {
477 477
 			echo 'DATA : ident : '.$this->all_tracked[$id]['ident'].' - type : '.$this->all_tracked[$id]['type'].' - Latitude : '.$this->all_tracked[$id]['latitude'].' - Longitude : '.$this->all_tracked[$id]['longitude'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n";
478
-		    }
479
-		    $ignoreImport = false;
478
+			}
479
+			$ignoreImport = false;
480 480
 
481
-		    if (!$ignoreImport) {
481
+			if (!$ignoreImport) {
482 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
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
485
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
486 486
 					$timeelapsed = microtime(true);
487 487
 					$MarineLive = new MarineLive($this->db);
488 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 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 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']);
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
 					if ($stats_heading == 16) $stats_heading = 0;
525 525
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
526 526
 						for ($i=0;$i<=15;$i++) {
527
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
527
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
528 528
 						}
529 529
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
530 530
 					} else {
@@ -537,11 +537,11 @@  discard block
 block discarded – undo
537 537
 					//var_dump($this->stats);
538 538
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
539 539
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
540
-						    end($this->stats[$current_date][$source]['hist']);
541
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
540
+							end($this->stats[$current_date][$source]['hist']);
541
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
542 542
 						} else $mini = 0;
543 543
 						for ($i=$mini;$i<=$distance;$i+=10) {
544
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
544
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
545 545
 						}
546 546
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
547 547
 					} else {
@@ -557,24 +557,24 @@  discard block
 block discarded – undo
557 557
 			
558 558
 			
559 559
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
560
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
560
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
561 561
 				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
562 562
 				$MarineLive = new MarineLive($this->db);
563 563
 				$MarineLive->deleteLiveMarineDataNotUpdated();
564 564
 				$MarineLive->db = null;
565 565
 				//MarineLive->deleteLiveMarineData();
566 566
 				if ($globalDebug) echo " Done\n";
567
-			    }
568
-			    $this->last_delete_hourly = time();
567
+				}
568
+				$this->last_delete_hourly = time();
569 569
 			}
570 570
 			
571
-		    }
572
-		    //$ignoreImport = false;
571
+			}
572
+			//$ignoreImport = false;
573 573
 		}
574 574
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
575 575
 		if ($send) return $this->all_tracked[$id];
576
-	    }
576
+		}
577
+	}
577 578
 	}
578
-    }
579 579
 }
580 580
 ?>
Please login to merge, or discard this 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.
Braces   +202 added lines, -69 removed lines patch added patch discarded remove patch
@@ -54,7 +54,9 @@  discard block
 block discarded – undo
54 54
     public function checkAll() {
55 55
 	global $globalDebug, $globalNoDB;
56 56
 	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
57
-	    if ($globalDebug) echo "Update last seen tracked data...\n";
57
+	    if ($globalDebug) {
58
+	    	echo "Update last seen tracked data...\n";
59
+	    }
58 60
 	    foreach ($this->all_tracked as $key => $flight) {
59 61
 		if (isset($this->all_tracked[$key]['id'])) {
60 62
 		    //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
@@ -68,13 +70,17 @@  discard block
 block discarded – undo
68 70
     public function del() {
69 71
 	global $globalDebug, $globalNoDB, $globalNoImport;
70 72
 	// Delete old infos
71
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
73
+	if ($globalDebug) {
74
+		echo 'Delete old values and update latest data...'."\n";
75
+	}
72 76
 	foreach ($this->all_tracked as $key => $flight) {
73 77
     	    if (isset($flight['lastupdate'])) {
74 78
         	if ($flight['lastupdate'] < (time()-3000)) {
75 79
             	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
76 80
             		if (isset($this->all_tracked[$key]['id'])) {
77
-            		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
81
+            		    if ($globalDebug) {
82
+            		    	echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
83
+            		    }
78 84
 			    /*
79 85
 			    $MarineLive = new MarineLive();
80 86
             		    $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
@@ -84,7 +90,9 @@  discard block
 block discarded – undo
84 90
             		    $Marine = new Marine($this->db);
85 91
             		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
86 92
 				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
87
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
93
+				if ($globalDebug && $result != 'success') {
94
+					echo '!!! ERROR : '.$result."\n";
95
+				}
88 96
 			    }
89 97
 			    // Put in archive
90 98
 //				$Marine->db = null;
@@ -98,7 +106,9 @@  discard block
 block discarded – undo
98 106
 
99 107
     public function add($line) {
100 108
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine;
101
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
109
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
110
+		$globalCoordMinChange = '0.02';
111
+	}
102 112
 	date_default_timezone_set('UTC');
103 113
 	$dataFound = false;
104 114
 	$send = false;
@@ -112,20 +122,30 @@  discard block
 block discarded – undo
112 122
 		// Increment message number
113 123
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
114 124
 		    $current_date = date('Y-m-d');
115
-		    if (isset($line['source_name'])) $source = $line['source_name'];
116
-		    else $source = '';
117
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
125
+		    if (isset($line['source_name'])) {
126
+		    	$source = $line['source_name'];
127
+		    } else {
128
+		    	$source = '';
129
+		    }
130
+		    if ($source == '' || $line['format_source'] == 'aprs') {
131
+		    	$source = $line['format_source'];
132
+		    }
118 133
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
119 134
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
120 135
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
121
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
136
+		    } else {
137
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
138
+		    }
122 139
 		}
123 140
 		
124 141
 		
125 142
 		$Common = new Common();
126 143
 		$AIS = new AIS();
127
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
128
-	        else $id = trim($line['id']);
144
+	        if (!isset($line['id'])) {
145
+	        	$id = trim($line['mmsi']);
146
+	        } else {
147
+	        	$id = trim($line['id']);
148
+	        }
129 149
 		
130 150
 		if (!isset($this->all_tracked[$id])) {
131 151
 		    $this->all_tracked[$id] = array();
@@ -133,10 +153,16 @@  discard block
 block discarded – undo
133 153
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '','captain_id' => '','captain_name' => '','race_id' => '','race_name' => ''));
134 154
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
135 155
 		    if (!isset($line['id'])) {
136
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
156
+			if (!isset($globalDaemon)) {
157
+				$globalDaemon = TRUE;
158
+			}
137 159
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
138
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
139
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
160
+		     } else {
161
+		     	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
162
+		     }
163
+		    if ($globalAllTracked !== FALSE) {
164
+		    	$dataFound = true;
165
+		    }
140 166
 		}
141 167
 		
142 168
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
@@ -191,7 +217,9 @@  discard block
 block discarded – undo
191 217
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
192 218
 		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
193 219
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
194
-			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
220
+			if ($globalDebug) {
221
+				echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
222
+			}
195 223
 			if ($this->all_tracked[$id]['addedMarine'] != 0) {
196 224
 			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
197 225
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -204,7 +232,9 @@  discard block
 block discarded – undo
204 232
 			}
205 233
 		    } elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) {
206 234
 			$this->all_tracked[$id]['arrival_code'] = $line['arrival_code'];
207
-			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
235
+			if ($globalDebug) {
236
+				echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
237
+			}
208 238
 			if (!isset($line['id'])) {
209 239
 				$this->all_tracked[$id]['id'] = $id.'-'.date('YmdHi');
210 240
 				$this->all_tracked[$id]['forcenew'] = 1;
@@ -213,7 +243,9 @@  discard block
 block discarded – undo
213 243
 		    }
214 244
 		}
215 245
 		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']));
246
+		    if (strtotime($line['arrival_date']) > time()) {
247
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
248
+		    }
217 249
 		}
218 250
 		if (isset($line['captain_id']) && $line['captain_id'] != '') {
219 251
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_id' => $line['captain_id']));
@@ -246,34 +278,49 @@  discard block
 block discarded – undo
246 278
 				$Marine = new Marine($this->db);
247 279
 				$fromsource = NULL;
248 280
 				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
249
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
281
+				if ($globalDebug && $result != 'success') {
282
+					echo '!!! ERROR : '.$result."\n";
283
+				}
250 284
 				$Marine->db = null;
251
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
285
+				if ($globalDebugTimeElapsed) {
286
+					echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
287
+				}
252 288
 			    }
253 289
 			}
254 290
 		    }
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']));
291
+		    if (!isset($this->all_tracked[$id]['id'])) {
292
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
293
+		    }
256 294
 		}
257 295
 
258 296
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
259 297
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
260 298
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
261 299
 		    } else {
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
-				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";
300
+				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
301
+					echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
302
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
303
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
304
+				}
264 305
 				return '';
265 306
 		    }
266 307
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
267
-			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
308
+			if ($globalDebug) {
309
+				echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
310
+			}
268 311
 			return '';
269 312
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
270
-			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
313
+			if ($globalDebug) {
314
+				echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
315
+			}
271 316
 			return '';
272 317
 		} elseif (!isset($line['datetime'])) {
273 318
 			date_default_timezone_set('UTC');
274 319
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
275 320
 		} else {
276
-			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
321
+			if ($globalDebug) {
322
+				echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
323
+			}
277 324
 			return '';
278 325
 		}
279 326
 
@@ -286,14 +333,21 @@  discard block
 block discarded – undo
286 333
 		    if ($distance > 1000 && $distance < 10000) {
287 334
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
288 335
 			$speed = $speed*3.6;
289
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
290
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
336
+			if ($speed < 1000) {
337
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
338
+			}
339
+  			if ($globalDebug) {
340
+  				echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
341
+  			}
291 342
 		    }
292 343
 		}
293 344
 
294 345
 	        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']);
296
-	    	    else unset($timediff);
346
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) {
347
+	    	    	$timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
348
+	    	    } else {
349
+	    	    	unset($timediff);
350
+	    	    }
297 351
 	    	    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 352
 			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 353
 			    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'])) {
@@ -301,22 +355,32 @@  discard block
 block discarded – undo
301 355
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
302 356
 				$this->all_tracked[$id]['putinarchive'] = true;
303 357
 				
304
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
358
+				if ($globalDebug) {
359
+					echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
360
+				}
305 361
 				$timeelapsed = microtime(true);
306 362
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
307 363
 				    $Marine = new Marine($this->db);
308 364
 				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
309
-				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
365
+				    if (!empty($all_country)) {
366
+				    	$this->all_tracked[$id]['over_country'] = $all_country['iso2'];
367
+				    }
310 368
 				    $Marine->db = null;
311
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
369
+				    if ($globalDebugTimeElapsed) {
370
+				    	echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
371
+				    }
312 372
 				}
313 373
 				$this->tmd = 0;
314
-				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
374
+				if ($globalDebug) {
375
+					echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
376
+				}
315 377
 			    }
316 378
 			}
317 379
 
318 380
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
319
-				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
381
+				if (!isset($this->all_tracked[$id]['archive_latitude'])) {
382
+					$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
383
+				}
320 384
 				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 385
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
322 386
 				    $dataFound = true;
@@ -325,8 +389,12 @@  discard block
 block discarded – undo
325 389
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
326 390
 			}
327 391
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
328
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
329
-				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
392
+			    if ($line['longitude'] > 180) {
393
+			    	$line['longitude'] = $line['longitude'] - 360;
394
+			    }
395
+				if (!isset($this->all_tracked[$id]['archive_longitude'])) {
396
+					$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
397
+				}
330 398
 				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 399
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
332 400
 				    $dataFound = true;
@@ -344,7 +412,9 @@  discard block
 block discarded – undo
344 412
 		    }
345 413
 		}
346 414
 		if (isset($line['last_update']) && $line['last_update'] != '') {
347
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
415
+		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) {
416
+		    	$dataFound = true;
417
+		    }
348 418
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
349 419
 		}
350 420
 		if (isset($line['format_source']) && $line['format_source'] != '') {
@@ -358,15 +428,21 @@  discard block
 block discarded – undo
358 428
 		}
359 429
 		
360 430
 		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;
431
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) {
432
+		    	$this->all_tracked[$id]['putinarchive'] = true;
433
+		    }
362 434
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
363 435
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
364 436
 		    //$dataFound = true;
365 437
   		} 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 438
   		    $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 439
 		    $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
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
440
+		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) {
441
+		    	$this->all_tracked[$id]['putinarchive'] = true;
442
+		    }
443
+  		    if ($globalDebug) {
444
+  		    	echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
445
+  		    }
370 446
   		}
371 447
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
372 448
 
@@ -378,23 +454,38 @@  discard block
 block discarded – undo
378 454
 		        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 455
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
380 456
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
381
-				    if ($globalDebug) echo "Check if vessel is already in DB...";
457
+				    if ($globalDebug) {
458
+				    	echo "Check if vessel is already in DB...";
459
+				    }
382 460
 				    $timeelapsed = microtime(true);
383 461
 				    $MarineLive = new MarineLive($this->db);
384 462
 				    if (isset($line['id'])) {
385 463
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
386
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
464
+					if ($globalDebugTimeElapsed) {
465
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
466
+					}
387 467
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
388 468
 					$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";
469
+					if ($globalDebugTimeElapsed) {
470
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
471
+					}
390 472
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
391 473
 					$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";
393
-				    } else $recent_ident = '';
474
+					if ($globalDebugTimeElapsed) {
475
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
476
+					}
477
+				    } else {
478
+				    	$recent_ident = '';
479
+				    }
394 480
 				    $MarineLive->db=null;
395
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
396
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
397
-				} else $recent_ident = '';
481
+				    if ($globalDebug && $recent_ident == '') {
482
+				    	echo " Not in DB.\n";
483
+				    } elseif ($globalDebug && $recent_ident != '') {
484
+				    	echo " Already in DB.\n";
485
+				    }
486
+				} else {
487
+					$recent_ident = '';
488
+				}
398 489
 			    } else {
399 490
 				$recent_ident = '';
400 491
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
@@ -402,30 +493,44 @@  discard block
 block discarded – undo
402 493
 			    //if there was no vessel with the same callsign within the last hour and go post it into the archive
403 494
 			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
404 495
 			    {
405
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
496
+				if ($globalDebug) {
497
+					echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
498
+				}
406 499
 				//adds the spotter data for the archive
407 500
 				    $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')));
501
+				    if (!isset($this->all_tracked[$id]['id'])) {
502
+				    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
503
+				    }
409 504
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
410 505
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
411 506
 					    $timeelapsed = microtime(true);
412 507
 					    $Marine = new Marine($this->db);
413 508
 					    $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 509
 					    $Marine->db = null;
415
-					    if ($globalDebug && isset($result)) echo $result."\n";
416
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
510
+					    if ($globalDebug && isset($result)) {
511
+					    	echo $result."\n";
512
+					    }
513
+					    if ($globalDebugTimeElapsed) {
514
+					    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
515
+					    }
417 516
 					}
418 517
 				    }
419 518
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
420 519
 					// Add source stat in DB
421 520
 					$Stats = new Stats($this->db);
422 521
 					if (!empty($this->stats)) {
423
-					    if ($globalDebug) echo 'Add source stats : ';
522
+					    if ($globalDebug) {
523
+					    	echo 'Add source stats : ';
524
+					    }
424 525
 				    	    foreach($this->stats as $date => $data) {
425 526
 						foreach($data as $source => $sourced) {
426 527
 					    	    //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);
528
+				    	    	    if (isset($sourced['polar'])) {
529
+				    	    	    	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
530
+				    	    	    }
531
+				    	    	    if (isset($sourced['hist'])) {
532
+				    	    	    	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
533
+				    	    	    }
429 534
 				    		    if (isset($sourced['msg'])) {
430 535
 				    			if (time() - $sourced['msg']['date'] > 10) {
431 536
 				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -438,7 +543,9 @@  discard block
 block discarded – undo
438 543
 			    			    unset($this->stats[$date]);
439 544
 			    			}
440 545
 				    	    }
441
-				    	    if ($globalDebug) echo 'Done'."\n";
546
+				    	    if ($globalDebug) {
547
+				    	    	echo 'Done'."\n";
548
+				    	    }
442 549
 					}
443 550
 					$Stats->db = null;
444 551
 				    }
@@ -448,13 +555,17 @@  discard block
 block discarded – undo
448 555
 				$this->all_tracked[$id]['addedMarine'] = 1;
449 556
 				//print_r($this->all_tracked[$id]);
450 557
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
451
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
558
+				    if ($globalDebug) {
559
+				    	echo "---- Deleting Live Marine data older than 9 hours...";
560
+				    }
452 561
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
453 562
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
454 563
 					$MarineLive = new MarineLive($this->db);
455 564
 					$MarineLive->deleteLiveMarineData();
456 565
 					$MarineLive->db=null;
457
-					if ($globalDebug) echo " Done\n";
566
+					if ($globalDebug) {
567
+						echo " Done\n";
568
+					}
458 569
 				    }
459 570
 				    $this->last_delete = time();
460 571
 				}
@@ -480,15 +591,21 @@  discard block
 block discarded – undo
480 591
 
481 592
 		    if (!$ignoreImport) {
482 593
 			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
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
594
+				if ($globalDebug) {
595
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
596
+				}
484 597
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
485 598
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
486 599
 					$timeelapsed = microtime(true);
487 600
 					$MarineLive = new MarineLive($this->db);
488 601
 					$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 602
 					$MarineLive->db = null;
490
-					if ($globalDebug) echo $result."\n";
491
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
603
+					if ($globalDebug) {
604
+						echo $result."\n";
605
+					}
606
+					if ($globalDebugTimeElapsed) {
607
+						echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
608
+					}
492 609
 				    }
493 610
 				}
494 611
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
@@ -500,7 +617,9 @@  discard block
 block discarded – undo
500 617
 				
501 618
 				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
502 619
 					$source = $this->all_tracked[$id]['source_name'];
503
-					if ($source == '') $source = $this->all_tracked[$id]['format_source'];
620
+					if ($source == '') {
621
+						$source = $this->all_tracked[$id]['format_source'];
622
+					}
504 623
 					if (!isset($this->source_location[$source])) {
505 624
 						$Location = new Source($this->db);
506 625
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -521,7 +640,9 @@  discard block
 block discarded – undo
521 640
 					$stats_heading = round($stats_heading/22.5);
522 641
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
523 642
 					$current_date = date('Y-m-d');
524
-					if ($stats_heading == 16) $stats_heading = 0;
643
+					if ($stats_heading == 16) {
644
+						$stats_heading = 0;
645
+					}
525 646
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
526 647
 						for ($i=0;$i<=15;$i++) {
527 648
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -539,7 +660,9 @@  discard block
 block discarded – undo
539 660
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
540 661
 						    end($this->stats[$current_date][$source]['hist']);
541 662
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
542
-						} else $mini = 0;
663
+						} else {
664
+							$mini = 0;
665
+						}
543 666
 						for ($i=$mini;$i<=$distance;$i+=10) {
544 667
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
545 668
 						}
@@ -551,19 +674,27 @@  discard block
 block discarded – undo
551 674
 				
552 675
 
553 676
 				$this->all_tracked[$id]['lastupdate'] = time();
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";
677
+				if ($this->all_tracked[$id]['putinarchive']) {
678
+					$send = true;
679
+				}
680
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
681
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
682
+			}
556 683
 			//$this->del();
557 684
 			
558 685
 			
559 686
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
560 687
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
561
-				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
688
+				if ($globalDebug) {
689
+					echo "---- Deleting Live Marine data Not updated since 2 hour...";
690
+				}
562 691
 				$MarineLive = new MarineLive($this->db);
563 692
 				$MarineLive->deleteLiveMarineDataNotUpdated();
564 693
 				$MarineLive->db = null;
565 694
 				//MarineLive->deleteLiveMarineData();
566
-				if ($globalDebug) echo " Done\n";
695
+				if ($globalDebug) {
696
+					echo " Done\n";
697
+				}
567 698
 			    }
568 699
 			    $this->last_delete_hourly = time();
569 700
 			}
@@ -572,7 +703,9 @@  discard block
 block discarded – undo
572 703
 		    //$ignoreImport = false;
573 704
 		}
574 705
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
575
-		if ($send) return $this->all_tracked[$id];
706
+		if ($send) {
707
+			return $this->all_tracked[$id];
708
+		}
576 709
 	    }
577 710
 	}
578 711
     }
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.