Completed
Push — master ( 56221e...3c95ac )
by Yannick
07:57
created
require/class.APRS.php 2 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -88,6 +88,10 @@  discard block
 block discarded – undo
88 88
 	'y' => 'Yagi At QTH');
89 89
 	
90 90
 
91
+    /**
92
+     * @param integer $n
93
+     * @param integer $s
94
+     */
91 95
     private function urshift($n, $s) {
92 96
 	return ($n >= 0) ? ($n >> $s) :
93 97
 	    (($n & 0x7fffffff) >> $s) | 
@@ -442,6 +446,9 @@  discard block
 block discarded – undo
442 446
 	}
443 447
     }
444 448
     
449
+    /**
450
+     * @param string $data
451
+     */
445 452
     function send($data) {
446 453
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
447 454
 	if ($send === FALSE) $this->connect();
Please login to merge, or discard this patch.
Braces   +146 added lines, -56 removed lines patch added patch discarded remove patch
@@ -106,26 +106,36 @@  discard block
 block discarded – undo
106 106
 	
107 107
 	/* Check that end was found and body has at least one byte. */
108 108
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
109
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
109
+	    if ($globalDebug) {
110
+	    	echo '!!! APRS invalid : '.$input."\n";
111
+	    }
110 112
 	    return false;
111 113
 	}
112 114
 	
113
-	if ($debug) echo 'input : '.$input."\n";
115
+	if ($debug) {
116
+		echo 'input : '.$input."\n";
117
+	}
114 118
 	/* Save header and body. */
115 119
 	$body = substr($input,$splitpos+1,$input_len);
116 120
 	$body_len = strlen($body);
117 121
 	$header = substr($input,0,$splitpos);
118 122
 	//$header_len = strlen($header);
119
-	if ($debug) echo 'header : '.$header."\n";
123
+	if ($debug) {
124
+		echo 'header : '.$header."\n";
125
+	}
120 126
 	
121 127
 	/* Parse source, target and path. */
122 128
 	//FLRDF0A52>APRS,qAS,LSTB
123 129
 	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
124 130
 	    $ident = $matches[1];
125 131
 	    $all_elements = $matches[2];
126
-	    if ($debug) echo 'ident : '.$ident."\n";
132
+	    if ($debug) {
133
+	    	echo 'ident : '.$ident."\n";
134
+	    }
127 135
 	    $result['ident'] = $ident;
128
-	} else return false;
136
+	} else {
137
+		return false;
138
+	}
129 139
 	$elements = explode(',',$all_elements);
130 140
 	$source = end($elements);
131 141
 	$result['source'] = $source;
@@ -134,7 +144,9 @@  discard block
 block discarded – undo
134 144
 	        //echo "ok";
135 145
 	        //if ($element == 'TCPIP*') return false;
136 146
 	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
137
-		if ($debug) echo 'element : '.$element."\n";
147
+		if ($debug) {
148
+			echo 'element : '.$element."\n";
149
+		}
138 150
 		return false;
139 151
 	    }
140 152
 	    /*
@@ -147,7 +159,9 @@  discard block
 block discarded – undo
147 159
 	}
148 160
 	
149 161
 	$type = substr($body,0,1);
150
-	if ($debug) echo 'type : '.$type."\n";
162
+	if ($debug) {
163
+		echo 'type : '.$type."\n";
164
+	}
151 165
 	if ($type == ';') {
152 166
 		$result['ident'] = trim(substr($body,1,9));
153 167
 	} elseif ($type == ',') {
@@ -217,7 +231,9 @@  discard block
 block discarded – undo
217 231
 		//$symbol_table = $matches[4];
218 232
 		$lat = intval($lat_deg);
219 233
 		$lon = intval($lon_deg);
220
-		if ($lat > 89 || $lon > 179) return false;
234
+		if ($lat > 89 || $lon > 179) {
235
+			return false;
236
+		}
221 237
 	    
222 238
 	    /*
223 239
 	    $tmp_5b = str_replace('.','',$lat_min);
@@ -227,8 +243,12 @@  discard block
 block discarded – undo
227 243
 	    */
228 244
 		$latitude = $lat + floatval($lat_min)/60;
229 245
 		$longitude = $lon + floatval($lon_min)/60;
230
-		if ($sind == 'S') $latitude = 0-$latitude;
231
-		if ($wind == 'W') $longitude = 0-$longitude;
246
+		if ($sind == 'S') {
247
+			$latitude = 0-$latitude;
248
+		}
249
+		if ($wind == 'W') {
250
+			$longitude = 0-$longitude;
251
+		}
232 252
 		$result['latitude'] = $latitude;
233 253
 		$result['longitude'] = $longitude;
234 254
 		$body_parse = substr($body_parse,18);
@@ -261,7 +281,9 @@  discard block
 block discarded – undo
261 281
 			$body_parse = substr($body_parse,1);
262 282
 			$body_parse_len = strlen($body_parse);
263 283
 			$result['symbol_code'] = $symbol_code;
264
-			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
284
+			if (isset($this->symbols[$symbol_code])) {
285
+				$result['symbol'] = $this->symbols[$symbol_code];
286
+			}
265 287
 			if ($symbol_code != '_') {
266 288
 			}
267 289
 		    //$body_parse = substr($body_parse,1);
@@ -272,7 +294,9 @@  discard block
 block discarded – undo
272 294
 		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
273 295
 		    	    $course = substr($body_parse,0,3);
274 296
 		    	    $tmp_s = intval($course);
275
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
297
+		    	    if ($tmp_s >= 1 && $tmp_s <= 360) {
298
+		    	    	$result['heading'] = intval($course);
299
+		    	    }
276 300
 		    	    $speed = substr($body_parse,4,3);
277 301
 		    	    if ($speed != '...') {
278 302
 		    		    $result['speed'] = round($speed*1.852);
@@ -310,10 +334,16 @@  discard block
 block discarded – undo
310 334
 			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
311 335
 			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
312 336
 			    
313
-				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
314
-				else $result['latitude'] += $lat_off;
315
-				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
316
-				else $result['longitude'] += $lon_off;
337
+				if ($result['latitude'] < 0) {
338
+					$result['latitude'] -= $lat_off;
339
+				} else {
340
+					$result['latitude'] += $lat_off;
341
+				}
342
+				if ($result['longitude'] < 0) {
343
+					$result['longitude'] -= $lon_off;
344
+				} else {
345
+					$result['longitude'] += $lon_off;
346
+				}
317 347
 			    }
318 348
 		            $body_parse = substr($body_parse,6);
319 349
 		    }
@@ -336,27 +366,48 @@  discard block
 block discarded – undo
336 366
 			$address = substr($id,2);
337 367
 			//print_r($matches);
338 368
 			$addressType = (intval(substr($id,0,2),16))&3;
339
-			if ($addressType == 0) $result['addresstype'] = "RANDOM";
340
-			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
341
-			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
342
-			elseif ($addressType == 3) $result['addresstype'] = "OGN";
369
+			if ($addressType == 0) {
370
+				$result['addresstype'] = "RANDOM";
371
+			} elseif ($addressType == 1) {
372
+				$result['addresstype'] = "ICAO";
373
+			} elseif ($addressType == 2) {
374
+				$result['addresstype'] = "FLARM";
375
+			} elseif ($addressType == 3) {
376
+				$result['addresstype'] = "OGN";
377
+			}
343 378
 			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
344 379
 			$result['aircrafttype_code'] = $aircraftType;
345
-			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
346
-			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
347
-			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
348
-			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
349
-			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
350
-			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
351
-			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
352
-			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
353
-			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
354
-			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
355
-			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
356
-			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
357
-			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
358
-			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
359
-			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
380
+			if ($aircraftType == 0) {
381
+				$result['aircrafttype'] = "UNKNOWN";
382
+			} elseif ($aircraftType == 1) {
383
+				$result['aircrafttype'] = "GLIDER";
384
+			} elseif ($aircraftType == 2) {
385
+				$result['aircrafttype'] = "TOW_PLANE";
386
+			} elseif ($aircraftType == 3) {
387
+				$result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
388
+			} elseif ($aircraftType == 4) {
389
+				$result['aircrafttype'] = "PARACHUTE";
390
+			} elseif ($aircraftType == 5) {
391
+				$result['aircrafttype'] = "DROP_PLANE";
392
+			} elseif ($aircraftType == 6) {
393
+				$result['aircrafttype'] = "HANG_GLIDER";
394
+			} elseif ($aircraftType == 7) {
395
+				$result['aircrafttype'] = "PARA_GLIDER";
396
+			} elseif ($aircraftType == 8) {
397
+				$result['aircrafttype'] = "POWERED_AIRCRAFT";
398
+			} elseif ($aircraftType == 9) {
399
+				$result['aircrafttype'] = "JET_AIRCRAFT";
400
+			} elseif ($aircraftType == 10) {
401
+				$result['aircrafttype'] = "UFO";
402
+			} elseif ($aircraftType == 11) {
403
+				$result['aircrafttype'] = "BALLOON";
404
+			} elseif ($aircraftType == 12) {
405
+				$result['aircrafttype'] = "AIRSHIP";
406
+			} elseif ($aircraftType == 13) {
407
+				$result['aircrafttype'] = "UAV";
408
+			} elseif ($aircraftType == 15) {
409
+				$result['aircrafttype'] = "STATIC_OBJECT";
410
+			}
360 411
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
361 412
 			$result['stealth'] = $stealth;
362 413
 			$result['address'] = $address;
@@ -396,13 +447,21 @@  discard block
 block discarded – undo
396 447
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
397 448
 		    }
398 449
 		}
399
-		} else $result['comment'] = trim($body_parse);
450
+		} else {
451
+			$result['comment'] = trim($body_parse);
452
+		}
400 453
 
401 454
 	    }
402 455
 	//}
403
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
404
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
405
-	if ($debug) print_r($result);
456
+	if (isset($result['latitude'])) {
457
+		$result['latitude'] = round($result['latitude'],4);
458
+	}
459
+	if (isset($result['longitude'])) {
460
+		$result['longitude'] = round($result['longitude'],4);
461
+	}
462
+	if ($debug) {
463
+		print_r($result);
464
+	}
406 465
 	return $result;
407 466
     }
408 467
     
@@ -411,12 +470,21 @@  discard block
 block discarded – undo
411 470
 	$aprs_connect = 0;
412 471
 	$aprs_keep = 120;
413 472
 	$aprs_last_tx = time();
414
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
415
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
416
-	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
417
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
418
-	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
419
-	else $aprs_pass = '-1';
473
+	if (isset($globalAPRSversion)) {
474
+		$aprs_version = $globalAPRSversion;
475
+	} else {
476
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
477
+	}
478
+	if (isset($globalServerAPRSssid)) {
479
+		$aprs_ssid = $globalServerAPRSssid;
480
+	} else {
481
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
482
+	}
483
+	if (isset($globalServerAPRSpass)) {
484
+		$aprs_pass = $globalServerAPRSpass;
485
+	} else {
486
+		$aprs_pass = '-1';
487
+	}
420 488
 	
421 489
 	$aprs_filter  = '';
422 490
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
@@ -444,7 +512,9 @@  discard block
 block discarded – undo
444 512
     
445 513
     function send($data) {
446 514
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
447
-	if ($send === FALSE) $this->connect();
515
+	if ($send === FALSE) {
516
+		$this->connect();
517
+	}
448 518
     }
449 519
 }
450 520
 
@@ -461,18 +531,26 @@  discard block
 block discarded – undo
461 531
 		//$w = '00';
462 532
 		$custom = '';
463 533
 		if ($ident != '') {
464
-			if ($custom != '') $custom .= '/';
534
+			if ($custom != '') {
535
+				$custom .= '/';
536
+			}
465 537
 			$custom .= 'CS='.$ident;
466 538
 		}
467 539
 		if ($squawk != '') {
468
-			if ($custom != '') $custom .= '/';
540
+			if ($custom != '') {
541
+				$custom .= '/';
542
+			}
469 543
 			$custom .= 'SQ='.$squawk;
470 544
 		}
471 545
 		if ($aircraft_icao != '' && $aircraft_icao != 'NA') {
472
-			if ($custom != '') $custom .= '/';
546
+			if ($custom != '') {
547
+				$custom .= '/';
548
+			}
473 549
 			$custom .= 'AI='.$aircraft_icao;
474 550
 		}
475
-		if ($custom != '') $custom = ' '.$custom;
551
+		if ($custom != '') {
552
+			$custom = ' '.$custom;
553
+		}
476 554
 			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
477 555
 		}
478 556
 	}
@@ -490,26 +568,38 @@  discard block
 block discarded – undo
490 568
 		//$w = '00';
491 569
 		$custom = '';
492 570
 		if ($ident != '') {
493
-			if ($custom != '') $custom .= '/';
571
+			if ($custom != '') {
572
+				$custom .= '/';
573
+			}
494 574
 			$custom .= 'CS='.$ident;
495 575
 		}
496 576
 		if ($typeid != '') {
497
-			if ($custom != '') $custom .= '/';
577
+			if ($custom != '') {
578
+				$custom .= '/';
579
+			}
498 580
 			$custom .= 'TI='.$typeid;
499 581
 		}
500 582
 		if ($imo != '') {
501
-			if ($custom != '') $custom .= '/';
583
+			if ($custom != '') {
584
+				$custom .= '/';
585
+			}
502 586
 			$custom .= 'IMO='.$imo;
503 587
 		}
504 588
 		if ($arrival_date != '') {
505
-			if ($custom != '') $custom .= '/';
589
+			if ($custom != '') {
590
+				$custom .= '/';
591
+			}
506 592
 			$custom .= 'AD='.$arrival_date;
507 593
 		}
508 594
 		if ($arrival_code != '') {
509
-			if ($custom != '') $custom .= '/';
595
+			if ($custom != '') {
596
+				$custom .= '/';
597
+			}
510 598
 			$custom .= 'AC='.$arrival_code;
511 599
 		}
512
-		if ($custom != '') $custom = ' '.$custom;
600
+		if ($custom != '') {
601
+			$custom = ' '.$custom;
602
+		}
513 603
 		$altitude = 0;
514 604
 			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
515 605
 		}
Please login to merge, or discard this patch.
require/class.Common.php 2 patches
Doc Comments   +12 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,6 +90,10 @@  discard block
 block discarded – undo
90 90
 		return strlen($headerLine); // Needed by curl
91 91
 	}
92 92
 
93
+	/**
94
+	 * @param string $url
95
+	 * @param string $file
96
+	 */
93 97
 	public static function download($url, $file, $referer = '') {
94 98
 		global $globalDebug;
95 99
 		$fp = fopen($file, 'w');
@@ -190,7 +194,7 @@  discard block
 block discarded – undo
190 194
 	* Check is distance realistic
191 195
 	* @param int $timeDifference the time between the reception of both messages
192 196
 	* @param float $distance distance covered
193
-	* @return whether distance is realistic
197
+	* @return boolean distance is realistic
194 198
 	*/
195 199
 	public function withinThreshold ($timeDifference, $distance) {
196 200
 		$x = abs($timeDifference);
@@ -213,6 +217,9 @@  discard block
 block discarded – undo
213 217
 	}
214 218
 
215 219
 
220
+	/**
221
+	 * @param string $latlong
222
+	 */
216 223
 	public function convertDec($dms,$latlong) {
217 224
 		if ($latlong == 'latitude') {
218 225
 			$deg = substr($dms, 0, 2);
@@ -224,6 +231,9 @@  discard block
 block discarded – undo
224 231
 		return $deg+(($min*60)/3600);
225 232
 	}
226 233
 	
234
+	/**
235
+	 * @param string $latlong
236
+	 */
227 237
 	public function convertDM($coord,$latlong) {
228 238
 		if ($latlong == 'latitude') {
229 239
 			if ($coord < 0) $NSEW = 'S';
@@ -352,7 +362,7 @@  discard block
 block discarded – undo
352 362
 	/**
353 363
 	* Returns list of available locales
354 364
 	*
355
-	* @return array
365
+	* @return string[]
356 366
 	 */
357 367
 	public function listLocaleDir()
358 368
 	{
Please login to merge, or discard this patch.
Braces   +73 added lines, -30 removed lines patch added patch discarded remove patch
@@ -37,8 +37,11 @@  discard block
 block discarded – undo
37 37
 		} else {
38 38
 			curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
39 39
 		}
40
-		if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
41
-		else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 
40
+		if ($timeout == '') {
41
+			curl_setopt($ch, CURLOPT_TIMEOUT, 10);
42
+		} else {
43
+			curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
44
+		}
42 45
 		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback"));
43 46
 		if ($type == 'post') {
44 47
 			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
@@ -85,8 +88,9 @@  discard block
 block discarded – undo
85 88
 	private function curlResponseHeaderCallback($ch, $headerLine) {
86 89
 		//global $cookies;
87 90
 		$cookies = array();
88
-		if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1)
89
-			$cookies[] = $cookie;
91
+		if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1) {
92
+					$cookies[] = $cookie;
93
+		}
90 94
 		return strlen($headerLine); // Needed by curl
91 95
 	}
92 96
 
@@ -97,11 +101,15 @@  discard block
 block discarded – undo
97 101
 		curl_setopt($ch, CURLOPT_URL, $url);
98 102
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
99 103
 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
100
-		if ($referer != '') curl_setopt($ch, CURLOPT_REFERER, $referer);
104
+		if ($referer != '') {
105
+			curl_setopt($ch, CURLOPT_REFERER, $referer);
106
+		}
101 107
 		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');
102 108
 		curl_setopt($ch, CURLOPT_FILE, $fp);
103 109
 		curl_exec($ch);
104
-		if (curl_errno($ch) && $globalDebug) echo 'Download error: '.curl_error($ch);
110
+		if (curl_errno($ch) && $globalDebug) {
111
+			echo 'Download error: '.curl_error($ch);
112
+		}
105 113
 		curl_close($ch);
106 114
 		fclose($fp);
107 115
 	}
@@ -112,10 +120,16 @@  discard block
 block discarded – undo
112 120
 	* @return Array array of the tables in HTML page
113 121
 	*/
114 122
 	public function table2array($data) {
115
-		if (!is_string($data)) return array();
116
-		if ($data == '') return array();
123
+		if (!is_string($data)) {
124
+			return array();
125
+		}
126
+		if ($data == '') {
127
+			return array();
128
+		}
117 129
 		$html = str_get_html($data);
118
-		if ($html === false) return array();
130
+		if ($html === false) {
131
+			return array();
132
+		}
119 133
 		$tabledata=array();
120 134
 		foreach($html->find('tr') as $element)
121 135
 		{
@@ -150,7 +164,9 @@  discard block
 block discarded – undo
150 164
 	*/
151 165
 	public function text2array($data) {
152 166
 		$html = str_get_html($data);
153
-		if ($html === false) return array();
167
+		if ($html === false) {
168
+			return array();
169
+		}
154 170
 		$tabledata=array();
155 171
 		foreach($html->find('p') as $element)
156 172
 		{
@@ -171,7 +187,9 @@  discard block
 block discarded – undo
171 187
 	* @return Float Distance in $unit
172 188
 	*/
173 189
 	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
174
-		if ($lat == $latc && $lon == $lonc) return 0;
190
+		if ($lat == $latc && $lon == $lonc) {
191
+			return 0;
192
+		}
175 193
 		$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;
176 194
 		if ($unit == "km") {
177 195
 			return round($dist * 1.609344);
@@ -195,10 +213,16 @@  discard block
 block discarded – undo
195 213
 	public function withinThreshold ($timeDifference, $distance) {
196 214
 		$x = abs($timeDifference);
197 215
 		$d = abs($distance);
198
-		if ($x == 0 || $d == 0) return true;
216
+		if ($x == 0 || $d == 0) {
217
+			return true;
218
+		}
199 219
 		// may be due to Internet jitter; distance is realistic
200
-		if ($x < 0.7 && $d < 2000) return true;
201
-		else return $d/$x < 1500*0.27778; // 1500 km/h max
220
+		if ($x < 0.7 && $d < 2000) {
221
+			return true;
222
+		} else {
223
+			return $d/$x < 1500*0.27778;
224
+		}
225
+		// 1500 km/h max
202 226
 	}
203 227
 
204 228
 
@@ -226,11 +250,17 @@  discard block
 block discarded – undo
226 250
 	
227 251
 	public function convertDM($coord,$latlong) {
228 252
 		if ($latlong == 'latitude') {
229
-			if ($coord < 0) $NSEW = 'S';
230
-			else $NSEW = 'N';
253
+			if ($coord < 0) {
254
+				$NSEW = 'S';
255
+			} else {
256
+				$NSEW = 'N';
257
+			}
231 258
 		} elseif ($latlong == 'longitude') {
232
-			if ($coord < 0) $NSEW = 'W';
233
-			else $NSEW = 'E';
259
+			if ($coord < 0) {
260
+				$NSEW = 'W';
261
+			} else {
262
+				$NSEW = 'E';
263
+			}
234 264
 		}
235 265
 		$coord = abs($coord);
236 266
 		$deg = floor($coord);
@@ -273,7 +303,9 @@  discard block
 block discarded – undo
273 303
 	public function hex2str($hex) {
274 304
 		$str = '';
275 305
 		$hexln = strlen($hex);
276
-		for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
306
+		for($i=0;$i<$hexln;$i+=2) {
307
+			$str .= chr(hexdec(substr($hex,$i,2)));
308
+		}
277 309
 		return $str;
278 310
 	}
279 311
 	
@@ -301,8 +333,11 @@  discard block
 block discarded – undo
301 333
 		$b = $lat2 - $lat1;
302 334
 		$c = -($a*$lat1+$b*$lon1);
303 335
 		$d = $a*$lat3+$b*$lon3+$c;
304
-		if ($d > -$approx && $d < $approx) return true;
305
-		else return false;
336
+		if ($d > -$approx && $d < $approx) {
337
+			return true;
338
+		} else {
339
+			return false;
340
+		}
306 341
 	}
307 342
 	
308 343
 	public function array_merge_noappend() {
@@ -361,7 +396,9 @@  discard block
 block discarded – undo
361 396
 			return $result;
362 397
 		}
363 398
 		$handle = @opendir('./locale');
364
-		if ($handle === false) return $result;
399
+		if ($handle === false) {
400
+			return $result;
401
+		}
365 402
 		while (false !== ($file = readdir($handle))) {
366 403
 			$path = './locale'.'/'.$file.'/LC_MESSAGES/fam.mo';
367 404
 			if ($file != "." && $file != ".." && @file_exists($path)) {
@@ -428,8 +465,9 @@  discard block
 block discarded – undo
428 465
 		$error = false; 
429 466
 		if ($fp_out = gzopen($dest, $mode)) { 
430 467
 			if ($fp_in = fopen($source,'rb')) { 
431
-				while (!feof($fp_in)) 
432
-					gzwrite($fp_out, fread($fp_in, 1024 * 512)); 
468
+				while (!feof($fp_in)) {
469
+									gzwrite($fp_out, fread($fp_in, 1024 * 512));
470
+				}
433 471
 				fclose($fp_in); 
434 472
 			} else {
435 473
 				$error = true; 
@@ -438,14 +476,17 @@  discard block
 block discarded – undo
438 476
 		} else {
439 477
 			$error = true; 
440 478
 		}
441
-		if ($error)
442
-			return false; 
443
-		else
444
-			return $dest; 
479
+		if ($error) {
480
+					return false;
481
+		} else {
482
+					return $dest;
483
+		}
445 484
 	} 
446 485
 	
447 486
 	public function remove_accents($string) {
448
-		if ( !preg_match('/[\x80-\xff]/', $string) ) return $string;
487
+		if ( !preg_match('/[\x80-\xff]/', $string) ) {
488
+			return $string;
489
+		}
449 490
 		$chars = array(
450 491
 		    // Decompositions for Latin-1 Supplement
451 492
 		    chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
@@ -569,7 +610,9 @@  discard block
 block discarded – undo
569 610
 		$ip = gethostbyname($host);
570 611
 		$s = socket_create(AF_INET, SOCK_STREAM, 0);
571 612
 		$r = @socket_connect($s, $ip, $port);
572
-		if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
613
+		if (!socket_set_nonblock($s)) {
614
+			echo "Unable to set nonblock on socket\n";
615
+		}
573 616
 		if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
574 617
 			return $s;
575 618
 		}
Please login to merge, or discard this patch.
require/class.Marine.php 1 patch
Doc Comments   +2 added lines, -21 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
 	
21 21
 	public function getFilter($filter = array(),$where = false,$and = false) {
@@ -552,25 +552,6 @@  discard block
 block discarded – undo
552 552
 	*
553 553
 	* @param String $fammarine_id the ID
554 554
 	* @param String $ident the marine ident
555
-	* @param String $departure_airport_icao the departure airport
556
-	* @param String $arrival_airport_icao the arrival airport
557
-	* @param String $latitude latitude of flight
558
-	* @param String $longitude latitude of flight
559
-	* @param String $waypoints waypoints of flight
560
-	* @param String $heading heading of flight
561
-	* @param String $groundspeed speed of flight
562
-	* @param String $date date of flight
563
-	* @param String $departure_airport_time departure time of flight
564
-	* @param String $arrival_airport_time arrival time of flight
565
-	* @param String $squawk squawk code of flight
566
-	* @param String $route_stop route stop of flight
567
-	* @param String $highlight highlight or not
568
-	* @param String $ModeS ModesS code of flight
569
-	* @param String $registration registration code of flight
570
-	* @param String $pilot_id pilot id of flight (for virtual airlines)
571
-	* @param String $pilot_name pilot name of flight (for virtual airlines)
572
-	* @param String $verticalrate vertival rate of flight
573
-	* @return String success or false
574 555
 	*/
575 556
 	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '',$type = '',$typeid = '',$imo = '',$callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$format_source = '', $source_name = '')
576 557
 	{
@@ -1444,7 +1425,7 @@  discard block
 block discarded – undo
1444 1425
 	/**
1445 1426
 	* Parses the direction degrees to working
1446 1427
 	*
1447
-	* @param Float $direction the direction in degrees
1428
+	* @param integer $direction the direction in degrees
1448 1429
 	* @return Array the direction information
1449 1430
 	*
1450 1431
 	*/
Please login to merge, or discard this patch.
require/class.MarineLive.php 1 patch
Doc Comments   +1 added lines, -5 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
 	public function getFilter($filter = array(),$where = false,$and = false) {
20 20
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
@@ -762,10 +762,6 @@  discard block
 block discarded – undo
762 762
 	*
763 763
 	* @param String $fammarine_id the ID from flightaware
764 764
 	* @param String $ident the flight ident
765
-	* @param String $aircraft_icao the aircraft type
766
-	* @param String $departure_airport_icao the departure airport
767
-	* @param String $arrival_airport_icao the arrival airport
768
-	* @return String success or false
769 765
 	*
770 766
 	*/
771 767
 	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '',$type = '',$typeid = '',$imo = '', $callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '')
Please login to merge, or discard this patch.
require/class.SpotterImport.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -46,6 +46,10 @@
 block discarded – undo
46 46
 
47 47
     }
48 48
 
49
+    /**
50
+     * @param string $id
51
+     * @param string $ident
52
+     */
49 53
     public function get_Schedule($id,$ident) {
50 54
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
51 55
 	// Get schedule here, so it's done only one time
Please login to merge, or discard this patch.
Braces   +331 added lines, -117 removed lines patch added patch discarded remove patch
@@ -59,7 +59,9 @@  discard block
 block discarded – undo
59 59
 	$dbc = $this->db;
60 60
 	$this->all_flights[$id]['schedule_check'] = true;
61 61
 	if ($globalSchedulesFetch) {
62
-	if ($globalDebug) echo 'Getting schedule info...'."\n";
62
+	if ($globalDebug) {
63
+		echo 'Getting schedule info...'."\n";
64
+	}
63 65
 	$Spotter = new Spotter($dbc);
64 66
 	$Schedule = new Schedule($dbc);
65 67
 	$Translation = new Translation($dbc);
@@ -70,7 +72,9 @@  discard block
 block discarded – undo
70 72
 	    if ($Schedule->checkSchedule($operator) == 0) {
71 73
 		$schedule = $Schedule->fetchSchedule($operator);
72 74
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
73
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
75
+		    if ($globalDebug) {
76
+		    	echo "-> Schedule info for ".$operator." (".$ident.")\n";
77
+		    }
74 78
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
75 79
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
76 80
 		    // Should also check if route schedule = route from DB
@@ -79,7 +83,9 @@  discard block
 block discarded – undo
79 83
 			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
80 84
 			    if (trim($airport_icao) != '') {
81 85
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
82
-				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
86
+				if ($globalDebug) {
87
+					echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
88
+				}
83 89
 			    }
84 90
 			}
85 91
 		    }
@@ -88,17 +94,25 @@  discard block
 block discarded – undo
88 94
 			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
89 95
 			    if (trim($airport_icao) != '') {
90 96
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
91
-				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
97
+				if ($globalDebug) {
98
+					echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
99
+				}
92 100
 			    }
93 101
 			}
94 102
 		    }
95 103
 		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
96 104
 		}
97
-	    } else $scheduleexist = true;
98
-	} else $scheduleexist = true;
105
+	    } else {
106
+	    	$scheduleexist = true;
107
+	    }
108
+	} else {
109
+		$scheduleexist = true;
110
+	}
99 111
 	// close connection, at least one way will work ?
100 112
        if ($scheduleexist) {
101
-		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
113
+		if ($globalDebug) {
114
+			echo "-> get arrival/departure airport info for ".$ident."\n";
115
+		}
102 116
     		$sch = $Schedule->getSchedule($operator);
103 117
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
104 118
        }
@@ -120,7 +134,9 @@  discard block
 block discarded – undo
120 134
 
121 135
     public function checkAll() {
122 136
 	global $globalDebug, $globalNoImport;
123
-	if ($globalDebug) echo "Update last seen flights data...\n";
137
+	if ($globalDebug) {
138
+		echo "Update last seen flights data...\n";
139
+	}
124 140
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
125 141
 	    foreach ($this->all_flights as $key => $flight) {
126 142
 		if (isset($this->all_flights[$key]['id'])) {
@@ -135,24 +151,32 @@  discard block
 block discarded – undo
135 151
 
136 152
     public function arrival($key) {
137 153
 	global $globalClosestMinDist, $globalDebug;
138
-	if ($globalDebug) echo 'Update arrival...'."\n";
154
+	if ($globalDebug) {
155
+		echo 'Update arrival...'."\n";
156
+	}
139 157
 	$Spotter = new Spotter($this->db);
140 158
         $airport_icao = '';
141 159
         $airport_time = '';
142
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
160
+        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') {
161
+        	$globalClosestMinDist = 50;
162
+        }
143 163
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
144 164
 	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
145 165
     	    if (isset($closestAirports[0])) {
146 166
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
147 167
         	    $airport_icao = $closestAirports[0]['icao'];
148 168
         	    $airport_time = $this->all_flights[$key]['datetime'];
149
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
169
+        	    if ($globalDebug) {
170
+        	    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
171
+        	    }
150 172
         	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
151 173
         	    foreach ($closestAirports as $airport) {
152 174
         		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
153 175
         		    $airport_icao = $airport['icao'];
154 176
         		    $airport_time = $this->all_flights[$key]['datetime'];
155
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
177
+        		    if ($globalDebug) {
178
+        		    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
179
+        		    }
156 180
         		    break;
157 181
         		}
158 182
         	    }
@@ -160,14 +184,20 @@  discard block
 block discarded – undo
160 184
         		$airport_icao = $closestAirports[0]['icao'];
161 185
         		$airport_time = $this->all_flights[$key]['datetime'];
162 186
         	} else {
163
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
187
+        		if ($globalDebug) {
188
+        			echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
189
+        		}
164 190
         	}
165 191
     	    } else {
166
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
192
+    		    if ($globalDebug) {
193
+    		    	echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
194
+    		    }
167 195
     	    }
168 196
 
169 197
         } else {
170
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
198
+        	if ($globalDebug) {
199
+        		echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
200
+        	}
171 201
         }
172 202
         return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
173 203
     }
@@ -177,12 +207,16 @@  discard block
 block discarded – undo
177 207
     public function del() {
178 208
 	global $globalDebug, $globalNoImport;
179 209
 	// Delete old infos
180
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
210
+	if ($globalDebug) {
211
+		echo 'Delete old values and update latest data...'."\n";
212
+	}
181 213
 	foreach ($this->all_flights as $key => $flight) {
182 214
     	    if (isset($flight['lastupdate'])) {
183 215
         	if ($flight['lastupdate'] < (time()-3000)) {
184 216
             	    if (isset($this->all_flights[$key]['id'])) {
185
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
217
+            		if ($globalDebug) {
218
+            			echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
219
+            		}
186 220
 			/*
187 221
 			$SpotterLive = new SpotterLive();
188 222
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
@@ -193,7 +227,9 @@  discard block
 block discarded – undo
193 227
             		    $Spotter = new Spotter($this->db);
194 228
             	    	    if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
195 229
 				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
196
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
230
+				if ($globalDebug && $result != 'success') {
231
+					echo '!!! ERROR : '.$result."\n";
232
+				}
197 233
 			    }
198 234
 			// Put in archive
199 235
 //				$Spotter->db = null;
@@ -208,8 +244,10 @@  discard block
 block discarded – undo
208 244
     public function add($line) {
209 245
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport;
210 246
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
211
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
212
-/*
247
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
248
+		$globalCoordMinChange = '0.02';
249
+	}
250
+	/*
213 251
 	$Spotter = new Spotter();
214 252
 	$dbc = $Spotter->db;
215 253
 	$SpotterLive = new SpotterLive($dbc);
@@ -237,11 +275,15 @@  discard block
 block discarded – undo
237 275
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
238 276
 		    $current_date = date('Y-m-d');
239 277
 		    $source = $line['source_name'];
240
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
278
+		    if ($source == '' || $line['format_source'] == 'aprs') {
279
+		    	$source = $line['format_source'];
280
+		    }
241 281
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
242 282
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
243 283
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
244
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
284
+		    } else {
285
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
286
+		    }
245 287
 		}
246 288
 		
247 289
 		/*
@@ -257,8 +299,11 @@  discard block
 block discarded – undo
257 299
 		//$this->db = $dbc;
258 300
 
259 301
 		//$hex = trim($line['hex']);
260
-	        if (!isset($line['id'])) $id = trim($line['hex']);
261
-	        else $id = trim($line['id']);
302
+	        if (!isset($line['id'])) {
303
+	        	$id = trim($line['hex']);
304
+	        } else {
305
+	        	$id = trim($line['id']);
306
+	        }
262 307
 		
263 308
 		if (!isset($this->all_flights[$id])) {
264 309
 		    $this->all_flights[$id] = array();
@@ -266,13 +311,21 @@  discard block
 block discarded – undo
266 311
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
267 312
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
268 313
 		    if (!isset($line['id'])) {
269
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
270
-//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
314
+			if (!isset($globalDaemon)) {
315
+				$globalDaemon = TRUE;
316
+			}
317
+			//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
271 318
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
272
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
319
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
320
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
321
+			}
273 322
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
274
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
275
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
323
+		     } else {
324
+		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
325
+		     }
326
+		    if ($globalAllFlights !== FALSE) {
327
+		    	$dataFound = true;
328
+		    }
276 329
 		}
277 330
 		if (isset($line['source_type']) && $line['source_type'] != '') {
278 331
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
@@ -293,11 +346,19 @@  discard block
 block discarded – undo
293 346
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
294 347
 			}
295 348
 			$Spotter->db = null;
296
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
297
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
349
+			if ($globalDebugTimeElapsed) {
350
+				echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
351
+			}
352
+			if ($aircraft_icao != '') {
353
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
354
+			}
355
+		    }
356
+		    if ($globalAllFlights !== FALSE) {
357
+		    	$dataFound = true;
358
+		    }
359
+		    if ($globalDebug) {
360
+		    	echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
298 361
 		    }
299
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
300
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
301 362
 		}
302 363
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
303 364
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
@@ -307,14 +368,23 @@  discard block
 block discarded – undo
307 368
 			$Spotter = new Spotter($this->db);
308 369
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
309 370
 			$Spotter->db = null;
310
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
371
+			if ($aircraft_icao != '') {
372
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
373
+			}
311 374
 		}
312 375
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
313
-			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
314
-			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
315
-			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
316
-			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
317
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
376
+			if ($line['aircraft_type'] == 'PARA_GLIDER') {
377
+				$aircraft_icao = 'GLID';
378
+			} elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') {
379
+				$aircraft_icao = 'UHEL';
380
+			} elseif ($line['aircraft_type'] == 'TOW_PLANE') {
381
+				$aircraft_icao = 'TOWPLANE';
382
+			} elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') {
383
+				$aircraft_icao = 'POWAIRC';
384
+			}
385
+			if (isset($aircraft_icao)) {
386
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
387
+			}
318 388
 		}
319 389
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
320 390
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
@@ -324,8 +394,11 @@  discard block
 block discarded – undo
324 394
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
325 395
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
326 396
 		    } else {
327
-				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
328
-				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
397
+				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
398
+					echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
399
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
400
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
401
+				}
329 402
 				/*
330 403
 				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
331 404
 				print_r($this->all_flights[$id]);
@@ -357,15 +430,25 @@  discard block
 block discarded – undo
357 430
 			$timeelapsed = microtime(true);
358 431
             		$Spotter = new Spotter($this->db);
359 432
             		$fromsource = NULL;
360
-            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
361
-            		elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
362
-			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
363
-			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
364
-			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
433
+            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') {
434
+            			$fromsource = $globalAirlinesSource;
435
+            		} elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') {
436
+            			$fromsource = 'vatsim';
437
+            		} elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') {
438
+				$fromsource = 'ivao';
439
+			} elseif (isset($globalVATSIM) && $globalVATSIM) {
440
+				$fromsource = 'vatsim';
441
+			} elseif (isset($globalIVAO) && $globalIVAO) {
442
+				$fromsource = 'ivao';
443
+			}
365 444
             		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
366
-			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
445
+			if ($globalDebug && $result != 'success') {
446
+				echo '!!! ERROR : '.$result."\n";
447
+			}
367 448
 			$Spotter->db = null;
368
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
449
+			if ($globalDebugTimeElapsed) {
450
+				echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
451
+			}
369 452
 		    }
370 453
 
371 454
 /*
@@ -376,7 +459,9 @@  discard block
 block discarded – undo
376 459
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
377 460
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
378 461
   */
379
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
462
+		    if (!isset($this->all_flights[$id]['id'])) {
463
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
464
+		    }
380 465
 
381 466
 		    //$putinarchive = true;
382 467
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
@@ -393,7 +478,9 @@  discard block
 block discarded – undo
393 478
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
394 479
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
395 480
 		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
396
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
481
+				if ($globalDebugTimeElapsed) {
482
+					echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
483
+				}
397 484
 
398 485
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
399 486
 			$timeelapsed = microtime(true);
@@ -406,7 +493,9 @@  discard block
 block discarded – undo
406 493
 				$Translation->db = null;
407 494
 			}
408 495
 			$Spotter->db = null;
409
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
496
+			if ($globalDebugTimeElapsed) {
497
+				echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
498
+			}
410 499
 
411 500
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
412 501
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
@@ -415,9 +504,13 @@  discard block
 block discarded – undo
415 504
 		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
416 505
 		    	    }
417 506
 			}
418
-			if (!isset($globalFork)) $globalFork = TRUE;
507
+			if (!isset($globalFork)) {
508
+				$globalFork = TRUE;
509
+			}
419 510
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
420
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
511
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) {
512
+					$this->get_Schedule($id,trim($line['ident']));
513
+				}
421 514
 			}
422 515
 		    }
423 516
 		}
@@ -433,16 +526,23 @@  discard block
 block discarded – undo
433 526
 		    // use datetime
434 527
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
435 528
 			$speed = $speed*3.6;
436
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
437
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
529
+			if ($speed < 1000) {
530
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
531
+			}
532
+  			if ($globalDebug) {
533
+  				echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
534
+  			}
438 535
 		    }
439 536
 		}
440 537
 
441 538
 
442 539
 
443 540
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
444
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
445
-	    	    else unset($timediff);
541
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) {
542
+	    	    	$timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
543
+	    	    } else {
544
+	    	    	unset($timediff);
545
+	    	    }
446 546
 	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
447 547
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
448 548
 			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
@@ -450,21 +550,31 @@  discard block
 block discarded – undo
450 550
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
451 551
 				$this->all_flights[$id]['putinarchive'] = true;
452 552
 				
453
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
553
+				if ($globalDebug) {
554
+					echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
555
+				}
454 556
 				$timeelapsed = microtime(true);
455 557
 				$Spotter = new Spotter($this->db);
456 558
 				$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
457
-				if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
559
+				if (!empty($all_country)) {
560
+					$this->all_flights[$id]['over_country'] = $all_country['iso2'];
561
+				}
458 562
 				$Spotter->db = null;
459
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
563
+				if ($globalDebugTimeElapsed) {
564
+					echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
565
+				}
460 566
 				$this->tmd = 0;
461
-				if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
567
+				if ($globalDebug) {
568
+					echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
569
+				}
462 570
 			    }
463 571
 			}
464 572
 
465 573
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
466 574
 			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
467
-				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
575
+				if (!isset($this->all_flights[$id]['archive_latitude'])) {
576
+					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
577
+				}
468 578
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
469 579
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
470 580
 				    $dataFound = true;
@@ -486,9 +596,13 @@  discard block
 block discarded – undo
486 596
 			    */
487 597
 			}
488 598
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
489
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
599
+			    if ($line['longitude'] > 180) {
600
+			    	$line['longitude'] = $line['longitude'] - 360;
601
+			    }
490 602
 			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
491
-				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
603
+				if (!isset($this->all_flights[$id]['archive_longitude'])) {
604
+					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
605
+				}
492 606
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
493 607
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
494 608
 				    $dataFound = true;
@@ -519,7 +633,9 @@  discard block
 block discarded – undo
519 633
 		    }
520 634
 		}
521 635
 		if (isset($line['last_update']) && $line['last_update'] != '') {
522
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
636
+		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) {
637
+		    	$dataFound = true;
638
+		    }
523 639
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
524 640
 		}
525 641
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
@@ -541,40 +657,60 @@  discard block
 block discarded – undo
541 657
 			// Here we force archive of flight because after ground it's a new one (or should be)
542 658
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
543 659
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
544
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
545
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
546
-			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
660
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) {
661
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
662
+			} elseif (isset($line['id'])) {
663
+		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
664
+		        } elseif (isset($this->all_flights[$id]['ident'])) {
665
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
666
+			}
667
+		    }
668
+		    if ($line['ground'] != 1) {
669
+		    	$line['ground'] = 0;
547 670
 		    }
548
-		    if ($line['ground'] != 1) $line['ground'] = 0;
549 671
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
550 672
 		    //$dataFound = true;
551 673
 		}
552 674
 		if (isset($line['squawk']) && $line['squawk'] != '') {
553 675
 		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
554
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
676
+			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) {
677
+			    	$this->all_flights[$id]['putinarchive'] = true;
678
+			    }
555 679
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
556 680
 			    $highlight = '';
557
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
558
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
559
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
681
+			    if ($this->all_flights[$id]['squawk'] == '7500') {
682
+			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
683
+			    }
684
+			    if ($this->all_flights[$id]['squawk'] == '7600') {
685
+			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
686
+			    }
687
+			    if ($this->all_flights[$id]['squawk'] == '7700') {
688
+			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
689
+			    }
560 690
 			    if ($highlight != '') {
561 691
 				$timeelapsed = microtime(true);
562 692
 				$Spotter = new Spotter($this->db);
563 693
 				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
564 694
 				$Spotter->db = null;
565
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
695
+				if ($globalDebugTimeElapsed) {
696
+					echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
697
+				}
566 698
 
567 699
 				//$putinarchive = true;
568 700
 				//$highlight = '';
569 701
 			    }
570 702
 			    
571
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
703
+		    } else {
704
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
705
+		    }
572 706
 		    //$dataFound = true;
573 707
 		}
574 708
 
575 709
 		if (isset($line['altitude']) && $line['altitude'] != '') {
576 710
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
577
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
711
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) {
712
+				$this->all_flights[$id]['putinarchive'] = true;
713
+			}
578 714
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
579 715
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
580 716
 			//$dataFound = true;
@@ -586,21 +722,30 @@  discard block
 block discarded – undo
586 722
 		}
587 723
 		
588 724
 		if (isset($line['heading']) && $line['heading'] != '') {
589
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
725
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) {
726
+		    	$this->all_flights[$id]['putinarchive'] = true;
727
+		    }
590 728
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
591 729
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
592 730
 		    //$dataFound = true;
593 731
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
594 732
   		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
595 733
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
596
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
597
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
734
+		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) {
735
+		    	$this->all_flights[$id]['putinarchive'] = true;
736
+		    }
737
+  		    if ($globalDebug) {
738
+  		    	echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
739
+  		    }
598 740
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
599 741
   		    // If not enough messages and ACARS set heading to 0
600 742
   		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
601 743
   		}
602
-		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
603
-		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
744
+		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) {
745
+			$dataFound = false;
746
+		} elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) {
747
+			$dataFound = false;
748
+		}
604 749
 
605 750
 //		print_r($this->all_flights[$id]);
606 751
 		//gets the callsign from the last hour
@@ -615,23 +760,36 @@  discard block
 block discarded – undo
615 760
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
616 761
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
617 762
 			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
618
-				if ($globalDebug) echo "Check if aircraft is already in DB...";
763
+				if ($globalDebug) {
764
+					echo "Check if aircraft is already in DB...";
765
+				}
619 766
 				$timeelapsed = microtime(true);
620 767
 				$SpotterLive = new SpotterLive($this->db);
621 768
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
622 769
 				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
623
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
770
+				    if ($globalDebugTimeElapsed) {
771
+				    	echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
772
+				    }
624 773
 				} elseif (isset($line['id'])) {
625 774
 				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
626
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
775
+				    if ($globalDebugTimeElapsed) {
776
+				    	echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
777
+				    }
627 778
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
628 779
 				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
629
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
630
-				} else $recent_ident = '';
780
+				    if ($globalDebugTimeElapsed) {
781
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
782
+				    }
783
+				} else {
784
+					$recent_ident = '';
785
+				}
631 786
 				$SpotterLive->db=null;
632 787
 
633
-				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
634
-				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
788
+				if ($globalDebug && $recent_ident == '') {
789
+					echo " Not in DB.\n";
790
+				} elseif ($globalDebug && $recent_ident != '') {
791
+					echo " Already in DB.\n";
792
+				}
635 793
 			    } else {
636 794
 				$recent_ident = '';
637 795
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
@@ -639,7 +797,9 @@  discard block
 block discarded – undo
639 797
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
640 798
 			    if($recent_ident == "")
641 799
 			    {
642
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
800
+				if ($globalDebug) {
801
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
802
+				}
643 803
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
644 804
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
645 805
 				//adds the spotter data for the archive
@@ -683,28 +843,46 @@  discard block
 block discarded – undo
683 843
 				
684 844
 				if (!$ignoreImport) {
685 845
 				    $highlight = '';
686
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
687
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
688
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
689
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
846
+				    if ($this->all_flights[$id]['squawk'] == '7500') {
847
+				    	$highlight = 'Squawk 7500 : Hijack';
848
+				    }
849
+				    if ($this->all_flights[$id]['squawk'] == '7600') {
850
+				    	$highlight = 'Squawk 7600 : Lost Comm (radio failure)';
851
+				    }
852
+				    if ($this->all_flights[$id]['squawk'] == '7700') {
853
+				    	$highlight = 'Squawk 7700 : Emergency';
854
+				    }
855
+				    if (!isset($this->all_flights[$id]['id'])) {
856
+				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
857
+				    }
690 858
 				    $timeelapsed = microtime(true);
691 859
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
692 860
 					$Spotter = new Spotter($this->db);
693 861
 					$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
694 862
 					$Spotter->db = null;
695
-					if ($globalDebug && isset($result)) echo $result."\n";
863
+					if ($globalDebug && isset($result)) {
864
+						echo $result."\n";
865
+					}
866
+				    }
867
+				    if ($globalDebugTimeElapsed) {
868
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
696 869
 				    }
697
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
698 870
 				    
699 871
 				    // Add source stat in DB
700 872
 				    $Stats = new Stats($this->db);
701 873
 				    if (!empty($this->stats)) {
702
-					if ($globalDebug) echo 'Add source stats : ';
874
+					if ($globalDebug) {
875
+						echo 'Add source stats : ';
876
+					}
703 877
 				        foreach($this->stats as $date => $data) {
704 878
 					    foreach($data as $source => $sourced) {
705 879
 					        //print_r($sourced);
706
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
707
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
880
+				    	        if (isset($sourced['polar'])) {
881
+				    	        	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
882
+				    	        }
883
+				    	        if (isset($sourced['hist'])) {
884
+				    	        	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
885
+				    	        }
708 886
 				    		if (isset($sourced['msg'])) {
709 887
 				    		    if (time() - $sourced['msg']['date'] > 10) {
710 888
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -717,13 +895,17 @@  discard block
 block discarded – undo
717 895
 			    			unset($this->stats[$date]);
718 896
 			    		    }
719 897
 				    	}
720
-				    	if ($globalDebug) echo 'Done'."\n";
898
+				    	if ($globalDebug) {
899
+				    		echo 'Done'."\n";
900
+				    	}
721 901
 
722 902
 				    }
723 903
 				    $Stats->db = null;
724 904
 				    
725 905
 				    $this->del();
726
-				} elseif ($globalDebug) echo 'Ignore data'."\n";
906
+				} elseif ($globalDebug) {
907
+					echo 'Ignore data'."\n";
908
+				}
727 909
 				//$ignoreImport = false;
728 910
 				$this->all_flights[$id]['addedSpotter'] = 1;
729 911
 				//print_r($this->all_flights[$id]);
@@ -740,14 +922,18 @@  discard block
 block discarded – undo
740 922
 			*/
741 923
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
742 924
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
743
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
925
+				    if ($globalDebug) {
926
+				    	echo "---- Deleting Live Spotter data older than 9 hours...";
927
+				    }
744 928
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
745 929
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
746 930
 					$SpotterLive = new SpotterLive($this->db);
747 931
 					$SpotterLive->deleteLiveSpotterData();
748 932
 					$SpotterLive->db=null;
749 933
 				    }
750
-				    if ($globalDebug) echo " Done\n";
934
+				    if ($globalDebug) {
935
+				    	echo " Done\n";
936
+				    }
751 937
 				    $this->last_delete = time();
752 938
 				}
753 939
 			    } else {
@@ -772,11 +958,17 @@  discard block
 block discarded – undo
772 958
 		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
773 959
 		    if ($globalDebug) {
774 960
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
775
-				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
776
-				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
961
+				if (isset($this->all_flights[$id]['source_name'])) {
962
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
963
+				} else {
964
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
965
+				}
777 966
 			} else {
778
-				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
779
-				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
967
+				if (isset($this->all_flights[$id]['source_name'])) {
968
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
969
+				} else {
970
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
971
+				}
780 972
 			}
781 973
 		    }
782 974
 		    $ignoreImport = false;
@@ -822,7 +1014,9 @@  discard block
 block discarded – undo
822 1014
 
823 1015
 		    if (!$ignoreImport) {
824 1016
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
825
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1017
+				if ($globalDebug) {
1018
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1019
+				}
826 1020
 				$timeelapsed = microtime(true);
827 1021
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
828 1022
 					$SpotterLive = new SpotterLive($this->db);
@@ -833,14 +1027,18 @@  discard block
 block discarded – undo
833 1027
 					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
834 1028
 				}
835 1029
 				$this->all_flights[$id]['putinarchive'] = false;
836
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1030
+				if ($globalDebugTimeElapsed) {
1031
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1032
+				}
837 1033
 
838 1034
 				// Put statistics in $this->stats variable
839 1035
 				//if ($line['format_source'] != 'aprs') {
840 1036
 				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
841 1037
 				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
842 1038
 					$source = $this->all_flights[$id]['source_name'];
843
-					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1039
+					if ($source == '') {
1040
+						$source = $this->all_flights[$id]['format_source'];
1041
+					}
844 1042
 					if (!isset($this->source_location[$source])) {
845 1043
 						$Location = new Source();
846 1044
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -861,7 +1059,9 @@  discard block
 block discarded – undo
861 1059
 					$stats_heading = round($stats_heading/22.5);
862 1060
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
863 1061
 					$current_date = date('Y-m-d');
864
-					if ($stats_heading == 16) $stats_heading = 0;
1062
+					if ($stats_heading == 16) {
1063
+						$stats_heading = 0;
1064
+					}
865 1065
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
866 1066
 						for ($i=0;$i<=15;$i++) {
867 1067
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -879,7 +1079,9 @@  discard block
 block discarded – undo
879 1079
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
880 1080
 						    end($this->stats[$current_date][$source]['hist']);
881 1081
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
882
-						} else $mini = 0;
1082
+						} else {
1083
+							$mini = 0;
1084
+						}
883 1085
 						for ($i=$mini;$i<=$distance;$i+=10) {
884 1086
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
885 1087
 						}
@@ -890,20 +1092,30 @@  discard block
 block discarded – undo
890 1092
 				}
891 1093
 
892 1094
 				$this->all_flights[$id]['lastupdate'] = time();
893
-				if ($this->all_flights[$id]['putinarchive']) $send = true;
1095
+				if ($this->all_flights[$id]['putinarchive']) {
1096
+					$send = true;
1097
+				}
894 1098
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
895
-				if ($globalDebug) echo $result."\n";
896
-			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1099
+				if ($globalDebug) {
1100
+					echo $result."\n";
1101
+				}
1102
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
1103
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1104
+			}
897 1105
 			//$this->del();
898 1106
 			
899 1107
 			
900 1108
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
901
-			    if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1109
+			    if ($globalDebug) {
1110
+			    	echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1111
+			    }
902 1112
 			    $SpotterLive = new SpotterLive($this->db);
903 1113
 			    $SpotterLive->deleteLiveSpotterDataNotUpdated();
904 1114
 			    $SpotterLive->db = null;
905 1115
 			    //SpotterLive->deleteLiveSpotterData();
906
-			    if ($globalDebug) echo " Done\n";
1116
+			    if ($globalDebug) {
1117
+			    	echo " Done\n";
1118
+			    }
907 1119
 			    $this->last_delete_hourly = time();
908 1120
 			}
909 1121
 			
@@ -911,7 +1123,9 @@  discard block
 block discarded – undo
911 1123
 		    //$ignoreImport = false;
912 1124
 		}
913 1125
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
914
-		if ($send) return $this->all_flights[$id];
1126
+		if ($send) {
1127
+			return $this->all_flights[$id];
1128
+		}
915 1129
 	    }
916 1130
 	}
917 1131
     }
Please login to merge, or discard this patch.
require/class.MarineImport.php 1 patch
Braces   +149 added lines, -51 removed lines patch added patch discarded remove patch
@@ -45,7 +45,9 @@  discard block
 block discarded – undo
45 45
 
46 46
     public function checkAll() {
47 47
 	global $globalDebug;
48
-	if ($globalDebug) echo "Update last seen tracked data...\n";
48
+	if ($globalDebug) {
49
+		echo "Update last seen tracked data...\n";
50
+	}
49 51
 	foreach ($this->all_tracked as $key => $flight) {
50 52
 	    if (isset($this->all_tracked[$key]['id'])) {
51 53
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
@@ -58,12 +60,16 @@  discard block
 block discarded – undo
58 60
     public function del() {
59 61
 	global $globalDebug;
60 62
 	// Delete old infos
61
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
63
+	if ($globalDebug) {
64
+		echo 'Delete old values and update latest data...'."\n";
65
+	}
62 66
 	foreach ($this->all_tracked as $key => $flight) {
63 67
     	    if (isset($flight['lastupdate'])) {
64 68
         	if ($flight['lastupdate'] < (time()-3000)) {
65 69
             	    if (isset($this->all_tracked[$key]['id'])) {
66
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
70
+            		if ($globalDebug) {
71
+            			echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
72
+            		}
67 73
 			/*
68 74
 			$MarineLive = new MarineLive();
69 75
             		$MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
@@ -73,7 +79,9 @@  discard block
 block discarded – undo
73 79
             		$Marine = new Marine($this->db);
74 80
             		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
75 81
 				$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']);
76
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
82
+				if ($globalDebug && $result != 'success') {
83
+					echo '!!! ERROR : '.$result."\n";
84
+				}
77 85
 			}
78 86
 			// Put in archive
79 87
 //			$Marine->db = null;
@@ -86,7 +94,9 @@  discard block
 block discarded – undo
86 94
 
87 95
     public function add($line) {
88 96
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked;
89
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
97
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
98
+		$globalCoordMinChange = '0.02';
99
+	}
90 100
 	date_default_timezone_set('UTC');
91 101
 	$dataFound = false;
92 102
 	$send = false;
@@ -111,8 +121,11 @@  discard block
 block discarded – undo
111 121
 		
112 122
 		$Common = new Common();
113 123
 		$AIS = new AIS();
114
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
115
-	        else $id = trim($line['id']);
124
+	        if (!isset($line['id'])) {
125
+	        	$id = trim($line['mmsi']);
126
+	        } else {
127
+	        	$id = trim($line['id']);
128
+	        }
116 129
 		
117 130
 		if (!isset($this->all_tracked[$id])) {
118 131
 		    $this->all_tracked[$id] = array();
@@ -120,10 +133,16 @@  discard block
 block discarded – undo
120 133
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => ''));
121 134
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
122 135
 		    if (!isset($line['id'])) {
123
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
136
+			if (!isset($globalDaemon)) {
137
+				$globalDaemon = TRUE;
138
+			}
124 139
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
125
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
126
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
140
+		     } else {
141
+		     	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
142
+		     }
143
+		    if ($globalAllTracked !== FALSE) {
144
+		    	$dataFound = true;
145
+		    }
127 146
 		}
128 147
 		
129 148
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
@@ -166,11 +185,17 @@  discard block
 block discarded – undo
166 185
             		$Marine = new Marine($this->db);
167 186
             		$fromsource = NULL;
168 187
             		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
169
-			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
188
+			if ($globalDebug && $result != 'success') {
189
+				echo '!!! ERROR : '.$result."\n";
190
+			}
170 191
 			$Marine->db = null;
171
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
192
+			if ($globalDebugTimeElapsed) {
193
+				echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
194
+			}
195
+		    }
196
+		    if (!isset($this->all_tracked[$id]['id'])) {
197
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
172 198
 		    }
173
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
174 199
 		}
175 200
 
176 201
 		if (isset($line['speed']) && $line['speed'] != '') {
@@ -181,14 +206,21 @@  discard block
 block discarded – undo
181 206
 		    if ($distance > 1000 && $distance < 10000) {
182 207
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
183 208
 			$speed = $speed*3.6;
184
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
185
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
209
+			if ($speed < 1000) {
210
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
211
+			}
212
+  			if ($globalDebug) {
213
+  				echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
214
+  			}
186 215
 		    }
187 216
 		}
188 217
 
189 218
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
190
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
191
-	    	    else unset($timediff);
219
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) {
220
+	    	    	$timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
221
+	    	    } else {
222
+	    	    	unset($timediff);
223
+	    	    }
192 224
 	    	    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')))) {
193 225
 			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'])) {
194 226
 			    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'])) {
@@ -196,20 +228,30 @@  discard block
 block discarded – undo
196 228
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
197 229
 				$this->all_tracked[$id]['putinarchive'] = true;
198 230
 				
199
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
231
+				if ($globalDebug) {
232
+					echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
233
+				}
200 234
 				$timeelapsed = microtime(true);
201 235
 				$Marine = new Marine($this->db);
202 236
 				$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
203
-				if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
237
+				if (!empty($all_country)) {
238
+					$this->all_tracked[$id]['over_country'] = $all_country['iso2'];
239
+				}
204 240
 				$Marine->db = null;
205
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
241
+				if ($globalDebugTimeElapsed) {
242
+					echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
243
+				}
206 244
 				$this->tmd = 0;
207
-				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
245
+				if ($globalDebug) {
246
+					echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
247
+				}
208 248
 			    }
209 249
 			}
210 250
 
211 251
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
212
-				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
252
+				if (!isset($this->all_tracked[$id]['archive_latitude'])) {
253
+					$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
254
+				}
213 255
 				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') {
214 256
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
215 257
 				    $dataFound = true;
@@ -218,8 +260,12 @@  discard block
 block discarded – undo
218 260
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
219 261
 			}
220 262
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
221
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
222
-				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
263
+			    if ($line['longitude'] > 180) {
264
+			    	$line['longitude'] = $line['longitude'] - 360;
265
+			    }
266
+				if (!isset($this->all_tracked[$id]['archive_longitude'])) {
267
+					$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
268
+				}
223 269
 				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') {
224 270
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
225 271
 				    $dataFound = true;
@@ -237,7 +283,9 @@  discard block
 block discarded – undo
237 283
 		    }
238 284
 		}
239 285
 		if (isset($line['last_update']) && $line['last_update'] != '') {
240
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
286
+		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) {
287
+		    	$dataFound = true;
288
+		    }
241 289
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
242 290
 		}
243 291
 		if (isset($line['format_source']) && $line['format_source'] != '') {
@@ -255,15 +303,21 @@  discard block
 block discarded – undo
255 303
 		}
256 304
 		
257 305
 		if (isset($line['heading']) && $line['heading'] != '') {
258
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
306
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) {
307
+		    	$this->all_tracked[$id]['putinarchive'] = true;
308
+		    }
259 309
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
260 310
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
261 311
 		    //$dataFound = true;
262 312
   		} 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']) {
263 313
   		    $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']);
264 314
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
265
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
266
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
315
+		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) {
316
+		    	$this->all_tracked[$id]['putinarchive'] = true;
317
+		    }
318
+  		    if ($globalDebug) {
319
+  		    	echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
320
+  		    }
267 321
   		}
268 322
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
269 323
 
@@ -271,8 +325,11 @@  discard block
 block discarded – undo
271 325
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
272 326
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
273 327
 		    } else {
274
-				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";
275
-				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";
328
+				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
329
+					echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
330
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
331
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
332
+				}
276 333
 				return '';
277 334
 		    }
278 335
 		} else {
@@ -286,22 +343,35 @@  discard block
 block discarded – undo
286 343
 		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
287 344
 		        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'])) {
288 345
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
289
-				if ($globalDebug) echo "Check if aircraft is already in DB...";
346
+				if ($globalDebug) {
347
+					echo "Check if aircraft is already in DB...";
348
+				}
290 349
 				$timeelapsed = microtime(true);
291 350
 				$MarineLive = new MarineLive($this->db);
292 351
 				if (isset($line['id'])) {
293 352
 				    $recent_ident = $MarineLive->checkIdRecent($line['id']);
294
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
353
+				    if ($globalDebugTimeElapsed) {
354
+				    	echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
355
+				    }
295 356
 				} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
296 357
 				    $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
297
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
358
+				    if ($globalDebugTimeElapsed) {
359
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
360
+				    }
298 361
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
299 362
 				    $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
300
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
301
-				} else $recent_ident = '';
363
+				    if ($globalDebugTimeElapsed) {
364
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
365
+				    }
366
+				} else {
367
+					$recent_ident = '';
368
+				}
302 369
 				$MarineLive->db=null;
303
-				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
304
-				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
370
+				if ($globalDebug && $recent_ident == '') {
371
+					echo " Not in DB.\n";
372
+				} elseif ($globalDebug && $recent_ident != '') {
373
+					echo " Already in DB.\n";
374
+				}
305 375
 			    } else {
306 376
 				$recent_ident = '';
307 377
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
@@ -309,16 +379,24 @@  discard block
 block discarded – undo
309 379
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
310 380
 			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
311 381
 			    {
312
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
382
+				if ($globalDebug) {
383
+					echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
384
+				}
313 385
 				//adds the spotter data for the archive
314 386
 				    $highlight = '';
315
-				    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')));
387
+				    if (!isset($this->all_tracked[$id]['id'])) {
388
+				    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
389
+				    }
316 390
 				    $timeelapsed = microtime(true);
317 391
 				    $Marine = new Marine($this->db);
318 392
 				    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
319 393
 				    $Marine->db = null;
320
-				    if ($globalDebug && isset($result)) echo $result."\n";
321
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
394
+				    if ($globalDebug && isset($result)) {
395
+				    	echo $result."\n";
396
+				    }
397
+				    if ($globalDebugTimeElapsed) {
398
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
399
+				    }
322 400
 				    
323 401
 				    /*
324 402
 				    // Add source stat in DB
@@ -352,12 +430,16 @@  discard block
 block discarded – undo
352 430
 				$this->all_tracked[$id]['addedMarine'] = 1;
353 431
 				//print_r($this->all_tracked[$id]);
354 432
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
355
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
433
+				    if ($globalDebug) {
434
+				    	echo "---- Deleting Live Marine data older than 9 hours...";
435
+				    }
356 436
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
357 437
 				    $MarineLive = new MarineLive($this->db);
358 438
 				    $MarineLive->deleteLiveMarineData();
359 439
 				    $MarineLive->db=null;
360
-				    if ($globalDebug) echo " Done\n";
440
+				    if ($globalDebug) {
441
+				    	echo " Done\n";
442
+				    }
361 443
 				    $this->last_delete = time();
362 444
 				}
363 445
 			    } elseif ($recent_ident != '') {
@@ -380,13 +462,17 @@  discard block
 block discarded – undo
380 462
 
381 463
 		    if (!$ignoreImport) {
382 464
 			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'])) {
383
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
465
+				if ($globalDebug) {
466
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
467
+				}
384 468
 				$timeelapsed = microtime(true);
385 469
 				$MarineLive = new MarineLive($this->db);
386 470
 				$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
387 471
 				$MarineLive->db = null;
388 472
 				$this->all_tracked[$id]['putinarchive'] = false;
389
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
473
+				if ($globalDebugTimeElapsed) {
474
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
475
+				}
390 476
 
391 477
 				// Put statistics in $this->stats variable
392 478
 				/*
@@ -443,19 +529,29 @@  discard block
 block discarded – undo
443 529
 				*/
444 530
 
445 531
 				$this->all_tracked[$id]['lastupdate'] = time();
446
-				if ($this->all_tracked[$id]['putinarchive']) $send = true;
447
-				if ($globalDebug) echo $result."\n";
448
-			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
532
+				if ($this->all_tracked[$id]['putinarchive']) {
533
+					$send = true;
534
+				}
535
+				if ($globalDebug) {
536
+					echo $result."\n";
537
+				}
538
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
539
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
540
+			}
449 541
 			//$this->del();
450 542
 			
451 543
 			
452 544
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
453
-			    if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
545
+			    if ($globalDebug) {
546
+			    	echo "---- Deleting Live Marine data Not updated since 2 hour...";
547
+			    }
454 548
 			    $MarineLive = new MarineLive($this->db);
455 549
 			    $MarineLive->deleteLiveMarineDataNotUpdated();
456 550
 			    $MarineLive->db = null;
457 551
 			    //MarineLive->deleteLiveMarineData();
458
-			    if ($globalDebug) echo " Done\n";
552
+			    if ($globalDebug) {
553
+			    	echo " Done\n";
554
+			    }
459 555
 			    $this->last_delete_hourly = time();
460 556
 			}
461 557
 			
@@ -463,7 +559,9 @@  discard block
 block discarded – undo
463 559
 		    //$ignoreImport = false;
464 560
 		}
465 561
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
466
-		if ($send) return $this->all_tracked[$id];
562
+		if ($send) {
563
+			return $this->all_tracked[$id];
564
+		}
467 565
 	    }
468 566
 	}
469 567
     }
Please login to merge, or discard this patch.
require/class.AIS.php 1 patch
Braces   +322 added lines, -140 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@  discard block
 block discarded – undo
35 35
 			$temp += 1;
36 36
 			$flat = (float)($temp / (60.0 * 10000.0));
37 37
 			$flat *= -1.0;
38
-		} else $flat = (float)($temp / (60.0 * 10000.0));
38
+		} else {
39
+			$flat = (float)($temp / (60.0 * 10000.0));
40
+		}
39 41
 		return $flat; // float
40 42
 	}
41 43
 
@@ -47,7 +49,9 @@  discard block
 block discarded – undo
47 49
 			$temp += 1;
48 50
 			$flon = (float)($temp / (60.0 * 10000.0));
49 51
 			$flon *= -1.0;
50
-		} else $flon = (float)($temp / (60.0 * 10000.0));
52
+		} else {
53
+			$flon = (float)($temp / (60.0 * 10000.0));
54
+		}
51 55
 		return $flon;
52 56
 	}
53 57
 
@@ -70,10 +74,8 @@  discard block
 block discarded – undo
70 74
     */
71 75
 	private function asciidec_2_8bit($ascii) {
72 76
 		//only process in the following range: 48-87, 96-119
73
-		if ($ascii < 48) { }
74
-		else {
75
-			if($ascii>119) { }
76
-			else {
77
+		if ($ascii < 48) { } else {
78
+			if($ascii>119) { } else {
77 79
 				if ($ascii>87 && $ascii<96) ;
78 80
 				else {
79 81
 					$ascii=$ascii+40;
@@ -175,7 +177,9 @@  discard block
 block discarded – undo
175 177
 			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28)));
176 178
 			$ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27)));
177 179
 			$ro->heading = bindec(substr($_aisdata,124,9));
178
-			if ($ro->heading == 511) $ro->heading = '';
180
+			if ($ro->heading == 511) {
181
+				$ro->heading = '';
182
+			}
179 183
 			$ro->cls = 2; // class B
180 184
 		} else if ($ro->id == 19) {
181 185
 			$ro->cog = bindec(substr($_aisdata,112,12))/10;
@@ -185,7 +189,9 @@  discard block
 block discarded – undo
185 189
 			$ro->name = $this->binchar($_aisdata,143,120);
186 190
 			$ro->cls = 2; // class B
187 191
 			$ro->heading = bindec(substr($_aisdata,124,9));
188
-			if ($ro->heading == 511) $ro->heading = '';
192
+			if ($ro->heading == 511) {
193
+				$ro->heading = '';
194
+			}
189 195
 			$ro->typeid = bindec(substr($_aisdata,263,8));
190 196
 			$ro->type = $this->getShipType($ro->typeid);
191 197
 			//$ro->to_bow = bindec(substr($_aisdata,271,9));
@@ -216,9 +222,13 @@  discard block
 block discarded – undo
216 222
 			$ro->cls = 2; // class B
217 223
 		} else if ($ro->id == 27) {
218 224
 			$ro->cog = bindec(substr($_aisdata,85,9));
219
-			if ($ro->cog == 511) $ro->cog = 0.0;
225
+			if ($ro->cog == 511) {
226
+				$ro->cog = 0.0;
227
+			}
220 228
 			$ro->sog = bindec(substr($_aisdata,79,6));
221
-			if ($ro->sog == 63) $ro->sog = 0.0;
229
+			if ($ro->sog == 63) {
230
+				$ro->sog = 0.0;
231
+			}
222 232
 			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10);
223 233
 			$ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10);
224 234
 			$ro->cls = 1; // class A
@@ -267,88 +277,171 @@  discard block
 block discarded – undo
267 277
 	}
268 278
 	
269 279
 	public function getShipType($code) {
270
-		if ($code == 0) return 'Not available (default)';
271
-		elseif ($code >= 1 && $code <= 19) return 'Reserved for future use';
272
-		elseif ($code == 20) return 'Wing in ground (WIG), all ships of this type';
273
-		elseif ($code == 21) return 'Wing in ground (WIG), Hazardous category A';
274
-		elseif ($code == 22) return 'Wing in ground (WIG), Hazardous category B';
275
-		elseif ($code == 23) return 'Wing in ground (WIG), Hazardous category C';
276
-		elseif ($code == 24) return 'Wing in ground (WIG), Hazardous category D';
277
-		elseif ($code == 25) return 'Wing in ground (WIG), Reserved for future use';
278
-		elseif ($code == 26) return 'Wing in ground (WIG), Reserved for future use';
279
-		elseif ($code == 27) return 'Wing in ground (WIG), Reserved for future use';
280
-		elseif ($code == 28) return 'Wing in ground (WIG), Reserved for future use';
281
-		elseif ($code == 29) return 'Wing in ground (WIG), Reserved for future use';
282
-		elseif ($code == 30) return 'Fishing';
283
-		elseif ($code == 31) return 'Towing';
284
-		elseif ($code == 32) return 'Towing: length exceeds 200m or breadth exceeds 25m';
285
-		elseif ($code == 33) return 'Dredging or underwater ops';
286
-		elseif ($code == 34) return 'Diving ops';
287
-		elseif ($code == 35) return 'Military ops';
288
-		elseif ($code == 36) return 'Sailing';
289
-		elseif ($code == 37) return 'Pleasure Craft';
290
-		elseif ($code == 38) return 'Reserved';
291
-		elseif ($code == 39) return 'Reserved';
292
-		elseif ($code == 40) return 'High speed craft (HSC), all ships of this type';
293
-		elseif ($code == 41) return 'High speed craft (HSC), Hazardous category A';
294
-		elseif ($code == 42) return 'High speed craft (HSC), Hazardous category B';
295
-		elseif ($code == 43) return 'High speed craft (HSC), Hazardous category C';
296
-		elseif ($code == 44) return 'High speed craft (HSC), Hazardous category D';
297
-		elseif ($code == 45) return 'High speed craft (HSC), Reserved for future use';
298
-		elseif ($code == 46) return 'High speed craft (HSC), Reserved for future use';
299
-		elseif ($code == 47) return 'High speed craft (HSC), Reserved for future use';
300
-		elseif ($code == 48) return 'High speed craft (HSC), Reserved for future use';
301
-		elseif ($code == 49) return 'High speed craft (HSC), No additional information';
302
-		elseif ($code == 50) return 'Pilot Vessel';
303
-		elseif ($code == 51) return 'Search and Rescue vessel';
304
-		elseif ($code == 52) return 'Tug';
305
-		elseif ($code == 53) return 'Port Tender';
306
-		elseif ($code == 54) return 'Anti-pollution equipment';
307
-		elseif ($code == 55) return 'Law Enforcement';
308
-		elseif ($code == 56) return 'Spare - Local Vessel';
309
-		elseif ($code == 57) return 'Spare - Local Vessel';
310
-		elseif ($code == 58) return 'Medical Transport';
311
-		elseif ($code == 59) return 'Noncombatant ship according to RR Resolution No. 18';
312
-		elseif ($code == 60) return 'Passenger, all ships of this type';
313
-		elseif ($code == 61) return 'Passenger, Hazardous category A';
314
-		elseif ($code == 62) return 'Passenger, Hazardous category B';
315
-		elseif ($code == 63) return 'Passenger, Hazardous category C';
316
-		elseif ($code == 64) return 'Passenger, Hazardous category D';
317
-		elseif ($code == 65) return 'Passenger, Reserved for future use';
318
-		elseif ($code == 66) return 'Passenger, Reserved for future use';
319
-		elseif ($code == 67) return 'Passenger, Reserved for future use';
320
-		elseif ($code == 68) return 'Passenger, Reserved for future use';
321
-		elseif ($code == 69) return 'Passenger, No additional information';
322
-		elseif ($code == 70) return 'Cargo, all ships of this type';
323
-		elseif ($code == 71) return 'Cargo, Hazardous category A';
324
-		elseif ($code == 72) return 'Cargo, Hazardous category B';
325
-		elseif ($code == 73) return 'Cargo, Hazardous category C';
326
-		elseif ($code == 74) return 'Cargo, Hazardous category D';
327
-		elseif ($code == 75) return 'Cargo, Reserved for future use';
328
-		elseif ($code == 76) return 'Cargo, Reserved for future use';
329
-		elseif ($code == 77) return 'Cargo, Reserved for future use';
330
-		elseif ($code == 78) return 'Cargo, Reserved for future use';
331
-		elseif ($code == 79) return 'Cargo, No additional information';
332
-		elseif ($code == 80) return 'Tanker, all ships of this type';
333
-		elseif ($code == 81) return 'Tanker, Hazardous category A';
334
-		elseif ($code == 82) return 'Tanker, Hazardous category B';
335
-		elseif ($code == 83) return 'Tanker, Hazardous category C';
336
-		elseif ($code == 84) return 'Tanker, Hazardous category D';
337
-		elseif ($code == 85) return 'Tanker, Reserved for future use';
338
-		elseif ($code == 86) return 'Tanker, Reserved for future use';
339
-		elseif ($code == 87) return 'Tanker, Reserved for future use';
340
-		elseif ($code == 88) return 'Tanker, Reserved for future use';
341
-		elseif ($code == 89) return 'Tanker, No additional information';
342
-		elseif ($code == 90) return 'Other Type, all ships of this type';
343
-		elseif ($code == 91) return 'Other Type, Hazardous category A';
344
-		elseif ($code == 92) return 'Other Type, Hazardous category B';
345
-		elseif ($code == 93) return 'Other Type, Hazardous category C';
346
-		elseif ($code == 94) return 'Other Type, Hazardous category D';
347
-		elseif ($code == 95) return 'Other Type, Reserved for future use';
348
-		elseif ($code == 96) return 'Other Type, Reserved for future use';
349
-		elseif ($code == 97) return 'Other Type, Reserved for future use';
350
-		elseif ($code == 98) return 'Other Type, Reserved for future use';
351
-		elseif ($code == 99) return 'Other Type, no additional information';
280
+		if ($code == 0) {
281
+			return 'Not available (default)';
282
+		} elseif ($code >= 1 && $code <= 19) {
283
+			return 'Reserved for future use';
284
+		} elseif ($code == 20) {
285
+			return 'Wing in ground (WIG), all ships of this type';
286
+		} elseif ($code == 21) {
287
+			return 'Wing in ground (WIG), Hazardous category A';
288
+		} elseif ($code == 22) {
289
+			return 'Wing in ground (WIG), Hazardous category B';
290
+		} elseif ($code == 23) {
291
+			return 'Wing in ground (WIG), Hazardous category C';
292
+		} elseif ($code == 24) {
293
+			return 'Wing in ground (WIG), Hazardous category D';
294
+		} elseif ($code == 25) {
295
+			return 'Wing in ground (WIG), Reserved for future use';
296
+		} elseif ($code == 26) {
297
+			return 'Wing in ground (WIG), Reserved for future use';
298
+		} elseif ($code == 27) {
299
+			return 'Wing in ground (WIG), Reserved for future use';
300
+		} elseif ($code == 28) {
301
+			return 'Wing in ground (WIG), Reserved for future use';
302
+		} elseif ($code == 29) {
303
+			return 'Wing in ground (WIG), Reserved for future use';
304
+		} elseif ($code == 30) {
305
+			return 'Fishing';
306
+		} elseif ($code == 31) {
307
+			return 'Towing';
308
+		} elseif ($code == 32) {
309
+			return 'Towing: length exceeds 200m or breadth exceeds 25m';
310
+		} elseif ($code == 33) {
311
+			return 'Dredging or underwater ops';
312
+		} elseif ($code == 34) {
313
+			return 'Diving ops';
314
+		} elseif ($code == 35) {
315
+			return 'Military ops';
316
+		} elseif ($code == 36) {
317
+			return 'Sailing';
318
+		} elseif ($code == 37) {
319
+			return 'Pleasure Craft';
320
+		} elseif ($code == 38) {
321
+			return 'Reserved';
322
+		} elseif ($code == 39) {
323
+			return 'Reserved';
324
+		} elseif ($code == 40) {
325
+			return 'High speed craft (HSC), all ships of this type';
326
+		} elseif ($code == 41) {
327
+			return 'High speed craft (HSC), Hazardous category A';
328
+		} elseif ($code == 42) {
329
+			return 'High speed craft (HSC), Hazardous category B';
330
+		} elseif ($code == 43) {
331
+			return 'High speed craft (HSC), Hazardous category C';
332
+		} elseif ($code == 44) {
333
+			return 'High speed craft (HSC), Hazardous category D';
334
+		} elseif ($code == 45) {
335
+			return 'High speed craft (HSC), Reserved for future use';
336
+		} elseif ($code == 46) {
337
+			return 'High speed craft (HSC), Reserved for future use';
338
+		} elseif ($code == 47) {
339
+			return 'High speed craft (HSC), Reserved for future use';
340
+		} elseif ($code == 48) {
341
+			return 'High speed craft (HSC), Reserved for future use';
342
+		} elseif ($code == 49) {
343
+			return 'High speed craft (HSC), No additional information';
344
+		} elseif ($code == 50) {
345
+			return 'Pilot Vessel';
346
+		} elseif ($code == 51) {
347
+			return 'Search and Rescue vessel';
348
+		} elseif ($code == 52) {
349
+			return 'Tug';
350
+		} elseif ($code == 53) {
351
+			return 'Port Tender';
352
+		} elseif ($code == 54) {
353
+			return 'Anti-pollution equipment';
354
+		} elseif ($code == 55) {
355
+			return 'Law Enforcement';
356
+		} elseif ($code == 56) {
357
+			return 'Spare - Local Vessel';
358
+		} elseif ($code == 57) {
359
+			return 'Spare - Local Vessel';
360
+		} elseif ($code == 58) {
361
+			return 'Medical Transport';
362
+		} elseif ($code == 59) {
363
+			return 'Noncombatant ship according to RR Resolution No. 18';
364
+		} elseif ($code == 60) {
365
+			return 'Passenger, all ships of this type';
366
+		} elseif ($code == 61) {
367
+			return 'Passenger, Hazardous category A';
368
+		} elseif ($code == 62) {
369
+			return 'Passenger, Hazardous category B';
370
+		} elseif ($code == 63) {
371
+			return 'Passenger, Hazardous category C';
372
+		} elseif ($code == 64) {
373
+			return 'Passenger, Hazardous category D';
374
+		} elseif ($code == 65) {
375
+			return 'Passenger, Reserved for future use';
376
+		} elseif ($code == 66) {
377
+			return 'Passenger, Reserved for future use';
378
+		} elseif ($code == 67) {
379
+			return 'Passenger, Reserved for future use';
380
+		} elseif ($code == 68) {
381
+			return 'Passenger, Reserved for future use';
382
+		} elseif ($code == 69) {
383
+			return 'Passenger, No additional information';
384
+		} elseif ($code == 70) {
385
+			return 'Cargo, all ships of this type';
386
+		} elseif ($code == 71) {
387
+			return 'Cargo, Hazardous category A';
388
+		} elseif ($code == 72) {
389
+			return 'Cargo, Hazardous category B';
390
+		} elseif ($code == 73) {
391
+			return 'Cargo, Hazardous category C';
392
+		} elseif ($code == 74) {
393
+			return 'Cargo, Hazardous category D';
394
+		} elseif ($code == 75) {
395
+			return 'Cargo, Reserved for future use';
396
+		} elseif ($code == 76) {
397
+			return 'Cargo, Reserved for future use';
398
+		} elseif ($code == 77) {
399
+			return 'Cargo, Reserved for future use';
400
+		} elseif ($code == 78) {
401
+			return 'Cargo, Reserved for future use';
402
+		} elseif ($code == 79) {
403
+			return 'Cargo, No additional information';
404
+		} elseif ($code == 80) {
405
+			return 'Tanker, all ships of this type';
406
+		} elseif ($code == 81) {
407
+			return 'Tanker, Hazardous category A';
408
+		} elseif ($code == 82) {
409
+			return 'Tanker, Hazardous category B';
410
+		} elseif ($code == 83) {
411
+			return 'Tanker, Hazardous category C';
412
+		} elseif ($code == 84) {
413
+			return 'Tanker, Hazardous category D';
414
+		} elseif ($code == 85) {
415
+			return 'Tanker, Reserved for future use';
416
+		} elseif ($code == 86) {
417
+			return 'Tanker, Reserved for future use';
418
+		} elseif ($code == 87) {
419
+			return 'Tanker, Reserved for future use';
420
+		} elseif ($code == 88) {
421
+			return 'Tanker, Reserved for future use';
422
+		} elseif ($code == 89) {
423
+			return 'Tanker, No additional information';
424
+		} elseif ($code == 90) {
425
+			return 'Other Type, all ships of this type';
426
+		} elseif ($code == 91) {
427
+			return 'Other Type, Hazardous category A';
428
+		} elseif ($code == 92) {
429
+			return 'Other Type, Hazardous category B';
430
+		} elseif ($code == 93) {
431
+			return 'Other Type, Hazardous category C';
432
+		} elseif ($code == 94) {
433
+			return 'Other Type, Hazardous category D';
434
+		} elseif ($code == 95) {
435
+			return 'Other Type, Reserved for future use';
436
+		} elseif ($code == 96) {
437
+			return 'Other Type, Reserved for future use';
438
+		} elseif ($code == 97) {
439
+			return 'Other Type, Reserved for future use';
440
+		} elseif ($code == 98) {
441
+			return 'Other Type, Reserved for future use';
442
+		} elseif ($code == 99) {
443
+			return 'Other Type, no additional information';
444
+		}
352 445
 	}
353 446
 
354 447
 	public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) {
@@ -386,19 +479,34 @@  discard block
 block discarded – undo
386 479
 		// assume 1st ! is valid
387 480
 		// find * ensure that it is at correct position
388 481
 		$end = strrpos ( $rawdata , '*' );
389
-		if ($end === FALSE) return -1; // check for NULLS!!!
482
+		if ($end === FALSE) {
483
+			return -1;
484
+		}
485
+		// check for NULLS!!!
390 486
 		$cs = substr( $rawdata, $end + 1 );
391
-		if ( strlen($cs) != 2 ) return -1; // correct cs length
487
+		if ( strlen($cs) != 2 ) {
488
+			return -1;
489
+		}
490
+		// correct cs length
392 491
 		$dcs = (int)hexdec( $cs );
393
-		for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum
492
+		for ( $alias=1; $alias<$end; $alias++) {
493
+			$chksum ^= ord( $rawdata[$alias] );
494
+		}
495
+		// perform XOR for NMEA checksum
394 496
 		if ( $chksum == $dcs ) { // NMEA checksum pass
395 497
 			$pcs = explode(',', $rawdata);
396 498
 			// !AI??? identifier
397 499
 			$num_seq = (int)$pcs[1]; // number of sequences
398 500
 			$seq = (int)$pcs[2]; // get sequence
399 501
 			// get msg sequence id
400
-			if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1
401
-			else $msg_sid = (int)$pcs[3]; // multipart message
502
+			if ($pcs[3] == '') {
503
+				$msg_sid = -1;
504
+			}
505
+			// non-multipart message, set to -1
506
+			else {
507
+				$msg_sid = (int)$pcs[3];
508
+			}
509
+			// multipart message
402 510
 			$ais_ch = $pcs[4]; // get AIS channel
403 511
 			// message sequence checking
404 512
 			if ($num_seq < 1 || $num_seq > 9) {
@@ -459,10 +567,18 @@  discard block
 block discarded – undo
459 567
 				//DEBUG echo "[$start $end $tst]\n";
460 568
 				$result = $this->process_ais_raw( $tst, "" );
461 569
 				$last_pos = $end + 1;
462
-			} else break;
570
+			} else {
571
+				break;
572
+			}
573
+		}
574
+		if ($last_pos > 0) {
575
+			$cbuf = substr($cbuf, $last_pos);
463 576
 		}
464
-		if ($last_pos > 0) $cbuf = substr($cbuf, $last_pos); // move...
465
-		if (strlen($cbuf) > 1024) $cbuf = ""; // prevent overflow simple mode...
577
+		// move...
578
+		if (strlen($cbuf) > 1024) {
579
+			$cbuf = "";
580
+		}
581
+		// prevent overflow simple mode...
466 582
 		return $result;
467 583
 	}
468 584
 
@@ -482,7 +598,9 @@  discard block
 block discarded – undo
482 598
 		if ($lat<0.0) {
483 599
 			$lat = -$lat;
484 600
 			$neg=true;
485
-		} else $neg=false;
601
+		} else {
602
+			$neg=false;
603
+		}
486 604
 		$latd = 0x00000000;
487 605
 		$latd = intval ($lat * 600000.0);
488 606
 		if ($neg==true) {
@@ -498,7 +616,9 @@  discard block
 block discarded – undo
498 616
 		if ($lon<0.0) {
499 617
 			$lon = -$lon;
500 618
 			$neg=true;
501
-		} else $neg=false;
619
+		} else {
620
+			$neg=false;
621
+		}
502 622
 		$lond = 0x00000000;
503 623
 		$lond = intval ($lon * 600000.0);
504 624
 		if ($neg==true) {
@@ -511,9 +631,14 @@  discard block
 block discarded – undo
511 631
 
512 632
 	private function char2bin($name, $max_len) {
513 633
 		$len = strlen($name);
514
-		if ($len > $max_len) $name = substr($name,0,$max_len);
515
-		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6);
516
-		else $pad = '';
634
+		if ($len > $max_len) {
635
+			$name = substr($name,0,$max_len);
636
+		}
637
+		if ($len < $max_len) {
638
+			$pad = str_repeat('0', ($max_len - $len) * 6);
639
+		} else {
640
+			$pad = '';
641
+		}
517 642
 		$rv = '';
518 643
 		$ais_chars = array(
519 644
 		    '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9,
@@ -526,9 +651,12 @@  discard block
 block discarded – undo
526 651
 		);
527 652
 		// "
528 653
 		$_a = str_split($name);
529
-		if ($_a) foreach ($_a as $_1) {
654
+		if ($_a) {
655
+			foreach ($_a as $_1) {
530 656
 			if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1];
531
-			else $dec = 0;
657
+		} else {
658
+				$dec = 0;
659
+			}
532 660
 			$bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT);
533 661
 			$rv .= $bin;
534 662
 			//echo "$_1 $dec ($bin)<br/>";
@@ -540,7 +668,9 @@  discard block
 block discarded – undo
540 668
 		$len_bit = strlen($_enc);
541 669
 		$rem6 = $len_bit % 6;
542 670
 		$pad6_len = 0;
543
-		if ($rem6) $pad6_len = 6 - $rem6;
671
+		if ($rem6) {
672
+			$pad6_len = 6 - $rem6;
673
+		}
544 674
 		//echo  $pad6_len.'<br>';
545 675
 		$_enc .= str_repeat("0", $pad6_len); // pad the text...
546 676
 		$len_enc = strlen($_enc) / 6;
@@ -549,8 +679,11 @@  discard block
 block discarded – undo
549 679
 		for ($i=0; $i<$len_enc; $i++) {
550 680
 			$offset = $i * 6;
551 681
 			$dec = bindec(substr($_enc,$offset,6));
552
-			if ($dec < 40) $dec += 48;
553
-			else $dec += 56;
682
+			if ($dec < 40) {
683
+				$dec += 48;
684
+			} else {
685
+				$dec += 56;
686
+			}
554 687
 			//echo chr($dec)." $dec<br/>";
555 688
 			$itu .= chr($dec);
556 689
 		}
@@ -563,25 +696,41 @@  discard block
 block discarded – undo
563 696
 		}
564 697
 		$hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
565 698
 		$lsb = $chksum & 0x0F;
566
-		if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb];
567
-		else $lsbc = '0';
699
+		if ($lsb >=0 && $lsb <= 15 ) {
700
+			$lsbc = $hex_arr[$lsb];
701
+		} else {
702
+			$lsbc = '0';
703
+		}
568 704
 		$msb = (($chksum & 0xF0) >> 4) & 0x0F;
569
-		if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb];
570
-		else $msbc = '0';
705
+		if ($msb >=0 && $msb <= 15 ) {
706
+			$msbc = $hex_arr[$msb];
707
+		} else {
708
+			$msbc = '0';
709
+		}
571 710
 		$itu = '!'.$itu."*{$msbc}{$lsbc}\r\n";
572 711
 		return $itu;
573 712
 	}
574 713
 
575 714
 	public function parse($buffer) {
576 715
 		$data = $this->process_ais_buf($buffer);
577
-		if (!is_object($data)) return array();
578
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
579
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
716
+		if (!is_object($data)) {
717
+			return array();
718
+		}
719
+		if ($data->lon != 0) {
720
+			$result['longitude'] = $data->lon;
721
+		}
722
+		if ($data->lat != 0) {
723
+			$result['latitude'] = $data->lat;
724
+		}
580 725
 		$result['ident'] = trim($data->name);
581 726
 		$result['timestamp'] = $data->ts;
582 727
 		$result['mmsi'] = $data->mmsi;
583
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
584
-		if ($data->cog != 0) $result['heading'] = $data->cog;
728
+		if ($data->sog != -1.0) {
729
+			$result['speed'] = $data->sog;
730
+		}
731
+		if ($data->cog != 0) {
732
+			$result['heading'] = $data->cog;
733
+		}
585 734
 		/*
586 735
 		    $ro->cls = 0; // AIS class undefined, also indicate unparsed msg
587 736
 		    $ro->id = bindec(substr($_aisdata,0,6));
@@ -591,15 +740,25 @@  discard block
 block discarded – undo
591 740
 
592 741
 	public function mmsitype($mmsi) {
593 742
 		if (strlen($mmsi) == 9) {
594
-			if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
595
-			elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device';
596
-			elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)';
597
-			elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft';
598
-			elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship';
599
-			elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation';
600
-			elseif (substr($mmsi,0,2) == '00') return 'Coastal stations';
601
-			elseif (substr($mmsi,0,1) == '0') return 'Group of ships';
602
-			else return 'Ship';
743
+			if (substr($mmsi,0,3) == '974') {
744
+				return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
745
+			} elseif (substr($mmsi,0,3) == '972') {
746
+				return 'MOB (Man Overboard) device';
747
+			} elseif (substr($mmsi,0,3) == '970') {
748
+				return 'AIS SART (Search and Rescue Transmitter)';
749
+			} elseif (substr($mmsi,0,3) == '111') {
750
+				return 'SAR (Search and Rescue) aircraft';
751
+			} elseif (substr($mmsi,0,2) == '98') {
752
+				return 'Auxiliary craft associated with a parent ship';
753
+			} elseif (substr($mmsi,0,2) == '99') {
754
+				return 'Aids to Navigation';
755
+			} elseif (substr($mmsi,0,2) == '00') {
756
+				return 'Coastal stations';
757
+			} elseif (substr($mmsi,0,1) == '0') {
758
+				return 'Group of ships';
759
+			} else {
760
+				return 'Ship';
761
+			}
603 762
 		}
604 763
 
605 764
 	
@@ -616,25 +775,48 @@  discard block
 block discarded – undo
616 775
 			//if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n";
617 776
 			return array();
618 777
 		}
619
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
620
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
778
+		if ($data->lon != 0) {
779
+			$result['longitude'] = $data->lon;
780
+		}
781
+		if ($data->lat != 0) {
782
+			$result['latitude'] = $data->lat;
783
+		}
621 784
 		$result['ident'] = trim(str_replace('@','',$data->name));
622 785
 		$result['timestamp'] = $data->ts;
623 786
 		$result['mmsi'] = $data->mmsi;
624
-		if (strlen($result['mmsi']) == 8 && susbtr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
787
+		if (strlen($result['mmsi']) == 8 && susbtr($result['mmsi'],0,3) == '669') {
788
+			$result['mmsi'] = '3'.$result['mmsi'];
789
+		}
625 790
 		$result['mmsi_type'] = $this->mmsitype($result['mmsi']);
626
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
627
-		if ($data->heading != '') $result['heading'] = $data->heading;
628
-		elseif ($data->cog != 0) $result['heading'] = $data->cog;
629
-		if ($data->status != '') $result['status'] = $data->status;
630
-		if ($data->type != '') $result['type'] = $data->type;
631
-		if ($data->typeid != '') $result['typeid'] = $data->typeid;
632
-		if ($data->imo != '') $result['imo'] = $data->imo;
633
-		if ($data->callsign != '') $result['callsign'] = $data->callsign;
791
+		if ($data->sog != -1.0) {
792
+			$result['speed'] = $data->sog;
793
+		}
794
+		if ($data->heading != '') {
795
+			$result['heading'] = $data->heading;
796
+		} elseif ($data->cog != 0) {
797
+			$result['heading'] = $data->cog;
798
+		}
799
+		if ($data->status != '') {
800
+			$result['status'] = $data->status;
801
+		}
802
+		if ($data->type != '') {
803
+			$result['type'] = $data->type;
804
+		}
805
+		if ($data->typeid != '') {
806
+			$result['typeid'] = $data->typeid;
807
+		}
808
+		if ($data->imo != '') {
809
+			$result['imo'] = $data->imo;
810
+		}
811
+		if ($data->callsign != '') {
812
+			$result['callsign'] = $data->callsign;
813
+		}
634 814
 		if ($data->eta_month != '' && $data->eta_day != '' && $data->eta_hour != '' && $data->eta_minute != '') {
635 815
 			$result['eta_ts'] = strtotime(date('Y').'-'.$data->eta_month.'-'.$data->eta_day.' '.$data->eta_hour.':'.$data->eta_minute.':00');
636 816
 		}
637
-		if ($data->destination != '') $result['destination'] = $data->destination;
817
+		if ($data->destination != '') {
818
+			$result['destination'] = $data->destination;
819
+		}
638 820
 		$result['all'] = (array) $data;
639 821
 		/*
640 822
 		    $ro->cls = 0; // AIS class undefined, also indicate unparsed msg
Please login to merge, or discard this patch.
scripts/daemon-spotter.php 1 patch
Braces   +707 added lines, -244 removed lines patch added patch discarded remove patch
@@ -13,13 +13,17 @@  discard block
 block discarded – undo
13 13
 require_once(dirname(__FILE__).'/../require/class.SBS.php');
14 14
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
16
+if (isset($globalTracker) && $globalTracker) {
17
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18
+}
17 19
 if (isset($globalMarine) && $globalMarine) {
18 20
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
19 21
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 22
 }
21 23
 
22
-if (!isset($globalDebug)) $globalDebug = FALSE;
24
+if (!isset($globalDebug)) {
25
+	$globalDebug = FALSE;
26
+}
23 27
 
24 28
 // Check if schema is at latest version
25 29
 $Connection = new Connection();
@@ -59,19 +63,30 @@  discard block
 block discarded – undo
59 63
     $globalSources = array();
60 64
     $globalSources[] = array('host' => $options['source']);
61 65
 }
62
-if (isset($options['server'])) $globalServer = TRUE;
63
-if (isset($options['idsource'])) $id_source = $options['idsource'];
64
-else $id_source = 1;
66
+if (isset($options['server'])) {
67
+	$globalServer = TRUE;
68
+}
69
+if (isset($options['idsource'])) {
70
+	$id_source = $options['idsource'];
71
+} else {
72
+	$id_source = 1;
73
+}
65 74
 if (isset($globalServer) && $globalServer) {
66
-    if ($globalDebug) echo "Using Server Mode\n";
75
+    if ($globalDebug) {
76
+    	echo "Using Server Mode\n";
77
+    }
67 78
     $SI=new SpotterServer();
68 79
 /*
69 80
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
70 81
     $SI = new adsb2aprs();
71 82
     $SI->connect();
72 83
 */
73
-} else $SI=new SpotterImport($Connection->db);
74
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
84
+} else {
85
+	$SI=new SpotterImport($Connection->db);
86
+}
87
+if (isset($globalTracker) && $globalTracker) {
88
+	$TI = new TrackerImport($Connection->db);
89
+}
75 90
 if (isset($globalMarine) && $globalMarine) {
76 91
     $AIS = new AIS();
77 92
     $MI = new MarineImport($Connection->db);
@@ -93,7 +108,9 @@  discard block
 block discarded – undo
93 108
 }
94 109
 
95 110
 // let's try and connect
96
-if ($globalDebug) echo "Connecting...\n";
111
+if ($globalDebug) {
112
+	echo "Connecting...\n";
113
+}
97 114
 $use_aprs = false;
98 115
 $aprs_full = false;
99 116
 $reset = 0;
@@ -102,7 +119,9 @@  discard block
 block discarded – undo
102 119
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
103 120
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
104 121
     $reset++;
105
-    if ($globalDebug) echo 'Connect to all...'."\n";
122
+    if ($globalDebug) {
123
+    	echo 'Connect to all...'."\n";
124
+    }
106 125
     foreach ($hosts as $id => $value) {
107 126
 	$host = $value['host'];
108 127
 	$globalSources[$id]['last_exec'] = 0;
@@ -112,27 +131,37 @@  discard block
 block discarded – undo
112 131
         	//$formats[$id] = 'deltadbtxt';
113 132
         	$globalSources[$id]['format'] = 'deltadbtxt';
114 133
         	//$last_exec['deltadbtxt'] = 0;
115
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
134
+        	if ($globalDebug) {
135
+        		echo "Connect to deltadb source (".$host.")...\n";
136
+        	}
116 137
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
117 138
         	//$formats[$id] = 'vatsimtxt';
118 139
         	$globalSources[$id]['format'] = 'vatsimtxt';
119 140
         	//$last_exec['vatsimtxt'] = 0;
120
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
141
+        	if ($globalDebug) {
142
+        		echo "Connect to vatsim source (".$host.")...\n";
143
+        	}
121 144
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
122 145
         	//$formats[$id] = 'aircraftlistjson';
123 146
         	$globalSources[$id]['format'] = 'aircraftlistjson';
124 147
         	//$last_exec['aircraftlistjson'] = 0;
125
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
148
+        	if ($globalDebug) {
149
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
150
+        	}
126 151
     	    } else if (preg_match('/opensky/i',$host)) {
127 152
         	//$formats[$id] = 'aircraftlistjson';
128 153
         	$globalSources[$id]['format'] = 'opensky';
129 154
         	//$last_exec['aircraftlistjson'] = 0;
130
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
155
+        	if ($globalDebug) {
156
+        		echo "Connect to opensky source (".$host.")...\n";
157
+        	}
131 158
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
132 159
         	//$formats[$id] = 'radarvirtueljson';
133 160
         	$globalSources[$id]['format'] = 'radarvirtueljson';
134 161
         	//$last_exec['radarvirtueljson'] = 0;
135
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
162
+        	if ($globalDebug) {
163
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
164
+        	}
136 165
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
137 166
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
138 167
         	    exit(0);
@@ -141,7 +170,9 @@  discard block
 block discarded – undo
141 170
         	//$formats[$id] = 'planeupdatefaa';
142 171
         	$globalSources[$id]['format'] = 'planeupdatefaa';
143 172
         	//$last_exec['planeupdatefaa'] = 0;
144
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
173
+        	if ($globalDebug) {
174
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
175
+        	}
145 176
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
146 177
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
147 178
         	    exit(0);
@@ -150,26 +181,36 @@  discard block
 block discarded – undo
150 181
         	//$formats[$id] = 'phpvmacars';
151 182
         	$globalSources[$id]['format'] = 'phpvmacars';
152 183
         	//$last_exec['phpvmacars'] = 0;
153
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
184
+        	if ($globalDebug) {
185
+        		echo "Connect to phpvmacars source (".$host.")...\n";
186
+        	}
154 187
             } else if (preg_match('/VAM-json.php$/i',$host)) {
155 188
         	//$formats[$id] = 'phpvmacars';
156 189
         	$globalSources[$id]['format'] = 'vam';
157
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
190
+        	if ($globalDebug) {
191
+        		echo "Connect to Vam source (".$host.")...\n";
192
+        	}
158 193
             } else if (preg_match('/whazzup/i',$host)) {
159 194
         	//$formats[$id] = 'whazzup';
160 195
         	$globalSources[$id]['format'] = 'whazzup';
161 196
         	//$last_exec['whazzup'] = 0;
162
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
197
+        	if ($globalDebug) {
198
+        		echo "Connect to whazzup source (".$host.")...\n";
199
+        	}
163 200
             } else if (preg_match('/recentpireps/i',$host)) {
164 201
         	//$formats[$id] = 'pirepsjson';
165 202
         	$globalSources[$id]['format'] = 'pirepsjson';
166 203
         	//$last_exec['pirepsjson'] = 0;
167
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
204
+        	if ($globalDebug) {
205
+        		echo "Connect to pirepsjson source (".$host.")...\n";
206
+        	}
168 207
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
169 208
         	//$formats[$id] = 'fr24json';
170 209
         	$globalSources[$id]['format'] = 'fr24json';
171 210
         	//$last_exec['fr24json'] = 0;
172
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
211
+        	if ($globalDebug) {
212
+        		echo "Connect to fr24 source (".$host.")...\n";
213
+        	}
173 214
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
174 215
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
175 216
         	    exit(0);
@@ -178,7 +219,9 @@  discard block
 block discarded – undo
178 219
         	//$formats[$id] = 'fr24json';
179 220
         	$globalSources[$id]['format'] = 'myshiptracking';
180 221
         	//$last_exec['fr24json'] = 0;
181
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
222
+        	if ($globalDebug) {
223
+        		echo "Connect to myshiptracking source (".$host.")...\n";
224
+        	}
182 225
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
183 226
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
184 227
         	    exit(0);
@@ -187,17 +230,24 @@  discard block
 block discarded – undo
187 230
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188 231
         	//$formats[$id] = 'tsv';
189 232
         	$globalSources[$id]['format'] = 'tsv';
190
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
233
+        	if ($globalDebug) {
234
+        		echo "Connect to tsv source (".$host.")...\n";
235
+        	}
191 236
             }
192 237
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
193 238
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
194 239
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
195 240
     		    if ($idf !== false) {
196 241
     			$httpfeeds[$id] = $idf;
197
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
242
+        		if ($globalDebug) {
243
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
244
+        		}
245
+    		    } elseif ($globalDebug) {
246
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
198 247
     		    }
199
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
200
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
248
+    		} elseif ($globalDebug) {
249
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
250
+    		}
201 251
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
202 252
 	    $hostport = explode(':',$host);
203 253
 	    if (isset($hostport[1])) {
@@ -235,17 +285,25 @@  discard block
 block discarded – undo
235 285
         		//$formats[$id] = 'beast';
236 286
         		$globalSources[$id]['format'] = 'beast';
237 287
 		    //} else $formats[$id] = 'sbs';
238
-		    } else $globalSources[$id]['format'] = 'sbs';
288
+		    } else {
289
+		    	$globalSources[$id]['format'] = 'sbs';
290
+		    }
239 291
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
240 292
 		}
241
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
293
+		if ($globalDebug) {
294
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
295
+		}
242 296
             } else {
243
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
297
+		if ($globalDebug) {
298
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
299
+		}
244 300
     	    }
245 301
         }
246 302
     }
247 303
 }
248
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
304
+if (!isset($globalMinFetch)) {
305
+	$globalMinFetch = 15;
306
+}
249 307
 
250 308
 // Initialize all
251 309
 $status = array();
@@ -254,13 +312,19 @@  discard block
 block discarded – undo
254 312
 $formats = array();
255 313
 $last_exec = array();
256 314
 $time = time();
257
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
258
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
259
-else $timeout = 20;
315
+if (isset($globalSourcesTimeout)) {
316
+	$timeout = $globalSourcesTimeOut;
317
+} else if (isset($globalSBS1TimeOut)) {
318
+	$timeout = $globalSBS1TimeOut;
319
+} else {
320
+	$timeout = 20;
321
+}
260 322
 $errno = '';
261 323
 $errstr='';
262 324
 
263
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
325
+if (!isset($globalDaemon)) {
326
+	$globalDaemon = TRUE;
327
+}
264 328
 /* Initiate connections to all the hosts simultaneously */
265 329
 //connect_all($hosts);
266 330
 //connect_all($globalSources);
@@ -286,7 +350,9 @@  discard block
 block discarded – undo
286 350
     if (isset($source['format']) && $source['format'] == 'aprs') {
287 351
 	$aprs_connect = 0;
288 352
 	$use_aprs = true;
289
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
353
+	if (isset($source['port']) && $source['port'] == '10152') {
354
+		$aprs_full = true;
355
+	}
290 356
 	break;
291 357
     }
292 358
 }
@@ -297,25 +363,48 @@  discard block
 block discarded – undo
297 363
 	$aprs_connect = 0;
298 364
 	$aprs_keep = 120;
299 365
 	$aprs_last_tx = time();
300
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
301
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
302
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
303
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
304
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
305
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
306
-	if ($aprs_full) $aprs_filter = '';
307
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
308
-	else $aprs_pass = '-1';
366
+	if (isset($globalAPRSversion)) {
367
+		$aprs_version = $globalAPRSversion;
368
+	} else {
369
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
370
+	}
371
+	if (isset($globalAPRSssid)) {
372
+		$aprs_ssid = $globalAPRSssid;
373
+	} else {
374
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
375
+	}
376
+	if (isset($globalAPRSfilter)) {
377
+		$aprs_filter = $globalAPRSfilter;
378
+	} else {
379
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
380
+	}
381
+	if ($aprs_full) {
382
+		$aprs_filter = '';
383
+	}
384
+	if (isset($globalAPRSpass)) {
385
+		$aprs_pass = $globalAPRSpass;
386
+	} else {
387
+		$aprs_pass = '-1';
388
+	}
309 389
 
310
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
311
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
312
-}
390
+	if ($aprs_filter != '') {
391
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
392
+	} else {
393
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
394
+	}
395
+	}
313 396
 
314 397
 // connected - lets do some work
315
-if ($globalDebug) echo "Connected!\n";
398
+if ($globalDebug) {
399
+	echo "Connected!\n";
400
+}
316 401
 sleep(1);
317
-if ($globalDebug) echo "SCAN MODE \n\n";
318
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
402
+if ($globalDebug) {
403
+	echo "SCAN MODE \n\n";
404
+}
405
+if (!isset($globalCronEnd)) {
406
+	$globalCronEnd = 60;
407
+}
319 408
 $endtime = time()+$globalCronEnd;
320 409
 $i = 1;
321 410
 $tt = array();
@@ -329,10 +418,14 @@  discard block
 block discarded – undo
329 418
 
330 419
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
331 420
 while ($i > 0) {
332
-    if (!$globalDaemon) $i = $endtime-time();
421
+    if (!$globalDaemon) {
422
+    	$i = $endtime-time();
423
+    }
333 424
     // Delete old ATC
334 425
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
335
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
426
+	if ($globalDebug) {
427
+		echo 'Delete old ATC...'."\n";
428
+	}
336 429
         $ATC->deleteOldATC();
337 430
     }
338 431
     
@@ -340,10 +433,14 @@  discard block
 block discarded – undo
340 433
     if (count($last_exec) == count($globalSources)) {
341 434
 	$max = $globalMinFetch;
342 435
 	foreach ($last_exec as $last) {
343
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
436
+	    if ((time() - $last['last']) < $max) {
437
+	    	$max = time() - $last['last'];
438
+	    }
344 439
 	}
345 440
 	if ($max != $globalMinFetch) {
346
-	    if ($globalDebug) echo 'Sleeping...'."\n";
441
+	    if ($globalDebug) {
442
+	    	echo 'Sleeping...'."\n";
443
+	    }
347 444
 	    sleep($globalMinFetch-$max+2);
348 445
 	}
349 446
     }
@@ -352,11 +449,15 @@  discard block
 block discarded – undo
352 449
     //foreach ($formats as $id => $value) {
353 450
     foreach ($globalSources as $id => $value) {
354 451
 	date_default_timezone_set('UTC');
355
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
452
+	if (!isset($last_exec[$id]['last'])) {
453
+		$last_exec[$id]['last'] = 0;
454
+	}
356 455
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
357 456
 	    //$buffer = $Common->getData($hosts[$id]);
358 457
 	    $buffer = $Common->getData($value['host']);
359
-	    if ($buffer != '') $reset = 0;
458
+	    if ($buffer != '') {
459
+	    	$reset = 0;
460
+	    }
360 461
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
361 462
 	    $buffer = explode('\n',$buffer);
362 463
 	    foreach ($buffer as $line) {
@@ -365,19 +466,38 @@  discard block
 block discarded – undo
365 466
 	            $data = array();
366 467
 	            $data['hex'] = $line[1]; // hex
367 468
 	            $data['ident'] = $line[2]; // ident
368
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
369
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
370
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
371
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
372
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
469
+	            if (isset($line[3])) {
470
+	            	$data['altitude'] = $line[3];
471
+	            }
472
+	            // altitude
473
+	            if (isset($line[4])) {
474
+	            	$data['speed'] = $line[4];
475
+	            }
476
+	            // speed
477
+	            if (isset($line[5])) {
478
+	            	$data['heading'] = $line[5];
479
+	            }
480
+	            // heading
481
+	            if (isset($line[6])) {
482
+	            	$data['latitude'] = $line[6];
483
+	            }
484
+	            // lat
485
+	            if (isset($line[7])) {
486
+	            	$data['longitude'] = $line[7];
487
+	            }
488
+	            // long
373 489
 	            $data['verticalrate'] = ''; // vertical rate
374 490
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
375 491
 	            $data['emergency'] = ''; // emergency
376 492
 		    $data['datetime'] = date('Y-m-d H:i:s');
377 493
 		    $data['format_source'] = 'deltadbtxt';
378 494
     		    $data['id_source'] = $id_source;
379
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
380
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
495
+		    if (isset($value['name']) && $value['name'] != '') {
496
+		    	$data['source_name'] = $value['name'];
497
+		    }
498
+		    if (isset($value['sourcestats'])) {
499
+		    	$data['sourcestats'] = $value['sourcestats'];
500
+		    }
381 501
     		    $SI->add($data);
382 502
 		    unset($data);
383 503
     		}
@@ -387,7 +507,9 @@  discard block
 block discarded – undo
387 507
 	    date_default_timezone_set('CET');
388 508
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
389 509
 	    date_default_timezone_set('UTC');
390
-	    if ($buffer != '') $reset = 0;
510
+	    if ($buffer != '') {
511
+	    	$reset = 0;
512
+	    }
391 513
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
392 514
 	    $buffer = explode('\n',$buffer);
393 515
 	    foreach ($buffer as $line) {
@@ -396,16 +518,36 @@  discard block
 block discarded – undo
396 518
 		    $add = false;
397 519
 		    $ais_data = $AIS->parse_line(trim($line));
398 520
 		    $data = array();
399
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
400
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
401
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
402
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
403
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
404
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
405
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
406
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
407
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
408
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
521
+		    if (isset($ais_data['ident'])) {
522
+		    	$data['ident'] = $ais_data['ident'];
523
+		    }
524
+		    if (isset($ais_data['mmsi'])) {
525
+		    	$data['mmsi'] = $ais_data['mmsi'];
526
+		    }
527
+		    if (isset($ais_data['speed'])) {
528
+		    	$data['speed'] = $ais_data['speed'];
529
+		    }
530
+		    if (isset($ais_data['heading'])) {
531
+		    	$data['heading'] = $ais_data['heading'];
532
+		    }
533
+		    if (isset($ais_data['latitude'])) {
534
+		    	$data['latitude'] = $ais_data['latitude'];
535
+		    }
536
+		    if (isset($ais_data['longitude'])) {
537
+		    	$data['longitude'] = $ais_data['longitude'];
538
+		    }
539
+		    if (isset($ais_data['status'])) {
540
+		    	$data['status'] = $ais_data['status'];
541
+		    }
542
+		    if (isset($ais_data['type'])) {
543
+		    	$data['type'] = $ais_data['type'];
544
+		    }
545
+		    if (isset($ais_data['imo'])) {
546
+		    	$data['imo'] = $ais_data['imo'];
547
+		    }
548
+		    if (isset($ais_data['callsign'])) {
549
+		    	$data['callsign'] = $ais_data['callsign'];
550
+		    }
409 551
 		    if (isset($ais_data['timestamp'])) {
410 552
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
411 553
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -420,7 +562,9 @@  discard block
 block discarded – undo
420 562
     		    $data['id_source'] = $id_source;
421 563
 		    print_r($data);
422 564
 		    echo 'Add...'."\n";
423
-		    if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
565
+		    if ($add && $ais_data['mmsi_type'] == 'Ship') {
566
+		    	$MI->add($data);
567
+		    }
424 568
 		    unset($data);
425 569
 		}
426 570
     	    }
@@ -440,18 +584,42 @@  discard block
 block discarded – undo
440 584
 			if ($line != '') {
441 585
 			    $ais_data = $AIS->parse_line(trim($line));
442 586
 			    $data = array();
443
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
444
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
445
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
446
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
447
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
448
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
449
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
450
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
451
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
452
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
453
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
454
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
587
+			    if (isset($ais_data['ident'])) {
588
+			    	$data['ident'] = $ais_data['ident'];
589
+			    }
590
+			    if (isset($ais_data['mmsi'])) {
591
+			    	$data['mmsi'] = $ais_data['mmsi'];
592
+			    }
593
+			    if (isset($ais_data['speed'])) {
594
+			    	$data['speed'] = $ais_data['speed'];
595
+			    }
596
+			    if (isset($ais_data['heading'])) {
597
+			    	$data['heading'] = $ais_data['heading'];
598
+			    }
599
+			    if (isset($ais_data['latitude'])) {
600
+			    	$data['latitude'] = $ais_data['latitude'];
601
+			    }
602
+			    if (isset($ais_data['longitude'])) {
603
+			    	$data['longitude'] = $ais_data['longitude'];
604
+			    }
605
+			    if (isset($ais_data['status'])) {
606
+			    	$data['status'] = $ais_data['status'];
607
+			    }
608
+			    if (isset($ais_data['type'])) {
609
+			    	$data['type'] = $ais_data['type'];
610
+			    }
611
+			    if (isset($ais_data['imo'])) {
612
+			    	$data['imo'] = $ais_data['imo'];
613
+			    }
614
+			    if (isset($ais_data['callsign'])) {
615
+			    	$data['callsign'] = $ais_data['callsign'];
616
+			    }
617
+			    if (isset($ais_data['destination'])) {
618
+			    	$data['arrival_code'] = $ais_data['destination'];
619
+			    }
620
+			    if (isset($ais_data['eta_ts'])) {
621
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
622
+			    }
455 623
 			    if (isset($ais_data['timestamp'])) {
456 624
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
457 625
 			    } else {
@@ -459,7 +627,9 @@  discard block
 block discarded – undo
459 627
 			    }
460 628
 			    $data['format_source'] = 'aisnmeahttp';
461 629
 			    $data['id_source'] = $id_source;
462
-			    if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
630
+			    if ($ais_data['mmsi_type'] == 'Ship') {
631
+			    	$MI->add($data);
632
+			    }
463 633
 			    unset($data);
464 634
 			}
465 635
 		    }
@@ -512,7 +682,9 @@  discard block
 block discarded – undo
512 682
 			$data['callsign'] = $line['callsign'];
513 683
 			$data['mmsi'] = $line['mmsi'];
514 684
 			$data['speed'] = $line['sog'];
515
-			if ($line['heading'] != '511') $data['heading'] = $line['heading'];
685
+			if ($line['heading'] != '511') {
686
+				$data['heading'] = $line['heading'];
687
+			}
516 688
 			$data['latitude'] = $line['latitude'];
517 689
 			$data['longitude'] = $line['longitude'];
518 690
 			$data['type_id'] = $line['shiptype'];
@@ -532,7 +704,9 @@  discard block
 block discarded – undo
532 704
 	    echo 'download...';
533 705
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
534 706
 	    echo 'done !'."\n";
535
-	    if ($buffer != '') $reset = 0;
707
+	    if ($buffer != '') {
708
+	    	$reset = 0;
709
+	    }
536 710
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537 711
 	    $buffer = explode('\n',$buffer);
538 712
 	    foreach ($buffer as $line) {
@@ -576,16 +750,28 @@  discard block
 block discarded – undo
576 750
     		    $line = explode(':', $line);
577 751
     		    if (count($line) > 30 && $line[0] != 'callsign') {
578 752
 			$data = array();
579
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
580
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
753
+			if (isset($line[37]) && $line[37] != '') {
754
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
755
+			} else {
756
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
757
+			}
581 758
 			$data['pilot_id'] = $line[1];
582 759
 			$data['pilot_name'] = $line[2];
583 760
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
584 761
 			$data['ident'] = $line[0]; // ident
585
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
762
+			if ($line[7] != '' && $line[7] != 0) {
763
+				$data['altitude'] = $line[7];
764
+			}
765
+			// altitude
586 766
 			$data['speed'] = $line[8]; // speed
587
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
588
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
767
+			if (isset($line[45])) {
768
+				$data['heading'] = $line[45];
769
+			}
770
+			// heading
771
+			elseif (isset($line[38])) {
772
+				$data['heading'] = $line[38];
773
+			}
774
+			// heading
589 775
 			$data['latitude'] = $line[5]; // lat
590 776
 	        	$data['longitude'] = $line[6]; // long
591 777
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -601,7 +787,9 @@  discard block
 block discarded – undo
601 787
 			$data['frequency'] = $line[4];
602 788
 			$data['type'] = $line[18];
603 789
 			$data['range'] = $line[19];
604
-			if (isset($line[35])) $data['info'] = $line[35];
790
+			if (isset($line[35])) {
791
+				$data['info'] = $line[35];
792
+			}
605 793
     			$data['id_source'] = $id_source;
606 794
 	    		//$data['arrival_airport_time'] = ;
607 795
 	    		if ($line[9] != '') {
@@ -615,24 +803,41 @@  discard block
 block discarded – undo
615 803
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
616 804
 	    		*/
617 805
 	    		$data['format_source'] = $value['format'];
618
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
619
-    			if ($line[3] == 'PILOT') $SI->add($data);
620
-			elseif ($line[3] == 'ATC') {
806
+			if (isset($value['name']) && $value['name'] != '') {
807
+				$data['source_name'] = $value['name'];
808
+			}
809
+    			if ($line[3] == 'PILOT') {
810
+    				$SI->add($data);
811
+    			} elseif ($line[3] == 'ATC') {
621 812
 				//print_r($data);
622 813
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
623 814
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
624 815
 				$typec = substr($data['ident'],-3);
625
-				if ($typec == 'APP') $data['type'] = 'Approach';
626
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
627
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
628
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
629
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
630
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
631
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
632
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
633
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
634
-				if (!isset($data['source_name'])) $data['source_name'] = '';
635
-				if (isset($ATC)) 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']);
816
+				if ($typec == 'APP') {
817
+					$data['type'] = 'Approach';
818
+				} elseif ($typec == 'TWR') {
819
+					$data['type'] = 'Tower';
820
+				} elseif ($typec == 'OBS') {
821
+					$data['type'] = 'Observer';
822
+				} elseif ($typec == 'GND') {
823
+					$data['type'] = 'Ground';
824
+				} elseif ($typec == 'DEL') {
825
+					$data['type'] = 'Delivery';
826
+				} elseif ($typec == 'DEP') {
827
+					$data['type'] = 'Departure';
828
+				} elseif ($typec == 'FSS') {
829
+					$data['type'] = 'Flight Service Station';
830
+				} elseif ($typec == 'CTR') {
831
+					$data['type'] = 'Control Radar or Centre';
832
+				} elseif ($data['type'] == '') {
833
+					$data['type'] = 'Observer';
834
+				}
835
+				if (!isset($data['source_name'])) {
836
+					$data['source_name'] = '';
837
+				}
838
+				if (isset($ATC)) {
839
+					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']);
840
+				}
636 841
 			}
637 842
     			unset($data);
638 843
     		    }
@@ -651,26 +856,55 @@  discard block
 block discarded – undo
651 856
 		foreach ($all_data['acList'] as $line) {
652 857
 		    $data = array();
653 858
 		    $data['hex'] = $line['Icao']; // hex
654
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
655
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
656
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
657
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
658
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
659
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
859
+		    if (isset($line['Call'])) {
860
+		    	$data['ident'] = $line['Call'];
861
+		    }
862
+		    // ident
863
+		    if (isset($line['Alt'])) {
864
+		    	$data['altitude'] = $line['Alt'];
865
+		    }
866
+		    // altitude
867
+		    if (isset($line['Spd'])) {
868
+		    	$data['speed'] = $line['Spd'];
869
+		    }
870
+		    // speed
871
+		    if (isset($line['Trak'])) {
872
+		    	$data['heading'] = $line['Trak'];
873
+		    }
874
+		    // heading
875
+		    if (isset($line['Lat'])) {
876
+		    	$data['latitude'] = $line['Lat'];
877
+		    }
878
+		    // lat
879
+		    if (isset($line['Long'])) {
880
+		    	$data['longitude'] = $line['Long'];
881
+		    }
882
+		    // long
660 883
 		    //$data['verticalrate'] = $line['']; // verticale rate
661
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
884
+		    if (isset($line['Sqk'])) {
885
+		    	$data['squawk'] = $line['Sqk'];
886
+		    }
887
+		    // squawk
662 888
 		    $data['emergency'] = ''; // emergency
663
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
889
+		    if (isset($line['Reg'])) {
890
+		    	$data['registration'] = $line['Reg'];
891
+		    }
664 892
 		    /*
665 893
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
666 894
 		    else $data['datetime'] = date('Y-m-d H:i:s');
667 895
 		    */
668 896
 		    $data['datetime'] = date('Y-m-d H:i:s');
669
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
897
+		    if (isset($line['Type'])) {
898
+		    	$data['aircraft_icao'] = $line['Type'];
899
+		    }
670 900
 	    	    $data['format_source'] = 'aircraftlistjson';
671 901
 		    $data['id_source'] = $id_source;
672
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
673
-		    if (isset($data['datetime'])) $SI->add($data);
902
+		    if (isset($value['name']) && $value['name'] != '') {
903
+		    	$data['source_name'] = $value['name'];
904
+		    }
905
+		    if (isset($data['datetime'])) {
906
+		    	$SI->add($data);
907
+		    }
674 908
 		    unset($data);
675 909
 		}
676 910
 	    } else {
@@ -690,7 +924,9 @@  discard block
 block discarded – undo
690 924
 		    $data['datetime'] = date('Y-m-d H:i:s');
691 925
 	    	    $data['format_source'] = 'aircraftlistjson';
692 926
     		    $data['id_source'] = $id_source;
693
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
927
+		    if (isset($value['name']) && $value['name'] != '') {
928
+		    	$data['source_name'] = $value['name'];
929
+		    }
694 930
 		    $SI->add($data);
695 931
 		    unset($data);
696 932
 		}
@@ -726,7 +962,9 @@  discard block
 block discarded – undo
726 962
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
727 963
 	    	    $data['format_source'] = 'planeupdatefaa';
728 964
     		    $data['id_source'] = $id_source;
729
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
965
+		    if (isset($value['name']) && $value['name'] != '') {
966
+		    	$data['source_name'] = $value['name'];
967
+		    }
730 968
 		    $SI->add($data);
731 969
 		    unset($data);
732 970
 		}
@@ -766,7 +1004,9 @@  discard block
 block discarded – undo
766 1004
 	    //$buffer = $Common->getData($hosts[$id]);
767 1005
 	    $buffer = $Common->getData($value['host']);
768 1006
 	    $all_data = json_decode($buffer,true);
769
-	    if (!empty($all_data)) $reset = 0;
1007
+	    if (!empty($all_data)) {
1008
+	    	$reset = 0;
1009
+	    }
770 1010
 	    foreach ($all_data as $key => $line) {
771 1011
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
772 1012
 		    $data = array();
@@ -787,7 +1027,9 @@  discard block
 block discarded – undo
787 1027
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
788 1028
 	    	    $data['format_source'] = 'fr24json';
789 1029
     		    $data['id_source'] = $id_source;
790
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1030
+		    if (isset($value['name']) && $value['name'] != '') {
1031
+		    	$data['source_name'] = $value['name'];
1032
+		    }
791 1033
 		    $SI->add($data);
792 1034
 		    unset($data);
793 1035
 		}
@@ -811,23 +1053,39 @@  discard block
 block discarded – undo
811 1053
 		    if (isset($line['inf'])) {
812 1054
 			$data = array();
813 1055
 			$data['hex'] = $line['inf']['ia'];
814
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1056
+			if (isset($line['inf']['cs'])) {
1057
+				$data['ident'] = $line['inf']['cs'];
1058
+			}
1059
+			//$line[13]
815 1060
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
816
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
817
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1061
+	    		if (isset($line['inf']['gs'])) {
1062
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1063
+	    		}
1064
+	    		// speed
1065
+	    		if (isset($line['inf']['tr'])) {
1066
+	    			$data['heading'] = $line['inf']['tr'];
1067
+	    		}
1068
+	    		// heading
818 1069
 	    		$data['latitude'] = $line['pt'][0]; // lat
819 1070
 	    		$data['longitude'] = $line['pt'][1]; // long
820 1071
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
821
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1072
+	    		if (isset($line['inf']['sq'])) {
1073
+	    			$data['squawk'] = $line['inf']['sq'];
1074
+	    		}
1075
+	    		// squawk
822 1076
 	    		//$data['aircraft_icao'] = $line[8];
823
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1077
+	    		if (isset($line['inf']['rc'])) {
1078
+	    			$data['registration'] = $line['inf']['rc'];
1079
+	    		}
824 1080
 			//$data['departure_airport_iata'] = $line[11];
825 1081
 			//$data['arrival_airport_iata'] = $line[12];
826 1082
 	    		//$data['emergency'] = ''; // emergency
827 1083
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
828 1084
 	    		$data['format_source'] = 'radarvirtueljson';
829 1085
     			$data['id_source'] = $id_source;
830
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1086
+			if (isset($value['name']) && $value['name'] != '') {
1087
+				$data['source_name'] = $value['name'];
1088
+			}
831 1089
 			$SI->add($data);
832 1090
 			unset($data);
833 1091
 		    }
@@ -848,29 +1106,62 @@  discard block
 block discarded – undo
848 1106
 		    $data['id'] = $line['id'];
849 1107
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
850 1108
 		    $data['ident'] = $line['callsign']; // ident
851
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
852
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
853
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
854
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
855
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
856
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1109
+		    if (isset($line['pilotid'])) {
1110
+		    	$data['pilot_id'] = $line['pilotid'];
1111
+		    }
1112
+		    // pilot id
1113
+		    if (isset($line['name'])) {
1114
+		    	$data['pilot_name'] = $line['name'];
1115
+		    }
1116
+		    // pilot name
1117
+		    if (isset($line['alt'])) {
1118
+		    	$data['altitude'] = $line['alt'];
1119
+		    }
1120
+		    // altitude
1121
+		    if (isset($line['gs'])) {
1122
+		    	$data['speed'] = $line['gs'];
1123
+		    }
1124
+		    // speed
1125
+		    if (isset($line['heading'])) {
1126
+		    	$data['heading'] = $line['heading'];
1127
+		    }
1128
+		    // heading
1129
+		    if (isset($line['route'])) {
1130
+		    	$data['waypoints'] = $line['route'];
1131
+		    }
1132
+		    // route
857 1133
 		    $data['latitude'] = $line['lat']; // lat
858 1134
 		    $data['longitude'] = $line['lon']; // long
859 1135
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
860 1136
 		    //$data['squawk'] = $line['squawk']; // squawk
861 1137
 		    //$data['emergency'] = ''; // emergency
862
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
863
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
864
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1138
+		    if (isset($line['depicao'])) {
1139
+		    	$data['departure_airport_icao'] = $line['depicao'];
1140
+		    }
1141
+		    if (isset($line['deptime'])) {
1142
+		    	$data['departure_airport_time'] = $line['deptime'];
1143
+		    }
1144
+		    if (isset($line['arricao'])) {
1145
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1146
+		    }
865 1147
 		    //$data['arrival_airport_time'] = $line['arrtime'];
866
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
867
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
868
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
869
-		    else $data['info'] = '';
1148
+		    if (isset($line['aircraft'])) {
1149
+		    	$data['aircraft_icao'] = $line['aircraft'];
1150
+		    }
1151
+		    if (isset($line['transponder'])) {
1152
+		    	$data['squawk'] = $line['transponder'];
1153
+		    }
1154
+		    if (isset($line['atis'])) {
1155
+		    	$data['info'] = $line['atis'];
1156
+		    } else {
1157
+		    	$data['info'] = '';
1158
+		    }
870 1159
 		    $data['format_source'] = 'pireps';
871 1160
     		    $data['id_source'] = $id_source;
872 1161
 		    $data['datetime'] = date('Y-m-d H:i:s');
873
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1162
+		    if (isset($value['name']) && $value['name'] != '') {
1163
+		    	$data['source_name'] = $value['name'];
1164
+		    }
874 1165
 		    if ($line['icon'] == 'plane') {
875 1166
 			$SI->add($data);
876 1167
 		    //    print_r($data);
@@ -879,16 +1170,28 @@  discard block
 block discarded – undo
879 1170
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
880 1171
 			$typec = substr($data['ident'],-3);
881 1172
 			$data['type'] = '';
882
-			if ($typec == 'APP') $data['type'] = 'Approach';
883
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
884
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
885
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
886
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
887
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
888
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
889
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
890
-			else $data['type'] = 'Observer';
891
-			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']);
1173
+			if ($typec == 'APP') {
1174
+				$data['type'] = 'Approach';
1175
+			} elseif ($typec == 'TWR') {
1176
+				$data['type'] = 'Tower';
1177
+			} elseif ($typec == 'OBS') {
1178
+				$data['type'] = 'Observer';
1179
+			} elseif ($typec == 'GND') {
1180
+				$data['type'] = 'Ground';
1181
+			} elseif ($typec == 'DEL') {
1182
+				$data['type'] = 'Delivery';
1183
+			} elseif ($typec == 'DEP') {
1184
+				$data['type'] = 'Departure';
1185
+			} elseif ($typec == 'FSS') {
1186
+				$data['type'] = 'Flight Service Station';
1187
+			} elseif ($typec == 'CTR') {
1188
+				$data['type'] = 'Control Radar or Centre';
1189
+			} else {
1190
+				$data['type'] = 'Observer';
1191
+			}
1192
+			if (isset($ATC)) {
1193
+				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']);
1194
+			}
892 1195
 		    }
893 1196
 		    unset($data);
894 1197
 		}
@@ -898,7 +1201,9 @@  discard block
 block discarded – undo
898 1201
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
899 1202
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
900 1203
 	    //$buffer = $Common->getData($hosts[$id]);
901
-	    if ($globalDebug) echo 'Get Data...'."\n";
1204
+	    if ($globalDebug) {
1205
+	    	echo 'Get Data...'."\n";
1206
+	    }
902 1207
 	    $buffer = $Common->getData($value['host']);
903 1208
 	    $all_data = json_decode($buffer,true);
904 1209
 	    if ($buffer != '' && is_array($all_data)) {
@@ -906,10 +1211,16 @@  discard block
 block discarded – undo
906 1211
 		foreach ($all_data as $line) {
907 1212
 	    	    $data = array();
908 1213
 	    	    //$data['id'] = $line['id']; // id not usable
909
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1214
+	    	    if (isset($line['pilotid'])) {
1215
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1216
+	    	    }
910 1217
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
911
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
912
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1218
+	    	    if (isset($line['pilotname'])) {
1219
+	    	    	$data['pilot_name'] = $line['pilotname'];
1220
+	    	    }
1221
+	    	    if (isset($line['pilotid'])) {
1222
+	    	    	$data['pilot_id'] = $line['pilotid'];
1223
+	    	    }
913 1224
 	    	    $data['ident'] = $line['flightnum']; // ident
914 1225
 	    	    $data['altitude'] = $line['alt']; // altitude
915 1226
 	    	    $data['speed'] = $line['gs']; // speed
@@ -927,27 +1238,41 @@  discard block
 block discarded – undo
927 1238
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
928 1239
     		    $data['arrival_airport_time'] = $line['arrtime'];
929 1240
     		    $data['registration'] = $line['aircraft'];
930
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1241
+		    if (isset($line['route'])) {
1242
+		    	$data['waypoints'] = $line['route'];
1243
+		    }
1244
+		    // route
931 1245
 		    if (isset($line['aircraftname'])) {
932 1246
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
933 1247
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
934 1248
 	    		$aircraft_data = explode('-',$line['aircraftname']);
935
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
936
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
937
-	    		else {
1249
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) {
1250
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1251
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) {
1252
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1253
+	    		} else {
938 1254
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
939
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
940
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
1255
+	    		    if (isset($aircraft_data[1])) {
1256
+	    		    	$data['aircraft_icao'] = $aircraft_data[1];
1257
+	    		    } else {
1258
+	    		    	$data['aircraft_icao'] = $line['aircraftname'];
1259
+	    		    }
941 1260
 	    		}
942 1261
 	    	    }
943
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1262
+    		    if (isset($line['route'])) {
1263
+    		    	$data['waypoints'] = $line['route'];
1264
+    		    }
944 1265
     		    $data['id_source'] = $id_source;
945 1266
 	    	    $data['format_source'] = 'phpvmacars';
946
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1267
+		    if (isset($value['name']) && $value['name'] != '') {
1268
+		    	$data['source_name'] = $value['name'];
1269
+		    }
947 1270
 		    $SI->add($data);
948 1271
 		    unset($data);
949 1272
 		}
950
-		if ($globalDebug) echo 'No more data...'."\n";
1273
+		if ($globalDebug) {
1274
+			echo 'No more data...'."\n";
1275
+		}
951 1276
 		unset($buffer);
952 1277
 		unset($all_data);
953 1278
 	    }
@@ -955,7 +1280,9 @@  discard block
 block discarded – undo
955 1280
     	    $last_exec[$id]['last'] = time();
956 1281
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
957 1282
 	    //$buffer = $Common->getData($hosts[$id]);
958
-	    if ($globalDebug) echo 'Get Data...'."\n";
1283
+	    if ($globalDebug) {
1284
+	    	echo 'Get Data...'."\n";
1285
+	    }
959 1286
 	    $buffer = $Common->getData($value['host']);
960 1287
 	    $all_data = json_decode($buffer,true);
961 1288
 	    if ($buffer != '' && is_array($all_data)) {
@@ -984,15 +1311,22 @@  discard block
 block discarded – undo
984 1311
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
985 1312
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
986 1313
     		    //$data['registration'] = $line['aircraft'];
987
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1314
+		    if (isset($line['route'])) {
1315
+		    	$data['waypoints'] = $line['route'];
1316
+		    }
1317
+		    // route
988 1318
 	    	    $data['aircraft_icao'] = $line['plane_type'];
989 1319
     		    $data['id_source'] = $id_source;
990 1320
 	    	    $data['format_source'] = 'vam';
991
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1321
+		    if (isset($value['name']) && $value['name'] != '') {
1322
+		    	$data['source_name'] = $value['name'];
1323
+		    }
992 1324
 		    $SI->add($data);
993 1325
 		    unset($data);
994 1326
 		}
995
-		if ($globalDebug) echo 'No more data...'."\n";
1327
+		if ($globalDebug) {
1328
+			echo 'No more data...'."\n";
1329
+		}
996 1330
 		unset($buffer);
997 1331
 		unset($all_data);
998 1332
 	    }
@@ -1000,7 +1334,9 @@  discard block
 block discarded – undo
1000 1334
     	    $last_exec[$id]['last'] = time();
1001 1335
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1002 1336
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais') {
1003
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1337
+	    if (function_exists('pcntl_fork')) {
1338
+	    	pcntl_signal_dispatch();
1339
+	    }
1004 1340
     	    //$last_exec[$id]['last'] = time();
1005 1341
 
1006 1342
 	    //$read = array( $sockets[$id] );
@@ -1008,7 +1344,9 @@  discard block
 block discarded – undo
1008 1344
 	    $write = NULL;
1009 1345
 	    $e = NULL;
1010 1346
 	    $n = socket_select($read, $write, $e, $timeout);
1011
-	    if ($e != NULL) var_dump($e);
1347
+	    if ($e != NULL) {
1348
+	    	var_dump($e);
1349
+	    }
1012 1350
 	    if ($n > 0) {
1013 1351
 		$reset = 0;
1014 1352
 		foreach ($read as $nb => $r) {
@@ -1030,7 +1368,9 @@  discard block
 block discarded – undo
1030 1368
 		    if ($buffer != '') {
1031 1369
 			$tt[$format] = 0;
1032 1370
 			if ($format == 'acarssbs3') {
1033
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1371
+                    	    if ($globalDebug) {
1372
+                    	    	echo 'ACARS : '.$buffer."\n";
1373
+                    	    }
1034 1374
 			    $ACARS->add(trim($buffer));
1035 1375
 			    $ACARS->deleteLiveAcarsData();
1036 1376
 			} elseif ($format == 'raw') {
@@ -1039,25 +1379,55 @@  discard block
 block discarded – undo
1039 1379
 			    if (is_array($data)) {
1040 1380
 				$data['datetime'] = date('Y-m-d H:i:s');
1041 1381
 				$data['format_source'] = 'raw';
1042
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1043
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1044
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1382
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1383
+					$data['source_name'] = $globalSources[$nb]['name'];
1384
+				}
1385
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1386
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1387
+    				}
1388
+                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1389
+                                	$SI->add($data);
1390
+                                }
1045 1391
                             }
1046 1392
                         } elseif ($format == 'ais') {
1047 1393
 			    $ais_data = $AIS->parse_line(trim($buffer));
1048 1394
 			    $data = array();
1049
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1050
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1051
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1052
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1053
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1054
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1055
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1056
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1057
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1058
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1059
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1060
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1395
+			    if (isset($ais_data['ident'])) {
1396
+			    	$data['ident'] = $ais_data['ident'];
1397
+			    }
1398
+			    if (isset($ais_data['mmsi'])) {
1399
+			    	$data['mmsi'] = $ais_data['mmsi'];
1400
+			    }
1401
+			    if (isset($ais_data['speed'])) {
1402
+			    	$data['speed'] = $ais_data['speed'];
1403
+			    }
1404
+			    if (isset($ais_data['heading'])) {
1405
+			    	$data['heading'] = $ais_data['heading'];
1406
+			    }
1407
+			    if (isset($ais_data['latitude'])) {
1408
+			    	$data['latitude'] = $ais_data['latitude'];
1409
+			    }
1410
+			    if (isset($ais_data['longitude'])) {
1411
+			    	$data['longitude'] = $ais_data['longitude'];
1412
+			    }
1413
+			    if (isset($ais_data['status'])) {
1414
+			    	$data['status'] = $ais_data['status'];
1415
+			    }
1416
+			    if (isset($ais_data['type'])) {
1417
+			    	$data['type'] = $ais_data['type'];
1418
+			    }
1419
+			    if (isset($ais_data['imo'])) {
1420
+			    	$data['imo'] = $ais_data['imo'];
1421
+			    }
1422
+			    if (isset($ais_data['callsign'])) {
1423
+			    	$data['callsign'] = $ais_data['callsign'];
1424
+			    }
1425
+			    if (isset($ais_data['destination'])) {
1426
+			    	$data['arrival_code'] = $ais_data['destination'];
1427
+			    }
1428
+			    if (isset($ais_data['eta_ts'])) {
1429
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1430
+			    }
1061 1431
 
1062 1432
 			    if (isset($ais_data['timestamp'])) {
1063 1433
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1066,7 +1436,9 @@  discard block
 block discarded – undo
1066 1436
 			    }
1067 1437
 			    $data['format_source'] = 'aisnmea';
1068 1438
     			    $data['id_source'] = $id_source;
1069
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1439
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1440
+			    	$MI->add($data);
1441
+			    }
1070 1442
 			    unset($data);
1071 1443
                         } elseif ($format == 'flightgearsp') {
1072 1444
                     	    //echo $buffer."\n";
@@ -1084,11 +1456,15 @@  discard block
 block discarded – undo
1084 1456
 				$data['speed'] = round($line[5]*1.94384);
1085 1457
 				$data['datetime'] = date('Y-m-d H:i:s');
1086 1458
 				$data['format_source'] = 'flightgearsp';
1087
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1459
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1460
+					$SI->add($data);
1461
+				}
1088 1462
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1089 1463
 			    }
1090 1464
                         } elseif ($format == 'acars') {
1091
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1465
+                    	    if ($globalDebug) {
1466
+                    	    	echo 'ACARS : '.$buffer."\n";
1467
+                    	    }
1092 1468
 			    $ACARS->add(trim($buffer));
1093 1469
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1094 1470
 			    $ACARS->deleteLiveAcarsData();
@@ -1109,7 +1485,9 @@  discard block
 block discarded – undo
1109 1485
 				    $aircraft_type = $line[10];
1110 1486
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1111 1487
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1112
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1488
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1489
+				    	$SI->add($data);
1490
+				    }
1113 1491
 				}
1114 1492
 			    }
1115 1493
 			} elseif ($format == 'beast') {
@@ -1125,21 +1503,43 @@  discard block
 block discarded – undo
1125 1503
     				$data['hex'] = $lined['hexid'];
1126 1504
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1127 1505
     				$data['datetime'] = date('Y-m-d H:i:s');;
1128
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1129
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1130
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1131
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1132
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1133
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1134
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1506
+    				if (isset($lined['ident'])) {
1507
+    					$data['ident'] = $lined['ident'];
1508
+    				}
1509
+    				if (isset($lined['lat'])) {
1510
+    					$data['latitude'] = $lined['lat'];
1511
+    				}
1512
+    				if (isset($lined['lon'])) {
1513
+    					$data['longitude'] = $lined['lon'];
1514
+    				}
1515
+    				if (isset($lined['speed'])) {
1516
+    					$data['speed'] = $lined['speed'];
1517
+    				}
1518
+    				if (isset($lined['squawk'])) {
1519
+    					$data['squawk'] = $lined['squawk'];
1520
+    				}
1521
+    				if (isset($lined['alt'])) {
1522
+    					$data['altitude'] = $lined['alt'];
1523
+    				}
1524
+    				if (isset($lined['heading'])) {
1525
+    					$data['heading'] = $lined['heading'];
1526
+    				}
1135 1527
     				$data['id_source'] = $id_source;
1136 1528
     				$data['format_source'] = 'tsv';
1137
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1138
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1139
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1529
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1530
+    					$data['source_name'] = $globalSources[$nb]['name'];
1531
+    				}
1532
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1533
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1534
+    				}
1535
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1536
+    					$SI->add($data);
1537
+    				}
1140 1538
     				unset($lined);
1141 1539
     				unset($data);
1142
-    			    } else $error = true;
1540
+    			    } else {
1541
+    			    	$error = true;
1542
+    			    }
1143 1543
 			} elseif ($format == 'aprs' && $use_aprs) {
1144 1544
 			    if ($aprs_connect == 0) {
1145 1545
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1165,47 +1565,72 @@  discard block
 block discarded – undo
1165 1565
 				    $aprs_last_tx = time();
1166 1566
 				    $data = array();
1167 1567
 				    //print_r($line);
1168
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1169
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1170
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1568
+				    if (isset($line['address'])) {
1569
+				    	$data['hex'] = $line['address'];
1570
+				    }
1571
+				    if (isset($line['timestamp'])) {
1572
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1573
+				    } else {
1574
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1575
+				    }
1171 1576
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1172 1577
 				    $data['ident'] = $line['ident'];
1173 1578
 				    $data['latitude'] = $line['latitude'];
1174 1579
 				    $data['longitude'] = $line['longitude'];
1175 1580
 				    //$data['verticalrate'] = $line[16];
1176
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1177
-				    else $data['speed'] = 0;
1178
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1179
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1180
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1181
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1581
+				    if (isset($line['speed'])) {
1582
+				    	$data['speed'] = $line['speed'];
1583
+				    } else {
1584
+				    	$data['speed'] = 0;
1585
+				    }
1586
+				    if (isset($line['altitude'])) {
1587
+				    	$data['altitude'] = $line['altitude'];
1588
+				    }
1589
+				    if (isset($line['comment'])) {
1590
+				    	$data['comment'] = $line['comment'];
1591
+				    }
1592
+				    if (isset($line['symbol'])) {
1593
+				    	$data['type'] = $line['symbol'];
1594
+				    }
1595
+				    if (isset($line['heading'])) {
1596
+				    	$data['heading'] = $line['heading'];
1597
+				    }
1182 1598
 				    //else $data['heading'] = 0;
1183
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1184
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1599
+				    if (isset($line['stealth'])) {
1600
+				    	$data['aircraft_type'] = $line['stealth'];
1601
+				    }
1602
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
1603
+				    	$data['noarchive'] = true;
1604
+				    }
1185 1605
     				    $data['id_source'] = $id_source;
1186 1606
 				    $data['format_source'] = 'aprs';
1187 1607
 				    $data['source_name'] = $line['source'];
1188 1608
 				    $data['source_type'] = 'flarm';
1189
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1609
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1610
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1611
+    				    }
1190 1612
 				    $currentdate = date('Y-m-d H:i:s');
1191 1613
 				    $aprsdate = strtotime($data['datetime']);
1192 1614
 				    // Accept data if time <= system time + 20s
1193 1615
 				    if (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'])))) {
1194 1616
 					$send = $SI->add($data);
1195 1617
 				    } elseif (isset($line['stealth'])) {
1196
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1197
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1618
+					if ($line['stealth'] != 0) {
1619
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1620
+					} else {
1621
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1622
+					}
1198 1623
 				    //} elseif (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' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1199 1624
 				    } 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') {
1200 1625
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1201
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1626
+					if (isset($globalTracker) && $globalTracker) {
1627
+						$send = $TI->add($data);
1628
+					}
1202 1629
 				    }
1203 1630
 				    unset($data);
1204
-				} 
1205
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1631
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1206 1632
 					echo '!! Weather Station not yet supported'."\n";
1207
-				}
1208
-				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')) {
1633
+				} 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')) {
1209 1634
 					echo '!! Car & Trucks not yet supported'."\n";
1210 1635
 				}
1211 1636
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
@@ -1238,25 +1663,42 @@  discard block
 block discarded – undo
1238 1663
     				$data['ground'] = $line[21];
1239 1664
     				$data['emergency'] = $line[19];
1240 1665
     				$data['format_source'] = 'sbs';
1241
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1242
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1666
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1667
+					$data['source_name'] = $globalSources[$nb]['name'];
1668
+				}
1669
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1670
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1671
+    				}
1243 1672
     				$data['id_source'] = $id_source;
1244
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1245
-    				else $error = true;
1673
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1674
+    					$send = $SI->add($data);
1675
+    				} else {
1676
+    					$error = true;
1677
+    				}
1246 1678
     				unset($data);
1247
-    			    } else $error = true;
1679
+    			    } else {
1680
+    			    	$error = true;
1681
+    			    }
1248 1682
 			    if ($error) {
1249 1683
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1250
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1684
+					if ($globalDebug) {
1685
+						echo "Not a message. Ignoring... \n";
1686
+					}
1251 1687
 				} else {
1252
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1688
+					if ($globalDebug) {
1689
+						echo "Wrong line format. Ignoring... \n";
1690
+					}
1253 1691
 					if ($globalDebug) {
1254 1692
 						echo $buffer;
1255 1693
 						print_r($line);
1256 1694
 					}
1257 1695
 					//socket_close($r);
1258
-					if ($globalDebug) echo "Reconnect after an error...\n";
1259
-					if ($format == 'aprs') $aprs_connect = 0;
1696
+					if ($globalDebug) {
1697
+						echo "Reconnect after an error...\n";
1698
+					}
1699
+					if ($format == 'aprs') {
1700
+						$aprs_connect = 0;
1701
+					}
1260 1702
 					$sourceer[$nb] = $globalSources[$nb];
1261 1703
 					connect_all($sourceer);
1262 1704
 					$sourceer = array();
@@ -1264,10 +1706,14 @@  discard block
 block discarded – undo
1264 1706
 			    }
1265 1707
 			}
1266 1708
 			// Sleep for xxx microseconds
1267
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1709
+			if (isset($globalSBSSleep)) {
1710
+				usleep($globalSBSSleep);
1711
+			}
1268 1712
 		    } else {
1269 1713
 			if ($format == 'flightgearmp') {
1270
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1714
+			    	if ($globalDebug) {
1715
+			    		echo "Reconnect FlightGear MP...";
1716
+			    	}
1271 1717
 				//@socket_close($r);
1272 1718
 				sleep($globalMinFetch);
1273 1719
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1276,10 +1722,15 @@  discard block
 block discarded – undo
1276 1722
 				break;
1277 1723
 				
1278 1724
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1279
-			    if (isset($tt[$format])) $tt[$format]++;
1280
-			    else $tt[$format] = 0;
1725
+			    if (isset($tt[$format])) {
1726
+			    	$tt[$format]++;
1727
+			    } else {
1728
+			    	$tt[$format] = 0;
1729
+			    }
1281 1730
 			    if ($tt[$format] > 30) {
1282
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1731
+				if ($globalDebug) {
1732
+					echo "ERROR : Reconnect ".$format."...";
1733
+				}
1283 1734
 				//@socket_close($r);
1284 1735
 				sleep(2);
1285 1736
 				$aprs_connect = 0;
@@ -1296,11 +1747,17 @@  discard block
 block discarded – undo
1296 1747
 	    } else {
1297 1748
 		$error = socket_strerror(socket_last_error());
1298 1749
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1299
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1300
-			if (isset($globalDebug)) echo "Restarting...\n";
1750
+			if ($globalDebug) {
1751
+				echo "ERROR : socket_select give this error ".$error . "\n";
1752
+			}
1753
+			if (isset($globalDebug)) {
1754
+				echo "Restarting...\n";
1755
+			}
1301 1756
 			// Restart the script if possible
1302 1757
 			if (is_array($sockets)) {
1303
-			    if ($globalDebug) echo "Shutdown all sockets...";
1758
+			    if ($globalDebug) {
1759
+			    	echo "Shutdown all sockets...";
1760
+			    }
1304 1761
 			    
1305 1762
 			    foreach ($sockets as $sock) {
1306 1763
 				@socket_shutdown($sock,2);
@@ -1308,18 +1765,24 @@  discard block
 block discarded – undo
1308 1765
 			    }
1309 1766
 			    
1310 1767
 			}
1311
-			if ($globalDebug) echo "Restart all connections...";
1768
+			if ($globalDebug) {
1769
+				echo "Restart all connections...";
1770
+			}
1312 1771
 			sleep(2);
1313 1772
 			$time = time();
1314 1773
 			//connect_all($hosts);
1315 1774
 			$aprs_connect = 0;
1316
-			if ($reset > 40) exit('Too many attempts...');
1775
+			if ($reset > 40) {
1776
+				exit('Too many attempts...');
1777
+			}
1317 1778
 			connect_all($globalSources);
1318 1779
 		}
1319 1780
 	    }
1320 1781
 	}
1321 1782
 	if ($globalDaemon === false) {
1322
-	    if ($globalDebug) echo 'Check all...'."\n";
1783
+	    if ($globalDebug) {
1784
+	    	echo 'Check all...'."\n";
1785
+	    }
1323 1786
 	    $SI->checkAll();
1324 1787
 	}
1325 1788
     }
Please login to merge, or discard this patch.