Completed
Push — master ( 5b2234...f7c0d7 )
by Yannick
07:17
created
require/class.Marine.php 4 patches
Braces   +145 added lines, -52 removed lines patch added patch discarded remove patch
@@ -31,7 +31,9 @@  discard block
 block discarded – undo
31 31
 		if (isset($filter[0]['source'])) {
32 32
 			$filters = array_merge($filters,$filter);
33 33
 		}
34
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
34
+		if (is_array($globalFilter)) {
35
+			$filter = array_merge($filter,$globalFilter);
36
+		}
35 37
 		$filter_query_join = '';
36 38
 		$filter_query_where = '';
37 39
 		foreach($filters as $flt) {
@@ -70,8 +72,11 @@  discard block
 block discarded – undo
70 72
 				$filter_query_where .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'";
71 73
 			}
72 74
 		}
73
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
74
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
75
+		if ($filter_query_where == '' && $where) {
76
+			$filter_query_where = ' WHERE';
77
+		} elseif ($filter_query_where != '' && $and) {
78
+			$filter_query_where .= ' AND';
79
+		}
75 80
 		if ($filter_query_where != '') {
76 81
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
77 82
 		}
@@ -125,25 +130,40 @@  discard block
 block discarded – undo
125 130
 				$temp_array['spotter_id'] = $row['spotter_archive_id'];
126 131
 			} elseif (isset($row['spotter_archive_output_id'])) {
127 132
 				$temp_array['spotter_id'] = $row['spotter_archive_output_id'];
128
-			*/} 
129
-			elseif (isset($row['marineid'])) {
133
+			*/} elseif (isset($row['marineid'])) {
130 134
 				$temp_array['marineid'] = $row['marineid'];
131 135
 			} else {
132 136
 				$temp_array['marineid'] = '';
133 137
 			}
134
-			if (isset($row['fammarine_id'])) $temp_array['fammarine_id'] = $row['fammarine_id'];
135
-			if (isset($row['mmsi'])) $temp_array['mmsi'] = $row['mmsi'];
136
-			if (isset($row['type'])) $temp_array['type'] = $row['type'];
138
+			if (isset($row['fammarine_id'])) {
139
+				$temp_array['fammarine_id'] = $row['fammarine_id'];
140
+			}
141
+			if (isset($row['mmsi'])) {
142
+				$temp_array['mmsi'] = $row['mmsi'];
143
+			}
144
+			if (isset($row['type'])) {
145
+				$temp_array['type'] = $row['type'];
146
+			}
137 147
 			$temp_array['ident'] = $row['ident'];
138
-			if (isset($row['latitude'])) $temp_array['latitude'] = $row['latitude'];
139
-			if (isset($row['longitude'])) $temp_array['longitude'] = $row['longitude'];
140
-			if (isset($row['format_source'])) $temp_array['format_source'] = $row['format_source'];
148
+			if (isset($row['latitude'])) {
149
+				$temp_array['latitude'] = $row['latitude'];
150
+			}
151
+			if (isset($row['longitude'])) {
152
+				$temp_array['longitude'] = $row['longitude'];
153
+			}
154
+			if (isset($row['format_source'])) {
155
+				$temp_array['format_source'] = $row['format_source'];
156
+			}
141 157
 			if (isset($row['heading'])) {
142 158
 				$temp_array['heading'] = $row['heading'];
143 159
 				$heading_direction = $this->parseDirection($row['heading']);
144
-				if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
160
+				if (isset($heading_direction[0]['direction_fullname'])) {
161
+					$temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
162
+				}
163
+			}
164
+			if (isset($row['ground_speed'])) {
165
+				$temp_array['ground_speed'] = $row['ground_speed'];
145 166
 			}
146
-			if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed'];
147 167
 			
148 168
 			if (isset($row['date'])) {
149 169
 				$dateArray = $this->parseDateString($row['date']);
@@ -186,13 +206,21 @@  discard block
 block discarded – undo
186 206
 			}
187 207
 			
188 208
 			$fromsource = NULL;
189
-			if (isset($row['source_name']) && $row['source_name'] != '') $temp_array['source_name'] = $row['source_name'];
190
-			if (isset($row['over_country']) && $row['over_country'] != '') $temp_array['over_country'] = $row['over_country'];
191
-			if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance'];
209
+			if (isset($row['source_name']) && $row['source_name'] != '') {
210
+				$temp_array['source_name'] = $row['source_name'];
211
+			}
212
+			if (isset($row['over_country']) && $row['over_country'] != '') {
213
+				$temp_array['over_country'] = $row['over_country'];
214
+			}
215
+			if (isset($row['distance']) && $row['distance'] != '') {
216
+				$temp_array['distance'] = $row['distance'];
217
+			}
192 218
 			$temp_array['query_number_rows'] = $num_rows;
193 219
 			$spotter_array[] = $temp_array;
194 220
 		}
195
-		if ($num_rows == 0) return array();
221
+		if ($num_rows == 0) {
222
+			return array();
223
+		}
196 224
 		$spotter_array[0]['query_number_rows'] = $num_rows;
197 225
 		return $spotter_array;
198 226
 	}	
@@ -223,8 +251,12 @@  discard block
 block discarded – undo
223 251
 			{
224 252
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
225 253
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
226
-			} else $limit_query = "";
227
-		} else $limit_query = "";
254
+			} else {
255
+				$limit_query = "";
256
+			}
257
+		} else {
258
+			$limit_query = "";
259
+		}
228 260
 		
229 261
 		if ($sort != "")
230 262
 		{
@@ -252,7 +284,9 @@  discard block
 block discarded – undo
252 284
 		global $global_query;
253 285
 		
254 286
 		date_default_timezone_set('UTC');
255
-		if ($id == '') return array();
287
+		if ($id == '') {
288
+			return array();
289
+		}
256 290
 		$additional_query = "marine_output.fammarine_id = :id";
257 291
 		$query_values = array(':id' => $id);
258 292
 		$query  = $global_query." WHERE ".$additional_query." ";
@@ -395,8 +429,11 @@  discard block
 block discarded – undo
395 429
 		$query .= " ORDER BY marine_output.source_name ASC";
396 430
 
397 431
 		$sth = $this->db->prepare($query);
398
-		if (!empty($query_values)) $sth->execute($query_values);
399
-		else $sth->execute();
432
+		if (!empty($query_values)) {
433
+			$sth->execute($query_values);
434
+		} else {
435
+			$sth->execute();
436
+		}
400 437
 
401 438
 		$source_array = array();
402 439
 		$temp_array = array();
@@ -451,8 +488,11 @@  discard block
 block discarded – undo
451 488
 		$sth = $this->db->prepare($query);
452 489
 		$sth->execute(array(':mmsi' => $mmsi));
453 490
 		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
454
-		if (isset($result[0])) return $result[0];
455
-		else return array();
491
+		if (isset($result[0])) {
492
+			return $result[0];
493
+		} else {
494
+			return array();
495
+		}
456 496
 	}
457 497
 
458 498
 	/*
@@ -468,7 +508,9 @@  discard block
 block discarded – undo
468 508
 			date_default_timezone_set($globalTimezone);
469 509
 			$datetime = new DateTime();
470 510
 			$offset = $datetime->format('P');
471
-		} else $offset = '+00:00';
511
+		} else {
512
+			$offset = '+00:00';
513
+		}
472 514
 
473 515
 		if ($globalDBdriver == 'mysql') {
474 516
 			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
@@ -663,9 +705,15 @@  discard block
 block discarded – undo
663 705
             		$latitude = 0;
664 706
             		$longitude = 0;
665 707
             	}
666
-                if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
667
-                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
668
-                if ($arrival_date == '') $arrival_date = NULL;
708
+                if ($heading == '' || $Common->isInteger($heading) === false) {
709
+                	$heading = 0;
710
+                }
711
+                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) {
712
+                	$groundspeed = 0;
713
+                }
714
+                if ($arrival_date == '') {
715
+                	$arrival_date = NULL;
716
+                }
669 717
 		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
670 718
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)";
671 719
 
@@ -829,12 +877,18 @@  discard block
 block discarded – undo
829 877
 		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
830 878
                     FROM marine_output".$filter_query." marine_output.ident <> ''";
831 879
 		 if ($olderthanmonths > 0) {
832
-			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
833
-			else $query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
880
+			if ($globalDBdriver == 'mysql') {
881
+				$query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
882
+			} else {
883
+				$query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
884
+			}
834 885
 		}
835 886
 		if ($sincedate != '') {
836
-			if ($globalDBdriver == 'mysql') $query .= " AND marine_output.date > '".$sincedate."'";
837
-			else $query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
887
+			if ($globalDBdriver == 'mysql') {
888
+				$query .= " AND marine_output.date > '".$sincedate."'";
889
+			} else {
890
+				$query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
891
+			}
838 892
 		}
839 893
 		$query_values = array();
840 894
 		if ($year != '') {
@@ -865,7 +919,9 @@  discard block
 block discarded – undo
865 919
 			}
866 920
 		}
867 921
 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
868
-		if ($limit) $query .= " LIMIT 10 OFFSET 0";
922
+		if ($limit) {
923
+			$query .= " LIMIT 10 OFFSET 0";
924
+		}
869 925
       		
870 926
 		$sth = $this->db->prepare($query);
871 927
 		$sth->execute($query_values);
@@ -900,7 +956,9 @@  discard block
 block discarded – undo
900 956
 			date_default_timezone_set($globalTimezone);
901 957
 			$datetime = new DateTime();
902 958
 			$offset = $datetime->format('P');
903
-		} else $offset = '+00:00';
959
+		} else {
960
+			$offset = '+00:00';
961
+		}
904 962
 
905 963
 		if ($globalDBdriver == 'mysql') {
906 964
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -950,7 +1008,9 @@  discard block
 block discarded – undo
950 1008
 			date_default_timezone_set($globalTimezone);
951 1009
 			$datetime = new DateTime();
952 1010
 			$offset = $datetime->format('P');
953
-		} else $offset = '+00:00';
1011
+		} else {
1012
+			$offset = '+00:00';
1013
+		}
954 1014
 		$filter_query = $this->getFilter($filters,true,true);
955 1015
 		if ($globalDBdriver == 'mysql') {
956 1016
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -996,7 +1056,9 @@  discard block
 block discarded – undo
996 1056
 			date_default_timezone_set($globalTimezone);
997 1057
 			$datetime = new DateTime();
998 1058
 			$offset = $datetime->format('P');
999
-		} else $offset = '+00:00';
1059
+		} else {
1060
+			$offset = '+00:00';
1061
+		}
1000 1062
 		$filter_query = $this->getFilter($filters,true,true);
1001 1063
 		if ($globalDBdriver == 'mysql') {
1002 1064
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -1044,7 +1106,9 @@  discard block
 block discarded – undo
1044 1106
 			date_default_timezone_set($globalTimezone);
1045 1107
 			$datetime = new DateTime();
1046 1108
 			$offset = $datetime->format('P');
1047
-		} else $offset = '+00:00';
1109
+		} else {
1110
+			$offset = '+00:00';
1111
+		}
1048 1112
 
1049 1113
 		if ($globalDBdriver == 'mysql') {
1050 1114
 			$query  = "SELECT YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count
@@ -1093,7 +1157,9 @@  discard block
 block discarded – undo
1093 1157
 			date_default_timezone_set($globalTimezone);
1094 1158
 			$datetime = new DateTime();
1095 1159
 			$offset = $datetime->format('P');
1096
-		} else $offset = '+00:00';
1160
+		} else {
1161
+			$offset = '+00:00';
1162
+		}
1097 1163
 		$filter_query = $this->getFilter($filters,true,true);
1098 1164
 		if ($globalDBdriver == 'mysql') {
1099 1165
 			$query  = "SELECT MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count
@@ -1142,7 +1208,9 @@  discard block
 block discarded – undo
1142 1208
 			date_default_timezone_set($globalTimezone);
1143 1209
 			$datetime = new DateTime();
1144 1210
 			$offset = $datetime->format('P');
1145
-		} else $offset = '+00:00';
1211
+		} else {
1212
+			$offset = '+00:00';
1213
+		}
1146 1214
 
1147 1215
 		$orderby_sql = '';
1148 1216
 		if ($orderby == "hour")
@@ -1211,7 +1279,9 @@  discard block
 block discarded – undo
1211 1279
 			date_default_timezone_set($globalTimezone);
1212 1280
 			$datetime = new DateTime($date);
1213 1281
 			$offset = $datetime->format('P');
1214
-		} else $offset = '+00:00';
1282
+		} else {
1283
+			$offset = '+00:00';
1284
+		}
1215 1285
 
1216 1286
 		if ($globalDBdriver == 'mysql') {
1217 1287
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1259,7 +1329,9 @@  discard block
 block discarded – undo
1259 1329
 			date_default_timezone_set($globalTimezone);
1260 1330
 			$datetime = new DateTime();
1261 1331
 			$offset = $datetime->format('P');
1262
-		} else $offset = '+00:00';
1332
+		} else {
1333
+			$offset = '+00:00';
1334
+		}
1263 1335
 
1264 1336
 		if ($globalDBdriver == 'mysql') {
1265 1337
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1323,8 +1395,11 @@  discard block
 block discarded – undo
1323 1395
 				$query_values = array_merge($query_values,array(':month' => $month));
1324 1396
 			}
1325 1397
 		}
1326
-		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1327
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1398
+		if (empty($query_values)) {
1399
+			$queryi .= $this->getFilter($filters);
1400
+		} else {
1401
+			$queryi .= $this->getFilter($filters,true,true).substr($query,4);
1402
+		}
1328 1403
 		
1329 1404
 		$sth = $this->db->prepare($queryi);
1330 1405
 		$sth->execute($query_values);
@@ -1346,7 +1421,9 @@  discard block
 block discarded – undo
1346 1421
 			date_default_timezone_set($globalTimezone);
1347 1422
 			$datetime = new DateTime();
1348 1423
 			$offset = $datetime->format('P');
1349
-		} else $offset = '+00:00';
1424
+		} else {
1425
+			$offset = '+00:00';
1426
+		}
1350 1427
 
1351 1428
 		if ($globalDBdriver == 'mysql') {
1352 1429
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1450,7 +1527,9 @@  discard block
 block discarded – undo
1450 1527
 	*/
1451 1528
 	public function parseDirection($direction = 0)
1452 1529
 	{
1453
-		if ($direction == '') $direction = 0;
1530
+		if ($direction == '') {
1531
+			$direction = 0;
1532
+		}
1454 1533
 		$direction_array = array();
1455 1534
 		$temp_array = array();
1456 1535
 
@@ -1539,7 +1618,9 @@  discard block
 block discarded – undo
1539 1618
 		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1540 1619
 	
1541 1620
 		$Connection = new Connection($this->db);
1542
-		if (!$Connection->tableExists('countries')) return '';
1621
+		if (!$Connection->tableExists('countries')) {
1622
+			return '';
1623
+		}
1543 1624
 	
1544 1625
 		try {
1545 1626
 			/*
@@ -1559,9 +1640,13 @@  discard block
 block discarded – undo
1559 1640
 			$sth->closeCursor();
1560 1641
 			if (count($row) > 0) {
1561 1642
 				return $row;
1562
-			} else return '';
1643
+			} else {
1644
+				return '';
1645
+			}
1563 1646
 		} catch (PDOException $e) {
1564
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
1647
+			if (isset($globalDebug) && $globalDebug) {
1648
+				echo 'Error : '.$e->getMessage()."\n";
1649
+			}
1565 1650
 			return '';
1566 1651
 		}
1567 1652
 	
@@ -1579,7 +1664,9 @@  discard block
 block discarded – undo
1579 1664
 		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
1580 1665
 	
1581 1666
 		$Connection = new Connection($this->db);
1582
-		if (!$Connection->tableExists('countries')) return '';
1667
+		if (!$Connection->tableExists('countries')) {
1668
+			return '';
1669
+		}
1583 1670
 	
1584 1671
 		try {
1585 1672
 			$query = "SELECT name,iso2,iso3 FROM countries WHERE iso2 = :iso2 LIMIT 1";
@@ -1591,9 +1678,13 @@  discard block
 block discarded – undo
1591 1678
 			$sth->closeCursor();
1592 1679
 			if (count($row) > 0) {
1593 1680
 				return $row;
1594
-			} else return '';
1681
+			} else {
1682
+				return '';
1683
+			}
1595 1684
 		} catch (PDOException $e) {
1596
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
1685
+			if (isset($globalDebug) && $globalDebug) {
1686
+				echo 'Error : '.$e->getMessage()."\n";
1687
+			}
1597 1688
 			return '';
1598 1689
 		}
1599 1690
 	
@@ -1611,7 +1702,9 @@  discard block
 block discarded – undo
1611 1702
 	{
1612 1703
 		global $globalBitlyAccessToken;
1613 1704
 		
1614
-		if ($globalBitlyAccessToken == '') return $url;
1705
+		if ($globalBitlyAccessToken == '') {
1706
+			return $url;
1707
+		}
1615 1708
         
1616 1709
 		$google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url;
1617 1710
 		
Please login to merge, or discard this 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.
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@  discard block
 block discarded – undo
13 13
 	}
14 14
 
15 15
 	/**
16
-	* Get SQL query part for filter used
17
-	* @param Array $filter the filter
18
-	* @return Array the SQL part
19
-	*/
16
+	 * Get SQL query part for filter used
17
+	 * @param Array $filter the filter
18
+	 * @return Array the SQL part
19
+	 */
20 20
 	
21 21
 	public function getFilter($filter = array(),$where = false,$and = false) {
22 22
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
 	}
81 81
 
82 82
 	/**
83
-	* Executes the SQL statements to get the spotter information
84
-	*
85
-	* @param String $query the SQL query
86
-	* @param Array $params parameter of the query
87
-	* @param String $limitQuery the limit query
88
-	* @return Array the spotter information
89
-	*
90
-	*/
83
+	 * Executes the SQL statements to get the spotter information
84
+	 *
85
+	 * @param String $query the SQL query
86
+	 * @param Array $params parameter of the query
87
+	 * @param String $limitQuery the limit query
88
+	 * @return Array the spotter information
89
+	 *
90
+	 */
91 91
 	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false)
92 92
 	{
93 93
 		date_default_timezone_set('UTC');
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
 	
200 200
 	
201 201
 	/**
202
-	* Gets all the spotter information based on the latest data entry
203
-	*
204
-	* @return Array the spotter information
205
-	*
206
-	*/
202
+	 * Gets all the spotter information based on the latest data entry
203
+	 *
204
+	 * @return Array the spotter information
205
+	 *
206
+	 */
207 207
 	public function getLatestMarineData($limit = '', $sort = '', $filter = array())
208 208
 	{
209 209
 		global $global_query;
@@ -261,11 +261,11 @@  discard block
 block discarded – undo
261 261
 	}
262 262
 
263 263
 	/**
264
-	* Gets all the spotter information based on the callsign
265
-	*
266
-	* @return Array the spotter information
267
-	*
268
-	*/
264
+	 * Gets all the spotter information based on the callsign
265
+	 *
266
+	 * @return Array the spotter information
267
+	 *
268
+	 */
269 269
 	public function getMarineDataByIdent($ident = '', $limit = '', $sort = '', $filter = array())
270 270
 	{
271 271
 		global $global_query;
@@ -376,12 +376,12 @@  discard block
 block discarded – undo
376 376
 
377 377
 
378 378
 	/**
379
-	* Gets all source name
380
-	*
381
-	* @param String type format of source
382
-	* @return Array list of source name
383
-	*
384
-	*/
379
+	 * Gets all source name
380
+	 *
381
+	 * @param String type format of source
382
+	 * @return Array list of source name
383
+	 *
384
+	 */
385 385
 	public function getAllSourceName($type = '',$filters = array())
386 386
 	{
387 387
 		$filter_query = $this->getFilter($filters,true,true);
@@ -411,11 +411,11 @@  discard block
 block discarded – undo
411 411
 
412 412
 
413 413
 	/**
414
-	* Gets a list of all idents/callsigns
415
-	*
416
-	* @return Array list of ident/callsign names
417
-	*
418
-	*/
414
+	 * Gets a list of all idents/callsigns
415
+	 *
416
+	 * @return Array list of ident/callsign names
417
+	 *
418
+	 */
419 419
 	public function getAllIdents($filters = array())
420 420
 	{
421 421
 		$filter_query = $this->getFilter($filters,true,true);
@@ -439,11 +439,11 @@  discard block
 block discarded – undo
439 439
 	}
440 440
 
441 441
 	/**
442
-	* Gets all info from a mmsi
443
-	*
444
-	* @return Array list of mmsi info
445
-	*
446
-	*/
442
+	 * Gets all info from a mmsi
443
+	 *
444
+	 * @return Array list of mmsi info
445
+	 *
446
+	 */
447 447
 	public function getIdentity($mmsi)
448 448
 	{
449 449
 		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
@@ -500,18 +500,18 @@  discard block
 block discarded – undo
500 500
 	
501 501
 	
502 502
 	/**
503
-	* Update ident tracker data
504
-	*
505
-	* @param String $fammarine_id the ID
506
-	* @param String $ident the marine ident
507
-	* @return String success or false
508
-	*
509
-	*/	
503
+	 * Update ident tracker data
504
+	 *
505
+	 * @param String $fammarine_id the ID
506
+	 * @param String $ident the marine ident
507
+	 * @return String success or false
508
+	 *
509
+	 */	
510 510
 	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL)
511 511
 	{
512 512
 
513 513
 		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id';
514
-                $query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
514
+				$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
515 515
 
516 516
 		try {
517 517
 			$sth = $this->db->prepare($query);
@@ -524,17 +524,17 @@  discard block
 block discarded – undo
524 524
 
525 525
 	}
526 526
 	/**
527
-	* Update latest marine data
528
-	*
529
-	* @param String $fammarine_id the ID
530
-	* @param String $ident the marine ident
531
-	* @return String success or false
532
-	*
533
-	*/	
527
+	 * Update latest marine data
528
+	 *
529
+	 * @param String $fammarine_id the ID
530
+	 * @param String $ident the marine ident
531
+	 * @return String success or false
532
+	 *
533
+	 */	
534 534
 	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '')
535 535
 	{
536 536
 		$query = 'UPDATE marine_output SET ident = :ident, last_latitude = :last_latitude, last_longitude = :last_longitude, last_seen = :last_seen, last_ground_speed = :last_ground_speed WHERE fammarine_id = :fammarine_id';
537
-                $query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
537
+				$query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
538 538
 
539 539
 		try {
540 540
 			$sth = $this->db->prepare($query);
@@ -548,30 +548,30 @@  discard block
 block discarded – undo
548 548
 	}
549 549
 
550 550
 	/**
551
-	* Adds a new spotter data
552
-	*
553
-	* @param String $fammarine_id the ID
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
-	*/
551
+	 * Adds a new spotter data
552
+	 *
553
+	 * @param String $fammarine_id the ID
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
+	 */
575 575
 	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 576
 	{
577 577
 		global $globalURL;
@@ -659,13 +659,13 @@  discard block
 block discarded – undo
659 659
 		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
660 660
 		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
661 661
 	
662
-                if ($latitude == '' && $longitude == '') {
663
-            		$latitude = 0;
664
-            		$longitude = 0;
665
-            	}
666
-                if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
667
-                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
668
-                if ($arrival_date == '') $arrival_date = NULL;
662
+				if ($latitude == '' && $longitude == '') {
663
+					$latitude = 0;
664
+					$longitude = 0;
665
+				}
666
+				if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
667
+				if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
668
+				if ($arrival_date == '') $arrival_date = NULL;
669 669
 		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
670 670
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)";
671 671
 
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 			$sth->execute($query_values);
677 677
 			$this->db = null;
678 678
 		} catch (PDOException $e) {
679
-		    return "error : ".$e->getMessage();
679
+			return "error : ".$e->getMessage();
680 680
 		}
681 681
 		
682 682
 		return "success";
@@ -685,11 +685,11 @@  discard block
 block discarded – undo
685 685
 	
686 686
   
687 687
 	/**
688
-	* Gets the aircraft ident within the last hour
689
-	*
690
-	* @return String the ident
691
-	*
692
-	*/
688
+	 * Gets the aircraft ident within the last hour
689
+	 *
690
+	 * @return String the ident
691
+	 *
692
+	 */
693 693
 	public function getIdentFromLastHour($ident)
694 694
 	{
695 695
 		global $globalDBdriver, $globalTimezone;
@@ -705,11 +705,11 @@  discard block
 block discarded – undo
705 705
 								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
706 706
 								AND marine_output.date < now() AT TIME ZONE 'UTC'";
707 707
 			$query_data = array(':ident' => $ident);
708
-    		}
708
+			}
709 709
 		
710 710
 		$sth = $this->db->prepare($query);
711 711
 		$sth->execute($query_data);
712
-    		$ident_result='';
712
+			$ident_result='';
713 713
 		while($row = $sth->fetch(PDO::FETCH_ASSOC))
714 714
 		{
715 715
 			$ident_result = $row['ident'];
@@ -720,11 +720,11 @@  discard block
 block discarded – undo
720 720
 	
721 721
 	
722 722
 	/**
723
-	* Gets the aircraft data from the last 20 seconds
724
-	*
725
-	* @return Array the spotter data
726
-	*
727
-	*/
723
+	 * Gets the aircraft data from the last 20 seconds
724
+	 *
725
+	 * @return Array the spotter data
726
+	 *
727
+	 */
728 728
 	public function getRealTimeData($q = '')
729 729
 	{
730 730
 		global $globalDBdriver;
@@ -762,11 +762,11 @@  discard block
 block discarded – undo
762 762
 	
763 763
 
764 764
 	/**
765
-	* Gets all number of flight over countries
766
-	*
767
-	* @return Array the airline country list
768
-	*
769
-	*/
765
+	 * Gets all number of flight over countries
766
+	 *
767
+	 * @return Array the airline country list
768
+	 *
769
+	 */
770 770
 /*
771 771
 	public function countAllTrackedOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array())
772 772
 	{
@@ -817,11 +817,11 @@  discard block
 block discarded – undo
817 817
 	
818 818
 	
819 819
 	/**
820
-	* Gets all callsigns that have flown over
821
-	*
822
-	* @return Array the callsign list
823
-	*
824
-	*/
820
+	 * Gets all callsigns that have flown over
821
+	 *
822
+	 * @return Array the callsign list
823
+	 *
824
+	 */
825 825
 	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
826 826
 	{
827 827
 		global $globalDBdriver;
@@ -888,11 +888,11 @@  discard block
 block discarded – undo
888 888
 
889 889
 
890 890
 	/**
891
-	* Counts all dates
892
-	*
893
-	* @return Array the date list
894
-	*
895
-	*/
891
+	 * Counts all dates
892
+	 *
893
+	 * @return Array the date list
894
+	 *
895
+	 */
896 896
 	public function countAllDates($filters = array())
897 897
 	{
898 898
 		global $globalTimezone, $globalDBdriver;
@@ -938,11 +938,11 @@  discard block
 block discarded – undo
938 938
 	
939 939
 	
940 940
 	/**
941
-	* Counts all dates during the last 7 days
942
-	*
943
-	* @return Array the date list
944
-	*
945
-	*/
941
+	 * Counts all dates during the last 7 days
942
+	 *
943
+	 * @return Array the date list
944
+	 *
945
+	 */
946 946
 	public function countAllDatesLast7Days($filters = array())
947 947
 	{
948 948
 		global $globalTimezone, $globalDBdriver;
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
 			$query .= " GROUP BY date_name 
965 965
 								ORDER BY date_name ASC";
966 966
 			$query_data = array(':offset' => $offset);
967
-    		}
967
+			}
968 968
 		
969 969
 		$sth = $this->db->prepare($query);
970 970
 		$sth->execute($query_data);
@@ -984,11 +984,11 @@  discard block
 block discarded – undo
984 984
 	}
985 985
 
986 986
 	/**
987
-	* Counts all dates during the last month
988
-	*
989
-	* @return Array the date list
990
-	*
991
-	*/
987
+	 * Counts all dates during the last month
988
+	 *
989
+	 * @return Array the date list
990
+	 *
991
+	 */
992 992
 	public function countAllDatesLastMonth($filters = array())
993 993
 	{
994 994
 		global $globalTimezone, $globalDBdriver;
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
 			$query .= " GROUP BY date_name 
1011 1011
 								ORDER BY date_name ASC";
1012 1012
 			$query_data = array(':offset' => $offset);
1013
-    		}
1013
+			}
1014 1014
 		
1015 1015
 		$sth = $this->db->prepare($query);
1016 1016
 		$sth->execute($query_data);
@@ -1032,11 +1032,11 @@  discard block
 block discarded – undo
1032 1032
 
1033 1033
 
1034 1034
 	/**
1035
-	* Counts all month
1036
-	*
1037
-	* @return Array the month list
1038
-	*
1039
-	*/
1035
+	 * Counts all month
1036
+	 *
1037
+	 * @return Array the month list
1038
+	 *
1039
+	 */
1040 1040
 	public function countAllMonths($filters = array())
1041 1041
 	{
1042 1042
 		global $globalTimezone, $globalDBdriver;
@@ -1081,11 +1081,11 @@  discard block
 block discarded – undo
1081 1081
 	
1082 1082
 
1083 1083
 	/**
1084
-	* Counts all dates during the last year
1085
-	*
1086
-	* @return Array the date list
1087
-	*
1088
-	*/
1084
+	 * Counts all dates during the last year
1085
+	 *
1086
+	 * @return Array the date list
1087
+	 *
1088
+	 */
1089 1089
 	public function countAllMonthsLastYear($filters)
1090 1090
 	{
1091 1091
 		global $globalTimezone, $globalDBdriver;
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
 			$query .= " GROUP BY year_name, month_name
1108 1108
 								ORDER BY year_name, month_name ASC";
1109 1109
 			$query_data = array(':offset' => $offset);
1110
-    		}
1110
+			}
1111 1111
 		
1112 1112
 		$sth = $this->db->prepare($query);
1113 1113
 		$sth->execute($query_data);
@@ -1130,11 +1130,11 @@  discard block
 block discarded – undo
1130 1130
 	
1131 1131
 	
1132 1132
 	/**
1133
-	* Counts all hours
1134
-	*
1135
-	* @return Array the hour list
1136
-	*
1137
-	*/
1133
+	 * Counts all hours
1134
+	 *
1135
+	 * @return Array the hour list
1136
+	 *
1137
+	 */
1138 1138
 	public function countAllHours($orderby,$filters = array())
1139 1139
 	{
1140 1140
 		global $globalTimezone, $globalDBdriver;
@@ -1197,11 +1197,11 @@  discard block
 block discarded – undo
1197 1197
 	
1198 1198
 	
1199 1199
 	/**
1200
-	* Counts all hours by date
1201
-	*
1202
-	* @return Array the hour list
1203
-	*
1204
-	*/
1200
+	 * Counts all hours by date
1201
+	 *
1202
+	 * @return Array the hour list
1203
+	 *
1204
+	 */
1205 1205
 	public function countAllHoursByDate($date, $filters = array())
1206 1206
 	{
1207 1207
 		global $globalTimezone, $globalDBdriver;
@@ -1245,11 +1245,11 @@  discard block
 block discarded – undo
1245 1245
 	
1246 1246
 	
1247 1247
 	/**
1248
-	* Counts all hours by a ident/callsign
1249
-	*
1250
-	* @return Array the hour list
1251
-	*
1252
-	*/
1248
+	 * Counts all hours by a ident/callsign
1249
+	 *
1250
+	 * @return Array the hour list
1251
+	 *
1252
+	 */
1253 1253
 	public function countAllHoursByIdent($ident, $filters = array())
1254 1254
 	{
1255 1255
 		global $globalTimezone, $globalDBdriver;
@@ -1294,11 +1294,11 @@  discard block
 block discarded – undo
1294 1294
 	
1295 1295
 	
1296 1296
 	/**
1297
-	* Counts all flights that have flown over
1298
-	*
1299
-	* @return Integer the number of flights
1300
-	*
1301
-	*/
1297
+	 * Counts all flights that have flown over
1298
+	 *
1299
+	 * @return Integer the number of flights
1300
+	 *
1301
+	 */
1302 1302
 	public function countOverallTracked($filters = array(),$year = '',$month = '')
1303 1303
 	{
1304 1304
 		global $globalDBdriver;
@@ -1333,11 +1333,11 @@  discard block
 block discarded – undo
1333 1333
 	
1334 1334
   
1335 1335
 	/**
1336
-	* Counts all hours of today
1337
-	*
1338
-	* @return Array the hour list
1339
-	*
1340
-	*/
1336
+	 * Counts all hours of today
1337
+	 *
1338
+	 * @return Array the hour list
1339
+	 *
1340
+	 */
1341 1341
 	public function countAllHoursFromToday($filters = array())
1342 1342
 	{
1343 1343
 		global $globalTimezone, $globalDBdriver;
@@ -1377,12 +1377,12 @@  discard block
 block discarded – undo
1377 1377
 	}
1378 1378
     
1379 1379
     
1380
-     /**
1381
-	* Gets the Barrie Spotter ID based on the FlightAware ID
1382
-	*
1383
-	* @return Integer the Barrie Spotter ID
1380
+	 /**
1381
+	  * Gets the Barrie Spotter ID based on the FlightAware ID
1382
+	  *
1383
+	  * @return Integer the Barrie Spotter ID
1384 1384
 q	*
1385
-	*/
1385
+	  */
1386 1386
 	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1387 1387
 	{
1388 1388
 		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
@@ -1403,13 +1403,13 @@  discard block
 block discarded – undo
1403 1403
   
1404 1404
  
1405 1405
 	/**
1406
-	* Parses a date string
1407
-	*
1408
-	* @param String $dateString the date string
1409
-	* @param String $timezone the timezone of a user
1410
-	* @return Array the time information
1411
-	*
1412
-	*/
1406
+	 * Parses a date string
1407
+	 *
1408
+	 * @param String $dateString the date string
1409
+	 * @param String $timezone the timezone of a user
1410
+	 * @return Array the time information
1411
+	 *
1412
+	 */
1413 1413
 	public function parseDateString($dateString, $timezone = '')
1414 1414
 	{
1415 1415
 		$time_array = array();
@@ -1442,12 +1442,12 @@  discard block
 block discarded – undo
1442 1442
 	}
1443 1443
 	
1444 1444
 	/**
1445
-	* Parses the direction degrees to working
1446
-	*
1447
-	* @param Float $direction the direction in degrees
1448
-	* @return Array the direction information
1449
-	*
1450
-	*/
1445
+	 * Parses the direction degrees to working
1446
+	 *
1447
+	 * @param Float $direction the direction in degrees
1448
+	 * @return Array the direction information
1449
+	 *
1450
+	 */
1451 1451
 	public function parseDirection($direction = 0)
1452 1452
 	{
1453 1453
 		if ($direction == '') $direction = 0;
@@ -1526,12 +1526,12 @@  discard block
 block discarded – undo
1526 1526
 	
1527 1527
 	
1528 1528
 	/**
1529
-	* Gets Country from latitude/longitude
1530
-	*
1531
-	* @param Float $latitude latitute of the flight
1532
-	* @param Float $longitude longitute of the flight
1533
-	* @return String the countrie
1534
-	*/
1529
+	 * Gets Country from latitude/longitude
1530
+	 *
1531
+	 * @param Float $latitude latitute of the flight
1532
+	 * @param Float $longitude longitute of the flight
1533
+	 * @return String the countrie
1534
+	 */
1535 1535
 	public function getCountryFromLatitudeLongitude($latitude,$longitude)
1536 1536
 	{
1537 1537
 		global $globalDBdriver, $globalDebug;
@@ -1568,11 +1568,11 @@  discard block
 block discarded – undo
1568 1568
 	}
1569 1569
 
1570 1570
 	/**
1571
-	* Gets Country from iso2
1572
-	*
1573
-	* @param String $iso2 ISO2 country code
1574
-	* @return String the countrie
1575
-	*/
1571
+	 * Gets Country from iso2
1572
+	 *
1573
+	 * @param String $iso2 ISO2 country code
1574
+	 * @return String the countrie
1575
+	 */
1576 1576
 	public function getCountryFromISO2($iso2)
1577 1577
 	{
1578 1578
 		global $globalDBdriver, $globalDebug;
@@ -1601,12 +1601,12 @@  discard block
 block discarded – undo
1601 1601
 
1602 1602
 	
1603 1603
 	/**
1604
-	* Gets the short url from bit.ly
1605
-	*
1606
-	* @param String $url the full url
1607
-	* @return String the bit.ly url
1608
-	*
1609
-	*/
1604
+	 * Gets the short url from bit.ly
1605
+	 *
1606
+	 * @param String $url the full url
1607
+	 * @return String the bit.ly url
1608
+	 *
1609
+	 */
1610 1610
 	public function getBitlyURL($url)
1611 1611
 	{
1612 1612
 		global $globalBitlyAccessToken;
Please login to merge, or discard this patch.
Spacing   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 require_once(dirname(__FILE__).'/class.Image.php');
5 5
 $global_query = "SELECT marine_output.* FROM marine_output";
6 6
 
7
-class Marine{
7
+class Marine {
8 8
 	public $db;
9 9
 	
10 10
 	public function __construct($dbc = null) {
@@ -18,33 +18,33 @@  discard block
 block discarded – undo
18 18
 	* @return Array the SQL part
19 19
 	*/
20 20
 	
21
-	public function getFilter($filter = array(),$where = false,$and = false) {
21
+	public function getFilter($filter = array(), $where = false, $and = false) {
22 22
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
23 23
 		$filters = array();
24 24
 		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) {
25 25
 			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) {
26 26
 				$filters = $globalStatsFilters[$globalFilterName];
27 27
 			} else {
28
-				$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]);
28
+				$filter = array_merge($filter, $globalStatsFilters[$globalFilterName]);
29 29
 			}
30 30
 		}
31 31
 		if (isset($filter[0]['source'])) {
32
-			$filters = array_merge($filters,$filter);
32
+			$filters = array_merge($filters, $filter);
33 33
 		}
34
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
34
+		if (is_array($globalFilter)) $filter = array_merge($filter, $globalFilter);
35 35
 		$filter_query_join = '';
36 36
 		$filter_query_where = '';
37
-		foreach($filters as $flt) {
37
+		foreach ($filters as $flt) {
38 38
 			if (isset($flt['idents']) && !empty($flt['idents'])) {
39 39
 				if (isset($flt['source'])) {
40
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
40
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."') AND spotter_output.format_source IN ('".implode("','", $flt['source'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
41 41
 				} else {
42
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
42
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
43 43
 				}
44 44
 			}
45 45
 		}
46 46
 		if (isset($filter['source']) && !empty($filter['source'])) {
47
-			$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')";
47
+			$filter_query_where .= " AND format_source IN ('".implode("','", $filter['source'])."')";
48 48
 		}
49 49
 		if (isset($filter['ident']) && !empty($filter['ident'])) {
50 50
 			$filter_query_where .= " AND ident = '".$filter['ident']."'";
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
74 74
 		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
75 75
 		if ($filter_query_where != '') {
76
-			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
76
+			$filter_query_where = preg_replace('/^ AND/', ' WHERE', $filter_query_where);
77 77
 		}
78 78
 		$filter_query = $filter_query_join.$filter_query_where;
79 79
 		return $filter_query;
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	* @return Array the spotter information
89 89
 	*
90 90
 	*/
91
-	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false)
91
+	public function getDataFromDB($query, $params = array(), $limitQuery = '', $schedules = false)
92 92
 	{
93 93
 		date_default_timezone_set('UTC');
94 94
 		if (!is_string($query))
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
 			$sth = $this->db->prepare($query.$limitQuery);
109 109
 			$sth->execute($params);
110 110
 		} catch (PDOException $e) {
111
-			printf("Invalid query : %s\nWhole query: %s\n",$e->getMessage(), $query.$limitQuery);
111
+			printf("Invalid query : %s\nWhole query: %s\n", $e->getMessage(), $query.$limitQuery);
112 112
 			exit();
113 113
 		}
114 114
 		
115 115
 		$num_rows = 0;
116 116
 		$spotter_array = array();
117
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
117
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
118 118
 		{
119 119
 			$num_rows++;
120 120
 			$temp_array = array();
@@ -169,17 +169,17 @@  discard block
 block discarded – undo
169 169
 				{
170 170
 					$temp_array['date'] = "about ".$dateArray['hours']." hours ago";
171 171
 				} else {
172
-					$temp_array['date'] = date("M j Y, g:i a",strtotime($row['date']." UTC"));
172
+					$temp_array['date'] = date("M j Y, g:i a", strtotime($row['date']." UTC"));
173 173
 				}
174 174
 				$temp_array['date_minutes_past'] = $dateArray['minutes'];
175
-				$temp_array['date_iso_8601'] = date("c",strtotime($row['date']." UTC"));
176
-				$temp_array['date_rfc_2822'] = date("r",strtotime($row['date']." UTC"));
175
+				$temp_array['date_iso_8601'] = date("c", strtotime($row['date']." UTC"));
176
+				$temp_array['date_rfc_2822'] = date("r", strtotime($row['date']." UTC"));
177 177
 				$temp_array['date_unix'] = strtotime($row['date']." UTC");
178 178
 				if (isset($row['last_seen']) && $row['last_seen'] != '') {
179 179
 					if (strtotime($row['last_seen']) > strtotime($row['date'])) {
180 180
 						$temp_array['duration'] = strtotime($row['last_seen']) - strtotime($row['date']);
181
-						$temp_array['last_seen_date_iso_8601'] = date("c",strtotime($row['last_seen']." UTC"));
182
-						$temp_array['last_seen_date_rfc_2822'] = date("r",strtotime($row['last_seen']." UTC"));
181
+						$temp_array['last_seen_date_iso_8601'] = date("c", strtotime($row['last_seen']." UTC"));
182
+						$temp_array['last_seen_date_rfc_2822'] = date("r", strtotime($row['last_seen']." UTC"));
183 183
 						$temp_array['last_seen_date_unix'] = strtotime($row['last_seen']." UTC");
184 184
 					}
185 185
 				}
@@ -216,8 +216,8 @@  discard block
 block discarded – undo
216 216
 		{
217 217
 			$limit_array = explode(",", $limit);
218 218
 			
219
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
220
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
219
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
220
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
221 221
 			
222 222
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
223 223
 			{
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
 			$orderby_query = " ORDER BY marine_output.date DESC";
235 235
 		}
236 236
 
237
-		$query  = $global_query.$filter_query." ".$orderby_query;
237
+		$query = $global_query.$filter_query." ".$orderby_query;
238 238
 
239
-		$spotter_array = $this->getDataFromDB($query, array(),$limit_query,true);
239
+		$spotter_array = $this->getDataFromDB($query, array(), $limit_query, true);
240 240
 
241 241
 		return $spotter_array;
242 242
 	}
@@ -255,8 +255,8 @@  discard block
 block discarded – undo
255 255
 		if ($id == '') return array();
256 256
 		$additional_query = "marine_output.fammarine_id = :id";
257 257
 		$query_values = array(':id' => $id);
258
-		$query  = $global_query." WHERE ".$additional_query." ";
259
-		$spotter_array = $this->getDataFromDB($query,$query_values);
258
+		$query = $global_query." WHERE ".$additional_query." ";
259
+		$spotter_array = $this->getDataFromDB($query, $query_values);
260 260
 		return $spotter_array;
261 261
 	}
262 262
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 		$query_values = array();
276 276
 		$limit_query = '';
277 277
 		$additional_query = '';
278
-		$filter_query = $this->getFilter($filter,true,true);
278
+		$filter_query = $this->getFilter($filter, true, true);
279 279
 		if ($ident != "")
280 280
 		{
281 281
 			if (!is_string($ident))
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
 		{
292 292
 			$limit_array = explode(",", $limit);
293 293
 			
294
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
295
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
294
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
295
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
296 296
 			
297 297
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
298 298
 			{
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		return $spotter_array;
317 317
 	}
318 318
 	
319
-	public function getSpotterDataByDate($date = '', $limit = '', $sort = '',$filter = array())
319
+	public function getSpotterDataByDate($date = '', $limit = '', $sort = '', $filter = array())
320 320
 	{
321 321
 		global $global_query, $globalTimezone, $globalDBdriver;
322 322
 		
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 		$limit_query = '';
325 325
 		$additional_query = '';
326 326
 
327
-		$filter_query = $this->getFilter($filter,true,true);
327
+		$filter_query = $this->getFilter($filter, true, true);
328 328
 		
329 329
 		if ($date != "")
330 330
 		{
@@ -350,8 +350,8 @@  discard block
 block discarded – undo
350 350
 		{
351 351
 			$limit_array = explode(",", $limit);
352 352
 			
353
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
354
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
353
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
354
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
355 355
 			
356 356
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
357 357
 			{
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
 	* @return Array list of source name
383 383
 	*
384 384
 	*/
385
-	public function getAllSourceName($type = '',$filters = array())
385
+	public function getAllSourceName($type = '', $filters = array())
386 386
 	{
387
-		$filter_query = $this->getFilter($filters,true,true);
387
+		$filter_query = $this->getFilter($filters, true, true);
388 388
 		$query_values = array();
389
-		$query  = "SELECT DISTINCT marine_output.source_name 
389
+		$query = "SELECT DISTINCT marine_output.source_name 
390 390
 				FROM marine_output".$filter_query." marine_output.source_name <> ''";
391 391
 		if ($type != '') {
392 392
 			$query_values = array(':type' => $type);
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 		$source_array = array();
402 402
 		$temp_array = array();
403 403
 		
404
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
404
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
405 405
 		{
406 406
 			$temp_array['source_name'] = $row['source_name'];
407 407
 			$source_array[] = $temp_array;
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
 	*/
419 419
 	public function getAllIdents($filters = array())
420 420
 	{
421
-		$filter_query = $this->getFilter($filters,true,true);
422
-		$query  = "SELECT DISTINCT marine_output.ident
421
+		$filter_query = $this->getFilter($filters, true, true);
422
+		$query = "SELECT DISTINCT marine_output.ident
423 423
 								FROM marine_output".$filter_query." marine_output.ident <> '' 
424 424
 								ORDER BY marine_output.date ASC LIMIT 700 OFFSET 0";
425 425
 
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 		$ident_array = array();
430 430
 		$temp_array = array();
431 431
 		
432
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
432
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
433 433
 		{
434 434
 			$temp_array['ident'] = $row['ident'];
435 435
 			$ident_array[] = $temp_array;
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 	*/
447 447
 	public function getIdentity($mmsi)
448 448
 	{
449
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
449
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
450 450
 		$query  = "SELECT * FROM marine_identity WHERE mmsi = :mmsi LIMIT 1";
451 451
 		$sth = $this->db->prepare($query);
452 452
 		$sth->execute(array(':mmsi' => $mmsi));
@@ -471,12 +471,12 @@  discard block
 block discarded – undo
471 471
 		} else $offset = '+00:00';
472 472
 
473 473
 		if ($globalDBdriver == 'mysql') {
474
-			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
474
+			$query = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
475 475
 								FROM marine_output
476 476
 								WHERE marine_output.date <> '' 
477 477
 								ORDER BY marine_output.date ASC LIMIT 0,200";
478 478
 		} else {
479
-			$query  = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
479
+			$query = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
480 480
 								FROM marine_output
481 481
 								WHERE marine_output.date <> '' 
482 482
 								ORDER BY marine_output.date ASC LIMIT 0,200";
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 		$date_array = array();
489 489
 		$temp_array = array();
490 490
 		
491
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
491
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
492 492
 		{
493 493
 			$temp_array['date'] = $row['date'];
494 494
 
@@ -507,11 +507,11 @@  discard block
 block discarded – undo
507 507
 	* @return String success or false
508 508
 	*
509 509
 	*/	
510
-	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL)
510
+	public function updateIdentMarineData($fammarine_id = '', $ident = '', $fromsource = NULL)
511 511
 	{
512 512
 
513 513
 		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id';
514
-                $query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
514
+                $query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident);
515 515
 
516 516
 		try {
517 517
 			$sth = $this->db->prepare($query);
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
 	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '')
535 535
 	{
536 536
 		$query = 'UPDATE marine_output SET ident = :ident, last_latitude = :last_latitude, last_longitude = :last_longitude, last_seen = :last_seen, last_ground_speed = :last_ground_speed WHERE fammarine_id = :fammarine_id';
537
-                $query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
537
+                $query_values = array(':fammarine_id' => $fammarine_id, ':last_latitude' => $latitude, ':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed, ':last_seen' => $date, ':ident' => $ident);
538 538
 
539 539
 		try {
540 540
 			$sth = $this->db->prepare($query);
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 	* @param String $verticalrate vertival rate of flight
573 573
 	* @return String success or false
574 574
 	*/
575
-	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 = '')
575
+	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 576
 	{
577 577
 		global $globalURL;
578 578
 		
@@ -639,25 +639,25 @@  discard block
 block discarded – undo
639 639
 		}
640 640
 
641 641
     
642
-		if ($date == "" || strtotime($date) < time()-20*60)
642
+		if ($date == "" || strtotime($date) < time() - 20*60)
643 643
 		{
644 644
 			$date = date("Y-m-d H:i:s", time());
645 645
 		}
646 646
 
647
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
648
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
649
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
650
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
651
-		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
652
-		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
653
-		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
654
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
655
-		$type = filter_var($type,FILTER_SANITIZE_STRING);
656
-		$status = filter_var($status,FILTER_SANITIZE_STRING);
657
-		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
658
-		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
659
-		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
660
-		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
647
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
648
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
649
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
650
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
651
+		$heading = filter_var($heading, FILTER_SANITIZE_NUMBER_INT);
652
+		$groundspeed = filter_var($groundspeed, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
653
+		$format_source = filter_var($format_source, FILTER_SANITIZE_STRING);
654
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
655
+		$type = filter_var($type, FILTER_SANITIZE_STRING);
656
+		$status = filter_var($status, FILTER_SANITIZE_STRING);
657
+		$imo = filter_var($imo, FILTER_SANITIZE_STRING);
658
+		$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
659
+		$arrival_code = filter_var($arrival_code, FILTER_SANITIZE_STRING);
660
+		$arrival_date = filter_var($arrival_date, FILTER_SANITIZE_STRING);
661 661
 	
662 662
                 if ($latitude == '' && $longitude == '') {
663 663
             		$latitude = 0;
@@ -666,10 +666,10 @@  discard block
 block discarded – undo
666 666
                 if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
667 667
                 if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
668 668
                 if ($arrival_date == '') $arrival_date = NULL;
669
-		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
669
+		$query = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
670 670
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)";
671 671
 
672
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':heading' => $heading,':speed' => $groundspeed,':date' => $date,':format_source' => $format_source, ':source_name' => $source_name,':mmsi' => $mmsi,':type' => $type,':status' => $status,':imo' => $imo,':arrival_port_name' => $arrival_code,':arrival_port_date' => $arrival_date);
672
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident, ':latitude' => $latitude, ':longitude' => $longitude, ':heading' => $heading, ':speed' => $groundspeed, ':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':mmsi' => $mmsi, ':type' => $type, ':status' => $status, ':imo' => $imo, ':arrival_port_name' => $arrival_code, ':arrival_port_date' => $arrival_date);
673 673
 		try {
674 674
 		        
675 675
 			$sth = $this->db->prepare($query);
@@ -694,13 +694,13 @@  discard block
 block discarded – undo
694 694
 	{
695 695
 		global $globalDBdriver, $globalTimezone;
696 696
 		if ($globalDBdriver == 'mysql') {
697
-			$query  = "SELECT marine_output.ident FROM marine_output 
697
+			$query = "SELECT marine_output.ident FROM marine_output 
698 698
 								WHERE marine_output.ident = :ident 
699 699
 								AND marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
700 700
 								AND marine_output.date < UTC_TIMESTAMP()";
701 701
 			$query_data = array(':ident' => $ident);
702 702
 		} else {
703
-			$query  = "SELECT marine_output.ident FROM marine_output 
703
+			$query = "SELECT marine_output.ident FROM marine_output 
704 704
 								WHERE marine_output.ident = :ident 
705 705
 								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
706 706
 								AND marine_output.date < now() AT TIME ZONE 'UTC'";
@@ -709,8 +709,8 @@  discard block
 block discarded – undo
709 709
 		
710 710
 		$sth = $this->db->prepare($query);
711 711
 		$sth->execute($query_data);
712
-    		$ident_result='';
713
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
712
+    		$ident_result = '';
713
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
714 714
 		{
715 715
 			$ident_result = $row['ident'];
716 716
 		}
@@ -736,8 +736,8 @@  discard block
 block discarded – undo
736 736
 				return false;
737 737
 			} else {
738 738
 				$q_array = explode(" ", $q);
739
-				foreach ($q_array as $q_item){
740
-					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
739
+				foreach ($q_array as $q_item) {
740
+					$q_item = filter_var($q_item, FILTER_SANITIZE_STRING);
741 741
 					$additional_query .= " AND (";
742 742
 					$additional_query .= "(marine_output.ident like '%".$q_item."%')";
743 743
 					$additional_query .= ")";
@@ -745,11 +745,11 @@  discard block
 block discarded – undo
745 745
 			}
746 746
 		}
747 747
 		if ($globalDBdriver == 'mysql') {
748
-			$query  = "SELECT marine_output.* FROM marine_output 
748
+			$query = "SELECT marine_output.* FROM marine_output 
749 749
 				WHERE marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query." 
750 750
 				AND marine_output.date < UTC_TIMESTAMP()";
751 751
 		} else {
752
-			$query  = "SELECT marine_output.* FROM marine_output 
752
+			$query = "SELECT marine_output.* FROM marine_output 
753 753
 				WHERE marine_output.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query." 
754 754
 				AND marine_output.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
755 755
 		}
@@ -822,11 +822,11 @@  discard block
 block discarded – undo
822 822
 	* @return Array the callsign list
823 823
 	*
824 824
 	*/
825
-	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
825
+	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array(), $year = '', $month = '', $day = '')
826 826
 	{
827 827
 		global $globalDBdriver;
828
-		$filter_query = $this->getFilter($filters,true,true);
829
-		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
828
+		$filter_query = $this->getFilter($filters, true, true);
829
+		$query = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
830 830
                     FROM marine_output".$filter_query." marine_output.ident <> ''";
831 831
 		 if ($olderthanmonths > 0) {
832 832
 			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
@@ -840,28 +840,28 @@  discard block
 block discarded – undo
840 840
 		if ($year != '') {
841 841
 			if ($globalDBdriver == 'mysql') {
842 842
 				$query .= " AND YEAR(marine_output.date) = :year";
843
-				$query_values = array_merge($query_values,array(':year' => $year));
843
+				$query_values = array_merge($query_values, array(':year' => $year));
844 844
 			} else {
845 845
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
846
-				$query_values = array_merge($query_values,array(':year' => $year));
846
+				$query_values = array_merge($query_values, array(':year' => $year));
847 847
 			}
848 848
 		}
849 849
 		if ($month != '') {
850 850
 			if ($globalDBdriver == 'mysql') {
851 851
 				$query .= " AND MONTH(marine_output.date) = :month";
852
-				$query_values = array_merge($query_values,array(':month' => $month));
852
+				$query_values = array_merge($query_values, array(':month' => $month));
853 853
 			} else {
854 854
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
855
-				$query_values = array_merge($query_values,array(':month' => $month));
855
+				$query_values = array_merge($query_values, array(':month' => $month));
856 856
 			}
857 857
 		}
858 858
 		if ($day != '') {
859 859
 			if ($globalDBdriver == 'mysql') {
860 860
 				$query .= " AND DAY(marine_output.date) = :day";
861
-				$query_values = array_merge($query_values,array(':day' => $day));
861
+				$query_values = array_merge($query_values, array(':day' => $day));
862 862
 			} else {
863 863
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
864
-				$query_values = array_merge($query_values,array(':day' => $day));
864
+				$query_values = array_merge($query_values, array(':day' => $day));
865 865
 			}
866 866
 		}
867 867
 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
 		$callsign_array = array();
874 874
 		$temp_array = array();
875 875
         
876
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
876
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
877 877
 		{
878 878
 			$temp_array['callsign_icao'] = $row['ident'];
879 879
 			$temp_array['airline_name'] = $row['airline_name'];
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
 		$date_array = array();
926 926
 		$temp_array = array();
927 927
         
928
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
928
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
929 929
 		{
930 930
 			$temp_array['date_name'] = $row['date_name'];
931 931
 			$temp_array['date_count'] = $row['date_count'];
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
 			$datetime = new DateTime();
952 952
 			$offset = $datetime->format('P');
953 953
 		} else $offset = '+00:00';
954
-		$filter_query = $this->getFilter($filters,true,true);
954
+		$filter_query = $this->getFilter($filters, true, true);
955 955
 		if ($globalDBdriver == 'mysql') {
956 956
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
957 957
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY)";
@@ -972,7 +972,7 @@  discard block
 block discarded – undo
972 972
 		$date_array = array();
973 973
 		$temp_array = array();
974 974
         
975
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
975
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
976 976
 		{
977 977
 			$temp_array['date_name'] = $row['date_name'];
978 978
 			$temp_array['date_count'] = $row['date_count'];
@@ -997,7 +997,7 @@  discard block
 block discarded – undo
997 997
 			$datetime = new DateTime();
998 998
 			$offset = $datetime->format('P');
999 999
 		} else $offset = '+00:00';
1000
-		$filter_query = $this->getFilter($filters,true,true);
1000
+		$filter_query = $this->getFilter($filters, true, true);
1001 1001
 		if ($globalDBdriver == 'mysql') {
1002 1002
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1003 1003
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MONTH)";
@@ -1018,7 +1018,7 @@  discard block
 block discarded – undo
1018 1018
 		$date_array = array();
1019 1019
 		$temp_array = array();
1020 1020
         
1021
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1021
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1022 1022
 		{
1023 1023
 			$temp_array['date_name'] = $row['date_name'];
1024 1024
 			$temp_array['date_count'] = $row['date_count'];
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
 		$date_array = array();
1066 1066
 		$temp_array = array();
1067 1067
         
1068
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1068
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1069 1069
 		{
1070 1070
 			$temp_array['month_name'] = $row['month_name'];
1071 1071
 			$temp_array['year_name'] = $row['year_name'];
@@ -1094,7 +1094,7 @@  discard block
 block discarded – undo
1094 1094
 			$datetime = new DateTime();
1095 1095
 			$offset = $datetime->format('P');
1096 1096
 		} else $offset = '+00:00';
1097
-		$filter_query = $this->getFilter($filters,true,true);
1097
+		$filter_query = $this->getFilter($filters, true, true);
1098 1098
 		if ($globalDBdriver == 'mysql') {
1099 1099
 			$query  = "SELECT MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count
1100 1100
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 YEAR)";
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
 		$date_array = array();
1116 1116
 		$temp_array = array();
1117 1117
         
1118
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1118
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1119 1119
 		{
1120 1120
 			$temp_array['year_name'] = $row['year_name'];
1121 1121
 			$temp_array['month_name'] = $row['month_name'];
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
 	* @return Array the hour list
1136 1136
 	*
1137 1137
 	*/
1138
-	public function countAllHours($orderby,$filters = array())
1138
+	public function countAllHours($orderby, $filters = array())
1139 1139
 	{
1140 1140
 		global $globalTimezone, $globalDBdriver;
1141 1141
 		if ($globalTimezone != '') {
@@ -1183,7 +1183,7 @@  discard block
 block discarded – undo
1183 1183
 		$hour_array = array();
1184 1184
 		$temp_array = array();
1185 1185
         
1186
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1186
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1187 1187
 		{
1188 1188
 			$temp_array['hour_name'] = $row['hour_name'];
1189 1189
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1205,8 +1205,8 @@  discard block
 block discarded – undo
1205 1205
 	public function countAllHoursByDate($date, $filters = array())
1206 1206
 	{
1207 1207
 		global $globalTimezone, $globalDBdriver;
1208
-		$filter_query = $this->getFilter($filters,true,true);
1209
-		$date = filter_var($date,FILTER_SANITIZE_STRING);
1208
+		$filter_query = $this->getFilter($filters, true, true);
1209
+		$date = filter_var($date, FILTER_SANITIZE_STRING);
1210 1210
 		if ($globalTimezone != '') {
1211 1211
 			date_default_timezone_set($globalTimezone);
1212 1212
 			$datetime = new DateTime($date);
@@ -1214,12 +1214,12 @@  discard block
 block discarded – undo
1214 1214
 		} else $offset = '+00:00';
1215 1215
 
1216 1216
 		if ($globalDBdriver == 'mysql') {
1217
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1217
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1218 1218
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = :date
1219 1219
 								GROUP BY hour_name 
1220 1220
 								ORDER BY hour_name ASC";
1221 1221
 		} else {
1222
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1222
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1223 1223
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset, 'YYYY-mm-dd') = :date
1224 1224
 								GROUP BY hour_name 
1225 1225
 								ORDER BY hour_name ASC";
@@ -1231,7 +1231,7 @@  discard block
 block discarded – undo
1231 1231
 		$hour_array = array();
1232 1232
 		$temp_array = array();
1233 1233
         
1234
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1234
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1235 1235
 		{
1236 1236
 			$temp_array['hour_name'] = $row['hour_name'];
1237 1237
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1253,8 +1253,8 @@  discard block
 block discarded – undo
1253 1253
 	public function countAllHoursByIdent($ident, $filters = array())
1254 1254
 	{
1255 1255
 		global $globalTimezone, $globalDBdriver;
1256
-		$filter_query = $this->getFilter($filters,true,true);
1257
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
1256
+		$filter_query = $this->getFilter($filters, true, true);
1257
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
1258 1258
 		if ($globalTimezone != '') {
1259 1259
 			date_default_timezone_set($globalTimezone);
1260 1260
 			$datetime = new DateTime();
@@ -1262,12 +1262,12 @@  discard block
 block discarded – undo
1262 1262
 		} else $offset = '+00:00';
1263 1263
 
1264 1264
 		if ($globalDBdriver == 'mysql') {
1265
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1265
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1266 1266
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1267 1267
 								GROUP BY hour_name 
1268 1268
 								ORDER BY hour_name ASC";
1269 1269
 		} else {
1270
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1270
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1271 1271
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1272 1272
 								GROUP BY hour_name 
1273 1273
 								ORDER BY hour_name ASC";
@@ -1275,12 +1275,12 @@  discard block
 block discarded – undo
1275 1275
       
1276 1276
 		
1277 1277
 		$sth = $this->db->prepare($query);
1278
-		$sth->execute(array(':ident' => $ident,':offset' => $offset));
1278
+		$sth->execute(array(':ident' => $ident, ':offset' => $offset));
1279 1279
       
1280 1280
 		$hour_array = array();
1281 1281
 		$temp_array = array();
1282 1282
         
1283
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1283
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1284 1284
 		{
1285 1285
 			$temp_array['hour_name'] = $row['hour_name'];
1286 1286
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1299,32 +1299,32 @@  discard block
 block discarded – undo
1299 1299
 	* @return Integer the number of flights
1300 1300
 	*
1301 1301
 	*/
1302
-	public function countOverallTracked($filters = array(),$year = '',$month = '')
1302
+	public function countOverallTracked($filters = array(), $year = '', $month = '')
1303 1303
 	{
1304 1304
 		global $globalDBdriver;
1305
-		$queryi  = "SELECT COUNT(marine_output.marine_id) AS flight_count FROM marine_output";
1305
+		$queryi = "SELECT COUNT(marine_output.marine_id) AS flight_count FROM marine_output";
1306 1306
 		$query_values = array();
1307 1307
 		$query = '';
1308 1308
 		if ($year != '') {
1309 1309
 			if ($globalDBdriver == 'mysql') {
1310 1310
 				$query .= " AND YEAR(marine_output.date) = :year";
1311
-				$query_values = array_merge($query_values,array(':year' => $year));
1311
+				$query_values = array_merge($query_values, array(':year' => $year));
1312 1312
 			} else {
1313 1313
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1314
-				$query_values = array_merge($query_values,array(':year' => $year));
1314
+				$query_values = array_merge($query_values, array(':year' => $year));
1315 1315
 			}
1316 1316
 		}
1317 1317
 		if ($month != '') {
1318 1318
 			if ($globalDBdriver == 'mysql') {
1319 1319
 				$query .= " AND MONTH(marine_output.date) = :month";
1320
-				$query_values = array_merge($query_values,array(':month' => $month));
1320
+				$query_values = array_merge($query_values, array(':month' => $month));
1321 1321
 			} else {
1322 1322
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1323
-				$query_values = array_merge($query_values,array(':month' => $month));
1323
+				$query_values = array_merge($query_values, array(':month' => $month));
1324 1324
 			}
1325 1325
 		}
1326 1326
 		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1327
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1327
+		else $queryi .= $this->getFilter($filters, true, true).substr($query, 4);
1328 1328
 		
1329 1329
 		$sth = $this->db->prepare($queryi);
1330 1330
 		$sth->execute($query_values);
@@ -1341,7 +1341,7 @@  discard block
 block discarded – undo
1341 1341
 	public function countAllHoursFromToday($filters = array())
1342 1342
 	{
1343 1343
 		global $globalTimezone, $globalDBdriver;
1344
-		$filter_query = $this->getFilter($filters,true,true);
1344
+		$filter_query = $this->getFilter($filters, true, true);
1345 1345
 		if ($globalTimezone != '') {
1346 1346
 			date_default_timezone_set($globalTimezone);
1347 1347
 			$datetime = new DateTime();
@@ -1349,12 +1349,12 @@  discard block
 block discarded – undo
1349 1349
 		} else $offset = '+00:00';
1350 1350
 
1351 1351
 		if ($globalDBdriver == 'mysql') {
1352
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1352
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1353 1353
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = CURDATE()
1354 1354
 								GROUP BY hour_name 
1355 1355
 								ORDER BY hour_name ASC";
1356 1356
 		} else {
1357
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1357
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1358 1358
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = CAST(NOW() AS date)
1359 1359
 								GROUP BY hour_name 
1360 1360
 								ORDER BY hour_name ASC";
@@ -1366,7 +1366,7 @@  discard block
 block discarded – undo
1366 1366
 		$hour_array = array();
1367 1367
 		$temp_array = array();
1368 1368
         
1369
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1369
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1370 1370
 		{
1371 1371
 			$temp_array['hour_name'] = $row['hour_name'];
1372 1372
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1385,9 +1385,9 @@  discard block
 block discarded – undo
1385 1385
 	*/
1386 1386
 	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1387 1387
 	{
1388
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
1388
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
1389 1389
 
1390
-		$query  = "SELECT marine_output.marine_id
1390
+		$query = "SELECT marine_output.marine_id
1391 1391
 				FROM marine_output 
1392 1392
 				WHERE marine_output.fammarine_id = '".$fammarine_id."'";
1393 1393
         
@@ -1395,7 +1395,7 @@  discard block
 block discarded – undo
1395 1395
 		$sth = $this->db->prepare($query);
1396 1396
 		$sth->execute();
1397 1397
 
1398
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1398
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1399 1399
 		{
1400 1400
 			return $row['marine_id'];
1401 1401
 		}
@@ -1420,23 +1420,23 @@  discard block
 block discarded – undo
1420 1420
 		}
1421 1421
 		
1422 1422
 		$current_date = date("Y-m-d H:i:s");
1423
-		$date = date("Y-m-d H:i:s",strtotime($dateString." UTC"));
1423
+		$date = date("Y-m-d H:i:s", strtotime($dateString." UTC"));
1424 1424
 		
1425 1425
 		$diff = abs(strtotime($current_date) - strtotime($date));
1426 1426
 
1427
-		$time_array['years'] = floor($diff / (365*60*60*24)); 
1427
+		$time_array['years'] = floor($diff/(365*60*60*24)); 
1428 1428
 		$years = $time_array['years'];
1429 1429
 		
1430
-		$time_array['months'] = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
1430
+		$time_array['months'] = floor(($diff - $years*365*60*60*24)/(30*60*60*24));
1431 1431
 		$months = $time_array['months'];
1432 1432
 		
1433
-		$time_array['days'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
1433
+		$time_array['days'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24)/(60*60*24));
1434 1434
 		$days = $time_array['days'];
1435
-		$time_array['hours'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60));
1435
+		$time_array['hours'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/(60*60));
1436 1436
 		$hours = $time_array['hours'];
1437
-		$time_array['minutes'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60);
1437
+		$time_array['minutes'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/60);
1438 1438
 		$minutes = $time_array['minutes'];
1439
-		$time_array['seconds'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1439
+		$time_array['seconds'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1440 1440
 		
1441 1441
 		return $time_array;
1442 1442
 	}
@@ -1459,63 +1459,63 @@  discard block
 block discarded – undo
1459 1459
 			$temp_array['direction_degree'] = $direction;
1460 1460
 			$temp_array['direction_shortname'] = "N";
1461 1461
 			$temp_array['direction_fullname'] = "North";
1462
-		} elseif ($direction >= 22.5 && $direction < 45){
1462
+		} elseif ($direction >= 22.5 && $direction < 45) {
1463 1463
 			$temp_array['direction_degree'] = $direction;
1464 1464
 			$temp_array['direction_shortname'] = "NNE";
1465 1465
 			$temp_array['direction_fullname'] = "North-Northeast";
1466
-		} elseif ($direction >= 45 && $direction < 67.5){
1466
+		} elseif ($direction >= 45 && $direction < 67.5) {
1467 1467
 			$temp_array['direction_degree'] = $direction;
1468 1468
 			$temp_array['direction_shortname'] = "NE";
1469 1469
 			$temp_array['direction_fullname'] = "Northeast";
1470
-		} elseif ($direction >= 67.5 && $direction < 90){
1470
+		} elseif ($direction >= 67.5 && $direction < 90) {
1471 1471
 			$temp_array['direction_degree'] = $direction;
1472 1472
 			$temp_array['direction_shortname'] = "ENE";
1473 1473
 			$temp_array['direction_fullname'] = "East-Northeast";
1474
-		} elseif ($direction >= 90 && $direction < 112.5){
1474
+		} elseif ($direction >= 90 && $direction < 112.5) {
1475 1475
 			$temp_array['direction_degree'] = $direction;
1476 1476
 			$temp_array['direction_shortname'] = "E";
1477 1477
 			$temp_array['direction_fullname'] = "East";
1478
-		} elseif ($direction >= 112.5 && $direction < 135){
1478
+		} elseif ($direction >= 112.5 && $direction < 135) {
1479 1479
 			$temp_array['direction_degree'] = $direction;
1480 1480
 			$temp_array['direction_shortname'] = "ESE";
1481 1481
 			$temp_array['direction_fullname'] = "East-Southeast";
1482
-		} elseif ($direction >= 135 && $direction < 157.5){
1482
+		} elseif ($direction >= 135 && $direction < 157.5) {
1483 1483
 			$temp_array['direction_degree'] = $direction;
1484 1484
 			$temp_array['direction_shortname'] = "SE";
1485 1485
 			$temp_array['direction_fullname'] = "Southeast";
1486
-		} elseif ($direction >= 157.5 && $direction < 180){
1486
+		} elseif ($direction >= 157.5 && $direction < 180) {
1487 1487
 			$temp_array['direction_degree'] = $direction;
1488 1488
 			$temp_array['direction_shortname'] = "SSE";
1489 1489
 			$temp_array['direction_fullname'] = "South-Southeast";
1490
-		} elseif ($direction >= 180 && $direction < 202.5){
1490
+		} elseif ($direction >= 180 && $direction < 202.5) {
1491 1491
 			$temp_array['direction_degree'] = $direction;
1492 1492
 			$temp_array['direction_shortname'] = "S";
1493 1493
 			$temp_array['direction_fullname'] = "South";
1494
-		} elseif ($direction >= 202.5 && $direction < 225){
1494
+		} elseif ($direction >= 202.5 && $direction < 225) {
1495 1495
 			$temp_array['direction_degree'] = $direction;
1496 1496
 			$temp_array['direction_shortname'] = "SSW";
1497 1497
 			$temp_array['direction_fullname'] = "South-Southwest";
1498
-		} elseif ($direction >= 225 && $direction < 247.5){
1498
+		} elseif ($direction >= 225 && $direction < 247.5) {
1499 1499
 			$temp_array['direction_degree'] = $direction;
1500 1500
 			$temp_array['direction_shortname'] = "SW";
1501 1501
 			$temp_array['direction_fullname'] = "Southwest";
1502
-		} elseif ($direction >= 247.5 && $direction < 270){
1502
+		} elseif ($direction >= 247.5 && $direction < 270) {
1503 1503
 			$temp_array['direction_degree'] = $direction;
1504 1504
 			$temp_array['direction_shortname'] = "WSW";
1505 1505
 			$temp_array['direction_fullname'] = "West-Southwest";
1506
-		} elseif ($direction >= 270 && $direction < 292.5){
1506
+		} elseif ($direction >= 270 && $direction < 292.5) {
1507 1507
 			$temp_array['direction_degree'] = $direction;
1508 1508
 			$temp_array['direction_shortname'] = "W";
1509 1509
 			$temp_array['direction_fullname'] = "West";
1510
-		} elseif ($direction >= 292.5 && $direction < 315){
1510
+		} elseif ($direction >= 292.5 && $direction < 315) {
1511 1511
 			$temp_array['direction_degree'] = $direction;
1512 1512
 			$temp_array['direction_shortname'] = "WNW";
1513 1513
 			$temp_array['direction_fullname'] = "West-Northwest";
1514
-		} elseif ($direction >= 315 && $direction < 337.5){
1514
+		} elseif ($direction >= 315 && $direction < 337.5) {
1515 1515
 			$temp_array['direction_degree'] = $direction;
1516 1516
 			$temp_array['direction_shortname'] = "NW";
1517 1517
 			$temp_array['direction_fullname'] = "Northwest";
1518
-		} elseif ($direction >= 337.5 && $direction < 360){
1518
+		} elseif ($direction >= 337.5 && $direction < 360) {
1519 1519
 			$temp_array['direction_degree'] = $direction;
1520 1520
 			$temp_array['direction_shortname'] = "NNW";
1521 1521
 			$temp_array['direction_fullname'] = "North-Northwest";
@@ -1532,11 +1532,11 @@  discard block
 block discarded – undo
1532 1532
 	* @param Float $longitude longitute of the flight
1533 1533
 	* @return String the countrie
1534 1534
 	*/
1535
-	public function getCountryFromLatitudeLongitude($latitude,$longitude)
1535
+	public function getCountryFromLatitudeLongitude($latitude, $longitude)
1536 1536
 	{
1537 1537
 		global $globalDBdriver, $globalDebug;
1538
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1539
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1538
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1539
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1540 1540
 	
1541 1541
 		$Connection = new Connection($this->db);
1542 1542
 		if (!$Connection->tableExists('countries')) return '';
@@ -1576,7 +1576,7 @@  discard block
 block discarded – undo
1576 1576
 	public function getCountryFromISO2($iso2)
1577 1577
 	{
1578 1578
 		global $globalDBdriver, $globalDebug;
1579
-		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
1579
+		$iso2 = filter_var($iso2, FILTER_SANITIZE_STRING);
1580 1580
 	
1581 1581
 		$Connection = new Connection($this->db);
1582 1582
 		if (!$Connection->tableExists('countries')) return '';
@@ -1624,7 +1624,7 @@  discard block
 block discarded – undo
1624 1624
 		
1625 1625
 		$bitly_data = json_decode($bitly_data);
1626 1626
 		$bitly_url = '';
1627
-		if ($bitly_data->status_txt = "OK"){
1627
+		if ($bitly_data->status_txt = "OK") {
1628 1628
 			$bitly_url = $bitly_data->data->url;
1629 1629
 		}
1630 1630
 
@@ -1634,7 +1634,7 @@  discard block
 block discarded – undo
1634 1634
 
1635 1635
 	public function getOrderBy()
1636 1636
 	{
1637
-		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_output.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_output.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_output.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_output.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_output.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_output.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_output.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_output.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_output.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_output.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_output.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_output.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_output.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_output.date DESC"),"distance_asc" => array("key" => "distance_asc","value" => "Distance - ASC","sql" => "ORDER BY distance ASC"),"distance_desc" => array("key" => "distance_desc","value" => "Distance - DESC","sql" => "ORDER BY distance DESC"));
1637
+		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_output.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_output.aircraft_icao DESC"), "manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_output.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_output.aircraft_manufacturer DESC"), "airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_output.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_output.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_output.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_output.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_output.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_output.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_output.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_output.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_output.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_output.date DESC"), "distance_asc" => array("key" => "distance_asc", "value" => "Distance - ASC", "sql" => "ORDER BY distance ASC"), "distance_desc" => array("key" => "distance_desc", "value" => "Distance - DESC", "sql" => "ORDER BY distance DESC"));
1638 1638
 		
1639 1639
 		return $orderby;
1640 1640
 		
Please login to merge, or discard this patch.
require/class.Common.php 4 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.
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
7 7
 	//protected $cookies = array();
8 8
 	
9 9
 	/**
10
-	* Get data from form result
11
-	* @param String $url form URL
12
-	* @param String $type type of submit form method (get or post)
13
-	* @param String|Array $data values form post method
14
-	* @param Array $headers header to submit with the form
15
-	* @return String the result
16
-	*/
10
+	 * Get data from form result
11
+	 * @param String $url form URL
12
+	 * @param String $type type of submit form method (get or post)
13
+	 * @param String|Array $data values form post method
14
+	 * @param Array $headers header to submit with the form
15
+	 * @return String the result
16
+	 */
17 17
 	public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '') {
18 18
 		global $globalProxy, $globalForceIPv4;
19 19
 		$ch = curl_init();
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
 	}
108 108
 	
109 109
 	/**
110
-	* Convert a HTML table to an array
111
-	* @param String $data HTML page
112
-	* @return Array array of the tables in HTML page
113
-	*/
110
+	 * Convert a HTML table to an array
111
+	 * @param String $data HTML page
112
+	 * @return Array array of the tables in HTML page
113
+	 */
114 114
 	public function table2array($data) {
115 115
 		if (!is_string($data)) return array();
116 116
 		if ($data == '') return array();
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
 	}
145 145
 	
146 146
 	/**
147
-	* Convert <p> part of a HTML page to an array
148
-	* @param String $data HTML page
149
-	* @return Array array of the <p> in HTML page
150
-	*/
147
+	 * Convert <p> part of a HTML page to an array
148
+	 * @param String $data HTML page
149
+	 * @return Array array of the <p> in HTML page
150
+	 */
151 151
 	public function text2array($data) {
152 152
 		$html = str_get_html($data);
153 153
 		if ($html === false) return array();
@@ -162,14 +162,14 @@  discard block
 block discarded – undo
162 162
 	}
163 163
 
164 164
 	/**
165
-	* Give distance between 2 coordonnates
166
-	* @param Float $lat latitude of first point
167
-	* @param Float $lon longitude of first point
168
-	* @param Float $latc latitude of second point
169
-	* @param Float $lonc longitude of second point
170
-	* @param String $unit km else no unit used
171
-	* @return Float Distance in $unit
172
-	*/
165
+	 * Give distance between 2 coordonnates
166
+	 * @param Float $lat latitude of first point
167
+	 * @param Float $lon longitude of first point
168
+	 * @param Float $latc latitude of second point
169
+	 * @param Float $lonc longitude of second point
170
+	 * @param String $unit km else no unit used
171
+	 * @return Float Distance in $unit
172
+	 */
173 173
 	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
174 174
 		if ($lat == $latc && $lon == $lonc) return 0;
175 175
 		$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;
@@ -187,11 +187,11 @@  discard block
 block discarded – undo
187 187
 	}
188 188
 
189 189
 	/**
190
-	* Check is distance realistic
191
-	* @param int $timeDifference the time between the reception of both messages
192
-	* @param float $distance distance covered
193
-	* @return whether distance is realistic
194
-	*/
190
+	 * Check is distance realistic
191
+	 * @param int $timeDifference the time between the reception of both messages
192
+	 * @param float $distance distance covered
193
+	 * @return whether distance is realistic
194
+	 */
195 195
 	public function withinThreshold ($timeDifference, $distance) {
196 196
 		$x = abs($timeDifference);
197 197
 		$d = abs($distance);
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	}
210 210
 
211 211
 	public function isInteger($input){
212
-	    return(ctype_digit(strval($input)));
212
+		return(ctype_digit(strval($input)));
213 213
 	}
214 214
 
215 215
 
@@ -240,11 +240,11 @@  discard block
 block discarded – undo
240 240
 	}
241 241
 	
242 242
 	/**
243
-	* Copy folder contents
244
-	* @param       string   $source    Source path
245
-	* @param       string   $dest      Destination path
246
-	* @return      bool     Returns true on success, false on failure
247
-	*/
243
+	 * Copy folder contents
244
+	 * @param       string   $source    Source path
245
+	 * @param       string   $dest      Destination path
246
+	 * @return      bool     Returns true on success, false on failure
247
+	 */
248 248
 	public function xcopy($source, $dest)
249 249
 	{
250 250
 		$files = glob($source.'*.*');
@@ -256,20 +256,20 @@  discard block
 block discarded – undo
256 256
 	}
257 257
 	
258 258
 	/**
259
-	* Check if an url exist
260
-	* @param	String $url url to check
261
-	* @return	bool Return true on succes false on failure
262
-	*/
259
+	 * Check if an url exist
260
+	 * @param	String $url url to check
261
+	 * @return	bool Return true on succes false on failure
262
+	 */
263 263
 	public function urlexist($url){
264 264
 		$headers=get_headers($url);
265 265
 		return stripos($headers[0],"200 OK")?true:false;
266 266
 	}
267 267
 	
268 268
 	/**
269
-	* Convert hexa to string
270
-	* @param	String $hex data in hexa
271
-	* @return	String Return result
272
-	*/
269
+	 * Convert hexa to string
270
+	 * @param	String $hex data in hexa
271
+	 * @return	String Return result
272
+	 */
273 273
 	public function hex2str($hex) {
274 274
 		$str = '';
275 275
 		$hexln = strlen($hex);
@@ -350,9 +350,9 @@  discard block
 block discarded – undo
350 350
 	}
351 351
 	
352 352
 	/**
353
-	* Returns list of available locales
354
-	*
355
-	* @return array
353
+	 * Returns list of available locales
354
+	 *
355
+	 * @return array
356 356
 	 */
357 357
 	public function listLocaleDir()
358 358
 	{
@@ -447,100 +447,100 @@  discard block
 block discarded – undo
447 447
 	public function remove_accents($string) {
448 448
 		if ( !preg_match('/[\x80-\xff]/', $string) ) return $string;
449 449
 		$chars = array(
450
-		    // Decompositions for Latin-1 Supplement
451
-		    chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
452
-		    chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
453
-		    chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
454
-		    chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
455
-		    chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
456
-		    chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
457
-		    chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
458
-		    chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
459
-		    chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
460
-		    chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
461
-		    chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
462
-		    chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
463
-		    chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
464
-		    chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
465
-		    chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
466
-		    chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
467
-		    chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
468
-		    chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
469
-		    chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
470
-		    chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
471
-		    chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
472
-		    chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
473
-		    chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
474
-		    chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
475
-		    chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
476
-		    chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
477
-		    chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
478
-		    chr(195).chr(191) => 'y',
479
-		    // Decompositions for Latin Extended-A
480
-		    chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
481
-		    chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
482
-		    chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
483
-		    chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
484
-		    chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
485
-		    chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
486
-		    chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
487
-		    chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
488
-		    chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
489
-		    chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
490
-		    chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
491
-		    chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
492
-		    chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
493
-		    chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
494
-		    chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
495
-		    chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
496
-		    chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
497
-		    chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
498
-		    chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
499
-		    chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
500
-		    chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
501
-		    chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
502
-		    chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
503
-		    chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
504
-		    chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
505
-		    chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
506
-		    chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
507
-		    chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
508
-		    chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
509
-		    chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
510
-		    chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
511
-		    chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
512
-		    chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
513
-		    chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
514
-		    chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
515
-		    chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
516
-		    chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
517
-		    chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
518
-		    chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
519
-		    chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
520
-		    chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
521
-		    chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
522
-		    chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
523
-		    chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
524
-		    chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
525
-		    chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
526
-		    chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
527
-		    chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
528
-		    chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
529
-		    chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
530
-		    chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
531
-		    chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
532
-		    chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
533
-		    chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
534
-		    chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
535
-		    chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
536
-		    chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
537
-		    chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
538
-		    chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
539
-		    chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
540
-		    chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
541
-		    chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
542
-		    chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
543
-		    chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
450
+			// Decompositions for Latin-1 Supplement
451
+			chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
452
+			chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
453
+			chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
454
+			chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
455
+			chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
456
+			chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
457
+			chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
458
+			chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
459
+			chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
460
+			chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
461
+			chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
462
+			chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
463
+			chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
464
+			chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
465
+			chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
466
+			chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
467
+			chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
468
+			chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
469
+			chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
470
+			chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
471
+			chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
472
+			chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
473
+			chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
474
+			chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
475
+			chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
476
+			chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
477
+			chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
478
+			chr(195).chr(191) => 'y',
479
+			// Decompositions for Latin Extended-A
480
+			chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
481
+			chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
482
+			chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
483
+			chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
484
+			chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
485
+			chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
486
+			chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
487
+			chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
488
+			chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
489
+			chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
490
+			chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
491
+			chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
492
+			chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
493
+			chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
494
+			chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
495
+			chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
496
+			chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
497
+			chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
498
+			chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
499
+			chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
500
+			chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
501
+			chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
502
+			chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
503
+			chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
504
+			chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
505
+			chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
506
+			chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
507
+			chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
508
+			chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
509
+			chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
510
+			chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
511
+			chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
512
+			chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
513
+			chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
514
+			chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
515
+			chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
516
+			chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
517
+			chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
518
+			chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
519
+			chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
520
+			chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
521
+			chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
522
+			chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
523
+			chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
524
+			chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
525
+			chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
526
+			chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
527
+			chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
528
+			chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
529
+			chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
530
+			chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
531
+			chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
532
+			chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
533
+			chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
534
+			chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
535
+			chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
536
+			chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
537
+			chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
538
+			chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
539
+			chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
540
+			chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
541
+			chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
542
+			chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
543
+			chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
544 544
 		);
545 545
 		$string = strtr($string, $chars);
546 546
 		return $string;
Please login to merge, or discard this patch.
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -14,12 +14,12 @@  discard block
 block discarded – undo
14 14
 	* @param Array $headers header to submit with the form
15 15
 	* @return String the result
16 16
 	*/
17
-	public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '') {
17
+	public function getData($url, $type = 'get', $data = '', $headers = '', $cookie = '', $referer = '', $timeout = '', $useragent = '') {
18 18
 		global $globalProxy, $globalForceIPv4;
19 19
 		$ch = curl_init();
20 20
 		curl_setopt($ch, CURLOPT_URL, $url);
21 21
 		if (isset($globalForceIPv4) && $globalForceIPv4) {
22
-			if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
22
+			if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) {
23 23
 				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
24 24
 			}
25 25
 		}
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
30 30
 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
31 31
 		curl_setopt($ch, CURLINFO_HEADER_OUT, true); 
32
-		curl_setopt($ch,CURLOPT_ENCODING , "gzip");
32
+		curl_setopt($ch, CURLOPT_ENCODING, "gzip");
33 33
 		//curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
34 34
 //		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0');
35 35
 		if ($useragent == '') {
@@ -39,13 +39,13 @@  discard block
 block discarded – undo
39 39
 		}
40 40
 		if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
41 41
 		else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 
42
-		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback"));
42
+		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common', "curlResponseHeaderCallback"));
43 43
 		if ($type == 'post') {
44 44
 			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
45 45
 			if (is_array($data)) {
46 46
 				curl_setopt($ch, CURLOPT_POST, count($data));
47 47
 				$data_string = '';
48
-				foreach($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; }
48
+				foreach ($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; }
49 49
 				rtrim($data_string, '&');
50 50
 				curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
51 51
 			} else {
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		}
58 58
 		if ($cookie != '') {
59 59
 			if (is_array($cookie)) {
60
-				curl_setopt($ch, CURLOPT_COOKIE, implode($cookie,';'));
60
+				curl_setopt($ch, CURLOPT_COOKIE, implode($cookie, ';'));
61 61
 			} else {
62 62
 				curl_setopt($ch, CURLOPT_COOKIE, $cookie);
63 63
 			}
@@ -69,13 +69,13 @@  discard block
 block discarded – undo
69 69
 		$info = curl_getinfo($ch);
70 70
 		//var_dump($info);
71 71
 		curl_close($ch);
72
-		if ($info['http_code'] == '503' && strstr($result,'DDoS protection by CloudFlare')) {
72
+		if ($info['http_code'] == '503' && strstr($result, 'DDoS protection by CloudFlare')) {
73 73
 			echo "Cloudflare Detected\n";
74 74
 			require_once(dirname(__FILE__).'/libs/cloudflare-bypass/libraries/cloudflareClass.php');
75 75
 			$useragent = UAgent::random();
76 76
 			cloudflare::useUserAgent($useragent);
77 77
 			if ($clearanceCookie = cloudflare::bypass($url)) {
78
-				return $this->getData($url,'get',$data,$headers,$clearanceCookie,$referer,$timeout,$useragent);
78
+				return $this->getData($url, 'get', $data, $headers, $clearanceCookie, $referer, $timeout, $useragent);
79 79
 			}
80 80
 		} else {
81 81
 			return $result;
@@ -116,27 +116,27 @@  discard block
 block discarded – undo
116 116
 		if ($data == '') return array();
117 117
 		$html = str_get_html($data);
118 118
 		if ($html === false) return array();
119
-		$tabledata=array();
120
-		foreach($html->find('tr') as $element)
119
+		$tabledata = array();
120
+		foreach ($html->find('tr') as $element)
121 121
 		{
122 122
 			$td = array();
123
-			foreach( $element->find('th') as $row)
123
+			foreach ($element->find('th') as $row)
124 124
 			{
125 125
 				$td [] = trim($row->plaintext);
126 126
 			}
127
-			$td=array_filter($td);
127
+			$td = array_filter($td);
128 128
 			$tabledata[] = $td;
129 129
 
130 130
 			$td = array();
131 131
 			$tdi = array();
132
-			foreach( $element->find('td') as $row)
132
+			foreach ($element->find('td') as $row)
133 133
 			{
134 134
 				$td [] = trim($row->plaintext);
135 135
 				$tdi [] = trim($row->innertext);
136 136
 			}
137
-			$td=array_filter($td);
138
-			$tdi=array_filter($tdi);
139
-			$tabledata[]=array_merge($td,$tdi);
137
+			$td = array_filter($td);
138
+			$tdi = array_filter($tdi);
139
+			$tabledata[] = array_merge($td, $tdi);
140 140
 		}
141 141
 		$html->clear();
142 142
 		unset($html);
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
 	public function text2array($data) {
152 152
 		$html = str_get_html($data);
153 153
 		if ($html === false) return array();
154
-		$tabledata=array();
155
-		foreach($html->find('p') as $element)
154
+		$tabledata = array();
155
+		foreach ($html->find('p') as $element)
156 156
 		{
157 157
 			$tabledata [] = trim($element->plaintext);
158 158
 		}
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
 	*/
173 173
 	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
174 174
 		if ($lat == $latc && $lon == $lonc) return 0;
175
-		$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;
175
+		$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 176
 		if ($unit == "km") {
177
-			return round($dist * 1.609344);
177
+			return round($dist*1.609344);
178 178
 		} elseif ($unit == "m") {
179
-			return round($dist * 1.609344 * 1000);
179
+			return round($dist*1.609344*1000);
180 180
 		} elseif ($unit == "mile" || $unit == "mi") {
181 181
 			return round($dist);
182 182
 		} elseif ($unit == "nm") {
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	* @param float $distance distance covered
193 193
 	* @return whether distance is realistic
194 194
 	*/
195
-	public function withinThreshold ($timeDifference, $distance) {
195
+	public function withinThreshold($timeDifference, $distance) {
196 196
 		$x = abs($timeDifference);
197 197
 		$d = abs($distance);
198 198
 		if ($x == 0 || $d == 0) return true;
@@ -208,12 +208,12 @@  discard block
 block discarded – undo
208 208
 		return ($array !== array_values($array));
209 209
 	}
210 210
 
211
-	public function isInteger($input){
211
+	public function isInteger($input) {
212 212
 	    return(ctype_digit(strval($input)));
213 213
 	}
214 214
 
215 215
 
216
-	public function convertDec($dms,$latlong) {
216
+	public function convertDec($dms, $latlong) {
217 217
 		if ($latlong == 'latitude') {
218 218
 			$deg = substr($dms, 0, 2);
219 219
 			$min = substr($dms, 2, 4);
@@ -221,10 +221,10 @@  discard block
 block discarded – undo
221 221
 			$deg = substr($dms, 0, 3);
222 222
 			$min = substr($dms, 3, 5);
223 223
 		}
224
-		return $deg+(($min*60)/3600);
224
+		return $deg + (($min*60)/3600);
225 225
 	}
226 226
 	
227
-	public function convertDM($coord,$latlong) {
227
+	public function convertDM($coord, $latlong) {
228 228
 		if ($latlong == 'latitude') {
229 229
 			if ($coord < 0) $NSEW = 'S';
230 230
 			else $NSEW = 'N';
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
 		}
235 235
 		$coord = abs($coord);
236 236
 		$deg = floor($coord);
237
-		$coord = ($coord-$deg)*60;
237
+		$coord = ($coord - $deg)*60;
238 238
 		$min = $coord;
239
-		return array('deg' => $deg,'min' => $min,'NSEW' => $NSEW);
239
+		return array('deg' => $deg, 'min' => $min, 'NSEW' => $NSEW);
240 240
 	}
241 241
 	
242 242
 	/**
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
 	public function xcopy($source, $dest)
249 249
 	{
250 250
 		$files = glob($source.'*.*');
251
-		foreach($files as $file){
252
-			$file_to_go = str_replace($source,$dest,$file);
251
+		foreach ($files as $file) {
252
+			$file_to_go = str_replace($source, $dest, $file);
253 253
 			copy($file, $file_to_go);
254 254
 		}
255 255
 		return true;
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
 	* @param	String $url url to check
261 261
 	* @return	bool Return true on succes false on failure
262 262
 	*/
263
-	public function urlexist($url){
264
-		$headers=get_headers($url);
265
-		return stripos($headers[0],"200 OK")?true:false;
263
+	public function urlexist($url) {
264
+		$headers = get_headers($url);
265
+		return stripos($headers[0], "200 OK") ? true : false;
266 266
 	}
267 267
 	
268 268
 	/**
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 	public function hex2str($hex) {
274 274
 		$str = '';
275 275
 		$hexln = strlen($hex);
276
-		for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
276
+		for ($i = 0; $i < $hexln; $i += 2) $str .= chr(hexdec(substr($hex, $i, 2)));
277 277
 		return $str;
278 278
 	}
279 279
 	
@@ -282,33 +282,33 @@  discard block
 block discarded – undo
282 282
 		//difference in longitudinal coordinates
283 283
 		$dLon = deg2rad($lon2) - deg2rad($lon1);
284 284
 		//difference in the phi of latitudinal coordinates
285
-		$dPhi = log(tan(deg2rad($lat2) / 2 + pi() / 4) / tan(deg2rad($lat1) / 2 + pi() / 4));
285
+		$dPhi = log(tan(deg2rad($lat2)/2 + pi()/4)/tan(deg2rad($lat1)/2 + pi()/4));
286 286
 		//we need to recalculate $dLon if it is greater than pi
287
-		if(abs($dLon) > pi()) {
288
-			if($dLon > 0) {
289
-				$dLon = (2 * pi() - $dLon) * -1;
287
+		if (abs($dLon) > pi()) {
288
+			if ($dLon > 0) {
289
+				$dLon = (2*pi() - $dLon)*-1;
290 290
 			} else {
291
-				$dLon = 2 * pi() + $dLon;
291
+				$dLon = 2*pi() + $dLon;
292 292
 			}
293 293
 		}
294 294
 		//return the angle, normalized
295
-		return (rad2deg(atan2($dLon, $dPhi)) + 360) % 360;
295
+		return (rad2deg(atan2($dLon, $dPhi)) + 360)%360;
296 296
 	}
297 297
 	
298
-	public function checkLine($lat1,$lon1,$lat2,$lon2,$lat3,$lon3,$approx = 0.2) {
298
+	public function checkLine($lat1, $lon1, $lat2, $lon2, $lat3, $lon3, $approx = 0.2) {
299 299
 		//$a = ($lon2-$lon1)*$lat3+($lat2-$lat1)*$lon3+($lat1*$lon2+$lat2*$lon1);
300
-		$a = -($lon2-$lon1);
300
+		$a = -($lon2 - $lon1);
301 301
 		$b = $lat2 - $lat1;
302
-		$c = -($a*$lat1+$b*$lon1);
303
-		$d = $a*$lat3+$b*$lon3+$c;
302
+		$c = -($a*$lat1 + $b*$lon1);
303
+		$d = $a*$lat3 + $b*$lon3 + $c;
304 304
 		if ($d > -$approx && $d < $approx) return true;
305 305
 		else return false;
306 306
 	}
307 307
 	
308 308
 	public function array_merge_noappend() {
309 309
 		$output = array();
310
-		foreach(func_get_args() as $array) {
311
-			foreach($array as $key => $value) {
310
+		foreach (func_get_args() as $array) {
311
+			foreach ($array as $key => $value) {
312 312
 				$output[$key] = isset($output[$key]) ?
313 313
 				array_merge($output[$key], $value) : $value;
314 314
 			}
@@ -372,34 +372,34 @@  discard block
 block discarded – undo
372 372
 		return $result;
373 373
 	}
374 374
 
375
-	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1){
375
+	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1) {
376 376
 		global $globalMapRefresh;
377 377
 		$distance = ($speed*0.514444*$globalMapRefresh*$archivespeed)/1000;
378 378
 		$r = 6378;
379 379
 		$latitude = deg2rad($latitude);
380 380
 		$longitude = deg2rad($longitude);
381 381
 		$bearing = deg2rad($heading); 
382
-		$latitude2 =  asin( (sin($latitude) * cos($distance/$r)) + (cos($latitude) * sin($distance/$r) * cos($bearing)) );
383
-		$longitude2 = $longitude + atan2( sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r)-(sin($latitude)*sin($latitude2)) );
384
-		return array('latitude' => number_format(rad2deg($latitude2),5,'.',''),'longitude' => number_format(rad2deg($longitude2),5,'.',''));
382
+		$latitude2 = asin((sin($latitude)*cos($distance/$r)) + (cos($latitude)*sin($distance/$r)*cos($bearing)));
383
+		$longitude2 = $longitude + atan2(sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r) - (sin($latitude)*sin($latitude2)));
384
+		return array('latitude' => number_format(rad2deg($latitude2), 5, '.', ''), 'longitude' => number_format(rad2deg($longitude2), 5, '.', ''));
385 385
 	}
386 386
 	
387
-	public function getCoordfromDistanceBearing($latitude,$longitude,$bearing,$distance) {
387
+	public function getCoordfromDistanceBearing($latitude, $longitude, $bearing, $distance) {
388 388
 		// distance in meter
389 389
 		$R = 6378.14;
390
-		$latitude1 = $latitude * (M_PI/180);
391
-		$longitude1 = $longitude * (M_PI/180);
392
-		$brng = $bearing * (M_PI/180);
390
+		$latitude1 = $latitude*(M_PI/180);
391
+		$longitude1 = $longitude*(M_PI/180);
392
+		$brng = $bearing*(M_PI/180);
393 393
 		$d = $distance;
394 394
 
395 395
 		$latitude2 = asin(sin($latitude1)*cos($d/$R) + cos($latitude1)*sin($d/$R)*cos($brng));
396
-		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1),cos($d/$R)-sin($latitude1)*sin($latitude2));
396
+		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1), cos($d/$R) - sin($latitude1)*sin($latitude2));
397 397
 
398
-		$latitude2 = $latitude2 * (180/M_PI);
399
-		$longitude2 = $longitude2 * (180/M_PI);
398
+		$latitude2 = $latitude2*(180/M_PI);
399
+		$longitude2 = $longitude2*(180/M_PI);
400 400
 
401
-		$flat = round ($latitude2,6);
402
-		$flong = round ($longitude2,6);
401
+		$flat = round($latitude2, 6);
402
+		$flong = round($longitude2, 6);
403 403
 /*
404 404
 		$dx = $distance*cos($bearing);
405 405
 		$dy = $distance*sin($bearing);
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 		$flong = $longitude + $dlong;
409 409
 		$flat = $latitude + $dlat;
410 410
 */
411
-		return array('latitude' => $flat,'longitude' => $flong);
411
+		return array('latitude' => $flat, 'longitude' => $flong);
412 412
 	}
413 413
 
414 414
 	/**
@@ -422,14 +422,14 @@  discard block
 block discarded – undo
422 422
 	 * @param integer $level GZIP compression level (default: 9)
423 423
 	 * @return string New filename (with .gz appended) if success, or false if operation fails
424 424
 	 */
425
-	public function gzCompressFile($source, $level = 9){ 
426
-		$dest = $source . '.gz'; 
427
-		$mode = 'wb' . $level; 
425
+	public function gzCompressFile($source, $level = 9) { 
426
+		$dest = $source.'.gz'; 
427
+		$mode = 'wb'.$level; 
428 428
 		$error = false; 
429 429
 		if ($fp_out = gzopen($dest, $mode)) { 
430
-			if ($fp_in = fopen($source,'rb')) { 
430
+			if ($fp_in = fopen($source, 'rb')) { 
431 431
 				while (!feof($fp_in)) 
432
-					gzwrite($fp_out, fread($fp_in, 1024 * 512)); 
432
+					gzwrite($fp_out, fread($fp_in, 1024*512)); 
433 433
 				fclose($fp_in); 
434 434
 			} else {
435 435
 				$error = true; 
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 	} 
446 446
 	
447 447
 	public function remove_accents($string) {
448
-		if ( !preg_match('/[\x80-\xff]/', $string) ) return $string;
448
+		if (!preg_match('/[\x80-\xff]/', $string)) return $string;
449 449
 		$chars = array(
450 450
 		    // Decompositions for Latin-1 Supplement
451 451
 		    chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 		    chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
503 503
 		    chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
504 504
 		    chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
505
-		    chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
505
+		    chr(196).chr(178) => 'IJ', chr(196).chr(179) => 'ij',
506 506
 		    chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
507 507
 		    chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
508 508
 		    chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
@@ -518,13 +518,13 @@  discard block
 block discarded – undo
518 518
 		    chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
519 519
 		    chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
520 520
 		    chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
521
-		    chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
522
-		    chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
523
-		    chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
524
-		    chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
525
-		    chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
526
-		    chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
527
-		    chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
521
+		    chr(197).chr(146) => 'OE', chr(197).chr(147) => 'oe',
522
+		    chr(197).chr(148) => 'R', chr(197).chr(149) => 'r',
523
+		    chr(197).chr(150) => 'R', chr(197).chr(151) => 'r',
524
+		    chr(197).chr(152) => 'R', chr(197).chr(153) => 'r',
525
+		    chr(197).chr(154) => 'S', chr(197).chr(155) => 's',
526
+		    chr(197).chr(156) => 'S', chr(197).chr(157) => 's',
527
+		    chr(197).chr(158) => 'S', chr(197).chr(159) => 's',
528 528
 		    chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
529 529
 		    chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
530 530
 		    chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 		for ($i = 0, $int = '', $concat_flag = true; $i < $length; $i++) {
559 559
 			if (is_numeric($string[$i]) && $concat_flag) {
560 560
 				$int .= $string[$i];
561
-			} elseif(!$concat && $concat_flag && strlen($int) > 0) {
561
+			} elseif (!$concat && $concat_flag && strlen($int) > 0) {
562 562
 				$concat_flag = false;
563 563
 			}
564 564
 		}
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.SpotterImport.php 4 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.
Indentation   +402 added lines, -402 removed lines patch added patch discarded remove patch
@@ -8,20 +8,20 @@  discard block
 block discarded – undo
8 8
 require_once(dirname(__FILE__).'/class.Stats.php');
9 9
 require_once(dirname(__FILE__).'/class.Source.php');
10 10
 if (isset($globalServerAPRS) && $globalServerAPRS) {
11
-    require_once(dirname(__FILE__).'/class.APRS.php');
11
+	require_once(dirname(__FILE__).'/class.APRS.php');
12 12
 }
13 13
 
14 14
 class SpotterImport {
15
-    private $all_flights = array();
16
-    private $last_delete_hourly = 0;
17
-    private $last_delete = 0;
18
-    private $stats = array();
19
-    private $tmd = 0;
20
-    private $source_location = array();
21
-    public $db = null;
22
-    public $nb = 0;
23
-
24
-    public function __construct($dbc = null) {
15
+	private $all_flights = array();
16
+	private $last_delete_hourly = 0;
17
+	private $last_delete = 0;
18
+	private $stats = array();
19
+	private $tmd = 0;
20
+	private $source_location = array();
21
+	public $db = null;
22
+	public $nb = 0;
23
+
24
+	public function __construct($dbc = null) {
25 25
 	global $globalBeta, $globalServerAPRS, $APRSSpotter, $globalNoDB;
26 26
 	if (!(isset($globalNoDB) && $globalNoDB)) {
27 27
 		$Connection = new Connection($dbc);
@@ -33,14 +33,14 @@  discard block
 block discarded – undo
33 33
 		$currentdate = date('Y-m-d');
34 34
 		$sourcestat = $Stats->getStatsSource($currentdate);
35 35
 		if (!empty($sourcestat)) {
36
-		    foreach($sourcestat as $srcst) {
37
-		    	$type = $srcst['stats_type'];
36
+			foreach($sourcestat as $srcst) {
37
+				$type = $srcst['stats_type'];
38 38
 			if ($type == 'polar' || $type == 'hist') {
39
-			    $source = $srcst['source_name'];
40
-			    $data = $srcst['source_data'];
41
-			    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
42
-	    		}
43
-		    }
39
+				$source = $srcst['source_name'];
40
+				$data = $srcst['source_data'];
41
+				$this->stats[$currentdate][$source][$type] = json_decode($data,true);
42
+				}
43
+			}
44 44
 		}
45 45
 	}
46 46
 	if (isset($globalServerAPRS) && $globalServerAPRS) {
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
 		//$APRSSpotter->connect();
49 49
 	}
50 50
 
51
-    }
51
+	}
52 52
 
53
-    public function get_Schedule($id,$ident) {
53
+	public function get_Schedule($id,$ident) {
54 54
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
55 55
 	// Get schedule here, so it's done only one time
56 56
 	
@@ -70,42 +70,42 @@  discard block
 block discarded – undo
70 70
 	$operator = $Spotter->getOperator($ident);
71 71
 	$scheduleexist = false;
72 72
 	if ($Schedule->checkSchedule($operator) == 0) {
73
-	    $operator = $Translation->checkTranslation($ident);
74
-	    if ($Schedule->checkSchedule($operator) == 0) {
73
+		$operator = $Translation->checkTranslation($ident);
74
+		if ($Schedule->checkSchedule($operator) == 0) {
75 75
 		$schedule = $Schedule->fetchSchedule($operator);
76 76
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
77
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
78
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
79
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
80
-		    // Should also check if route schedule = route from DB
81
-		    if ($schedule['DepartureAirportIATA'] != '') {
77
+			if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
78
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
79
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
80
+			// Should also check if route schedule = route from DB
81
+			if ($schedule['DepartureAirportIATA'] != '') {
82 82
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
83
-			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
84
-			    if (trim($airport_icao) != '') {
83
+				$airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
84
+				if (trim($airport_icao) != '') {
85 85
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
86 86
 				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
87
-			    }
87
+				}
88
+			}
88 89
 			}
89
-		    }
90
-		    if ($schedule['ArrivalAirportIATA'] != '') {
90
+			if ($schedule['ArrivalAirportIATA'] != '') {
91 91
 			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) {
92
-			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
93
-			    if (trim($airport_icao) != '') {
92
+				$airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
93
+				if (trim($airport_icao) != '') {
94 94
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
95 95
 				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
96
-			    }
96
+				}
97 97
 			}
98
-		    }
99
-		    $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']);
98
+			}
99
+			$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']);
100 100
 		}
101
-	    } else $scheduleexist = true;
101
+		} else $scheduleexist = true;
102 102
 	} else $scheduleexist = true;
103 103
 	// close connection, at least one way will work ?
104
-       if ($scheduleexist) {
104
+	   if ($scheduleexist) {
105 105
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
106
-    		$sch = $Schedule->getSchedule($operator);
106
+			$sch = $Schedule->getSchedule($operator);
107 107
 		$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']));
108
-       }
108
+	   }
109 109
 	$Spotter->db = null;
110 110
 	$Schedule->db = null;
111 111
 	$Translation->db = null;
@@ -120,96 +120,96 @@  discard block
 block discarded – undo
120 120
 	}
121 121
 	  */
122 122
 	}
123
-    }
123
+	}
124 124
 
125
-    public function checkAll() {
125
+	public function checkAll() {
126 126
 	global $globalDebug, $globalNoImport;
127 127
 	if ($globalDebug) echo "Update last seen flights data...\n";
128 128
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
129
-	    foreach ($this->all_flights as $key => $flight) {
129
+		foreach ($this->all_flights as $key => $flight) {
130 130
 		if (isset($this->all_flights[$key]['id'])) {
131
-		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
132
-    		    $Spotter = new Spotter($this->db);
133
-        	    $real_arrival = $this->arrival($key);
134
-        	    $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']);
135
-        	}
136
-	    }
131
+			//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
132
+				$Spotter = new Spotter($this->db);
133
+				$real_arrival = $this->arrival($key);
134
+				$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']);
135
+			}
136
+		}
137
+	}
137 138
 	}
138
-    }
139 139
 
140
-    public function arrival($key) {
140
+	public function arrival($key) {
141 141
 	global $globalClosestMinDist, $globalDebug;
142 142
 	if ($globalDebug) echo 'Update arrival...'."\n";
143 143
 	$Spotter = new Spotter($this->db);
144
-        $airport_icao = '';
145
-        $airport_time = '';
146
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
144
+		$airport_icao = '';
145
+		$airport_time = '';
146
+		if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
147 147
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
148
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
149
-    	    if (isset($closestAirports[0])) {
150
-        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
151
-        	    $airport_icao = $closestAirports[0]['icao'];
152
-        	    $airport_time = $this->all_flights[$key]['datetime'];
153
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
154
-        	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
155
-        	    foreach ($closestAirports as $airport) {
156
-        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
157
-        		    $airport_icao = $airport['icao'];
158
-        		    $airport_time = $this->all_flights[$key]['datetime'];
159
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
160
-        		    break;
161
-        		}
162
-        	    }
163
-        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
164
-        		$airport_icao = $closestAirports[0]['icao'];
165
-        		$airport_time = $this->all_flights[$key]['datetime'];
166
-        	} else {
167
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
168
-        	}
169
-    	    } else {
170
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
171
-    	    }
172
-
173
-        } else {
174
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
175
-        }
176
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
177
-    }
178
-
179
-
180
-
181
-    public function del() {
148
+		$closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
149
+			if (isset($closestAirports[0])) {
150
+			if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
151
+				$airport_icao = $closestAirports[0]['icao'];
152
+				$airport_time = $this->all_flights[$key]['datetime'];
153
+				if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
154
+			} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
155
+				foreach ($closestAirports as $airport) {
156
+				if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
157
+					$airport_icao = $airport['icao'];
158
+					$airport_time = $this->all_flights[$key]['datetime'];
159
+					if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
160
+					break;
161
+				}
162
+				}
163
+			} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
164
+				$airport_icao = $closestAirports[0]['icao'];
165
+				$airport_time = $this->all_flights[$key]['datetime'];
166
+			} else {
167
+				if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
168
+			}
169
+			} else {
170
+				if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
171
+			}
172
+
173
+		} else {
174
+			if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
175
+		}
176
+		return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
177
+	}
178
+
179
+
180
+
181
+	public function del() {
182 182
 	global $globalDebug, $globalNoImport, $globalNoDB;
183 183
 	// Delete old infos
184 184
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
185 185
 	foreach ($this->all_flights as $key => $flight) {
186
-    	    if (isset($flight['lastupdate'])) {
187
-        	if ($flight['lastupdate'] < (time()-3000)) {
188
-            	    if (isset($this->all_flights[$key]['id'])) {
189
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
186
+			if (isset($flight['lastupdate'])) {
187
+			if ($flight['lastupdate'] < (time()-3000)) {
188
+					if (isset($this->all_flights[$key]['id'])) {
189
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
190 190
 			/*
191 191
 			$SpotterLive = new SpotterLive();
192 192
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
193 193
 			$SpotterLive->db = null;
194 194
 			*/
195 195
 			if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
196
-            		    $real_arrival = $this->arrival($key);
197
-            		    $Spotter = new Spotter($this->db);
198
-            	    	    if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
196
+						$real_arrival = $this->arrival($key);
197
+						$Spotter = new Spotter($this->db);
198
+							if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
199 199
 				$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']);
200 200
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
201
-			    }
201
+				}
202 202
 			// Put in archive
203 203
 //				$Spotter->db = null;
204 204
 			}
205
-            	    }
206
-            	    unset($this->all_flights[$key]);
207
-    	        }
208
-	    }
209
-        }
210
-    }
205
+					}
206
+					unset($this->all_flights[$key]);
207
+				}
208
+		}
209
+		}
210
+	}
211 211
 
212
-    public function add($line) {
212
+	public function add($line) {
213 213
 	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, $globalNoDB;
214 214
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
215 215
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
@@ -234,18 +234,18 @@  discard block
 block discarded – undo
234 234
 	
235 235
 	// SBS format is CSV format
236 236
 	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
237
-	    //print_r($line);
238
-  	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
237
+		//print_r($line);
238
+  		if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
239 239
 
240 240
 		// Increment message number
241 241
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
242
-		    $current_date = date('Y-m-d');
243
-		    $source = $line['source_name'];
244
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
245
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
246
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
247
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
248
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
242
+			$current_date = date('Y-m-d');
243
+			$source = $line['source_name'];
244
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
245
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
246
+				$this->stats[$current_date][$source]['msg']['date'] = time();
247
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
248
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
249 249
 		}
250 250
 		
251 251
 		/*
@@ -261,49 +261,49 @@  discard block
 block discarded – undo
261 261
 		//$this->db = $dbc;
262 262
 
263 263
 		//$hex = trim($line['hex']);
264
-	        if (!isset($line['id'])) $id = trim($line['hex']);
265
-	        else $id = trim($line['id']);
264
+			if (!isset($line['id'])) $id = trim($line['hex']);
265
+			else $id = trim($line['id']);
266 266
 		
267 267
 		if (!isset($this->all_flights[$id])) {
268
-		    $this->all_flights[$id] = array();
269
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
270
-		    $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' => ''));
271
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
272
-		    if (!isset($line['id'])) {
268
+			$this->all_flights[$id] = array();
269
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
270
+			$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' => ''));
271
+			if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
272
+			if (!isset($line['id'])) {
273 273
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
274 274
 //			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')));
275 275
 //			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')));
276 276
 			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')));
277
-		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
278
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
279
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
277
+				//else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
278
+			 } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
279
+			if ($globalAllFlights !== FALSE) $dataFound = true;
280 280
 		}
281 281
 		if (isset($line['source_type']) && $line['source_type'] != '') {
282
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
282
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
283 283
 		}
284 284
 		
285 285
 		//print_r($this->all_flights);
286 286
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
287
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
288
-		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
287
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
288
+			//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
289 289
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
290
-		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
291
-		    if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
290
+			//} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
291
+			if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
292 292
 			$timeelapsed = microtime(true);
293 293
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
294
-			    $Spotter = new Spotter($this->db);
295
-			    if (isset($this->all_flights[$id]['source_type'])) {
294
+				$Spotter = new Spotter($this->db);
295
+				if (isset($this->all_flights[$id]['source_type'])) {
296 296
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
297
-			    } else {
297
+				} else {
298 298
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
299
-			    }
300
-			    $Spotter->db = null;
301
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
302
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
299
+				}
300
+				$Spotter->db = null;
301
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
302
+				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
303 303
 			}
304
-		    }
305
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
306
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
304
+			}
305
+			if ($globalAllFlights !== FALSE) $dataFound = true;
306
+			if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
307 307
 		}
308 308
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
309 309
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
@@ -329,9 +329,9 @@  discard block
 block discarded – undo
329 329
 		}
330 330
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
331 331
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60) {
332
-		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
332
+			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
333 333
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
334
-		    } else {
334
+			} else {
335 335
 				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";
336 336
 				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";
337 337
 				/*
@@ -340,43 +340,43 @@  discard block
 block discarded – undo
340 340
 				print_r($line);
341 341
 				*/
342 342
 				return '';
343
-		    }
343
+			}
344 344
 		} else {
345 345
 			date_default_timezone_set('UTC');
346 346
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
347 347
 		}
348 348
 
349 349
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
350
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
350
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
351 351
 		}
352 352
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
353
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
353
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
354 354
 		}
355 355
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
356
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
356
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
357 357
 		}
358 358
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
359
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
359
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
360 360
 		}
361 361
  
362 362
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
363
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
364
-		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
363
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
364
+			if ($this->all_flights[$id]['addedSpotter'] == 1) {
365 365
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
366
-			    $timeelapsed = microtime(true);
367
-            		    $Spotter = new Spotter($this->db);
368
-            		    $fromsource = NULL;
369
-            		    if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
370
-            		    elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
371
-			    elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
372
-			    elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
373
-			    elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
374
-            		    $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
375
-			    if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
376
-			    $Spotter->db = null;
377
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
378
-			}
379
-		    }
366
+				$timeelapsed = microtime(true);
367
+						$Spotter = new Spotter($this->db);
368
+						$fromsource = NULL;
369
+						if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
370
+						elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
371
+				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
372
+				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
373
+				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
374
+						$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
375
+				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
376
+				$Spotter->db = null;
377
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
378
+			}
379
+			}
380 380
 
381 381
 /*
382 382
 		    if (!isset($line['id'])) {
@@ -386,104 +386,104 @@  discard block
 block discarded – undo
386 386
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
387 387
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
388 388
   */
389
-		    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']));
389
+			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']));
390 390
 
391
-		    //$putinarchive = true;
392
-		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
391
+			//$putinarchive = true;
392
+			if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
393 393
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
394
-		    }
395
-		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
394
+			}
395
+			if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
396 396
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
397
-		    }
398
-		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
399
-		    		$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' => ''));
400
-		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
397
+			}
398
+			if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
399
+					$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' => ''));
400
+			} elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
401 401
 			$timeelapsed = microtime(true);
402 402
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
403 403
 				$Spotter = new Spotter($this->db);
404 404
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
405 405
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
406
-		    		$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' => ''));
406
+					$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' => ''));
407 407
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
408
-                        }
409
-		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
408
+						}
409
+			} elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
410 410
 			$timeelapsed = microtime(true);
411 411
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
412
-			    $Spotter = new Spotter($this->db);
413
-			    $route = $Spotter->getRouteInfo(trim($line['ident']));
414
-			    if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) {
412
+				$Spotter = new Spotter($this->db);
413
+				$route = $Spotter->getRouteInfo(trim($line['ident']));
414
+				if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) {
415 415
 				$Translation = new Translation($this->db);
416 416
 				$ident = $Translation->checkTranslation(trim($line['ident']));
417 417
 				$route = $Spotter->getRouteInfo($ident);
418 418
 				$Translation->db = null;
419
-			    }
420
-			    $Spotter->db = null;
421
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
422
-                    	}
419
+				}
420
+				$Spotter->db = null;
421
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
422
+						}
423 423
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
424
-			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
425
-			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
424
+				//if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
425
+				if ($route['fromairport_icao'] != $route['toairport_icao']) {
426 426
 				//    $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']));
427
-		    		$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']));
428
-		    	    }
427
+					$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']));
428
+					}
429 429
 			}
430 430
 			if (!isset($globalFork)) $globalFork = TRUE;
431 431
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
432 432
 				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
433 433
 			}
434
-		    }
434
+			}
435 435
 		}
436 436
 
437 437
 		if (isset($line['speed']) && $line['speed'] != '') {
438 438
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
439
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
440
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
441
-		    //$dataFound = true;
439
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
440
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
441
+			//$dataFound = true;
442 442
 		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
443
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
444
-		    if ($distance > 1000 && $distance < 10000) {
445
-		    // use datetime
443
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
444
+			if ($distance > 1000 && $distance < 10000) {
445
+			// use datetime
446 446
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
447 447
 			$speed = $speed*3.6;
448 448
 			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
449 449
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
450
-		    }
450
+			}
451 451
 		}
452 452
 
453 453
 
454 454
 
455
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
456
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
457
-	    	    else unset($timediff);
458
-	    	    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')))) {
455
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
456
+				if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
457
+				else unset($timediff);
458
+				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')))) {
459 459
 			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'])) {
460
-			    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'])) {
460
+				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'])) {
461 461
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
462 462
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
463 463
 				$this->all_flights[$id]['putinarchive'] = true;
464 464
 				$this->tmd = 0;
465 465
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
466
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
467
-				    $timeelapsed = microtime(true);
468
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
466
+					if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
467
+					$timeelapsed = microtime(true);
468
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
469 469
 					$Spotter = new Spotter($this->db);
470 470
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
471 471
 					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
472 472
 					$Spotter->db = null;
473 473
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
474 474
 					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
475
-				    }
475
+					}
476
+				}
476 477
 				}
477
-			    }
478 478
 			}
479 479
 
480 480
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
481
-			    //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) {
481
+				//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) {
482 482
 				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
483 483
 				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') {
484
-				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
485
-				    $dataFound = true;
486
-				    $this->all_flights[$id]['time_last_coord'] = time();
484
+					$this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
485
+					$dataFound = true;
486
+					$this->all_flights[$id]['time_last_coord'] = time();
487 487
 				}
488 488
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
489 489
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
@@ -494,20 +494,20 @@  discard block
 block discarded – undo
494 494
 				    //$putinarchive = true;
495 495
 				}
496 496
 				*/
497
-			    /*
497
+				/*
498 498
 			    } elseif (isset($this->all_flights[$id]['latitude'])) {
499 499
 				if ($globalDebug) echo '!!! Strange latitude value - diff : '.abs($this->all_flights[$id]['latitude']-$line['latitude']).'- previous lat : '.$this->all_flights[$id]['latitude'].'- new lat : '.$line['latitude']."\n";
500 500
 			    }
501 501
 			    */
502 502
 			}
503 503
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
504
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
505
-			    //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) {
504
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
505
+				//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) {
506 506
 				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
507 507
 				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') {
508
-				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
509
-				    $dataFound = true;
510
-				    $this->all_flights[$id]['time_last_coord'] = time();
508
+					$this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
509
+					$dataFound = true;
510
+					$this->all_flights[$id]['time_last_coord'] = time();
511 511
 				}
512 512
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
513 513
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
@@ -525,95 +525,95 @@  discard block
 block discarded – undo
525 525
 			    */
526 526
 			}
527 527
 
528
-		    } else if ($globalDebug && $timediff > 30) {
528
+			} else if ($globalDebug && $timediff > 30) {
529 529
 			$this->tmd = $this->tmd + 1;
530 530
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
531 531
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
532 532
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
533 533
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
534
-		    }
534
+			}
535 535
 		}
536 536
 		if (isset($line['last_update']) && $line['last_update'] != '') {
537
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
538
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
537
+			if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
538
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
539 539
 		}
540 540
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
541
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
542
-		    //$dataFound = true;
541
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
542
+			//$dataFound = true;
543 543
 		}
544 544
 		if (isset($line['format_source']) && $line['format_source'] != '') {
545
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
545
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
546 546
 		}
547 547
 		if (isset($line['source_name']) && $line['source_name'] != '') {
548
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
548
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
549 549
 		}
550 550
 		if (isset($line['emergency']) && $line['emergency'] != '') {
551
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
552
-		    //$dataFound = true;
551
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
552
+			//$dataFound = true;
553 553
 		}
554 554
 		if (isset($line['ground']) && $line['ground'] != '') {
555
-		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
555
+			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
556 556
 			// Here we force archive of flight because after ground it's a new one (or should be)
557 557
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
558 558
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
559 559
 			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')));
560
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
560
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
561 561
 			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']));
562
-		    }
563
-		    if ($line['ground'] != 1) $line['ground'] = 0;
564
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
565
-		    //$dataFound = true;
562
+			}
563
+			if ($line['ground'] != 1) $line['ground'] = 0;
564
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
565
+			//$dataFound = true;
566 566
 		}
567 567
 		if (isset($line['squawk']) && $line['squawk'] != '') {
568
-		    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'])) {
569
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
570
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
571
-			    $highlight = '';
572
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
573
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
574
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
575
-			    if ($highlight != '') {
568
+			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'])) {
569
+				if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
570
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
571
+				$highlight = '';
572
+				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
573
+				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
574
+				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
575
+				if ($highlight != '') {
576 576
 				$timeelapsed = microtime(true);
577 577
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
578
-				    $Spotter = new Spotter($this->db);
579
-				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
580
-				    $Spotter->db = null;
581
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
578
+					$Spotter = new Spotter($this->db);
579
+					$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
580
+					$Spotter->db = null;
581
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
582 582
 				}
583 583
 				//$putinarchive = true;
584 584
 				//$highlight = '';
585
-			    }
585
+				}
586 586
 			    
587
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
588
-		    //$dataFound = true;
587
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
588
+			//$dataFound = true;
589 589
 		}
590 590
 
591 591
 		if (isset($line['altitude']) && $line['altitude'] != '') {
592
-		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
592
+			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
593 593
 			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;
594 594
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
595 595
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
596 596
 			//$dataFound = true;
597
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
597
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
598 598
   		}
599 599
 
600 600
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
601
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
601
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
602 602
 		}
603 603
 		
604 604
 		if (isset($line['heading']) && $line['heading'] != '') {
605
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
606
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
607
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
608
-		    //$dataFound = true;
605
+			if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
606
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
607
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
608
+			//$dataFound = true;
609 609
   		} 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']) {
610
-  		    $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']);
611
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
612
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
613
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
610
+  			$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']);
611
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
612
+			if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
613
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
614 614
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
615
-  		    // If not enough messages and ACARS set heading to 0
616
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
615
+  			// If not enough messages and ACARS set heading to 0
616
+  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
617 617
   		}
618 618
 		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
619 619
 		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
@@ -624,125 +624,125 @@  discard block
 block discarded – undo
624 624
 		//if ($dataFound == true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
625 625
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
626 626
 		if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
627
-		    $this->all_flights[$id]['lastupdate'] = time();
628
-		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
629
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
630
-			    //print_r($this->all_flights);
631
-			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
632
-			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
633
-			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
627
+			$this->all_flights[$id]['lastupdate'] = time();
628
+			if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
629
+				if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
630
+				//print_r($this->all_flights);
631
+				//echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
632
+				//$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
633
+				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
634 634
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
635
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
636
-				    $timeelapsed = microtime(true);
637
-				    $SpotterLive = new SpotterLive($this->db);
638
-				    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')) {
635
+					if ($globalDebug) echo "Check if aircraft is already in DB...";
636
+					$timeelapsed = microtime(true);
637
+					$SpotterLive = new SpotterLive($this->db);
638
+					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')) {
639 639
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
640 640
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
641
-				    } elseif (isset($line['id'])) {
641
+					} elseif (isset($line['id'])) {
642 642
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
643 643
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
644
-				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
644
+					} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
645 645
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
646 646
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
647
-				    } else $recent_ident = '';
648
-				    $SpotterLive->db=null;
649
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
650
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
647
+					} else $recent_ident = '';
648
+					$SpotterLive->db=null;
649
+					if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
650
+					elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
651 651
 				} else $recent_ident = '';
652
-			    } else {
652
+				} else {
653 653
 				$recent_ident = '';
654 654
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
655
-			    }
656
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
657
-			    if($recent_ident == "")
658
-			    {
655
+				}
656
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
657
+				if($recent_ident == "")
658
+				{
659 659
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
660 660
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
661 661
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
662 662
 				//adds the spotter data for the archive
663 663
 				$ignoreImport = false;
664 664
 				foreach($globalAirportIgnore as $airportIgnore) {
665
-				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
665
+					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
666 666
 					$ignoreImport = true;
667
-				    }
667
+					}
668 668
 				}
669 669
 				if (count($globalAirportAccept) > 0) {
670
-				    $ignoreImport = true;
671
-				    foreach($globalAirportIgnore as $airportIgnore) {
670
+					$ignoreImport = true;
671
+					foreach($globalAirportIgnore as $airportIgnore) {
672 672
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
673
-					    $ignoreImport = false;
673
+						$ignoreImport = false;
674
+					}
674 675
 					}
675
-				    }
676 676
 				}
677 677
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
678
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
678
+					foreach($globalAirlineIgnore as $airlineIgnore) {
679 679
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
680
-					    $ignoreImport = true;
680
+						$ignoreImport = true;
681
+					}
681 682
 					}
682
-				    }
683 683
 				}
684 684
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
685
-				    $ignoreImport = true;
686
-				    foreach($globalAirlineAccept as $airlineAccept) {
685
+					$ignoreImport = true;
686
+					foreach($globalAirlineAccept as $airlineAccept) {
687 687
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
688
-					    $ignoreImport = false;
688
+						$ignoreImport = false;
689
+					}
689 690
 					}
690
-				    }
691 691
 				}
692 692
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
693
-				    $ignoreImport = true;
694
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
693
+					$ignoreImport = true;
694
+					foreach($globalPilotIdAccept as $pilotIdAccept) {
695 695
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
696
-					    $ignoreImport = false;
696
+						$ignoreImport = false;
697
+					}
697 698
 					}
698
-				    }
699 699
 				}
700 700
 				
701 701
 				if (!$ignoreImport) {
702
-				    $highlight = '';
703
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
704
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
705
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
706
-				    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')));
707
-				    $timeelapsed = microtime(true);
708
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
702
+					$highlight = '';
703
+					if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
704
+					if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
705
+					if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
706
+					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')));
707
+					$timeelapsed = microtime(true);
708
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
709 709
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
710
-					    $Spotter = new Spotter($this->db);
711
-					    $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]['altitude_real'], $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']);
712
-					    $Spotter->db = null;
713
-					    if ($globalDebug && isset($result)) echo $result."\n";
710
+						$Spotter = new Spotter($this->db);
711
+						$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]['altitude_real'], $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']);
712
+						$Spotter->db = null;
713
+						if ($globalDebug && isset($result)) echo $result."\n";
714
+					}
714 715
 					}
715
-				    }
716
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
717
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
716
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
717
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
718 718
 
719
-				    // Add source stat in DB
720
-				    $Stats = new Stats($this->db);
721
-				    if (!empty($this->stats)) {
719
+					// Add source stat in DB
720
+					$Stats = new Stats($this->db);
721
+					if (!empty($this->stats)) {
722 722
 					if ($globalDebug) echo 'Add source stats : ';
723
-				        foreach($this->stats as $date => $data) {
724
-					    foreach($data as $source => $sourced) {
725
-					        //print_r($sourced);
726
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
727
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
728
-				    		if (isset($sourced['msg'])) {
729
-				    		    if (time() - $sourced['msg']['date'] > 10) {
730
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
731
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
732
-			    			        unset($this->stats[$date][$source]['msg']);
733
-			    			    }
734
-			    			}
735
-			    		    }
736
-			    		    if ($date != date('Y-m-d')) {
737
-			    			unset($this->stats[$date]);
738
-			    		    }
739
-				    	}
740
-				    	if ($globalDebug) echo 'Done'."\n";
741
-
742
-				    }
743
-				    $Stats->db = null;
744
-				    }
745
-				    $this->del();
723
+						foreach($this->stats as $date => $data) {
724
+						foreach($data as $source => $sourced) {
725
+							//print_r($sourced);
726
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
727
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
728
+							if (isset($sourced['msg'])) {
729
+								if (time() - $sourced['msg']['date'] > 10) {
730
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
731
+									echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
732
+									unset($this->stats[$date][$source]['msg']);
733
+								}
734
+							}
735
+							}
736
+							if ($date != date('Y-m-d')) {
737
+							unset($this->stats[$date]);
738
+							}
739
+						}
740
+						if ($globalDebug) echo 'Done'."\n";
741
+
742
+					}
743
+					$Stats->db = null;
744
+					}
745
+					$this->del();
746 746
 				} elseif ($globalDebug) echo 'Ignore data'."\n";
747 747
 				//$ignoreImport = false;
748 748
 				$this->all_flights[$id]['addedSpotter'] = 1;
@@ -760,41 +760,41 @@  discard block
 block discarded – undo
760 760
 			*/
761 761
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
762 762
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
763
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
764
-				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
765
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
763
+					if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
764
+					//SpotterLive->deleteLiveSpotterDataNotUpdated();
765
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
766 766
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
767
-					    $SpotterLive = new SpotterLive($this->db);
768
-					    $SpotterLive->deleteLiveSpotterData();
769
-					    $SpotterLive->db=null;
767
+						$SpotterLive = new SpotterLive($this->db);
768
+						$SpotterLive->deleteLiveSpotterData();
769
+						$SpotterLive->db=null;
770
+					}
770 771
 					}
771
-				    }
772
-				    if ($globalDebug) echo " Done\n";
773
-				    $this->last_delete = time();
772
+					if ($globalDebug) echo " Done\n";
773
+					$this->last_delete = time();
774 774
 				}
775
-			    } else {
775
+				} else {
776 776
 				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')) {
777
-				    $this->all_flights[$id]['id'] = $recent_ident;
778
-				    $this->all_flights[$id]['addedSpotter'] = 1;
777
+					$this->all_flights[$id]['id'] = $recent_ident;
778
+					$this->all_flights[$id]['addedSpotter'] = 1;
779 779
 				}
780 780
 				if (isset($globalDaemon) && !$globalDaemon) {
781
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
781
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
782 782
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
783
-					    $Spotter = new Spotter($this->db);
784
-					    $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
785
-					    $Spotter->db = null;
783
+						$Spotter = new Spotter($this->db);
784
+						$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
785
+						$Spotter->db = null;
786
+					}
786 787
 					}
787
-				    }
788 788
 				}
789 789
 				
790
-			    }
790
+				}
791
+			}
791 792
 			}
792
-		    }
793
-		    //adds the spotter LIVE data
794
-		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
795
-		    //echo "\nAdd in Live !! \n";
796
-		    //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";
797
-		    if ($globalDebug) {
793
+			//adds the spotter LIVE data
794
+			//SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
795
+			//echo "\nAdd in Live !! \n";
796
+			//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";
797
+			if ($globalDebug) {
798 798
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
799 799
 				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";
800 800
 				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";
@@ -802,60 +802,60 @@  discard block
 block discarded – undo
802 802
 				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";
803 803
 				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";
804 804
 			}
805
-		    }
806
-		    $ignoreImport = false;
807
-		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
808
-		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
805
+			}
806
+			$ignoreImport = false;
807
+			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
808
+			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
809 809
 
810
-		    foreach($globalAirportIgnore as $airportIgnore) {
811
-		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
812
-			    $ignoreImport = true;
810
+			foreach($globalAirportIgnore as $airportIgnore) {
811
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
812
+				$ignoreImport = true;
813 813
 			}
814
-		    }
815
-		    if (count($globalAirportAccept) > 0) {
816
-		        $ignoreImport = true;
817
-		        foreach($globalAirportIgnore as $airportIgnore) {
818
-			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
814
+			}
815
+			if (count($globalAirportAccept) > 0) {
816
+				$ignoreImport = true;
817
+				foreach($globalAirportIgnore as $airportIgnore) {
818
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
819 819
 				$ignoreImport = false;
820
-			    }
820
+				}
821
+			}
821 822
 			}
822
-		    }
823
-		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
823
+			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
824 824
 			foreach($globalAirlineIgnore as $airlineIgnore) {
825
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
825
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
826 826
 				$ignoreImport = true;
827
-			    }
827
+				}
828 828
 			}
829
-		    }
830
-		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
829
+			}
830
+			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
831 831
 			$ignoreImport = true;
832 832
 			foreach($globalAirlineAccept as $airlineAccept) {
833
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
833
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
834 834
 				$ignoreImport = false;
835
-			    }
835
+				}
836
+			}
836 837
 			}
837
-		    }
838
-		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
838
+			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
839 839
 			$ignoreImport = true;
840 840
 			foreach($globalPilotIdAccept as $pilotIdAccept) {
841
-			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
842
-			        $ignoreImport = false;
843
-			    }
841
+				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
842
+					$ignoreImport = false;
843
+				}
844
+			}
844 845
 			}
845
-		    }
846 846
 
847
-		    if (!$ignoreImport) {
847
+			if (!$ignoreImport) {
848 848
 			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'])) {
849 849
 				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')));
850 850
 				$timeelapsed = microtime(true);
851 851
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
852
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
852
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
853 853
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
854 854
 					$SpotterLive = new SpotterLive($this->db);
855 855
 					$result = $SpotterLive->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]['altitude_real'], $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']);
856 856
 					$SpotterLive->db = null;
857 857
 					if ($globalDebug) echo $result."\n";
858
-				    }
858
+					}
859 859
 				}
860 860
 				if (isset($globalServerAPRS) && $globalServerAPRS) {
861 861
 					$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]['altitude_real'], $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']);
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
 				//if ($line['format_source'] != 'aprs') {
868 868
 				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
869 869
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
870
-				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
870
+					if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
871 871
 					$source = $this->all_flights[$id]['source_name'];
872 872
 					if ($source == '') $source = $this->all_flights[$id]['format_source'];
873 873
 					if (!isset($this->source_location[$source])) {
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
 					if ($stats_heading == 16) $stats_heading = 0;
894 894
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
895 895
 						for ($i=0;$i<=15;$i++) {
896
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
896
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
897 897
 						}
898 898
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
899 899
 					} else {
@@ -906,17 +906,17 @@  discard block
 block discarded – undo
906 906
 					//var_dump($this->stats);
907 907
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
908 908
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
909
-						    end($this->stats[$current_date][$source]['hist']);
910
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
909
+							end($this->stats[$current_date][$source]['hist']);
910
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
911 911
 						} else $mini = 0;
912 912
 						for ($i=$mini;$i<=$distance;$i+=10) {
913
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
913
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
914 914
 						}
915 915
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
916 916
 					} else {
917 917
 						$this->stats[$current_date][$source]['hist'][$distance] += 1;
918 918
 					}
919
-				    }
919
+					}
920 920
 				}
921 921
 
922 922
 				$this->all_flights[$id]['lastupdate'] = time();
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
 			//$this->del();
927 927
 			
928 928
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
929
-			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
929
+				if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
930 930
 				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
931 931
 				$SpotterLive = new SpotterLive($this->db);
932 932
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
@@ -934,19 +934,19 @@  discard block
 block discarded – undo
934 934
 				//SpotterLive->deleteLiveSpotterData();
935 935
 				if ($globalDebug) echo " Done\n";
936 936
 				$this->last_delete_hourly = time();
937
-			    } else {
937
+				} else {
938 938
 				$this->del();
939 939
 				$this->last_delete_hourly = time();
940
-			    }
940
+				}
941 941
 			}
942 942
 			
943
-		    }
944
-		    //$ignoreImport = false;
943
+			}
944
+			//$ignoreImport = false;
945 945
 		}
946 946
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
947 947
 		if ($send) return $this->all_flights[$id];
948
-	    }
948
+		}
949
+	}
949 950
 	}
950
-    }
951 951
 }
952 952
 ?>
Please login to merge, or discard this patch.
Spacing   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -33,12 +33,12 @@  discard block
 block discarded – undo
33 33
 		$currentdate = date('Y-m-d');
34 34
 		$sourcestat = $Stats->getStatsSource($currentdate);
35 35
 		if (!empty($sourcestat)) {
36
-		    foreach($sourcestat as $srcst) {
36
+		    foreach ($sourcestat as $srcst) {
37 37
 		    	$type = $srcst['stats_type'];
38 38
 			if ($type == 'polar' || $type == 'hist') {
39 39
 			    $source = $srcst['source_name'];
40 40
 			    $data = $srcst['source_data'];
41
-			    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
41
+			    $this->stats[$currentdate][$source][$type] = json_decode($data, true);
42 42
 	    		}
43 43
 		    }
44 44
 		}
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
     }
52 52
 
53
-    public function get_Schedule($id,$ident) {
53
+    public function get_Schedule($id, $ident) {
54 54
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
55 55
 	// Get schedule here, so it's done only one time
56 56
 	
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 		$schedule = $Schedule->fetchSchedule($operator);
76 76
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
77 77
 		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
78
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
79
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
78
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $schedule['DepartureTime']));
79
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $schedule['ArrivalTime']));
80 80
 		    // Should also check if route schedule = route from DB
81 81
 		    if ($schedule['DepartureAirportIATA'] != '') {
82 82
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 			    }
97 97
 			}
98 98
 		    }
99
-		    $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']);
99
+		    $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']);
100 100
 		}
101 101
 	    } else $scheduleexist = true;
102 102
 	} else $scheduleexist = true;
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
        if ($scheduleexist) {
105 105
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
106 106
     		$sch = $Schedule->getSchedule($operator);
107
-		$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']));
107
+		$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']));
108 108
        }
109 109
 	$Spotter->db = null;
110 110
 	$Schedule->db = null;
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
132 132
     		    $Spotter = new Spotter($this->db);
133 133
         	    $real_arrival = $this->arrival($key);
134
-        	    $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']);
134
+        	    $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']);
135 135
         	}
136 136
 	    }
137 137
 	}
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
         $airport_time = '';
146 146
         if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
147 147
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
148
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
148
+	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $globalClosestMinDist);
149 149
     	    if (isset($closestAirports[0])) {
150 150
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
151 151
         	    $airport_icao = $closestAirports[0]['icao'];
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
         		    break;
161 161
         		}
162 162
         	    }
163
-        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
163
+        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude'] + 5000))) {
164 164
         		$airport_icao = $closestAirports[0]['icao'];
165 165
         		$airport_time = $this->all_flights[$key]['datetime'];
166 166
         	} else {
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
         } else {
174 174
         	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
175 175
         }
176
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
176
+        return array('airport_icao' => $airport_icao, 'airport_time' => $airport_time);
177 177
     }
178 178
 
179 179
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
185 185
 	foreach ($this->all_flights as $key => $flight) {
186 186
     	    if (isset($flight['lastupdate'])) {
187
-        	if ($flight['lastupdate'] < (time()-3000)) {
187
+        	if ($flight['lastupdate'] < (time() - 3000)) {
188 188
             	    if (isset($this->all_flights[$key]['id'])) {
189 189
             		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
190 190
 			/*
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
             		    $real_arrival = $this->arrival($key);
197 197
             		    $Spotter = new Spotter($this->db);
198 198
             	    	    if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
199
-				$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']);
199
+				$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']);
200 200
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
201 201
 			    }
202 202
 			// Put in archive
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 	$send = false;
234 234
 	
235 235
 	// SBS format is CSV format
236
-	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
236
+	if (is_array($line) && (isset($line['hex']) || isset($line['id']))) {
237 237
 	    //print_r($line);
238 238
   	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
239 239
 
@@ -266,25 +266,25 @@  discard block
 block discarded – undo
266 266
 		
267 267
 		if (!isset($this->all_flights[$id])) {
268 268
 		    $this->all_flights[$id] = array();
269
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
270
-		    $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' => ''));
271
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
269
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
270
+		    $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' => ''));
271
+		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('lastupdate' => time()));
272 272
 		    if (!isset($line['id'])) {
273 273
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
274 274
 //			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')));
275 275
 //			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')));
276
-			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')));
276
+			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')));
277 277
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
278
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
278
+		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
279 279
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
280 280
 		}
281 281
 		if (isset($line['source_type']) && $line['source_type'] != '') {
282
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
282
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_type' => $line['source_type']));
283 283
 		}
284 284
 		
285 285
 		//print_r($this->all_flights);
286 286
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
287
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
287
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('hex' => trim($line['hex'])));
288 288
 		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
289 289
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
290 290
 		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -293,20 +293,20 @@  discard block
 block discarded – undo
293 293
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
294 294
 			    $Spotter = new Spotter($this->db);
295 295
 			    if (isset($this->all_flights[$id]['source_type'])) {
296
-				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
296
+				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']), $this->all_flights[$id]['source_type']);
297 297
 			    } else {
298 298
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
299 299
 			    }
300 300
 			    $Spotter->db = null;
301
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
302
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
301
+			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
302
+			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
303 303
 			}
304 304
 		    }
305 305
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
306 306
 		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
307 307
 		}
308 308
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
309
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
309
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $line['aircraft_icao']));
310 310
 		}
311 311
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_name'])) {
312 312
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 				$Spotter = new Spotter($this->db);
315 315
 				$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
316 316
 				$Spotter->db = null;
317
-				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
317
+				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
318 318
 			}
319 319
 		}
320 320
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
@@ -322,15 +322,15 @@  discard block
 block discarded – undo
322 322
 			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
323 323
 			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
324 324
 			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
325
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
325
+			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
326 326
 		}
327 327
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
328
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
328
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => 'NA'));
329 329
 		}
330 330
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
331
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60) {
331
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 20*60) {
332 332
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
333
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
333
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => $line['datetime']));
334 334
 		    } else {
335 335
 				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";
336 336
 				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";
@@ -343,24 +343,24 @@  discard block
 block discarded – undo
343 343
 		    }
344 344
 		} else {
345 345
 			date_default_timezone_set('UTC');
346
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
346
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => date('Y-m-d H:i:s')));
347 347
 		}
348 348
 
349 349
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
350
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
350
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('registration' => $line['registration']));
351 351
 		}
352 352
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
353
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
353
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('waypoints' => $line['waypoints']));
354 354
 		}
355 355
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
356
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
356
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_id' => $line['pilot_id']));
357 357
 		}
358 358
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
359
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
359
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_name' => $line['pilot_name']));
360 360
 		}
361 361
  
362 362
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
363
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
363
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident'])));
364 364
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
365 365
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
366 366
 			    $timeelapsed = microtime(true);
@@ -371,10 +371,10 @@  discard block
 block discarded – undo
371 371
 			    elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
372 372
 			    elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
373 373
 			    elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
374
-            		    $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
374
+            		    $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $fromsource);
375 375
 			    if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
376 376
 			    $Spotter->db = null;
377
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
377
+			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
378 378
 			}
379 379
 		    }
380 380
 
@@ -386,25 +386,25 @@  discard block
 block discarded – undo
386 386
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
387 387
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
388 388
   */
389
-		    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']));
389
+		    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']));
390 390
 
391 391
 		    //$putinarchive = true;
392 392
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
393
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
393
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $line['departure_airport_time']));
394 394
 		    }
395 395
 		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
396
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
396
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $line['arrival_airport_time']));
397 397
 		    }
398 398
 		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
399
-		    		$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' => ''));
399
+		    		$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' => ''));
400 400
 		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
401 401
 			$timeelapsed = microtime(true);
402 402
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
403 403
 				$Spotter = new Spotter($this->db);
404 404
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
405 405
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
406
-		    		$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' => ''));
407
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
406
+		    		$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' => ''));
407
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
408 408
                         }
409 409
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
410 410
 			$timeelapsed = microtime(true);
@@ -418,34 +418,34 @@  discard block
 block discarded – undo
418 418
 				$Translation->db = null;
419 419
 			    }
420 420
 			    $Spotter->db = null;
421
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
421
+			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
422 422
                     	}
423 423
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
424 424
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
425 425
 			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
426 426
 				//    $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']));
427
-		    		$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']));
427
+		    		$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']));
428 428
 		    	    }
429 429
 			}
430 430
 			if (!isset($globalFork)) $globalFork = TRUE;
431 431
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
432
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
432
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id, trim($line['ident']));
433 433
 			}
434 434
 		    }
435 435
 		}
436 436
 
437 437
 		if (isset($line['speed']) && $line['speed'] != '') {
438 438
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
439
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
440
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
439
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($line['speed'])));
440
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed_fromsrc' => true));
441 441
 		    //$dataFound = true;
442 442
 		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
443
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
443
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm');
444 444
 		    if ($distance > 1000 && $distance < 10000) {
445 445
 		    // use datetime
446 446
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
447 447
 			$speed = $speed*3.6;
448
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
448
+			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($speed)));
449 449
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
450 450
 		    }
451 451
 		}
@@ -453,11 +453,11 @@  discard block
 block discarded – undo
453 453
 
454 454
 
455 455
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
456
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
456
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time() - $this->all_flights[$id]['time_last_coord']);
457 457
 	    	    else unset($timediff);
458
-	    	    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')))) {
458
+	    	    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')))) {
459 459
 			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'])) {
460
-			    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'])) {
460
+			    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'])) {
461 461
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
462 462
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
463 463
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -467,10 +467,10 @@  discard block
 block discarded – undo
467 467
 				    $timeelapsed = microtime(true);
468 468
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
469 469
 					$Spotter = new Spotter($this->db);
470
-					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
470
+					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
471 471
 					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
472 472
 					$Spotter->db = null;
473
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
473
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
474 474
 					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
475 475
 				    }
476 476
 				}
@@ -480,13 +480,13 @@  discard block
 block discarded – undo
480 480
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
481 481
 			    //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) {
482 482
 				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
483
-				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') {
483
+				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') {
484 484
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
485 485
 				    $dataFound = true;
486 486
 				    $this->all_flights[$id]['time_last_coord'] = time();
487 487
 				}
488 488
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
489
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
489
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('latitude' => $line['latitude']));
490 490
 				/*
491 491
 				if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) {
492 492
 				    $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -504,13 +504,13 @@  discard block
 block discarded – undo
504 504
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
505 505
 			    //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) {
506 506
 				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
507
-				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') {
507
+				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') {
508 508
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
509 509
 				    $dataFound = true;
510 510
 				    $this->all_flights[$id]['time_last_coord'] = time();
511 511
 				}
512 512
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
513
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
513
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('longitude' => $line['longitude']));
514 514
 				/*
515 515
 				if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) {
516 516
 				    $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
@@ -528,46 +528,46 @@  discard block
 block discarded – undo
528 528
 		    } else if ($globalDebug && $timediff > 30) {
529 529
 			$this->tmd = $this->tmd + 1;
530 530
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
531
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
532
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
531
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')."m -";
532
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
533 533
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
534 534
 		    }
535 535
 		}
536 536
 		if (isset($line['last_update']) && $line['last_update'] != '') {
537 537
 		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
538
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
538
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('last_update' => $line['last_update']));
539 539
 		}
540 540
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
541
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
541
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('verticalrate' => $line['verticalrate']));
542 542
 		    //$dataFound = true;
543 543
 		}
544 544
 		if (isset($line['format_source']) && $line['format_source'] != '') {
545
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
545
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('format_source' => $line['format_source']));
546 546
 		}
547 547
 		if (isset($line['source_name']) && $line['source_name'] != '') {
548
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
548
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_name' => $line['source_name']));
549 549
 		}
550 550
 		if (isset($line['emergency']) && $line['emergency'] != '') {
551
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
551
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('emergency' => $line['emergency']));
552 552
 		    //$dataFound = true;
553 553
 		}
554 554
 		if (isset($line['ground']) && $line['ground'] != '') {
555 555
 		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
556 556
 			// Here we force archive of flight because after ground it's a new one (or should be)
557
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
558
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
559
-			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')));
560
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
561
-			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']));
557
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
558
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
559
+			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')));
560
+		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
561
+			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']));
562 562
 		    }
563 563
 		    if ($line['ground'] != 1) $line['ground'] = 0;
564
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
564
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ground' => $line['ground']));
565 565
 		    //$dataFound = true;
566 566
 		}
567 567
 		if (isset($line['squawk']) && $line['squawk'] != '') {
568 568
 		    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'])) {
569 569
 			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
570
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
570
+			    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
571 571
 			    $highlight = '';
572 572
 			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
573 573
 			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
@@ -576,47 +576,47 @@  discard block
 block discarded – undo
576 576
 				$timeelapsed = microtime(true);
577 577
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
578 578
 				    $Spotter = new Spotter($this->db);
579
-				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
579
+				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'], $highlight);
580 580
 				    $Spotter->db = null;
581
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
581
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
582 582
 				}
583 583
 				//$putinarchive = true;
584 584
 				//$highlight = '';
585 585
 			    }
586 586
 			    
587
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
587
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
588 588
 		    //$dataFound = true;
589 589
 		}
590 590
 
591 591
 		if (isset($line['altitude']) && $line['altitude'] != '') {
592 592
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
593
-			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;
594
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
595
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
593
+			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;
594
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude' => round($line['altitude']/100)));
595
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_real' => $line['altitude']));
596 596
 			//$dataFound = true;
597 597
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
598 598
   		}
599 599
 
600 600
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
601
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
601
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('noarchive' => true));
602 602
 		}
603 603
 		
604 604
 		if (isset($line['heading']) && $line['heading'] != '') {
605
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
606
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
607
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
605
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading'] - round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
606
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($line['heading'])));
607
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading_fromsrc' => true));
608 608
 		    //$dataFound = true;
609 609
   		} 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']) {
610
-  		    $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']);
611
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
612
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
610
+  		    $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']);
611
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($heading)));
612
+		    if (abs($this->all_flights[$id]['heading'] - round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
613 613
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
614 614
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
615 615
   		    // If not enough messages and ACARS set heading to 0
616
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
616
+  		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => 0));
617 617
   		}
618
-		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
619
-		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
618
+		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
619
+		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
620 620
 
621 621
 //		print_r($this->all_flights[$id]);
622 622
 		//gets the callsign from the last hour
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
 		if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
627 627
 		    $this->all_flights[$id]['lastupdate'] = time();
628 628
 		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
629
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
629
+		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == '' || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
630 630
 			    //print_r($this->all_flights);
631 631
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
632 632
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
@@ -637,61 +637,61 @@  discard block
 block discarded – undo
637 637
 				    $SpotterLive = new SpotterLive($this->db);
638 638
 				    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')) {
639 639
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
640
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
640
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
641 641
 				    } elseif (isset($line['id'])) {
642 642
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
643
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
643
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
644 644
 				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
645 645
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
646
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
646
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
647 647
 				    } else $recent_ident = '';
648
-				    $SpotterLive->db=null;
648
+				    $SpotterLive->db = null;
649 649
 				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
650 650
 				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
651 651
 				} else $recent_ident = '';
652 652
 			    } else {
653 653
 				$recent_ident = '';
654
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
654
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 0));
655 655
 			    }
656 656
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
657
-			    if($recent_ident == "")
657
+			    if ($recent_ident == "")
658 658
 			    {
659 659
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
660 660
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
661 661
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
662 662
 				//adds the spotter data for the archive
663 663
 				$ignoreImport = false;
664
-				foreach($globalAirportIgnore as $airportIgnore) {
664
+				foreach ($globalAirportIgnore as $airportIgnore) {
665 665
 				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
666 666
 					$ignoreImport = true;
667 667
 				    }
668 668
 				}
669 669
 				if (count($globalAirportAccept) > 0) {
670 670
 				    $ignoreImport = true;
671
-				    foreach($globalAirportIgnore as $airportIgnore) {
671
+				    foreach ($globalAirportIgnore as $airportIgnore) {
672 672
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
673 673
 					    $ignoreImport = false;
674 674
 					}
675 675
 				    }
676 676
 				}
677 677
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
678
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
679
-					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
678
+				    foreach ($globalAirlineIgnore as $airlineIgnore) {
679
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) {
680 680
 					    $ignoreImport = true;
681 681
 					}
682 682
 				    }
683 683
 				}
684 684
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
685 685
 				    $ignoreImport = true;
686
-				    foreach($globalAirlineAccept as $airlineAccept) {
687
-					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
686
+				    foreach ($globalAirlineAccept as $airlineAccept) {
687
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) {
688 688
 					    $ignoreImport = false;
689 689
 					}
690 690
 				    }
691 691
 				}
692 692
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
693 693
 				    $ignoreImport = true;
694
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
694
+				    foreach ($globalPilotIdAccept as $pilotIdAccept) {
695 695
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
696 696
 					    $ignoreImport = false;
697 697
 					}
@@ -703,32 +703,32 @@  discard block
 block discarded – undo
703 703
 				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
704 704
 				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
705 705
 				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
706
-				    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')));
706
+				    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')));
707 707
 				    $timeelapsed = microtime(true);
708 708
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
709 709
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
710 710
 					    $Spotter = new Spotter($this->db);
711
-					    $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]['altitude_real'], $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']);
711
+					    $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]['altitude_real'], $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']);
712 712
 					    $Spotter->db = null;
713 713
 					    if ($globalDebug && isset($result)) echo $result."\n";
714 714
 					}
715 715
 				    }
716
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
716
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
717 717
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
718 718
 
719 719
 				    // Add source stat in DB
720 720
 				    $Stats = new Stats($this->db);
721 721
 				    if (!empty($this->stats)) {
722 722
 					if ($globalDebug) echo 'Add source stats : ';
723
-				        foreach($this->stats as $date => $data) {
724
-					    foreach($data as $source => $sourced) {
723
+				        foreach ($this->stats as $date => $data) {
724
+					    foreach ($data as $source => $sourced) {
725 725
 					        //print_r($sourced);
726
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
727
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
726
+				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar', $date);
727
+				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist', $date);
728 728
 				    		if (isset($sourced['msg'])) {
729 729
 				    		    if (time() - $sourced['msg']['date'] > 10) {
730 730
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
731
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
731
+				    		        echo $Stats->addStatSource($nbmsg, $source, 'msg', $date);
732 732
 			    			        unset($this->stats[$date][$source]['msg']);
733 733
 			    			    }
734 734
 			    			}
@@ -766,14 +766,14 @@  discard block
 block discarded – undo
766 766
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
767 767
 					    $SpotterLive = new SpotterLive($this->db);
768 768
 					    $SpotterLive->deleteLiveSpotterData();
769
-					    $SpotterLive->db=null;
769
+					    $SpotterLive->db = null;
770 770
 					}
771 771
 				    }
772 772
 				    if ($globalDebug) echo " Done\n";
773 773
 				    $this->last_delete = time();
774 774
 				}
775 775
 			    } else {
776
-				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')) {
776
+				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')) {
777 777
 				    $this->all_flights[$id]['id'] = $recent_ident;
778 778
 				    $this->all_flights[$id]['addedSpotter'] = 1;
779 779
 				}
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
782 782
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
783 783
 					    $Spotter = new Spotter($this->db);
784
-					    $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
784
+					    $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time']);
785 785
 					    $Spotter->db = null;
786 786
 					}
787 787
 				    }
@@ -807,37 +807,37 @@  discard block
 block discarded – undo
807 807
 		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
808 808
 		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
809 809
 
810
-		    foreach($globalAirportIgnore as $airportIgnore) {
810
+		    foreach ($globalAirportIgnore as $airportIgnore) {
811 811
 		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
812 812
 			    $ignoreImport = true;
813 813
 			}
814 814
 		    }
815 815
 		    if (count($globalAirportAccept) > 0) {
816 816
 		        $ignoreImport = true;
817
-		        foreach($globalAirportIgnore as $airportIgnore) {
817
+		        foreach ($globalAirportIgnore as $airportIgnore) {
818 818
 			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
819 819
 				$ignoreImport = false;
820 820
 			    }
821 821
 			}
822 822
 		    }
823 823
 		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
824
-			foreach($globalAirlineIgnore as $airlineIgnore) {
825
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
824
+			foreach ($globalAirlineIgnore as $airlineIgnore) {
825
+			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) {
826 826
 				$ignoreImport = true;
827 827
 			    }
828 828
 			}
829 829
 		    }
830 830
 		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
831 831
 			$ignoreImport = true;
832
-			foreach($globalAirlineAccept as $airlineAccept) {
833
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
832
+			foreach ($globalAirlineAccept as $airlineAccept) {
833
+			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) {
834 834
 				$ignoreImport = false;
835 835
 			    }
836 836
 			}
837 837
 		    }
838 838
 		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
839 839
 			$ignoreImport = true;
840
-			foreach($globalPilotIdAccept as $pilotIdAccept) {
840
+			foreach ($globalPilotIdAccept as $pilotIdAccept) {
841 841
 			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
842 842
 			        $ignoreImport = false;
843 843
 			    }
@@ -845,23 +845,23 @@  discard block
 block discarded – undo
845 845
 		    }
846 846
 
847 847
 		    if (!$ignoreImport) {
848
-			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'])) {
849
-				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')));
848
+			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'])) {
849
+				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')));
850 850
 				$timeelapsed = microtime(true);
851 851
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
852 852
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
853 853
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
854 854
 					$SpotterLive = new SpotterLive($this->db);
855
-					$result = $SpotterLive->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]['altitude_real'], $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']);
855
+					$result = $SpotterLive->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]['altitude_real'], $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']);
856 856
 					$SpotterLive->db = null;
857 857
 					if ($globalDebug) echo $result."\n";
858 858
 				    }
859 859
 				}
860 860
 				if (isset($globalServerAPRS) && $globalServerAPRS) {
861
-					$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]['altitude_real'], $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']);
861
+					$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]['altitude_real'], $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']);
862 862
 				}
863 863
 				$this->all_flights[$id]['putinarchive'] = false;
864
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
864
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
865 865
 
866 866
 				// Put statistics in $this->stats variable
867 867
 				//if ($line['format_source'] != 'aprs') {
@@ -880,19 +880,19 @@  discard block
 block discarded – undo
880 880
 							$latitude = $globalCenterLatitude;
881 881
 							$longitude = $globalCenterLongitude;
882 882
 						}
883
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
883
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
884 884
 					} else {
885 885
 						$latitude = $this->source_location[$source]['latitude'];
886 886
 						$longitude = $this->source_location[$source]['longitude'];
887 887
 					}
888
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
888
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
889 889
 					//$stats_heading = $stats_heading%22.5;
890 890
 					$stats_heading = round($stats_heading/22.5);
891
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
891
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
892 892
 					$current_date = date('Y-m-d');
893 893
 					if ($stats_heading == 16) $stats_heading = 0;
894 894
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
895
-						for ($i=0;$i<=15;$i++) {
895
+						for ($i = 0; $i <= 15; $i++) {
896 896
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
897 897
 						}
898 898
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -907,9 +907,9 @@  discard block
 block discarded – undo
907 907
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
908 908
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
909 909
 						    end($this->stats[$current_date][$source]['hist']);
910
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
910
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
911 911
 						} else $mini = 0;
912
-						for ($i=$mini;$i<=$distance;$i+=10) {
912
+						for ($i = $mini; $i <= $distance; $i += 10) {
913 913
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
914 914
 						}
915 915
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
 				$this->all_flights[$id]['lastupdate'] = time();
923 923
 				if ($this->all_flights[$id]['putinarchive']) $send = true;
924 924
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
925
-			} 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";
925
+			} 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";
926 926
 			//$this->del();
927 927
 			
928 928
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
Please login to merge, or discard this patch.
Braces   +340 added lines, -120 removed lines patch added patch discarded remove patch
@@ -63,7 +63,9 @@  discard block
 block discarded – undo
63 63
 	$dbc = $this->db;
64 64
 	$this->all_flights[$id]['schedule_check'] = true;
65 65
 	if ($globalSchedulesFetch) {
66
-	if ($globalDebug) echo 'Getting schedule info...'."\n";
66
+	if ($globalDebug) {
67
+		echo 'Getting schedule info...'."\n";
68
+	}
67 69
 	$Spotter = new Spotter($dbc);
68 70
 	$Schedule = new Schedule($dbc);
69 71
 	$Translation = new Translation($dbc);
@@ -74,7 +76,9 @@  discard block
 block discarded – undo
74 76
 	    if ($Schedule->checkSchedule($operator) == 0) {
75 77
 		$schedule = $Schedule->fetchSchedule($operator);
76 78
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
77
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
79
+		    if ($globalDebug) {
80
+		    	echo "-> Schedule info for ".$operator." (".$ident.")\n";
81
+		    }
78 82
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
79 83
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
80 84
 		    // Should also check if route schedule = route from DB
@@ -83,7 +87,9 @@  discard block
 block discarded – undo
83 87
 			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
84 88
 			    if (trim($airport_icao) != '') {
85 89
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
86
-				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
90
+				if ($globalDebug) {
91
+					echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
92
+				}
87 93
 			    }
88 94
 			}
89 95
 		    }
@@ -92,17 +98,25 @@  discard block
 block discarded – undo
92 98
 			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
93 99
 			    if (trim($airport_icao) != '') {
94 100
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
95
-				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
101
+				if ($globalDebug) {
102
+					echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
103
+				}
96 104
 			    }
97 105
 			}
98 106
 		    }
99 107
 		    $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']);
100 108
 		}
101
-	    } else $scheduleexist = true;
102
-	} else $scheduleexist = true;
109
+	    } else {
110
+	    	$scheduleexist = true;
111
+	    }
112
+	} else {
113
+		$scheduleexist = true;
114
+	}
103 115
 	// close connection, at least one way will work ?
104 116
        if ($scheduleexist) {
105
-		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
117
+		if ($globalDebug) {
118
+			echo "-> get arrival/departure airport info for ".$ident."\n";
119
+		}
106 120
     		$sch = $Schedule->getSchedule($operator);
107 121
 		$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']));
108 122
        }
@@ -124,7 +138,9 @@  discard block
 block discarded – undo
124 138
 
125 139
     public function checkAll() {
126 140
 	global $globalDebug, $globalNoImport;
127
-	if ($globalDebug) echo "Update last seen flights data...\n";
141
+	if ($globalDebug) {
142
+		echo "Update last seen flights data...\n";
143
+	}
128 144
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
129 145
 	    foreach ($this->all_flights as $key => $flight) {
130 146
 		if (isset($this->all_flights[$key]['id'])) {
@@ -139,24 +155,32 @@  discard block
 block discarded – undo
139 155
 
140 156
     public function arrival($key) {
141 157
 	global $globalClosestMinDist, $globalDebug;
142
-	if ($globalDebug) echo 'Update arrival...'."\n";
158
+	if ($globalDebug) {
159
+		echo 'Update arrival...'."\n";
160
+	}
143 161
 	$Spotter = new Spotter($this->db);
144 162
         $airport_icao = '';
145 163
         $airport_time = '';
146
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
164
+        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') {
165
+        	$globalClosestMinDist = 50;
166
+        }
147 167
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
148 168
 	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
149 169
     	    if (isset($closestAirports[0])) {
150 170
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
151 171
         	    $airport_icao = $closestAirports[0]['icao'];
152 172
         	    $airport_time = $this->all_flights[$key]['datetime'];
153
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
173
+        	    if ($globalDebug) {
174
+        	    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
175
+        	    }
154 176
         	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
155 177
         	    foreach ($closestAirports as $airport) {
156 178
         		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
157 179
         		    $airport_icao = $airport['icao'];
158 180
         		    $airport_time = $this->all_flights[$key]['datetime'];
159
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
181
+        		    if ($globalDebug) {
182
+        		    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
183
+        		    }
160 184
         		    break;
161 185
         		}
162 186
         	    }
@@ -164,14 +188,20 @@  discard block
 block discarded – undo
164 188
         		$airport_icao = $closestAirports[0]['icao'];
165 189
         		$airport_time = $this->all_flights[$key]['datetime'];
166 190
         	} else {
167
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
191
+        		if ($globalDebug) {
192
+        			echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
193
+        		}
168 194
         	}
169 195
     	    } else {
170
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
196
+    		    if ($globalDebug) {
197
+    		    	echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
198
+    		    }
171 199
     	    }
172 200
 
173 201
         } else {
174
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
202
+        	if ($globalDebug) {
203
+        		echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
204
+        	}
175 205
         }
176 206
         return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
177 207
     }
@@ -181,12 +211,16 @@  discard block
 block discarded – undo
181 211
     public function del() {
182 212
 	global $globalDebug, $globalNoImport, $globalNoDB;
183 213
 	// Delete old infos
184
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
214
+	if ($globalDebug) {
215
+		echo 'Delete old values and update latest data...'."\n";
216
+	}
185 217
 	foreach ($this->all_flights as $key => $flight) {
186 218
     	    if (isset($flight['lastupdate'])) {
187 219
         	if ($flight['lastupdate'] < (time()-3000)) {
188 220
             	    if (isset($this->all_flights[$key]['id'])) {
189
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
221
+            		if ($globalDebug) {
222
+            			echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
223
+            		}
190 224
 			/*
191 225
 			$SpotterLive = new SpotterLive();
192 226
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
@@ -197,7 +231,9 @@  discard block
 block discarded – undo
197 231
             		    $Spotter = new Spotter($this->db);
198 232
             	    	    if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
199 233
 				$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']);
200
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
234
+				if ($globalDebug && $result != 'success') {
235
+					echo '!!! ERROR : '.$result."\n";
236
+				}
201 237
 			    }
202 238
 			// Put in archive
203 239
 //				$Spotter->db = null;
@@ -212,8 +248,10 @@  discard block
 block discarded – undo
212 248
     public function add($line) {
213 249
 	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, $globalNoDB;
214 250
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
215
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
216
-/*
251
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
252
+		$globalCoordMinChange = '0.02';
253
+	}
254
+	/*
217 255
 	$Spotter = new Spotter();
218 256
 	$dbc = $Spotter->db;
219 257
 	$SpotterLive = new SpotterLive($dbc);
@@ -241,11 +279,15 @@  discard block
 block discarded – undo
241 279
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
242 280
 		    $current_date = date('Y-m-d');
243 281
 		    $source = $line['source_name'];
244
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
282
+		    if ($source == '' || $line['format_source'] == 'aprs') {
283
+		    	$source = $line['format_source'];
284
+		    }
245 285
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
246 286
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
247 287
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
248
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
288
+		    } else {
289
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
290
+		    }
249 291
 		}
250 292
 		
251 293
 		/*
@@ -261,22 +303,35 @@  discard block
 block discarded – undo
261 303
 		//$this->db = $dbc;
262 304
 
263 305
 		//$hex = trim($line['hex']);
264
-	        if (!isset($line['id'])) $id = trim($line['hex']);
265
-	        else $id = trim($line['id']);
306
+	        if (!isset($line['id'])) {
307
+	        	$id = trim($line['hex']);
308
+	        } else {
309
+	        	$id = trim($line['id']);
310
+	        }
266 311
 		
267 312
 		if (!isset($this->all_flights[$id])) {
268 313
 		    $this->all_flights[$id] = array();
269 314
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
270 315
 		    $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' => ''));
271
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
316
+		    if (isset($globalDaemon) && $globalDaemon === FALSE) {
317
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
318
+		    }
272 319
 		    if (!isset($line['id'])) {
273
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
274
-//			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')));
320
+			if (!isset($globalDaemon)) {
321
+				$globalDaemon = TRUE;
322
+			}
323
+			//			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')));
275 324
 //			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')));
276
-			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')));
325
+			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')) {
326
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
327
+			}
277 328
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
278
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
279
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
329
+		     } else {
330
+		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
331
+		     }
332
+		    if ($globalAllFlights !== FALSE) {
333
+		    	$dataFound = true;
334
+		    }
280 335
 		}
281 336
 		if (isset($line['source_type']) && $line['source_type'] != '') {
282 337
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
@@ -298,12 +353,20 @@  discard block
 block discarded – undo
298 353
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
299 354
 			    }
300 355
 			    $Spotter->db = null;
301
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
302
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
356
+			    if ($globalDebugTimeElapsed) {
357
+			    	echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
358
+			    }
359
+			    if ($aircraft_icao != '') {
360
+			    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
361
+			    }
303 362
 			}
304 363
 		    }
305
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
306
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
364
+		    if ($globalAllFlights !== FALSE) {
365
+		    	$dataFound = true;
366
+		    }
367
+		    if ($globalDebug) {
368
+		    	echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
369
+		    }
307 370
 		}
308 371
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
309 372
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
@@ -314,15 +377,24 @@  discard block
 block discarded – undo
314 377
 				$Spotter = new Spotter($this->db);
315 378
 				$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
316 379
 				$Spotter->db = null;
317
-				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
380
+				if ($aircraft_icao != '') {
381
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
382
+				}
318 383
 			}
319 384
 		}
320 385
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
321
-			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
322
-			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
323
-			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
324
-			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
325
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
386
+			if ($line['aircraft_type'] == 'PARA_GLIDER') {
387
+				$aircraft_icao = 'GLID';
388
+			} elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') {
389
+				$aircraft_icao = 'UHEL';
390
+			} elseif ($line['aircraft_type'] == 'TOW_PLANE') {
391
+				$aircraft_icao = 'TOWPLANE';
392
+			} elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') {
393
+				$aircraft_icao = 'POWAIRC';
394
+			}
395
+			if (isset($aircraft_icao)) {
396
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
397
+			}
326 398
 		}
327 399
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
328 400
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
@@ -332,8 +404,11 @@  discard block
 block discarded – undo
332 404
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
333 405
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
334 406
 		    } else {
335
-				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";
336
-				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";
407
+				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
408
+					echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
409
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
410
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
411
+				}
337 412
 				/*
338 413
 				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
339 414
 				print_r($this->all_flights[$id]);
@@ -366,15 +441,25 @@  discard block
 block discarded – undo
366 441
 			    $timeelapsed = microtime(true);
367 442
             		    $Spotter = new Spotter($this->db);
368 443
             		    $fromsource = NULL;
369
-            		    if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
370
-            		    elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
371
-			    elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
372
-			    elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
373
-			    elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
444
+            		    if (isset($globalAirlinesSource) && $globalAirlinesSource != '') {
445
+            		    	$fromsource = $globalAirlinesSource;
446
+            		    } elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') {
447
+            		    	$fromsource = 'vatsim';
448
+            		    } elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') {
449
+			    	$fromsource = 'ivao';
450
+			    } elseif (isset($globalVATSIM) && $globalVATSIM) {
451
+			    	$fromsource = 'vatsim';
452
+			    } elseif (isset($globalIVAO) && $globalIVAO) {
453
+			    	$fromsource = 'ivao';
454
+			    }
374 455
             		    $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
375
-			    if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
456
+			    if ($globalDebug && $result != 'success') {
457
+			    	echo '!!! ERROR : '.$result."\n";
458
+			    }
376 459
 			    $Spotter->db = null;
377
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
460
+			    if ($globalDebugTimeElapsed) {
461
+			    	echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
462
+			    }
378 463
 			}
379 464
 		    }
380 465
 
@@ -386,7 +471,9 @@  discard block
 block discarded – undo
386 471
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
387 472
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
388 473
   */
389
-		    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']));
474
+		    if (!isset($this->all_flights[$id]['id'])) {
475
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
476
+		    }
390 477
 
391 478
 		    //$putinarchive = true;
392 479
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
@@ -404,7 +491,9 @@  discard block
 block discarded – undo
404 491
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
405 492
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
406 493
 		    		$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' => ''));
407
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
494
+				if ($globalDebugTimeElapsed) {
495
+					echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
496
+				}
408 497
                         }
409 498
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
410 499
 			$timeelapsed = microtime(true);
@@ -418,7 +507,9 @@  discard block
 block discarded – undo
418 507
 				$Translation->db = null;
419 508
 			    }
420 509
 			    $Spotter->db = null;
421
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
510
+			    if ($globalDebugTimeElapsed) {
511
+			    	echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
512
+			    }
422 513
                     	}
423 514
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
424 515
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
@@ -427,9 +518,13 @@  discard block
 block discarded – undo
427 518
 		    		$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']));
428 519
 		    	    }
429 520
 			}
430
-			if (!isset($globalFork)) $globalFork = TRUE;
521
+			if (!isset($globalFork)) {
522
+				$globalFork = TRUE;
523
+			}
431 524
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
432
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
525
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) {
526
+					$this->get_Schedule($id,trim($line['ident']));
527
+				}
433 528
 			}
434 529
 		    }
435 530
 		}
@@ -445,16 +540,23 @@  discard block
 block discarded – undo
445 540
 		    // use datetime
446 541
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
447 542
 			$speed = $speed*3.6;
448
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
449
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
543
+			if ($speed < 1000) {
544
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
545
+			}
546
+  			if ($globalDebug) {
547
+  				echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
548
+  			}
450 549
 		    }
451 550
 		}
452 551
 
453 552
 
454 553
 
455 554
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
456
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
457
-	    	    else unset($timediff);
555
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) {
556
+	    	    	$timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
557
+	    	    } else {
558
+	    	    	unset($timediff);
559
+	    	    }
458 560
 	    	    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')))) {
459 561
 			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'])) {
460 562
 			    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'])) {
@@ -463,15 +565,23 @@  discard block
 block discarded – undo
463 565
 				$this->all_flights[$id]['putinarchive'] = true;
464 566
 				$this->tmd = 0;
465 567
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
466
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
568
+				    if ($globalDebug) {
569
+				    	echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
570
+				    }
467 571
 				    $timeelapsed = microtime(true);
468 572
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
469 573
 					$Spotter = new Spotter($this->db);
470 574
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
471
-					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
575
+					if (!empty($all_country)) {
576
+						$this->all_flights[$id]['over_country'] = $all_country['iso2'];
577
+					}
472 578
 					$Spotter->db = null;
473
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
474
-					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
579
+					if ($globalDebugTimeElapsed) {
580
+						echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
581
+					}
582
+					if ($globalDebug) {
583
+						echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
584
+					}
475 585
 				    }
476 586
 				}
477 587
 			    }
@@ -479,7 +589,9 @@  discard block
 block discarded – undo
479 589
 
480 590
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
481 591
 			    //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) {
482
-				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
592
+				if (!isset($this->all_flights[$id]['archive_latitude'])) {
593
+					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
594
+				}
483 595
 				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') {
484 596
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
485 597
 				    $dataFound = true;
@@ -501,9 +613,13 @@  discard block
 block discarded – undo
501 613
 			    */
502 614
 			}
503 615
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
504
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
616
+			    if ($line['longitude'] > 180) {
617
+			    	$line['longitude'] = $line['longitude'] - 360;
618
+			    }
505 619
 			    //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) {
506
-				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
620
+				if (!isset($this->all_flights[$id]['archive_longitude'])) {
621
+					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
622
+				}
507 623
 				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') {
508 624
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
509 625
 				    $dataFound = true;
@@ -534,7 +650,9 @@  discard block
 block discarded – undo
534 650
 		    }
535 651
 		}
536 652
 		if (isset($line['last_update']) && $line['last_update'] != '') {
537
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
653
+		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) {
654
+		    	$dataFound = true;
655
+		    }
538 656
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
539 657
 		}
540 658
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
@@ -556,41 +674,61 @@  discard block
 block discarded – undo
556 674
 			// Here we force archive of flight because after ground it's a new one (or should be)
557 675
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
558 676
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
559
-			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')));
560
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
561
-			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']));
677
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) {
678
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
679
+			} elseif (isset($line['id'])) {
680
+		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
681
+		        } elseif (isset($this->all_flights[$id]['ident'])) {
682
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
683
+			}
684
+		    }
685
+		    if ($line['ground'] != 1) {
686
+		    	$line['ground'] = 0;
562 687
 		    }
563
-		    if ($line['ground'] != 1) $line['ground'] = 0;
564 688
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
565 689
 		    //$dataFound = true;
566 690
 		}
567 691
 		if (isset($line['squawk']) && $line['squawk'] != '') {
568 692
 		    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'])) {
569
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
693
+			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) {
694
+			    	$this->all_flights[$id]['putinarchive'] = true;
695
+			    }
570 696
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
571 697
 			    $highlight = '';
572
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
573
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
574
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
698
+			    if ($this->all_flights[$id]['squawk'] == '7500') {
699
+			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
700
+			    }
701
+			    if ($this->all_flights[$id]['squawk'] == '7600') {
702
+			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
703
+			    }
704
+			    if ($this->all_flights[$id]['squawk'] == '7700') {
705
+			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
706
+			    }
575 707
 			    if ($highlight != '') {
576 708
 				$timeelapsed = microtime(true);
577 709
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
578 710
 				    $Spotter = new Spotter($this->db);
579 711
 				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
580 712
 				    $Spotter->db = null;
581
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
713
+				    if ($globalDebugTimeElapsed) {
714
+				    	echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
715
+				    }
582 716
 				}
583 717
 				//$putinarchive = true;
584 718
 				//$highlight = '';
585 719
 			    }
586 720
 			    
587
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
721
+		    } else {
722
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
723
+		    }
588 724
 		    //$dataFound = true;
589 725
 		}
590 726
 
591 727
 		if (isset($line['altitude']) && $line['altitude'] != '') {
592 728
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
593
-			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;
729
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) {
730
+				$this->all_flights[$id]['putinarchive'] = true;
731
+			}
594 732
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
595 733
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
596 734
 			//$dataFound = true;
@@ -602,21 +740,30 @@  discard block
 block discarded – undo
602 740
 		}
603 741
 		
604 742
 		if (isset($line['heading']) && $line['heading'] != '') {
605
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
743
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) {
744
+		    	$this->all_flights[$id]['putinarchive'] = true;
745
+		    }
606 746
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
607 747
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
608 748
 		    //$dataFound = true;
609 749
   		} 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']) {
610 750
   		    $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']);
611 751
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
612
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
613
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
752
+		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) {
753
+		    	$this->all_flights[$id]['putinarchive'] = true;
754
+		    }
755
+  		    if ($globalDebug) {
756
+  		    	echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
757
+  		    }
614 758
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
615 759
   		    // If not enough messages and ACARS set heading to 0
616 760
   		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
617 761
   		}
618
-		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
619
-		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
762
+		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) {
763
+			$dataFound = false;
764
+		} elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) {
765
+			$dataFound = false;
766
+		}
620 767
 
621 768
 //		print_r($this->all_flights[$id]);
622 769
 		//gets the callsign from the last hour
@@ -632,23 +779,38 @@  discard block
 block discarded – undo
632 779
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
633 780
 			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
634 781
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
635
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
782
+				    if ($globalDebug) {
783
+				    	echo "Check if aircraft is already in DB...";
784
+				    }
636 785
 				    $timeelapsed = microtime(true);
637 786
 				    $SpotterLive = new SpotterLive($this->db);
638 787
 				    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')) {
639 788
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
640
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
789
+					if ($globalDebugTimeElapsed) {
790
+						echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
791
+					}
641 792
 				    } elseif (isset($line['id'])) {
642 793
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
643
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
794
+					if ($globalDebugTimeElapsed) {
795
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
796
+					}
644 797
 				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
645 798
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
646
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
647
-				    } else $recent_ident = '';
799
+					if ($globalDebugTimeElapsed) {
800
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
801
+					}
802
+				    } else {
803
+				    	$recent_ident = '';
804
+				    }
648 805
 				    $SpotterLive->db=null;
649
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
650
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
651
-				} else $recent_ident = '';
806
+				    if ($globalDebug && $recent_ident == '') {
807
+				    	echo " Not in DB.\n";
808
+				    } elseif ($globalDebug && $recent_ident != '') {
809
+				    	echo " Already in DB.\n";
810
+				    }
811
+				} else {
812
+					$recent_ident = '';
813
+				}
652 814
 			    } else {
653 815
 				$recent_ident = '';
654 816
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
@@ -656,7 +818,9 @@  discard block
 block discarded – undo
656 818
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
657 819
 			    if($recent_ident == "")
658 820
 			    {
659
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
821
+				if ($globalDebug) {
822
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
823
+				}
660 824
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
661 825
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
662 826
 				//adds the spotter data for the archive
@@ -700,31 +864,49 @@  discard block
 block discarded – undo
700 864
 				
701 865
 				if (!$ignoreImport) {
702 866
 				    $highlight = '';
703
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
704
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
705
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
706
-				    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')));
867
+				    if ($this->all_flights[$id]['squawk'] == '7500') {
868
+				    	$highlight = 'Squawk 7500 : Hijack';
869
+				    }
870
+				    if ($this->all_flights[$id]['squawk'] == '7600') {
871
+				    	$highlight = 'Squawk 7600 : Lost Comm (radio failure)';
872
+				    }
873
+				    if ($this->all_flights[$id]['squawk'] == '7700') {
874
+				    	$highlight = 'Squawk 7700 : Emergency';
875
+				    }
876
+				    if (!isset($this->all_flights[$id]['id'])) {
877
+				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
878
+				    }
707 879
 				    $timeelapsed = microtime(true);
708 880
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
709 881
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
710 882
 					    $Spotter = new Spotter($this->db);
711 883
 					    $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]['altitude_real'], $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']);
712 884
 					    $Spotter->db = null;
713
-					    if ($globalDebug && isset($result)) echo $result."\n";
885
+					    if ($globalDebug && isset($result)) {
886
+					    	echo $result."\n";
887
+					    }
714 888
 					}
715 889
 				    }
716
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
890
+				    if ($globalDebugTimeElapsed) {
891
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
892
+				    }
717 893
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
718 894
 
719 895
 				    // Add source stat in DB
720 896
 				    $Stats = new Stats($this->db);
721 897
 				    if (!empty($this->stats)) {
722
-					if ($globalDebug) echo 'Add source stats : ';
898
+					if ($globalDebug) {
899
+						echo 'Add source stats : ';
900
+					}
723 901
 				        foreach($this->stats as $date => $data) {
724 902
 					    foreach($data as $source => $sourced) {
725 903
 					        //print_r($sourced);
726
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
727
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
904
+				    	        if (isset($sourced['polar'])) {
905
+				    	        	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
906
+				    	        }
907
+				    	        if (isset($sourced['hist'])) {
908
+				    	        	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
909
+				    	        }
728 910
 				    		if (isset($sourced['msg'])) {
729 911
 				    		    if (time() - $sourced['msg']['date'] > 10) {
730 912
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -737,13 +919,17 @@  discard block
 block discarded – undo
737 919
 			    			unset($this->stats[$date]);
738 920
 			    		    }
739 921
 				    	}
740
-				    	if ($globalDebug) echo 'Done'."\n";
922
+				    	if ($globalDebug) {
923
+				    		echo 'Done'."\n";
924
+				    	}
741 925
 
742 926
 				    }
743 927
 				    $Stats->db = null;
744 928
 				    }
745 929
 				    $this->del();
746
-				} elseif ($globalDebug) echo 'Ignore data'."\n";
930
+				} elseif ($globalDebug) {
931
+					echo 'Ignore data'."\n";
932
+				}
747 933
 				//$ignoreImport = false;
748 934
 				$this->all_flights[$id]['addedSpotter'] = 1;
749 935
 				//print_r($this->all_flights[$id]);
@@ -760,7 +946,9 @@  discard block
 block discarded – undo
760 946
 			*/
761 947
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
762 948
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
763
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
949
+				    if ($globalDebug) {
950
+				    	echo "---- Deleting Live Spotter data older than 9 hours...";
951
+				    }
764 952
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
765 953
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
766 954
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -769,7 +957,9 @@  discard block
 block discarded – undo
769 957
 					    $SpotterLive->db=null;
770 958
 					}
771 959
 				    }
772
-				    if ($globalDebug) echo " Done\n";
960
+				    if ($globalDebug) {
961
+				    	echo " Done\n";
962
+				    }
773 963
 				    $this->last_delete = time();
774 964
 				}
775 965
 			    } else {
@@ -796,11 +986,17 @@  discard block
 block discarded – undo
796 986
 		    //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";
797 987
 		    if ($globalDebug) {
798 988
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
799
-				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";
800
-				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";
989
+				if (isset($this->all_flights[$id]['source_name'])) {
990
+					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";
991
+				} else {
992
+					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";
993
+				}
801 994
 			} else {
802
-				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";
803
-				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";
995
+				if (isset($this->all_flights[$id]['source_name'])) {
996
+					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";
997
+				} else {
998
+					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";
999
+				}
804 1000
 			}
805 1001
 		    }
806 1002
 		    $ignoreImport = false;
@@ -846,22 +1042,30 @@  discard block
 block discarded – undo
846 1042
 
847 1043
 		    if (!$ignoreImport) {
848 1044
 			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'])) {
849
-				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')));
1045
+				if (!isset($this->all_flights[$id]['id'])) {
1046
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1047
+				}
850 1048
 				$timeelapsed = microtime(true);
851 1049
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
852 1050
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
853
-					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1051
+					if ($globalDebug) {
1052
+						echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1053
+					}
854 1054
 					$SpotterLive = new SpotterLive($this->db);
855 1055
 					$result = $SpotterLive->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]['altitude_real'], $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']);
856 1056
 					$SpotterLive->db = null;
857
-					if ($globalDebug) echo $result."\n";
1057
+					if ($globalDebug) {
1058
+						echo $result."\n";
1059
+					}
858 1060
 				    }
859 1061
 				}
860 1062
 				if (isset($globalServerAPRS) && $globalServerAPRS) {
861 1063
 					$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]['altitude_real'], $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']);
862 1064
 				}
863 1065
 				$this->all_flights[$id]['putinarchive'] = false;
864
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1066
+				if ($globalDebugTimeElapsed) {
1067
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1068
+				}
865 1069
 
866 1070
 				// Put statistics in $this->stats variable
867 1071
 				//if ($line['format_source'] != 'aprs') {
@@ -869,7 +1073,9 @@  discard block
 block discarded – undo
869 1073
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
870 1074
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
871 1075
 					$source = $this->all_flights[$id]['source_name'];
872
-					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1076
+					if ($source == '') {
1077
+						$source = $this->all_flights[$id]['format_source'];
1078
+					}
873 1079
 					if (!isset($this->source_location[$source])) {
874 1080
 						$Location = new Source();
875 1081
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -890,7 +1096,9 @@  discard block
 block discarded – undo
890 1096
 					$stats_heading = round($stats_heading/22.5);
891 1097
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
892 1098
 					$current_date = date('Y-m-d');
893
-					if ($stats_heading == 16) $stats_heading = 0;
1099
+					if ($stats_heading == 16) {
1100
+						$stats_heading = 0;
1101
+					}
894 1102
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
895 1103
 						for ($i=0;$i<=15;$i++) {
896 1104
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -908,7 +1116,9 @@  discard block
 block discarded – undo
908 1116
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
909 1117
 						    end($this->stats[$current_date][$source]['hist']);
910 1118
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
911
-						} else $mini = 0;
1119
+						} else {
1120
+							$mini = 0;
1121
+						}
912 1122
 						for ($i=$mini;$i<=$distance;$i+=10) {
913 1123
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
914 1124
 						}
@@ -920,19 +1130,27 @@  discard block
 block discarded – undo
920 1130
 				}
921 1131
 
922 1132
 				$this->all_flights[$id]['lastupdate'] = time();
923
-				if ($this->all_flights[$id]['putinarchive']) $send = true;
1133
+				if ($this->all_flights[$id]['putinarchive']) {
1134
+					$send = true;
1135
+				}
924 1136
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
925
-			} 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";
1137
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
1138
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1139
+			}
926 1140
 			//$this->del();
927 1141
 			
928 1142
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
929 1143
 			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
930
-				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1144
+				if ($globalDebug) {
1145
+					echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1146
+				}
931 1147
 				$SpotterLive = new SpotterLive($this->db);
932 1148
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
933 1149
 				$SpotterLive->db = null;
934 1150
 				//SpotterLive->deleteLiveSpotterData();
935
-				if ($globalDebug) echo " Done\n";
1151
+				if ($globalDebug) {
1152
+					echo " Done\n";
1153
+				}
936 1154
 				$this->last_delete_hourly = time();
937 1155
 			    } else {
938 1156
 				$this->del();
@@ -944,7 +1162,9 @@  discard block
 block discarded – undo
944 1162
 		    //$ignoreImport = false;
945 1163
 		}
946 1164
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
947
-		if ($send) return $this->all_flights[$id];
1165
+		if ($send) {
1166
+			return $this->all_flights[$id];
1167
+		}
948 1168
 	    }
949 1169
 	}
950 1170
     }
Please login to merge, or discard this patch.
require/class.MarineImport.php 3 patches
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -10,16 +10,16 @@  discard block
 block discarded – undo
10 10
 require_once(dirname(__FILE__).'/class.Source.php');
11 11
 
12 12
 class MarineImport {
13
-    private $all_tracked = array();
14
-    private $last_delete_hourly = 0;
15
-    private $last_delete = 0;
16
-    private $stats = array();
17
-    private $tmd = 0;
18
-    private $source_location = array();
19
-    public $db = null;
20
-    public $nb = 0;
13
+	private $all_tracked = array();
14
+	private $last_delete_hourly = 0;
15
+	private $last_delete = 0;
16
+	private $stats = array();
17
+	private $tmd = 0;
18
+	private $source_location = array();
19
+	public $db = null;
20
+	public $nb = 0;
21 21
 
22
-    public function __construct($dbc = null) {
22
+	public function __construct($dbc = null) {
23 23
 	global $globalBeta;
24 24
 	$Connection = new Connection($dbc);
25 25
 	$this->db = $Connection->db();
@@ -41,50 +41,50 @@  discard block
 block discarded – undo
41 41
 	    }
42 42
 	}
43 43
 	*/
44
-    }
44
+	}
45 45
 
46
-    public function checkAll() {
46
+	public function checkAll() {
47 47
 	global $globalDebug;
48 48
 	if ($globalDebug) echo "Update last seen tracked data...\n";
49 49
 	foreach ($this->all_tracked as $key => $flight) {
50
-	    if (isset($this->all_tracked[$key]['id'])) {
50
+		if (isset($this->all_tracked[$key]['id'])) {
51 51
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
52
-    		$Marine = new Marine($this->db);
53
-        	$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
54
-            }
52
+			$Marine = new Marine($this->db);
53
+			$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
54
+			}
55
+	}
55 56
 	}
56
-    }
57 57
 
58
-    public function del() {
58
+	public function del() {
59 59
 	global $globalDebug;
60 60
 	// Delete old infos
61 61
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
62 62
 	foreach ($this->all_tracked as $key => $flight) {
63
-    	    if (isset($flight['lastupdate'])) {
64
-        	if ($flight['lastupdate'] < (time()-3000)) {
65
-            	    if (isset($this->all_tracked[$key]['id'])) {
66
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
63
+			if (isset($flight['lastupdate'])) {
64
+			if ($flight['lastupdate'] < (time()-3000)) {
65
+					if (isset($this->all_tracked[$key]['id'])) {
66
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
67 67
 			/*
68 68
 			$MarineLive = new MarineLive();
69 69
             		$MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
70 70
 			$MarineLive->db = null;
71 71
 			*/
72
-            		//$real_arrival = $this->arrival($key);
73
-            		$Marine = new Marine($this->db);
74
-            		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
72
+					//$real_arrival = $this->arrival($key);
73
+					$Marine = new Marine($this->db);
74
+					if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
75 75
 				$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 76
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
77 77
 			}
78 78
 			// Put in archive
79 79
 //			$Marine->db = null;
80
-            	    }
81
-            	    unset($this->all_tracked[$key]);
82
-    	        }
83
-	    }
84
-        }
85
-    }
80
+					}
81
+					unset($this->all_tracked[$key]);
82
+				}
83
+		}
84
+		}
85
+	}
86 86
 
87
-    public function add($line) {
87
+	public function add($line) {
88 88
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked;
89 89
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
90 90
 	date_default_timezone_set('UTC');
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
 	
94 94
 	// SBS format is CSV format
95 95
 	if(is_array($line) && isset($line['mmsi'])) {
96
-	    //print_r($line);
97
-  	    if (isset($line['mmsi'])) {
96
+		//print_r($line);
97
+  		if (isset($line['mmsi'])) {
98 98
 
99 99
 		/*
100 100
 		// Increment message number
@@ -111,87 +111,87 @@  discard block
 block discarded – undo
111 111
 		
112 112
 		$Common = new Common();
113 113
 		$AIS = new AIS();
114
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
115
-	        else $id = trim($line['id']);
114
+			if (!isset($line['id'])) $id = trim($line['mmsi']);
115
+			else $id = trim($line['id']);
116 116
 		
117 117
 		if (!isset($this->all_tracked[$id])) {
118
-		    $this->all_tracked[$id] = array();
119
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
120
-		    $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
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
122
-		    if (!isset($line['id'])) {
118
+			$this->all_tracked[$id] = array();
119
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
120
+			$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
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
122
+			if (!isset($line['id'])) {
123 123
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
124 124
 			$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;
125
+			 } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
126
+			if ($globalAllTracked !== FALSE) $dataFound = true;
127 127
 		}
128 128
 		
129 129
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
130
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
131
-		    $Marine = new Marine($this->db);
132
-		    $identity = $Marine->getIdentity($line['mmsi']);
133
-		    if (!empty($identity)) {
130
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
131
+			$Marine = new Marine($this->db);
132
+			$identity = $Marine->getIdentity($line['mmsi']);
133
+			if (!empty($identity)) {
134 134
 			$this->all_tracked[$id]['ident'] = $identity['ship_name'];
135 135
 			$this->all_tracked[$id]['type'] = $identity['type'];
136
-		    }
137
-		    //print_r($identity);
138
-		    unset($Marine);
139
-		    //$dataFound = true;
136
+			}
137
+			//print_r($identity);
138
+			unset($Marine);
139
+			//$dataFound = true;
140 140
 		}
141 141
 		if (isset($line['type_id']) && $line['type_id'] != '') {
142
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
142
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
143 143
 		}
144 144
 		if (isset($line['type']) && $line['type'] != '') {
145
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
145
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
146 146
 		}
147 147
 		if (isset($line['imo']) && $line['imo'] != '') {
148
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
148
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
149 149
 		}
150 150
 		if (isset($line['callsign']) && $line['callsign'] != '') {
151
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
151
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
152 152
 		}
153 153
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
154
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
154
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
155 155
 		}
156 156
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
157
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
157
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
158 158
 		}
159 159
 
160 160
 
161 161
 		//if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) {
162 162
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
163
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
164
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
163
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
164
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
165 165
 			$timeelapsed = microtime(true);
166
-            		$Marine = new Marine($this->db);
167
-            		$fromsource = NULL;
168
-            		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
166
+					$Marine = new Marine($this->db);
167
+					$fromsource = NULL;
168
+					$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
169 169
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
170 170
 			$Marine->db = null;
171 171
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
172
-		    }
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']));
172
+			}
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 174
 		}
175 175
 
176 176
 		if (isset($line['speed']) && $line['speed'] != '') {
177
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
178
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
177
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
178
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
179 179
 		} else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
180
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
181
-		    if ($distance > 1000 && $distance < 10000) {
180
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
181
+			if ($distance > 1000 && $distance < 10000) {
182 182
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
183 183
 			$speed = $speed*3.6;
184 184
 			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
185 185
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
186
-		    }
186
+			}
187 187
 		}
188 188
 
189
-	        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);
192
-	    	    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')))) {
189
+			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);
192
+				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 193
 			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
-			    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'])) {
194
+				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'])) {
195 195
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
196 196
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
197 197
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -205,76 +205,76 @@  discard block
 block discarded – undo
205 205
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
206 206
 				$this->tmd = 0;
207 207
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
208
-			    }
208
+				}
209 209
 			}
210 210
 
211 211
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
212 212
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
213 213
 				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
-				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
215
-				    $dataFound = true;
216
-				    $this->all_tracked[$id]['time_last_coord'] = time();
214
+					$this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
215
+					$dataFound = true;
216
+					$this->all_tracked[$id]['time_last_coord'] = time();
217 217
 				}
218 218
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
219 219
 			}
220 220
 			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;
221
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
222 222
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
223 223
 				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
-				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
225
-				    $dataFound = true;
226
-				    $this->all_tracked[$id]['time_last_coord'] = time();
224
+					$this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
225
+					$dataFound = true;
226
+					$this->all_tracked[$id]['time_last_coord'] = time();
227 227
 				}
228 228
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
229 229
 			}
230 230
 
231
-		    } else if ($globalDebug && $timediff > 20) {
231
+			} else if ($globalDebug && $timediff > 20) {
232 232
 			$this->tmd = $this->tmd + 1;
233 233
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
234 234
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
235 235
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
236 236
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
237
-		    }
237
+			}
238 238
 		}
239 239
 		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;
241
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('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;
241
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
242 242
 		}
243 243
 		if (isset($line['format_source']) && $line['format_source'] != '') {
244
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
244
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
245 245
 		}
246 246
 		if (isset($line['source_name']) && $line['source_name'] != '') {
247
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
247
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
248 248
 		}
249 249
 		if (isset($line['status']) && $line['status'] != '') {
250
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
250
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
251 251
 		}
252 252
 
253 253
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
254
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
254
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
255 255
 		}
256 256
 		
257 257
 		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;
259
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
260
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
261
-		    //$dataFound = true;
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;
259
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
260
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
261
+			//$dataFound = true;
262 262
   		} 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
-  		    $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
-		    $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";
263
+  			$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
+			$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";
267 267
   		}
268 268
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
269 269
 
270 270
 		if (isset($line['datetime'])) {
271
-		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
271
+			if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
272 272
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
273
-		    } else {
273
+			} else {
274 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 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";
276 276
 				return '';
277
-		    }
277
+			}
278 278
 		} else {
279 279
 			date_default_timezone_set('UTC');
280 280
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -282,45 +282,45 @@  discard block
 block discarded – undo
282 282
 
283 283
 
284 284
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
285
-		    $this->all_tracked[$id]['lastupdate'] = time();
286
-		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
287
-		        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
-			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
285
+			$this->all_tracked[$id]['lastupdate'] = time();
286
+			if ($this->all_tracked[$id]['addedMarine'] == 0) {
287
+				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
+				if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
289 289
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
290 290
 				$timeelapsed = microtime(true);
291 291
 				$MarineLive = new MarineLive($this->db);
292 292
 				if (isset($line['id'])) {
293
-				    $recent_ident = $MarineLive->checkIdRecent($line['id']);
294
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
293
+					$recent_ident = $MarineLive->checkIdRecent($line['id']);
294
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
295 295
 				} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
296
-				    $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";
296
+					$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";
298 298
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
299
-				    $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";
299
+					$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 301
 				} else $recent_ident = '';
302 302
 				$MarineLive->db=null;
303 303
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
304 304
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
305
-			    } else {
305
+				} else {
306 306
 				$recent_ident = '';
307 307
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
308
-			    }
309
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
310
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
311
-			    {
308
+				}
309
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
310
+				if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
311
+				{
312 312
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
313 313
 				//adds the spotter data for the archive
314
-				    $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')));
316
-				    $timeelapsed = microtime(true);
317
-				    $Marine = new Marine($this->db);
318
-				    $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
-				    $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";
314
+					$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')));
316
+					$timeelapsed = microtime(true);
317
+					$Marine = new Marine($this->db);
318
+					$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
+					$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";
322 322
 				    
323
-				    /*
323
+					/*
324 324
 				    // Add source stat in DB
325 325
 				    $Stats = new Stats($this->db);
326 326
 				    if (!empty($this->stats)) {
@@ -347,20 +347,20 @@  discard block
 block discarded – undo
347 347
 				    }
348 348
 				    $Stats->db = null;
349 349
 				    */
350
-				    $this->del();
350
+					$this->del();
351 351
 				//$ignoreImport = false;
352 352
 				$this->all_tracked[$id]['addedMarine'] = 1;
353 353
 				//print_r($this->all_tracked[$id]);
354 354
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
355
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
356
-				    //MarineLive->deleteLiveMarineDataNotUpdated();
357
-				    $MarineLive = new MarineLive($this->db);
358
-				    $MarineLive->deleteLiveMarineData();
359
-				    $MarineLive->db=null;
360
-				    if ($globalDebug) echo " Done\n";
361
-				    $this->last_delete = time();
355
+					if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
356
+					//MarineLive->deleteLiveMarineDataNotUpdated();
357
+					$MarineLive = new MarineLive($this->db);
358
+					$MarineLive->deleteLiveMarineData();
359
+					$MarineLive->db=null;
360
+					if ($globalDebug) echo " Done\n";
361
+					$this->last_delete = time();
362 362
 				}
363
-			    } elseif ($recent_ident != '') {
363
+				} elseif ($recent_ident != '') {
364 364
 				$this->all_tracked[$id]['id'] = $recent_ident;
365 365
 				$this->all_tracked[$id]['addedMarine'] = 1;
366 366
 				if (isset($globalDaemon) && !$globalDaemon) {
@@ -369,16 +369,16 @@  discard block
 block discarded – undo
369 369
 					$Marine->db = null;
370 370
 				}
371 371
 				
372
-			    }
372
+				}
373
+			}
373 374
 			}
374
-		    }
375
-		    //adds the spotter LIVE data
376
-		    if ($globalDebug) {
375
+			//adds the spotter LIVE data
376
+			if ($globalDebug) {
377 377
 			echo 'DATA : ident : '.$this->all_tracked[$id]['ident'].' - type : '.$this->all_tracked[$id]['type'].' - Latitude : '.$this->all_tracked[$id]['latitude'].' - Longitude : '.$this->all_tracked[$id]['longitude'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n";
378
-		    }
379
-		    $ignoreImport = false;
378
+			}
379
+			$ignoreImport = false;
380 380
 
381
-		    if (!$ignoreImport) {
381
+			if (!$ignoreImport) {
382 382
 			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 383
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
384 384
 				$timeelapsed = microtime(true);
@@ -450,22 +450,22 @@  discard block
 block discarded – undo
450 450
 			
451 451
 			
452 452
 			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...";
454
-			    $MarineLive = new MarineLive($this->db);
455
-			    $MarineLive->deleteLiveMarineDataNotUpdated();
456
-			    $MarineLive->db = null;
457
-			    //MarineLive->deleteLiveMarineData();
458
-			    if ($globalDebug) echo " Done\n";
459
-			    $this->last_delete_hourly = time();
453
+				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
454
+				$MarineLive = new MarineLive($this->db);
455
+				$MarineLive->deleteLiveMarineDataNotUpdated();
456
+				$MarineLive->db = null;
457
+				//MarineLive->deleteLiveMarineData();
458
+				if ($globalDebug) echo " Done\n";
459
+				$this->last_delete_hourly = time();
460 460
 			}
461 461
 			
462
-		    }
463
-		    //$ignoreImport = false;
462
+			}
463
+			//$ignoreImport = false;
464 464
 		}
465 465
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
466 466
 		if ($send) return $this->all_tracked[$id];
467
-	    }
467
+		}
468
+	}
468 469
 	}
469
-    }
470 470
 }
471 471
 ?>
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	    if (isset($this->all_tracked[$key]['id'])) {
51 51
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
52 52
     		$Marine = new Marine($this->db);
53
-        	$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
53
+        	$Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime']);
54 54
             }
55 55
 	}
56 56
     }
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
62 62
 	foreach ($this->all_tracked as $key => $flight) {
63 63
     	    if (isset($flight['lastupdate'])) {
64
-        	if ($flight['lastupdate'] < (time()-3000)) {
64
+        	if ($flight['lastupdate'] < (time() - 3000)) {
65 65
             	    if (isset($this->all_tracked[$key]['id'])) {
66 66
             		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
67 67
 			/*
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
             		//$real_arrival = $this->arrival($key);
73 73
             		$Marine = new Marine($this->db);
74 74
             		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
75
-				$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']);
75
+				$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 76
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
77 77
 			}
78 78
 			// Put in archive
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	$send = false;
93 93
 	
94 94
 	// SBS format is CSV format
95
-	if(is_array($line) && isset($line['mmsi'])) {
95
+	if (is_array($line) && isset($line['mmsi'])) {
96 96
 	    //print_r($line);
97 97
   	    if (isset($line['mmsi'])) {
98 98
 
@@ -116,18 +116,18 @@  discard block
 block discarded – undo
116 116
 		
117 117
 		if (!isset($this->all_tracked[$id])) {
118 118
 		    $this->all_tracked[$id] = array();
119
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
120
-		    $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
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
119
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('addedMarine' => 0));
120
+		    $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
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('lastupdate' => time()));
122 122
 		    if (!isset($line['id'])) {
123 123
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
124
-			$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']));
124
+			$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 126
 		    if ($globalAllTracked !== FALSE) $dataFound = true;
127 127
 		}
128 128
 		
129 129
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
130
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
130
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi' => $line['mmsi']));
131 131
 		    $Marine = new Marine($this->db);
132 132
 		    $identity = $Marine->getIdentity($line['mmsi']);
133 133
 		    if (!empty($identity)) {
@@ -139,59 +139,59 @@  discard block
 block discarded – undo
139 139
 		    //$dataFound = true;
140 140
 		}
141 141
 		if (isset($line['type_id']) && $line['type_id'] != '') {
142
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
142
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $AIS->getShipType($line['type_id'])));
143 143
 		}
144 144
 		if (isset($line['type']) && $line['type'] != '') {
145
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
145
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type']));
146 146
 		}
147 147
 		if (isset($line['imo']) && $line['imo'] != '') {
148
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
148
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('imo' => $line['imo']));
149 149
 		}
150 150
 		if (isset($line['callsign']) && $line['callsign'] != '') {
151
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
151
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('callsign' => $line['callsign']));
152 152
 		}
153 153
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
154
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
154
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code']));
155 155
 		}
156 156
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
157
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
157
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date']));
158 158
 		}
159 159
 
160 160
 
161 161
 		//if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) {
162 162
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
163
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
163
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident'])));
164 164
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
165 165
 			$timeelapsed = microtime(true);
166 166
             		$Marine = new Marine($this->db);
167 167
             		$fromsource = NULL;
168
-            		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
168
+            		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource);
169 169
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
170 170
 			$Marine->db = null;
171
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
171
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
172 172
 		    }
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']));
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 174
 		}
175 175
 
176 176
 		if (isset($line['speed']) && $line['speed'] != '') {
177
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
178
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
177
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed'])));
178
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true));
179 179
 		} else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
180
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
180
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm');
181 181
 		    if ($distance > 1000 && $distance < 10000) {
182 182
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
183 183
 			$speed = $speed*3.6;
184
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
184
+			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed)));
185 185
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
186 186
 		    }
187 187
 		}
188 188
 
189 189
 	        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']);
190
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']);
191 191
 	    	    else unset($timediff);
192
-	    	    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')))) {
192
+	    	    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 193
 			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
-			    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'])) {
194
+			    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'])) {
195 195
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
196 196
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
197 197
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
 				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
200 200
 				$timeelapsed = microtime(true);
201 201
 				$Marine = new Marine($this->db);
202
-				$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
202
+				$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
203 203
 				if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
204 204
 				$Marine->db = null;
205
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
205
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
206 206
 				$this->tmd = 0;
207 207
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
208 208
 			    }
@@ -210,66 +210,66 @@  discard block
 block discarded – undo
210 210
 
211 211
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
212 212
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
213
-				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') {
213
+				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 214
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
215 215
 				    $dataFound = true;
216 216
 				    $this->all_tracked[$id]['time_last_coord'] = time();
217 217
 				}
218
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
218
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude']));
219 219
 			}
220 220
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
221 221
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
222 222
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
223
-				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') {
223
+				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 224
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
225 225
 				    $dataFound = true;
226 226
 				    $this->all_tracked[$id]['time_last_coord'] = time();
227 227
 				}
228
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
228
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude']));
229 229
 			}
230 230
 
231 231
 		    } else if ($globalDebug && $timediff > 20) {
232 232
 			$this->tmd = $this->tmd + 1;
233 233
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
234
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
235
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
234
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -";
235
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
236 236
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
237 237
 		    }
238 238
 		}
239 239
 		if (isset($line['last_update']) && $line['last_update'] != '') {
240 240
 		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
241
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
241
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update']));
242 242
 		}
243 243
 		if (isset($line['format_source']) && $line['format_source'] != '') {
244
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
244
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source']));
245 245
 		}
246 246
 		if (isset($line['source_name']) && $line['source_name'] != '') {
247
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
247
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name']));
248 248
 		}
249 249
 		if (isset($line['status']) && $line['status'] != '') {
250
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
250
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status']));
251 251
 		}
252 252
 
253 253
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
254
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
254
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true));
255 255
 		}
256 256
 		
257 257
 		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;
259
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
260
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
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;
259
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading'])));
260
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true));
261 261
 		    //$dataFound = true;
262 262
   		} 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
-  		    $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
-		    $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;
263
+  		    $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
+		    $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 266
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
267 267
   		}
268 268
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
269 269
 
270 270
 		if (isset($line['datetime'])) {
271 271
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
272
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
272
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime']));
273 273
 		    } else {
274 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 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";
@@ -277,48 +277,48 @@  discard block
 block discarded – undo
277 277
 		    }
278 278
 		} else {
279 279
 			date_default_timezone_set('UTC');
280
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
280
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s')));
281 281
 		}
282 282
 
283 283
 
284 284
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
285 285
 		    $this->all_tracked[$id]['lastupdate'] = time();
286 286
 		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
287
-		        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'])) {
287
+		        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 288
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
289 289
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
290 290
 				$timeelapsed = microtime(true);
291 291
 				$MarineLive = new MarineLive($this->db);
292 292
 				if (isset($line['id'])) {
293 293
 				    $recent_ident = $MarineLive->checkIdRecent($line['id']);
294
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
294
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
295 295
 				} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
296 296
 				    $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";
297
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
298 298
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
299 299
 				    $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";
300
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
301 301
 				} else $recent_ident = '';
302
-				$MarineLive->db=null;
302
+				$MarineLive->db = null;
303 303
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
304 304
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
305 305
 			    } else {
306 306
 				$recent_ident = '';
307
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
307
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0));
308 308
 			    }
309 309
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
310
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
310
+			    if ($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
311 311
 			    {
312 312
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
313 313
 				//adds the spotter data for the archive
314 314
 				    $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')));
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')));
316 316
 				    $timeelapsed = microtime(true);
317 317
 				    $Marine = new Marine($this->db);
318
-				    $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']);
318
+				    $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 319
 				    $Marine->db = null;
320 320
 				    if ($globalDebug && isset($result)) echo $result."\n";
321
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
321
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
322 322
 				    
323 323
 				    /*
324 324
 				    // Add source stat in DB
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
357 357
 				    $MarineLive = new MarineLive($this->db);
358 358
 				    $MarineLive->deleteLiveMarineData();
359
-				    $MarineLive->db=null;
359
+				    $MarineLive->db = null;
360 360
 				    if ($globalDebug) echo " Done\n";
361 361
 				    $this->last_delete = time();
362 362
 				}
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 				$this->all_tracked[$id]['addedMarine'] = 1;
366 366
 				if (isset($globalDaemon) && !$globalDaemon) {
367 367
 					$Marine = new Marine($this->db);
368
-					$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime']);
368
+					$Marine->updateLatestMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime']);
369 369
 					$Marine->db = null;
370 370
 				}
371 371
 				
@@ -379,14 +379,14 @@  discard block
 block discarded – undo
379 379
 		    $ignoreImport = false;
380 380
 
381 381
 		    if (!$ignoreImport) {
382
-			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'])) {
382
+			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 383
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
384 384
 				$timeelapsed = microtime(true);
385 385
 				$MarineLive = new MarineLive($this->db);
386
-				$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']);
386
+				$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 387
 				$MarineLive->db = null;
388 388
 				$this->all_tracked[$id]['putinarchive'] = false;
389
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
389
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
390 390
 
391 391
 				// Put statistics in $this->stats variable
392 392
 				/*
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 				$this->all_tracked[$id]['lastupdate'] = time();
446 446
 				if ($this->all_tracked[$id]['putinarchive']) $send = true;
447 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";
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";
449 449
 			//$this->del();
450 450
 			
451 451
 			
Please login to merge, or discard this 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.APRS.php 4 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -89,6 +89,10 @@  discard block
 block discarded – undo
89 89
 	'y' => 'Yagi At QTH');
90 90
 	
91 91
 
92
+    /**
93
+     * @param integer $n
94
+     * @param integer $s
95
+     */
92 96
     private function urshift($n, $s) {
93 97
 	return ($n >= 0) ? ($n >> $s) :
94 98
 	    (($n & 0x7fffffff) >> $s) | 
@@ -462,6 +466,9 @@  discard block
 block discarded – undo
462 466
 	}
463 467
     }
464 468
     
469
+    /**
470
+     * @param string $data
471
+     */
465 472
     function send($data) {
466 473
 	if ($this->connected === false) $this->connect();
467 474
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
Please login to merge, or discard this patch.
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -2,10 +2,10 @@  discard block
 block discarded – undo
2 2
 require_once(dirname(__FILE__).'/settings.php');
3 3
 require_once(dirname(__FILE__).'/class.Common.php');
4 4
 class aprs {
5
-    private $socket;
6
-    private $connected = false;
5
+	private $socket;
6
+	private $connected = false;
7 7
 
8
-    protected $symbols = array('!' => 'Police',
8
+	protected $symbols = array('!' => 'Police',
9 9
 	'#' => 'DIGI',
10 10
 	'$' => 'Phone',
11 11
 	'%' => 'DX Cluster',
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
 	'y' => 'Yagi At QTH');
90 90
 	
91 91
 
92
-    private function urshift($n, $s) {
92
+	private function urshift($n, $s) {
93 93
 	return ($n >= 0) ? ($n >> $s) :
94
-	    (($n & 0x7fffffff) >> $s) | 
94
+		(($n & 0x7fffffff) >> $s) | 
95 95
 		(0x40000000 >> ($s - 1));
96
-    }
96
+	}
97 97
 
98
-    public function parse($input) {
98
+	public function parse($input) {
99 99
 	global $globalDebug;
100 100
 	$debug = false;
101 101
 	$result = array();
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 	
108 108
 	/* Check that end was found and body has at least one byte. */
109 109
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
110
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
111
-	    return false;
110
+		if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
111
+		return false;
112 112
 	}
113 113
 	
114 114
 	if ($debug) echo 'input : '.$input."\n";
@@ -122,31 +122,31 @@  discard block
 block discarded – undo
122 122
 	/* Parse source, target and path. */
123 123
 	//FLRDF0A52>APRS,qAS,LSTB
124 124
 	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
125
-	    $ident = $matches[1];
126
-	    $all_elements = $matches[2];
127
-	    if ($ident == 'AIRCRAFT') {
125
+		$ident = $matches[1];
126
+		$all_elements = $matches[2];
127
+		if ($ident == 'AIRCRAFT') {
128 128
 		$result['format_source'] = 'famaprs';
129 129
 		$result['source_type'] = 'modes';
130
-	    } elseif ($ident == 'MARINE') {
130
+		} elseif ($ident == 'MARINE') {
131 131
 		$result['format_source'] = 'famaprs';
132 132
 		$result['source_type'] = 'ais';
133
-	    } else {
133
+		} else {
134 134
 		if ($debug) echo 'ident : '.$ident."\n";
135 135
 		$result['ident'] = $ident;
136
-	    }
136
+		}
137 137
 	} else return false;
138 138
 	$elements = explode(',',$all_elements);
139 139
 	$source = end($elements);
140 140
 	$result['source'] = $source;
141 141
 	foreach ($elements as $element) {
142
-	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
143
-	        //echo "ok";
144
-	        //if ($element == 'TCPIP*') return false;
145
-	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
142
+		if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
143
+			//echo "ok";
144
+			//if ($element == 'TCPIP*') return false;
145
+		} elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
146 146
 		if ($debug) echo 'element : '.$element."\n";
147 147
 		return false;
148
-	    }
149
-	    /*
148
+		}
149
+		/*
150 150
 	    } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) {
151 151
 		//echo "ok";
152 152
 	    } else {
@@ -171,49 +171,49 @@  discard block
 block discarded – undo
171 171
 	$body_parse = substr($body,1);
172 172
 	//echo 'Body : '.$body."\n";
173 173
 	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
174
-	    $body_parse = substr($body_parse,10);
175
-	    $find = true;
176
-	    //echo $body_parse."\n";
174
+		$body_parse = substr($body_parse,10);
175
+		$find = true;
176
+		//echo $body_parse."\n";
177 177
 	}
178 178
 	if (preg_match('/^`(.*)\//',$body,$matches)) {
179
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
180
-	    $find = true;
181
-	    //echo $body_parse."\n";
179
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
180
+		$find = true;
181
+		//echo $body_parse."\n";
182 182
 	}
183 183
 	if (preg_match("/^'(.*)\//",$body,$matches)) {
184
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
185
-	    $find = true;
186
-	    //echo $body_parse."\n";
184
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
185
+		$find = true;
186
+		//echo $body_parse."\n";
187 187
 	}
188 188
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
189
-	    $find = true;
190
-	    //print_r($matches);
191
-	    $timestamp = $matches[0];
192
-	    if ($matches[4] == 'h') {
189
+		$find = true;
190
+		//print_r($matches);
191
+		$timestamp = $matches[0];
192
+		if ($matches[4] == 'h') {
193 193
 		$timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]);
194 194
 		//echo 'timestamp : '.$timestamp.' - now : '.time()."\n";
195 195
 		/*
196 196
 		if (time() + 3900 < $timestamp) $timestamp -= 86400;
197 197
 		elseif (time() - 82500 > $timestamp) $timestamp += 86400;
198 198
 		*/
199
-	    } elseif ($matches[4] == 'z' || $matches[4] == '/') {
199
+		} elseif ($matches[4] == 'z' || $matches[4] == '/') {
200 200
 		// This work or not ?
201 201
 		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
202
-	    }
203
-	    $body_parse = substr($body_parse,7);
204
-	    $result['timestamp'] = $timestamp;
205
-	    //echo date('Ymd H:i:s',$timestamp);
202
+		}
203
+		$body_parse = substr($body_parse,7);
204
+		$result['timestamp'] = $timestamp;
205
+		//echo date('Ymd H:i:s',$timestamp);
206 206
 	}
207 207
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) {
208
-	    $find = true;
209
-	    $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
210
-	    $body_parse = substr($body_parse,8);
211
-	    $result['timestamp'] = $timestamp;
212
-	    //echo date('Ymd H:i:s',$timestamp);
208
+		$find = true;
209
+		$timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
210
+		$body_parse = substr($body_parse,8);
211
+		$result['timestamp'] = $timestamp;
212
+		//echo date('Ymd H:i:s',$timestamp);
213 213
 	}
214 214
 	//if (strlen($body_parse) > 19) {
215
-	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
216
-	    $find = true;
215
+		if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
216
+		$find = true;
217 217
 		// 4658.70N/00707.78Ez
218 218
 		//print_r(str_split($body_parse));
219 219
 		
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 		$lon = intval($lon_deg);
231 231
 		if ($lat > 89 || $lon > 179) return false;
232 232
 	    
233
-	    /*
233
+		/*
234 234
 	    $tmp_5b = str_replace('.','',$lat_min);
235 235
 	    if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) {
236 236
 	        print_r($matches);
@@ -244,9 +244,9 @@  discard block
 block discarded – undo
244 244
 		$result['longitude'] = $longitude;
245 245
 		$body_parse = substr($body_parse,18);
246 246
 		$body_parse_len = strlen($body_parse);
247
-	    }
248
-	    $body_parse_len = strlen($body_parse);
249
-	    if ($body_parse_len > 0) {
247
+		}
248
+		$body_parse_len = strlen($body_parse);
249
+		if ($body_parse_len > 0) {
250 250
 		/*
251 251
 		if (!isset($result['timestamp']) && !isset($result['latitude'])) {
252 252
 			$body_split = str_split($body);
@@ -276,86 +276,86 @@  discard block
 block discarded – undo
276 276
 			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
277 277
 			if ($symbol_code != '_') {
278 278
 			}
279
-		    //$body_parse = substr($body_parse,1);
280
-		    //$body_parse = trim($body_parse);
281
-		    //$body_parse_len = strlen($body_parse);
282
-		    if ($body_parse_len >= 7) {
279
+			//$body_parse = substr($body_parse,1);
280
+			//$body_parse = trim($body_parse);
281
+			//$body_parse_len = strlen($body_parse);
282
+			if ($body_parse_len >= 7) {
283 283
 			
284
-		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285
-		    	    $course = substr($body_parse,0,3);
286
-		    	    $tmp_s = intval($course);
287
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
288
-		    	    $speed = substr($body_parse,4,3);
289
-		    	    if ($speed != '...') {
290
-		    		//$result['speed'] = round($speed*1.852);
291
-		    		$result['speed'] = intval($speed);
292
-		    	    }
293
-		    	    $body_parse = substr($body_parse,7);
294
-		        }
295
-		        // Check PHGR, PHG, RNG
296
-		    } 
297
-		    /*
284
+				if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285
+					$course = substr($body_parse,0,3);
286
+					$tmp_s = intval($course);
287
+					if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
288
+					$speed = substr($body_parse,4,3);
289
+					if ($speed != '...') {
290
+					//$result['speed'] = round($speed*1.852);
291
+					$result['speed'] = intval($speed);
292
+					}
293
+					$body_parse = substr($body_parse,7);
294
+				}
295
+				// Check PHGR, PHG, RNG
296
+			} 
297
+			/*
298 298
 		    else if ($body_parse_len > 0) {
299 299
 			$rest = $body_parse;
300 300
 		    }
301 301
 		    */
302
-		    if (strlen($body_parse) > 0) {
303
-		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
304
-		            $altitude = intval($matches[1]);
305
-		            //$result['altitude'] = round($altitude*0.3048);
306
-		            $result['altitude'] = $altitude;
307
-		            //$body_parse = trim(substr($body_parse,strlen($matches[0])));
308
-		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
309
-		        }
310
-		    }
302
+			if (strlen($body_parse) > 0) {
303
+				if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
304
+					$altitude = intval($matches[1]);
305
+					//$result['altitude'] = round($altitude*0.3048);
306
+					$result['altitude'] = $altitude;
307
+					//$body_parse = trim(substr($body_parse,strlen($matches[0])));
308
+					$body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
309
+				}
310
+			}
311 311
 		    
312
-		    // Telemetry
313
-		    /*
312
+			// Telemetry
313
+			/*
314 314
 		    if (preg_match('/^([0-9]+),(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,([01]{0,8})/',$body_parse,$matches)) {
315 315
 		        // Nothing yet...
316 316
 		    }
317 317
 		    */
318
-		    // DAO
319
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
320
-			    $dao = $matches[1];
321
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
318
+			// DAO
319
+			if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
320
+				$dao = $matches[1];
321
+				if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
322 322
 				$dao_split = str_split($dao);
323
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
324
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
323
+					$lat_off = (($dao_split[1])-48.0)*0.001/60.0;
324
+					$lon_off = (($dao_split[2])-48.0)*0.001/60.0;
325 325
 			    
326 326
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
327 327
 				else $result['latitude'] += $lat_off;
328 328
 				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
329 329
 				else $result['longitude'] += $lon_off;
330
-			    }
331
-		            $body_parse = substr($body_parse,6);
332
-		    }
330
+				}
331
+					$body_parse = substr($body_parse,6);
332
+			}
333 333
 		    
334
-		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
334
+			if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
335 335
 			$result['ident'] = $matches[1];
336
-		    }
337
-		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
336
+			}
337
+			if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
338 338
 			$result['squawk'] = $matches[1];
339
-		    }
340
-		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
339
+			}
340
+			if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
341 341
 			$result['aircraft_icao'] = $matches[1];
342
-		    }
343
-		    if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
342
+			}
343
+			if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
344 344
 			$result['typeid'] = $matches[1];
345
-		    }
346
-		    if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
345
+			}
346
+			if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
347 347
 			$result['imo'] = $matches[1];
348
-		    }
349
-		    if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
348
+			}
349
+			if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
350 350
 			$result['arrival_date'] = $matches[1];
351
-		    }
352
-		    if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
351
+			}
352
+			if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
353 353
 			$result['arrival_code'] = $matches[1];
354
-		    }
355
-		    // OGN comment
354
+			}
355
+			// OGN comment
356 356
 		   // echo "Before OGN : ".$body_parse."\n";
357
-		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
358
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
357
+			//if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
358
+			if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
359 359
 			$id = $matches[1];
360 360
 			//$mode = substr($id,0,2);
361 361
 			$address = substr($id,2);
@@ -385,53 +385,53 @@  discard block
 block discarded – undo
385 385
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
386 386
 			$result['stealth'] = $stealth;
387 387
 			$result['address'] = $address;
388
-		    }
388
+			}
389 389
 		    
390
-		    //Comment
391
-		    $result['comment'] = trim($body_parse);
390
+			//Comment
391
+			$result['comment'] = trim($body_parse);
392 392
 		} else {
393
-		    // parse weather
394
-		    //$body_parse = substr($body_parse,1);
395
-		    //$body_parse_len = strlen($body_parse);
393
+			// parse weather
394
+			//$body_parse = substr($body_parse,1);
395
+			//$body_parse_len = strlen($body_parse);
396 396
 
397
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
398
-			    $result['wind_dir'] = intval($matches[1]);
399
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
400
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
401
-			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
402
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
403
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
397
+			if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
398
+				$result['wind_dir'] = intval($matches[1]);
399
+				$result['wind_speed'] = round(intval($matches[2])*1.60934,1);
400
+				$result['wind_gust'] = round(intval($matches[3])*1.60934,1);
401
+				$result['temp'] = round(5/9*((intval($matches[4]))-32),1);
402
+					$body_parse = substr($body_parse,strlen($matches[0])+1);
403
+			} elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
404 404
 			$result['wind_dir'] = intval($matches[1]);
405 405
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
406 406
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
407 407
 			$result['temp'] = round(5/9*(($matches[4])-32),1);
408
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
409
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
408
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
409
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
410 410
 			$result['wind_dir'] = intval($matches[1]);
411 411
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
412 412
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
413
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
414
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
413
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
414
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
415 415
 			$result['wind_dir'] = intval($matches[1]);
416 416
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
417 417
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
418
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
419
-		    }
420
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
418
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
419
+			}
420
+			if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
421 421
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
422
-		    }
422
+			}
423 423
 		}
424 424
 		} else $result['comment'] = trim($body_parse);
425 425
 
426
-	    }
426
+		}
427 427
 	//}
428 428
 	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
429 429
 	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
430 430
 	if ($debug) print_r($result);
431 431
 	return $result;
432
-    }
432
+	}
433 433
     
434
-    function connect() {
434
+	function connect() {
435 435
 	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
436 436
 	$aprs_connect = 0;
437 437
 	$aprs_keep = 120;
@@ -454,24 +454,24 @@  discard block
 block discarded – undo
454 454
 		$send = socket_send( $this->socket  , $aprs_login , strlen($aprs_login) , 0 );
455 455
 		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
456 456
 			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
457
-			    echo 'APRS user verified !'."\n";
458
-			    $this->connected = true;
459
-			    return true;
460
-			    break;
457
+				echo 'APRS user verified !'."\n";
458
+				$this->connected = true;
459
+				return true;
460
+				break;
461 461
 			}
462 462
 			if (time()-$authstart > 5) {
463
-			    echo 'APRS timeout'."\n";
464
-			    break;
463
+				echo 'APRS timeout'."\n";
464
+				break;
465 465
 			}
466 466
 		}
467 467
 	}
468
-    }
468
+	}
469 469
     
470
-    function send($data) {
470
+	function send($data) {
471 471
 	if ($this->connected === false) $this->connect();
472 472
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
473 473
 	if ($send === FALSE) $this->connect();
474
-    }
474
+	}
475 475
 }
476 476
 
477 477
 class APRSSpotter extends APRS {
Please login to merge, or discard this patch.
Spacing   +95 added lines, -96 removed lines patch added patch discarded remove patch
@@ -90,8 +90,7 @@  discard block
 block discarded – undo
90 90
 	
91 91
 
92 92
     private function urshift($n, $s) {
93
-	return ($n >= 0) ? ($n >> $s) :
94
-	    (($n & 0x7fffffff) >> $s) | 
93
+	return ($n >= 0) ? ($n >> $s) : (($n&0x7fffffff) >> $s)| 
95 94
 		(0x40000000 >> ($s - 1));
96 95
     }
97 96
 
@@ -103,7 +102,7 @@  discard block
 block discarded – undo
103 102
 	//$split_input = str_split($input);
104 103
 
105 104
 	/* Find the end of header checking for NULL bytes while doing it. */
106
-	$splitpos = strpos($input,':');
105
+	$splitpos = strpos($input, ':');
107 106
 	
108 107
 	/* Check that end was found and body has at least one byte. */
109 108
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
@@ -113,15 +112,15 @@  discard block
 block discarded – undo
113 112
 	
114 113
 	if ($debug) echo 'input : '.$input."\n";
115 114
 	/* Save header and body. */
116
-	$body = substr($input,$splitpos+1,$input_len);
115
+	$body = substr($input, $splitpos + 1, $input_len);
117 116
 	$body_len = strlen($body);
118
-	$header = substr($input,0,$splitpos);
117
+	$header = substr($input, 0, $splitpos);
119 118
 	//$header_len = strlen($header);
120 119
 	if ($debug) echo 'header : '.$header."\n";
121 120
 	
122 121
 	/* Parse source, target and path. */
123 122
 	//FLRDF0A52>APRS,qAS,LSTB
124
-	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
123
+	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/', $header, $matches)) {
125 124
 	    $ident = $matches[1];
126 125
 	    $all_elements = $matches[2];
127 126
 	    if ($ident == 'AIRCRAFT') {
@@ -135,14 +134,14 @@  discard block
 block discarded – undo
135 134
 		$result['ident'] = $ident;
136 135
 	    }
137 136
 	} else return false;
138
-	$elements = explode(',',$all_elements);
137
+	$elements = explode(',', $all_elements);
139 138
 	$source = end($elements);
140 139
 	$result['source'] = $source;
141 140
 	foreach ($elements as $element) {
142
-	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
141
+	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/', $element)) {
143 142
 	        //echo "ok";
144 143
 	        //if ($element == 'TCPIP*') return false;
145
-	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
144
+	    } elseif (!preg_match('/^([0-9A-F]{32})$/', $element)) {
146 145
 		if ($debug) echo 'element : '.$element."\n";
147 146
 		return false;
148 147
 	    }
@@ -155,12 +154,12 @@  discard block
 block discarded – undo
155 154
 	    */
156 155
 	}
157 156
 	
158
-	$type = substr($body,0,1);
157
+	$type = substr($body, 0, 1);
159 158
 	if ($debug) echo 'type : '.$type."\n";
160 159
 	if ($type == ';') {
161 160
 		if (isset($result['source_type']) && $result['source_type'] == 'modes') {
162
-			$result['address'] = trim(substr($body,1,9));
163
-		} else $result['ident'] = trim(substr($body,1,9));
161
+			$result['address'] = trim(substr($body, 1, 9));
162
+		} else $result['ident'] = trim(substr($body, 1, 9));
164 163
 	} elseif ($type == ',') {
165 164
 		// Invalid data or test data
166 165
 		return false;
@@ -168,24 +167,24 @@  discard block
 block discarded – undo
168 167
 	
169 168
 	// Check for Timestamp
170 169
 	$find = false;
171
-	$body_parse = substr($body,1);
170
+	$body_parse = substr($body, 1);
172 171
 	//echo 'Body : '.$body."\n";
173
-	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
174
-	    $body_parse = substr($body_parse,10);
172
+	if (preg_match('/^;(.){9}\*/', $body, $matches)) {
173
+	    $body_parse = substr($body_parse, 10);
175 174
 	    $find = true;
176 175
 	    //echo $body_parse."\n";
177 176
 	}
178
-	if (preg_match('/^`(.*)\//',$body,$matches)) {
179
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
177
+	if (preg_match('/^`(.*)\//', $body, $matches)) {
178
+	    $body_parse = substr($body_parse, strlen($matches[1]) - 1);
180 179
 	    $find = true;
181 180
 	    //echo $body_parse."\n";
182 181
 	}
183
-	if (preg_match("/^'(.*)\//",$body,$matches)) {
184
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
182
+	if (preg_match("/^'(.*)\//", $body, $matches)) {
183
+	    $body_parse = substr($body_parse, strlen($matches[1]) - 1);
185 184
 	    $find = true;
186 185
 	    //echo $body_parse."\n";
187 186
 	}
188
-	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
187
+	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/', $body_parse, $matches)) {
189 188
 	    $find = true;
190 189
 	    //print_r($matches);
191 190
 	    $timestamp = $matches[0];
@@ -200,19 +199,19 @@  discard block
 block discarded – undo
200 199
 		// This work or not ?
201 200
 		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
202 201
 	    }
203
-	    $body_parse = substr($body_parse,7);
202
+	    $body_parse = substr($body_parse, 7);
204 203
 	    $result['timestamp'] = $timestamp;
205 204
 	    //echo date('Ymd H:i:s',$timestamp);
206 205
 	}
207
-	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) {
206
+	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $body_parse, $matches)) {
208 207
 	    $find = true;
209 208
 	    $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
210
-	    $body_parse = substr($body_parse,8);
209
+	    $body_parse = substr($body_parse, 8);
211 210
 	    $result['timestamp'] = $timestamp;
212 211
 	    //echo date('Ymd H:i:s',$timestamp);
213 212
 	}
214 213
 	//if (strlen($body_parse) > 19) {
215
-	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
214
+	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/', $body_parse, $matches)) {
216 215
 	    $find = true;
217 216
 		// 4658.70N/00707.78Ez
218 217
 		//print_r(str_split($body_parse));
@@ -238,11 +237,11 @@  discard block
 block discarded – undo
238 237
 	    */
239 238
 		$latitude = $lat + floatval($lat_min)/60;
240 239
 		$longitude = $lon + floatval($lon_min)/60;
241
-		if ($sind == 'S') $latitude = 0-$latitude;
242
-		if ($wind == 'W') $longitude = 0-$longitude;
240
+		if ($sind == 'S') $latitude = 0 - $latitude;
241
+		if ($wind == 'W') $longitude = 0 - $longitude;
243 242
 		$result['latitude'] = $latitude;
244 243
 		$result['longitude'] = $longitude;
245
-		$body_parse = substr($body_parse,18);
244
+		$body_parse = substr($body_parse, 18);
246 245
 		$body_parse_len = strlen($body_parse);
247 246
 	    }
248 247
 	    $body_parse_len = strlen($body_parse);
@@ -270,7 +269,7 @@  discard block
 block discarded – undo
270 269
 		//echo $body_parse;
271 270
 			//if ($type != ';' && $type != '>') {
272 271
 			if ($type != '') {
273
-			$body_parse = substr($body_parse,1);
272
+			$body_parse = substr($body_parse, 1);
274 273
 			$body_parse_len = strlen($body_parse);
275 274
 			$result['symbol_code'] = $symbol_code;
276 275
 			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
@@ -281,16 +280,16 @@  discard block
 block discarded – undo
281 280
 		    //$body_parse_len = strlen($body_parse);
282 281
 		    if ($body_parse_len >= 7) {
283 282
 			
284
-		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285
-		    	    $course = substr($body_parse,0,3);
283
+		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/', $body_parse)) {
284
+		    	    $course = substr($body_parse, 0, 3);
286 285
 		    	    $tmp_s = intval($course);
287 286
 		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
288
-		    	    $speed = substr($body_parse,4,3);
287
+		    	    $speed = substr($body_parse, 4, 3);
289 288
 		    	    if ($speed != '...') {
290 289
 		    		//$result['speed'] = round($speed*1.852);
291 290
 		    		$result['speed'] = intval($speed);
292 291
 		    	    }
293
-		    	    $body_parse = substr($body_parse,7);
292
+		    	    $body_parse = substr($body_parse, 7);
294 293
 		        }
295 294
 		        // Check PHGR, PHG, RNG
296 295
 		    } 
@@ -300,12 +299,12 @@  discard block
 block discarded – undo
300 299
 		    }
301 300
 		    */
302 301
 		    if (strlen($body_parse) > 0) {
303
-		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
302
+		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/', $body_parse, $matches)) {
304 303
 		            $altitude = intval($matches[1]);
305 304
 		            //$result['altitude'] = round($altitude*0.3048);
306 305
 		            $result['altitude'] = $altitude;
307 306
 		            //$body_parse = trim(substr($body_parse,strlen($matches[0])));
308
-		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
307
+		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/', '', $body_parse));
309 308
 		        }
310 309
 		    }
311 310
 		    
@@ -316,56 +315,56 @@  discard block
 block discarded – undo
316 315
 		    }
317 316
 		    */
318 317
 		    // DAO
319
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
318
+		    if (preg_match('/^!([0-9A-Z]{3})/', $body_parse, $matches)) {
320 319
 			    $dao = $matches[1];
321
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
320
+			    if (preg_match('/^([A-Z])([0-9]{2})/', $dao)) {
322 321
 				$dao_split = str_split($dao);
323
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
324
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
322
+			        $lat_off = (($dao_split[1]) - 48.0)*0.001/60.0;
323
+			        $lon_off = (($dao_split[2]) - 48.0)*0.001/60.0;
325 324
 			    
326 325
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
327 326
 				else $result['latitude'] += $lat_off;
328 327
 				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
329 328
 				else $result['longitude'] += $lon_off;
330 329
 			    }
331
-		            $body_parse = substr($body_parse,6);
330
+		            $body_parse = substr($body_parse, 6);
332 331
 		    }
333 332
 		    
334
-		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
333
+		    if (preg_match('/CS=([0-9A-Z]*)/', $body_parse, $matches)) {
335 334
 			$result['ident'] = $matches[1];
336 335
 		    }
337
-		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
336
+		    if (preg_match('/SQ=([0-9]{4})/', $body_parse, $matches)) {
338 337
 			$result['squawk'] = $matches[1];
339 338
 		    }
340
-		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
339
+		    if (preg_match('/AI=([0-9A-Z]{4})/', $body_parse, $matches)) {
341 340
 			$result['aircraft_icao'] = $matches[1];
342 341
 		    }
343
-		    if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
342
+		    if (preg_match('/TI=([0-9]*)/', $body_parse, $matches)) {
344 343
 			$result['typeid'] = $matches[1];
345 344
 		    }
346
-		    if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
345
+		    if (preg_match('/IMO=([0-9]{7})/', $body_parse, $matches)) {
347 346
 			$result['imo'] = $matches[1];
348 347
 		    }
349
-		    if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
348
+		    if (preg_match('/AD=([0-9]*)/', $body_parse, $matches)) {
350 349
 			$result['arrival_date'] = $matches[1];
351 350
 		    }
352
-		    if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
351
+		    if (preg_match('/AC=([0-9A-Z]*)/', $body_parse, $matches)) {
353 352
 			$result['arrival_code'] = $matches[1];
354 353
 		    }
355 354
 		    // OGN comment
356 355
 		   // echo "Before OGN : ".$body_parse."\n";
357 356
 		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
358
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
357
+		    if (preg_match('/^id([0-9A-F]{8})/', $body_parse, $matches)) {
359 358
 			$id = $matches[1];
360 359
 			//$mode = substr($id,0,2);
361
-			$address = substr($id,2);
360
+			$address = substr($id, 2);
362 361
 			//print_r($matches);
363
-			$addressType = (intval(substr($id,0,2),16))&3;
362
+			$addressType = (intval(substr($id, 0, 2), 16))&3;
364 363
 			if ($addressType == 0) $result['addresstype'] = "RANDOM";
365 364
 			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
366 365
 			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
367 366
 			elseif ($addressType == 3) $result['addresstype'] = "OGN";
368
-			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
367
+			$aircraftType = $this->urshift(((intval(substr($id, 0, 2), 16))&0b1111100), 2);
369 368
 			$result['aircrafttype_code'] = $aircraftType;
370 369
 			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
371 370
 			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
@@ -382,7 +381,7 @@  discard block
 block discarded – undo
382 381
 			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
383 382
 			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
384 383
 			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
385
-			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
384
+			$stealth = (intval(substr($id, 0, 2), 16)&0b10000000) != 0;
386 385
 			$result['stealth'] = $stealth;
387 386
 			$result['address'] = $address;
388 387
 		    }
@@ -394,72 +393,72 @@  discard block
 block discarded – undo
394 393
 		    //$body_parse = substr($body_parse,1);
395 394
 		    //$body_parse_len = strlen($body_parse);
396 395
 
397
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
396
+		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
398 397
 			    $result['wind_dir'] = intval($matches[1]);
399
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
400
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
401
-			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
402
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
403
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
398
+			    $result['wind_speed'] = round(intval($matches[2])*1.60934, 1);
399
+			    $result['wind_gust'] = round(intval($matches[3])*1.60934, 1);
400
+			    $result['temp'] = round(5/9*((intval($matches[4])) - 32), 1);
401
+		    	    $body_parse = substr($body_parse, strlen($matches[0]) + 1);
402
+		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
404 403
 			$result['wind_dir'] = intval($matches[1]);
405
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
406
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
407
-			$result['temp'] = round(5/9*(($matches[4])-32),1);
408
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
409
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
404
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
405
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
406
+			$result['temp'] = round(5/9*(($matches[4]) - 32), 1);
407
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
408
+		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
410 409
 			$result['wind_dir'] = intval($matches[1]);
411
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
412
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
413
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
414
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
410
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
411
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
412
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
413
+		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/', $body_parse, $matches)) {
415 414
 			$result['wind_dir'] = intval($matches[1]);
416
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
417
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
418
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
415
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
416
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
417
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
419 418
 		    }
420
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
421
-			$result['temp'] = round(5/9*(($matches[1])-32),1);
419
+		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/', $body_parse, $matches)) {
420
+			$result['temp'] = round(5/9*(($matches[1]) - 32), 1);
422 421
 		    }
423 422
 		}
424 423
 		} else $result['comment'] = trim($body_parse);
425 424
 
426 425
 	    }
427 426
 	//}
428
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
429
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
427
+	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'], 4);
428
+	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'], 4);
430 429
 	if ($debug) print_r($result);
431 430
 	return $result;
432 431
     }
433 432
     
434 433
     function connect() {
435
-	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
434
+	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass, $globalName, $globalServerAPRShost, $globalServerAPRSport;
436 435
 	$aprs_connect = 0;
437 436
 	$aprs_keep = 120;
438 437
 	$aprs_last_tx = time();
439 438
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
440
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
439
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
441 440
 	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
442
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
441
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
443 442
 	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
444 443
 	else $aprs_pass = '-1';
445 444
 	
446
-	$aprs_filter  = '';
445
+	$aprs_filter = '';
447 446
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
448 447
 	$Common = new Common();
449
-	$s = $Common->create_socket($globalServerAPRShost,$globalServerAPRSport,$errno,$errstr);
448
+	$s = $Common->create_socket($globalServerAPRShost, $globalServerAPRSport, $errno, $errstr);
450 449
 	if ($s !== false) {
451 450
 		echo 'Connected to APRS server! '."\n";
452 451
 		$authstart = time();
453 452
 		$this->socket = $s;
454
-		$send = socket_send( $this->socket  , $aprs_login , strlen($aprs_login) , 0 );
455
-		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
453
+		$send = socket_send($this->socket, $aprs_login, strlen($aprs_login), 0);
454
+		while ($msgin = socket_read($this->socket, 1000, PHP_NORMAL_READ)) {
456 455
 			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
457 456
 			    echo 'APRS user verified !'."\n";
458 457
 			    $this->connected = true;
459 458
 			    return true;
460 459
 			    break;
461 460
 			}
462
-			if (time()-$authstart > 5) {
461
+			if (time() - $authstart > 5) {
463 462
 			    echo 'APRS timeout'."\n";
464 463
 			    break;
465 464
 			}
@@ -469,20 +468,20 @@  discard block
 block discarded – undo
469 468
     
470 469
     function send($data) {
471 470
 	if ($this->connected === false) $this->connect();
472
-	$send = socket_send( $this->socket  , $data , strlen($data),0);
471
+	$send = socket_send($this->socket, $data, strlen($data), 0);
473 472
 	if ($send === FALSE) $this->connect();
474 473
     }
475 474
 }
476 475
 
477 476
 class APRSSpotter extends APRS {
478
-	function addLiveSpotterData($id,$ident,$aircraft_icao,$departure_airport,$arrival_airport,$latitude,$longitude,$waypoints,$altitude,$altitude_real,$heading,$speed,$datetime,$departure_airport_time,$arrival_airport_time,$squawk,$route_stop,$hex,$putinarchive,$registration,$pilot_id,$pilot_name, $verticalrate, $noarchive, $ground,$format_source,$source_name,$over_country) {
477
+	function addLiveSpotterData($id, $ident, $aircraft_icao, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $altitude_real, $heading, $speed, $datetime, $departure_airport_time, $arrival_airport_time, $squawk, $route_stop, $hex, $putinarchive, $registration, $pilot_id, $pilot_name, $verticalrate, $noarchive, $ground, $format_source, $source_name, $over_country) {
479 478
 		$Common = new Common();
480 479
 		if ($latitude != '' && $longitude != '') {
481
-			$latitude = $Common->convertDM($latitude,'latitude');
482
-			$longitude = $Common->convertDM($longitude,'longitude');
483
-			$coordinate = str_pad($latitude['deg'].number_format($latitude['min'],2,'.',''),7,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'],2,'.',''),8,'0',STR_PAD_LEFT).$longitude['NSEW'];
484
-			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
485
-			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
480
+			$latitude = $Common->convertDM($latitude, 'latitude');
481
+			$longitude = $Common->convertDM($longitude, 'longitude');
482
+			$coordinate = str_pad($latitude['deg'].number_format($latitude['min'], 2, '.', ''), 7, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'], 2, '.', ''), 8, '0', STR_PAD_LEFT).$longitude['NSEW'];
483
+			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000));
484
+			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000));
486 485
 			$w = $w1.$w2;
487 486
 			//$w = '00';
488 487
 			$custom = '';
@@ -499,19 +498,19 @@  discard block
 block discarded – undo
499 498
 				$custom .= 'AI='.$aircraft_icao;
500 499
 			}
501 500
 			if ($custom != '') $custom = ' '.$custom;
502
-			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His',strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
501
+			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His', strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading, 3, '0', STR_PAD_LEFT).'/'.str_pad($speed, 3, '0', STR_PAD_LEFT).'/A='.str_pad($altitude_real, 6, '0', STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
503 502
 		}
504 503
 	}
505 504
 }
506 505
 class APRSMarine extends APRS {
507
-	function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed,$datetime, $putinarchive,$mmsi,$type,$typeid,$imo,$callsign,$arrival_code,$arrival_date,$status,$noarchive,$format_source,$source_name,$over_country) {
506
+	function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed, $datetime, $putinarchive, $mmsi, $type, $typeid, $imo, $callsign, $arrival_code, $arrival_date, $status, $noarchive, $format_source, $source_name, $over_country) {
508 507
 		$Common = new Common();
509 508
 		if ($latitude != '' && $longitude != '') {
510
-			$latitude = $Common->convertDM($latitude,'latitude');
511
-			$longitude = $Common->convertDM($longitude,'longitude');
512
-			$coordinate = str_pad($latitude['deg'].number_format($latitude['min'],2,'.',''),7,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'],2,'.',''),8,'0',STR_PAD_LEFT).$longitude['NSEW'];
513
-			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
514
-			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
509
+			$latitude = $Common->convertDM($latitude, 'latitude');
510
+			$longitude = $Common->convertDM($longitude, 'longitude');
511
+			$coordinate = str_pad($latitude['deg'].number_format($latitude['min'], 2, '.', ''), 7, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'], 2, '.', ''), 8, '0', STR_PAD_LEFT).$longitude['NSEW'];
512
+			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000));
513
+			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000));
515 514
 			$w = $w1.$w2;
516 515
 			//$w = '00';
517 516
 			$custom = '';
@@ -537,7 +536,7 @@  discard block
 block discarded – undo
537 536
 			}
538 537
 			if ($custom != '') $custom = ' '.$custom;
539 538
 			$altitude = 0;
540
-			$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");
539
+			$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");
541 540
 		}
542 541
 	}
543 542
 }
Please login to merge, or discard this patch.
Braces   +152 added lines, -58 removed lines patch added patch discarded remove patch
@@ -107,17 +107,23 @@  discard block
 block discarded – undo
107 107
 	
108 108
 	/* Check that end was found and body has at least one byte. */
109 109
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
110
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
110
+	    if ($globalDebug) {
111
+	    	echo '!!! APRS invalid : '.$input."\n";
112
+	    }
111 113
 	    return false;
112 114
 	}
113 115
 	
114
-	if ($debug) echo 'input : '.$input."\n";
116
+	if ($debug) {
117
+		echo 'input : '.$input."\n";
118
+	}
115 119
 	/* Save header and body. */
116 120
 	$body = substr($input,$splitpos+1,$input_len);
117 121
 	$body_len = strlen($body);
118 122
 	$header = substr($input,0,$splitpos);
119 123
 	//$header_len = strlen($header);
120
-	if ($debug) echo 'header : '.$header."\n";
124
+	if ($debug) {
125
+		echo 'header : '.$header."\n";
126
+	}
121 127
 	
122 128
 	/* Parse source, target and path. */
123 129
 	//FLRDF0A52>APRS,qAS,LSTB
@@ -131,10 +137,14 @@  discard block
 block discarded – undo
131 137
 		$result['format_source'] = 'famaprs';
132 138
 		$result['source_type'] = 'ais';
133 139
 	    } else {
134
-		if ($debug) echo 'ident : '.$ident."\n";
140
+		if ($debug) {
141
+			echo 'ident : '.$ident."\n";
142
+		}
135 143
 		$result['ident'] = $ident;
136 144
 	    }
137
-	} else return false;
145
+	} else {
146
+		return false;
147
+	}
138 148
 	$elements = explode(',',$all_elements);
139 149
 	$source = end($elements);
140 150
 	$result['source'] = $source;
@@ -143,7 +153,9 @@  discard block
 block discarded – undo
143 153
 	        //echo "ok";
144 154
 	        //if ($element == 'TCPIP*') return false;
145 155
 	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
146
-		if ($debug) echo 'element : '.$element."\n";
156
+		if ($debug) {
157
+			echo 'element : '.$element."\n";
158
+		}
147 159
 		return false;
148 160
 	    }
149 161
 	    /*
@@ -156,11 +168,15 @@  discard block
 block discarded – undo
156 168
 	}
157 169
 	
158 170
 	$type = substr($body,0,1);
159
-	if ($debug) echo 'type : '.$type."\n";
171
+	if ($debug) {
172
+		echo 'type : '.$type."\n";
173
+	}
160 174
 	if ($type == ';') {
161 175
 		if (isset($result['source_type']) && $result['source_type'] == 'modes') {
162 176
 			$result['address'] = trim(substr($body,1,9));
163
-		} else $result['ident'] = trim(substr($body,1,9));
177
+		} else {
178
+			$result['ident'] = trim(substr($body,1,9));
179
+		}
164 180
 	} elseif ($type == ',') {
165 181
 		// Invalid data or test data
166 182
 		return false;
@@ -228,7 +244,9 @@  discard block
 block discarded – undo
228 244
 		//$symbol_table = $matches[4];
229 245
 		$lat = intval($lat_deg);
230 246
 		$lon = intval($lon_deg);
231
-		if ($lat > 89 || $lon > 179) return false;
247
+		if ($lat > 89 || $lon > 179) {
248
+			return false;
249
+		}
232 250
 	    
233 251
 	    /*
234 252
 	    $tmp_5b = str_replace('.','',$lat_min);
@@ -238,8 +256,12 @@  discard block
 block discarded – undo
238 256
 	    */
239 257
 		$latitude = $lat + floatval($lat_min)/60;
240 258
 		$longitude = $lon + floatval($lon_min)/60;
241
-		if ($sind == 'S') $latitude = 0-$latitude;
242
-		if ($wind == 'W') $longitude = 0-$longitude;
259
+		if ($sind == 'S') {
260
+			$latitude = 0-$latitude;
261
+		}
262
+		if ($wind == 'W') {
263
+			$longitude = 0-$longitude;
264
+		}
243 265
 		$result['latitude'] = $latitude;
244 266
 		$result['longitude'] = $longitude;
245 267
 		$body_parse = substr($body_parse,18);
@@ -273,7 +295,9 @@  discard block
 block discarded – undo
273 295
 			$body_parse = substr($body_parse,1);
274 296
 			$body_parse_len = strlen($body_parse);
275 297
 			$result['symbol_code'] = $symbol_code;
276
-			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
298
+			if (isset($this->symbols[$symbol_code])) {
299
+				$result['symbol'] = $this->symbols[$symbol_code];
300
+			}
277 301
 			if ($symbol_code != '_') {
278 302
 			}
279 303
 		    //$body_parse = substr($body_parse,1);
@@ -284,7 +308,9 @@  discard block
 block discarded – undo
284 308
 		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285 309
 		    	    $course = substr($body_parse,0,3);
286 310
 		    	    $tmp_s = intval($course);
287
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
311
+		    	    if ($tmp_s >= 1 && $tmp_s <= 360) {
312
+		    	    	$result['heading'] = intval($course);
313
+		    	    }
288 314
 		    	    $speed = substr($body_parse,4,3);
289 315
 		    	    if ($speed != '...') {
290 316
 		    		//$result['speed'] = round($speed*1.852);
@@ -323,10 +349,16 @@  discard block
 block discarded – undo
323 349
 			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
324 350
 			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
325 351
 			    
326
-				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
327
-				else $result['latitude'] += $lat_off;
328
-				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
329
-				else $result['longitude'] += $lon_off;
352
+				if ($result['latitude'] < 0) {
353
+					$result['latitude'] -= $lat_off;
354
+				} else {
355
+					$result['latitude'] += $lat_off;
356
+				}
357
+				if ($result['longitude'] < 0) {
358
+					$result['longitude'] -= $lon_off;
359
+				} else {
360
+					$result['longitude'] += $lon_off;
361
+				}
330 362
 			    }
331 363
 		            $body_parse = substr($body_parse,6);
332 364
 		    }
@@ -361,27 +393,48 @@  discard block
 block discarded – undo
361 393
 			$address = substr($id,2);
362 394
 			//print_r($matches);
363 395
 			$addressType = (intval(substr($id,0,2),16))&3;
364
-			if ($addressType == 0) $result['addresstype'] = "RANDOM";
365
-			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
366
-			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
367
-			elseif ($addressType == 3) $result['addresstype'] = "OGN";
396
+			if ($addressType == 0) {
397
+				$result['addresstype'] = "RANDOM";
398
+			} elseif ($addressType == 1) {
399
+				$result['addresstype'] = "ICAO";
400
+			} elseif ($addressType == 2) {
401
+				$result['addresstype'] = "FLARM";
402
+			} elseif ($addressType == 3) {
403
+				$result['addresstype'] = "OGN";
404
+			}
368 405
 			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
369 406
 			$result['aircrafttype_code'] = $aircraftType;
370
-			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
371
-			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
372
-			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
373
-			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
374
-			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
375
-			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
376
-			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
377
-			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
378
-			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
379
-			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
380
-			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
381
-			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
382
-			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
383
-			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
384
-			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
407
+			if ($aircraftType == 0) {
408
+				$result['aircrafttype'] = "UNKNOWN";
409
+			} elseif ($aircraftType == 1) {
410
+				$result['aircrafttype'] = "GLIDER";
411
+			} elseif ($aircraftType == 2) {
412
+				$result['aircrafttype'] = "TOW_PLANE";
413
+			} elseif ($aircraftType == 3) {
414
+				$result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
415
+			} elseif ($aircraftType == 4) {
416
+				$result['aircrafttype'] = "PARACHUTE";
417
+			} elseif ($aircraftType == 5) {
418
+				$result['aircrafttype'] = "DROP_PLANE";
419
+			} elseif ($aircraftType == 6) {
420
+				$result['aircrafttype'] = "HANG_GLIDER";
421
+			} elseif ($aircraftType == 7) {
422
+				$result['aircrafttype'] = "PARA_GLIDER";
423
+			} elseif ($aircraftType == 8) {
424
+				$result['aircrafttype'] = "POWERED_AIRCRAFT";
425
+			} elseif ($aircraftType == 9) {
426
+				$result['aircrafttype'] = "JET_AIRCRAFT";
427
+			} elseif ($aircraftType == 10) {
428
+				$result['aircrafttype'] = "UFO";
429
+			} elseif ($aircraftType == 11) {
430
+				$result['aircrafttype'] = "BALLOON";
431
+			} elseif ($aircraftType == 12) {
432
+				$result['aircrafttype'] = "AIRSHIP";
433
+			} elseif ($aircraftType == 13) {
434
+				$result['aircrafttype'] = "UAV";
435
+			} elseif ($aircraftType == 15) {
436
+				$result['aircrafttype'] = "STATIC_OBJECT";
437
+			}
385 438
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
386 439
 			$result['stealth'] = $stealth;
387 440
 			$result['address'] = $address;
@@ -421,13 +474,21 @@  discard block
 block discarded – undo
421 474
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
422 475
 		    }
423 476
 		}
424
-		} else $result['comment'] = trim($body_parse);
477
+		} else {
478
+			$result['comment'] = trim($body_parse);
479
+		}
425 480
 
426 481
 	    }
427 482
 	//}
428
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
429
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
430
-	if ($debug) print_r($result);
483
+	if (isset($result['latitude'])) {
484
+		$result['latitude'] = round($result['latitude'],4);
485
+	}
486
+	if (isset($result['longitude'])) {
487
+		$result['longitude'] = round($result['longitude'],4);
488
+	}
489
+	if ($debug) {
490
+		print_r($result);
491
+	}
431 492
 	return $result;
432 493
     }
433 494
     
@@ -436,12 +497,21 @@  discard block
 block discarded – undo
436 497
 	$aprs_connect = 0;
437 498
 	$aprs_keep = 120;
438 499
 	$aprs_last_tx = time();
439
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
440
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
441
-	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
442
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
443
-	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
444
-	else $aprs_pass = '-1';
500
+	if (isset($globalAPRSversion)) {
501
+		$aprs_version = $globalAPRSversion;
502
+	} else {
503
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
504
+	}
505
+	if (isset($globalServerAPRSssid)) {
506
+		$aprs_ssid = $globalServerAPRSssid;
507
+	} else {
508
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
509
+	}
510
+	if (isset($globalServerAPRSpass)) {
511
+		$aprs_pass = $globalServerAPRSpass;
512
+	} else {
513
+		$aprs_pass = '-1';
514
+	}
445 515
 	
446 516
 	$aprs_filter  = '';
447 517
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
@@ -468,9 +538,13 @@  discard block
 block discarded – undo
468 538
     }
469 539
     
470 540
     function send($data) {
471
-	if ($this->connected === false) $this->connect();
541
+	if ($this->connected === false) {
542
+		$this->connect();
543
+	}
472 544
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
473
-	if ($send === FALSE) $this->connect();
545
+	if ($send === FALSE) {
546
+		$this->connect();
547
+	}
474 548
     }
475 549
 }
476 550
 
@@ -487,18 +561,26 @@  discard block
 block discarded – undo
487 561
 			//$w = '00';
488 562
 			$custom = '';
489 563
 			if ($ident != '') {
490
-				if ($custom != '') $custom .= '/';
564
+				if ($custom != '') {
565
+					$custom .= '/';
566
+				}
491 567
 				$custom .= 'CS='.$ident;
492 568
 			}
493 569
 			if ($squawk != '') {
494
-				if ($custom != '') $custom .= '/';
570
+				if ($custom != '') {
571
+					$custom .= '/';
572
+				}
495 573
 				$custom .= 'SQ='.$squawk;
496 574
 			}
497 575
 			if ($aircraft_icao != '' && $aircraft_icao != 'NA') {
498
-				if ($custom != '') $custom .= '/';
576
+				if ($custom != '') {
577
+					$custom .= '/';
578
+				}
499 579
 				$custom .= 'AI='.$aircraft_icao;
500 580
 			}
501
-			if ($custom != '') $custom = ' '.$custom;
581
+			if ($custom != '') {
582
+				$custom = ' '.$custom;
583
+			}
502 584
 			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His',strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
503 585
 		}
504 586
 	}
@@ -516,26 +598,38 @@  discard block
 block discarded – undo
516 598
 			//$w = '00';
517 599
 			$custom = '';
518 600
 			if ($ident != '') {
519
-				if ($custom != '') $custom .= '/';
601
+				if ($custom != '') {
602
+					$custom .= '/';
603
+				}
520 604
 				$custom .= 'CS='.$ident;
521 605
 			}
522 606
 			if ($typeid != '') {
523
-				if ($custom != '') $custom .= '/';
607
+				if ($custom != '') {
608
+					$custom .= '/';
609
+				}
524 610
 				$custom .= 'TI='.$typeid;
525 611
 			}
526 612
 			if ($imo != '') {
527
-				if ($custom != '') $custom .= '/';
613
+				if ($custom != '') {
614
+					$custom .= '/';
615
+				}
528 616
 				$custom .= 'IMO='.$imo;
529 617
 			}
530 618
 			if ($arrival_date != '') {
531
-				if ($custom != '') $custom .= '/';
619
+				if ($custom != '') {
620
+					$custom .= '/';
621
+				}
532 622
 				$custom .= 'AD='.strtotime($arrival_date);
533 623
 			}
534 624
 			if ($arrival_code != '') {
535
-				if ($custom != '') $custom .= '/';
625
+				if ($custom != '') {
626
+					$custom .= '/';
627
+				}
536 628
 				$custom .= 'AC='.$arrival_code;
537 629
 			}
538
-			if ($custom != '') $custom = ' '.$custom;
630
+			if ($custom != '') {
631
+				$custom = ' '.$custom;
632
+			}
539 633
 			$altitude = 0;
540 634
 			$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");
541 635
 		}
Please login to merge, or discard this patch.
scripts/daemon-spotter.php 3 patches
Indentation   +859 added lines, -859 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16 16
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17 17
 if (isset($globalMarine) && $globalMarine) {
18
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
18
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 20
 }
21 21
 
22 22
 if (!isset($globalDebug)) $globalDebug = FALSE;
@@ -24,40 +24,40 @@  discard block
 block discarded – undo
24 24
 // Check if schema is at latest version
25 25
 $Connection = new Connection();
26 26
 if ($Connection->latest() === false) {
27
-    echo "You MUST update to latest schema. Run install/index.php";
28
-    exit();
27
+	echo "You MUST update to latest schema. Run install/index.php";
28
+	exit();
29 29
 }
30 30
 if (PHP_SAPI != 'cli') {
31
-    echo "This script MUST be called from console, not a web browser.";
31
+	echo "This script MUST be called from console, not a web browser.";
32 32
 //    exit();
33 33
 }
34 34
 
35 35
 // This is to be compatible with old version of settings.php
36 36
 if (!isset($globalSources)) {
37
-    if (isset($globalSBS1Hosts)) {
38
-        //$hosts = $globalSBS1Hosts;
39
-        foreach ($globalSBS1Hosts as $host) {
40
-	    $globalSources[] = array('host' => $host);
41
-    	}
42
-    } else {
43
-        if (!isset($globalSBS1Host)) {
44
-	    echo '$globalSources MUST be defined !';
45
-	    die;
37
+	if (isset($globalSBS1Hosts)) {
38
+		//$hosts = $globalSBS1Hosts;
39
+		foreach ($globalSBS1Hosts as $host) {
40
+		$globalSources[] = array('host' => $host);
41
+		}
42
+	} else {
43
+		if (!isset($globalSBS1Host)) {
44
+		echo '$globalSources MUST be defined !';
45
+		die;
46 46
 	}
47 47
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
48 48
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
49
-    }
49
+	}
50 50
 }
51 51
 
52 52
 $options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::'));
53 53
 //if (isset($options['s'])) $hosts = array($options['s']);
54 54
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 55
 if (isset($options['s'])) {
56
-    $globalSources = array();
57
-    $globalSources[] = array('host' => $options['s']);
56
+	$globalSources = array();
57
+	$globalSources[] = array('host' => $options['s']);
58 58
 } elseif (isset($options['source'])) {
59
-    $globalSources = array();
60
-    $globalSources[] = array('host' => $options['source']);
59
+	$globalSources = array();
60
+	$globalSources[] = array('host' => $options['source']);
61 61
 }
62 62
 if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
63 63
 if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 if (isset($options['idsource'])) $id_source = $options['idsource'];
67 67
 else $id_source = 1;
68 68
 if (isset($globalServer) && $globalServer) {
69
-    if ($globalDebug) echo "Using Server Mode\n";
70
-    $SI=new SpotterServer();
69
+	if ($globalDebug) echo "Using Server Mode\n";
70
+	$SI=new SpotterServer();
71 71
 /*
72 72
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
73 73
     $SI = new adsb2aprs();
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
 } else $SI=new SpotterImport($Connection->db);
77 77
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
78 78
 if (isset($globalMarine) && $globalMarine) {
79
-    $AIS = new AIS();
80
-    $MI = new MarineImport($Connection->db);
79
+	$AIS = new AIS();
80
+	$MI = new MarineImport($Connection->db);
81 81
 }
82 82
 //$APRS=new APRS($Connection->db);
83 83
 $SBS=new SBS();
@@ -87,12 +87,12 @@  discard block
 block discarded – undo
87 87
 //$servertz = system('date +%Z');
88 88
 // signal handler - playing nice with sockets and dump1090
89 89
 if (function_exists('pcntl_fork')) {
90
-    pcntl_signal(SIGINT,  function() {
91
-        global $sockets;
92
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
93
-        die("Bye!\n");
94
-    });
95
-    pcntl_signal_dispatch();
90
+	pcntl_signal(SIGINT,  function() {
91
+		global $sockets;
92
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
93
+		die("Bye!\n");
94
+	});
95
+	pcntl_signal_dispatch();
96 96
 }
97 97
 
98 98
 // let's try and connect
@@ -102,153 +102,153 @@  discard block
 block discarded – undo
102 102
 $reset = 0;
103 103
 
104 104
 function connect_all($hosts) {
105
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
106
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
107
-    $reset++;
108
-    if ($globalDebug) echo 'Connect to all...'."\n";
109
-    foreach ($hosts as $id => $value) {
105
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
106
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
107
+	$reset++;
108
+	if ($globalDebug) echo 'Connect to all...'."\n";
109
+	foreach ($hosts as $id => $value) {
110 110
 	$host = $value['host'];
111 111
 	$globalSources[$id]['last_exec'] = 0;
112 112
 	// Here we check type of source(s)
113 113
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
114
-            if (preg_match('/deltadb.txt$/i',$host)) {
115
-        	//$formats[$id] = 'deltadbtxt';
116
-        	$globalSources[$id]['format'] = 'deltadbtxt';
117
-        	//$last_exec['deltadbtxt'] = 0;
118
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
119
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
120
-        	//$formats[$id] = 'vatsimtxt';
121
-        	$globalSources[$id]['format'] = 'vatsimtxt';
122
-        	//$last_exec['vatsimtxt'] = 0;
123
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
124
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
125
-        	//$formats[$id] = 'aircraftlistjson';
126
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
127
-        	//$last_exec['aircraftlistjson'] = 0;
128
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
129
-    	    } else if (preg_match('/opensky/i',$host)) {
130
-        	//$formats[$id] = 'aircraftlistjson';
131
-        	$globalSources[$id]['format'] = 'opensky';
132
-        	//$last_exec['aircraftlistjson'] = 0;
133
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
134
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
135
-        	//$formats[$id] = 'radarvirtueljson';
136
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
137
-        	//$last_exec['radarvirtueljson'] = 0;
138
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
139
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
140
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
141
-        	    exit(0);
142
-        	}
143
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
144
-        	//$formats[$id] = 'planeupdatefaa';
145
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
146
-        	//$last_exec['planeupdatefaa'] = 0;
147
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
148
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
149
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
150
-        	    exit(0);
151
-        	}
152
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
153
-        	//$formats[$id] = 'phpvmacars';
154
-        	$globalSources[$id]['format'] = 'phpvmacars';
155
-        	//$last_exec['phpvmacars'] = 0;
156
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
157
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
158
-        	//$formats[$id] = 'phpvmacars';
159
-        	$globalSources[$id]['format'] = 'vam';
160
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
161
-            } else if (preg_match('/whazzup/i',$host)) {
162
-        	//$formats[$id] = 'whazzup';
163
-        	$globalSources[$id]['format'] = 'whazzup';
164
-        	//$last_exec['whazzup'] = 0;
165
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
166
-            } else if (preg_match('/recentpireps/i',$host)) {
167
-        	//$formats[$id] = 'pirepsjson';
168
-        	$globalSources[$id]['format'] = 'pirepsjson';
169
-        	//$last_exec['pirepsjson'] = 0;
170
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
171
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
172
-        	//$formats[$id] = 'fr24json';
173
-        	$globalSources[$id]['format'] = 'fr24json';
174
-        	//$last_exec['fr24json'] = 0;
175
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
176
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
177
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
178
-        	    exit(0);
179
-        	}
180
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
181
-        	//$formats[$id] = 'fr24json';
182
-        	$globalSources[$id]['format'] = 'myshiptracking';
183
-        	//$last_exec['fr24json'] = 0;
184
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
185
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
186
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
187
-        	    exit(0);
188
-        	}
189
-            //} else if (preg_match('/10001/',$host)) {
190
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
191
-        	//$formats[$id] = 'tsv';
192
-        	$globalSources[$id]['format'] = 'tsv';
193
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
194
-            }
195
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
196
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
197
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
198
-    		    if ($idf !== false) {
199
-    			$httpfeeds[$id] = $idf;
200
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
201
-    		    }
202
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
203
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
204
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
205
-	    $hostport = explode(':',$host);
206
-	    if (isset($hostport[1])) {
114
+			if (preg_match('/deltadb.txt$/i',$host)) {
115
+			//$formats[$id] = 'deltadbtxt';
116
+			$globalSources[$id]['format'] = 'deltadbtxt';
117
+			//$last_exec['deltadbtxt'] = 0;
118
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
119
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
120
+			//$formats[$id] = 'vatsimtxt';
121
+			$globalSources[$id]['format'] = 'vatsimtxt';
122
+			//$last_exec['vatsimtxt'] = 0;
123
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
124
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
125
+			//$formats[$id] = 'aircraftlistjson';
126
+			$globalSources[$id]['format'] = 'aircraftlistjson';
127
+			//$last_exec['aircraftlistjson'] = 0;
128
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
129
+			} else if (preg_match('/opensky/i',$host)) {
130
+			//$formats[$id] = 'aircraftlistjson';
131
+			$globalSources[$id]['format'] = 'opensky';
132
+			//$last_exec['aircraftlistjson'] = 0;
133
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
134
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
135
+			//$formats[$id] = 'radarvirtueljson';
136
+			$globalSources[$id]['format'] = 'radarvirtueljson';
137
+			//$last_exec['radarvirtueljson'] = 0;
138
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
139
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
140
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
141
+				exit(0);
142
+			}
143
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
144
+			//$formats[$id] = 'planeupdatefaa';
145
+			$globalSources[$id]['format'] = 'planeupdatefaa';
146
+			//$last_exec['planeupdatefaa'] = 0;
147
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
148
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
149
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
150
+				exit(0);
151
+			}
152
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
153
+			//$formats[$id] = 'phpvmacars';
154
+			$globalSources[$id]['format'] = 'phpvmacars';
155
+			//$last_exec['phpvmacars'] = 0;
156
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
157
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
158
+			//$formats[$id] = 'phpvmacars';
159
+			$globalSources[$id]['format'] = 'vam';
160
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
161
+			} else if (preg_match('/whazzup/i',$host)) {
162
+			//$formats[$id] = 'whazzup';
163
+			$globalSources[$id]['format'] = 'whazzup';
164
+			//$last_exec['whazzup'] = 0;
165
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
166
+			} else if (preg_match('/recentpireps/i',$host)) {
167
+			//$formats[$id] = 'pirepsjson';
168
+			$globalSources[$id]['format'] = 'pirepsjson';
169
+			//$last_exec['pirepsjson'] = 0;
170
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
171
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
172
+			//$formats[$id] = 'fr24json';
173
+			$globalSources[$id]['format'] = 'fr24json';
174
+			//$last_exec['fr24json'] = 0;
175
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
176
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
177
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
178
+				exit(0);
179
+			}
180
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
181
+			//$formats[$id] = 'fr24json';
182
+			$globalSources[$id]['format'] = 'myshiptracking';
183
+			//$last_exec['fr24json'] = 0;
184
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
185
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
186
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
187
+				exit(0);
188
+			}
189
+			//} else if (preg_match('/10001/',$host)) {
190
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
191
+			//$formats[$id] = 'tsv';
192
+			$globalSources[$id]['format'] = 'tsv';
193
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
194
+			}
195
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
196
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
197
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
198
+				if ($idf !== false) {
199
+				$httpfeeds[$id] = $idf;
200
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
201
+				}
202
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
203
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
204
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
205
+		$hostport = explode(':',$host);
206
+		if (isset($hostport[1])) {
207 207
 		$port = $hostport[1];
208 208
 		$hostn = $hostport[0];
209
-	    } else {
209
+		} else {
210 210
 		$port = $globalSources[$id]['port'];
211 211
 		$hostn = $globalSources[$id]['host'];
212
-	    }
213
-	    $Common = new Common();
214
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
215
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
216
-    	    } else {
217
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
218
-	    }
219
-	    if ($s) {
220
-    	        $sockets[$id] = $s;
221
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
222
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
212
+		}
213
+		$Common = new Common();
214
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
215
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
216
+			} else {
217
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
218
+		}
219
+		if ($s) {
220
+				$sockets[$id] = $s;
221
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
222
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
223 223
 			//$formats[$id] = 'aprs';
224 224
 			$globalSources[$id]['format'] = 'aprs';
225 225
 			//$aprs_connect = 0;
226 226
 			//$use_aprs = true;
227
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
227
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
228 228
 			$globalSources[$id]['format'] = 'vrstcp';
229
-    		    } elseif ($port == '10001') {
230
-        		//$formats[$id] = 'tsv';
231
-        		$globalSources[$id]['format'] = 'tsv';
232
-		    } elseif ($port == '30002') {
233
-        		//$formats[$id] = 'raw';
234
-        		$globalSources[$id]['format'] = 'raw';
235
-		    } elseif ($port == '5001') {
236
-        		//$formats[$id] = 'raw';
237
-        		$globalSources[$id]['format'] = 'flightgearmp';
238
-		    } elseif ($port == '30005') {
229
+				} elseif ($port == '10001') {
230
+				//$formats[$id] = 'tsv';
231
+				$globalSources[$id]['format'] = 'tsv';
232
+			} elseif ($port == '30002') {
233
+				//$formats[$id] = 'raw';
234
+				$globalSources[$id]['format'] = 'raw';
235
+			} elseif ($port == '5001') {
236
+				//$formats[$id] = 'raw';
237
+				$globalSources[$id]['format'] = 'flightgearmp';
238
+			} elseif ($port == '30005') {
239 239
 			// Not yet supported
240
-        		//$formats[$id] = 'beast';
241
-        		$globalSources[$id]['format'] = 'beast';
242
-		    //} else $formats[$id] = 'sbs';
243
-		    } else $globalSources[$id]['format'] = 'sbs';
244
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
240
+				//$formats[$id] = 'beast';
241
+				$globalSources[$id]['format'] = 'beast';
242
+			//} else $formats[$id] = 'sbs';
243
+			} else $globalSources[$id]['format'] = 'sbs';
244
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
245 245
 		}
246 246
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
247
-            } else {
247
+			} else {
248 248
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
249
-    	    }
250
-        }
251
-    }
249
+			}
250
+		}
251
+	}
252 252
 }
253 253
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
254 254
 
@@ -271,9 +271,9 @@  discard block
 block discarded – undo
271 271
 //connect_all($globalSources);
272 272
 
273 273
 if (isset($globalProxy) && $globalProxy) {
274
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
274
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
275 275
 } else {
276
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
276
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
277 277
 }
278 278
 
279 279
 // APRS Configuration
@@ -282,18 +282,18 @@  discard block
 block discarded – undo
282 282
 	die;
283 283
 }
284 284
 foreach ($globalSources as $key => $source) {
285
-    if (!isset($source['format'])) {
286
-        $globalSources[$key]['format'] = 'auto';
287
-    }
285
+	if (!isset($source['format'])) {
286
+		$globalSources[$key]['format'] = 'auto';
287
+	}
288 288
 }
289 289
 connect_all($globalSources);
290 290
 foreach ($globalSources as $key => $source) {
291
-    if (isset($source['format']) && $source['format'] == 'aprs') {
291
+	if (isset($source['format']) && $source['format'] == 'aprs') {
292 292
 	$aprs_connect = 0;
293 293
 	$use_aprs = true;
294 294
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
295 295
 	break;
296
-    }
296
+	}
297 297
 }
298 298
 
299 299
 if ($use_aprs) {
@@ -335,152 +335,152 @@  discard block
 block discarded – undo
335 335
 
336 336
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
337 337
 while ($i > 0) {
338
-    if (!$globalDaemon) $i = $endtime-time();
339
-    // Delete old ATC
340
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
338
+	if (!$globalDaemon) $i = $endtime-time();
339
+	// Delete old ATC
340
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
341 341
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
342
-        $ATC->deleteOldATC();
343
-    }
342
+		$ATC->deleteOldATC();
343
+	}
344 344
     
345
-    //if (count($last_exec) > 0) {
346
-    if (count($last_exec) == count($globalSources)) {
345
+	//if (count($last_exec) > 0) {
346
+	if (count($last_exec) == count($globalSources)) {
347 347
 	$max = $globalMinFetch;
348 348
 	foreach ($last_exec as $last) {
349
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
349
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
350 350
 	}
351 351
 	if ($max != $globalMinFetch) {
352
-	    if ($globalDebug) echo 'Sleeping...'."\n";
353
-	    sleep($globalMinFetch-$max+2);
352
+		if ($globalDebug) echo 'Sleeping...'."\n";
353
+		sleep($globalMinFetch-$max+2);
354
+	}
354 355
 	}
355
-    }
356 356
 
357 357
     
358
-    //foreach ($formats as $id => $value) {
359
-    foreach ($globalSources as $id => $value) {
358
+	//foreach ($formats as $id => $value) {
359
+	foreach ($globalSources as $id => $value) {
360 360
 	date_default_timezone_set('UTC');
361 361
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
362 362
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
363
-	    //$buffer = $Common->getData($hosts[$id]);
364
-	    $buffer = $Common->getData($value['host']);
365
-	    if ($buffer != '') $reset = 0;
366
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
367
-	    $buffer = explode('\n',$buffer);
368
-	    foreach ($buffer as $line) {
369
-    		if ($line != '' && count($line) > 7) {
370
-    		    $line = explode(',', $line);
371
-	            $data = array();
372
-	            $data['hex'] = $line[1]; // hex
373
-	            $data['ident'] = $line[2]; // ident
374
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
375
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
376
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
377
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
378
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
379
-	            $data['verticalrate'] = ''; // vertical rate
380
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
381
-	            $data['emergency'] = ''; // emergency
382
-		    $data['datetime'] = date('Y-m-d H:i:s');
383
-		    $data['format_source'] = 'deltadbtxt';
384
-    		    $data['id_source'] = $id_source;
385
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
386
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
387
-    		    $SI->add($data);
388
-		    unset($data);
389
-    		}
390
-    	    }
391
-    	    $last_exec[$id]['last'] = time();
363
+		//$buffer = $Common->getData($hosts[$id]);
364
+		$buffer = $Common->getData($value['host']);
365
+		if ($buffer != '') $reset = 0;
366
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
367
+		$buffer = explode('\n',$buffer);
368
+		foreach ($buffer as $line) {
369
+			if ($line != '' && count($line) > 7) {
370
+				$line = explode(',', $line);
371
+				$data = array();
372
+				$data['hex'] = $line[1]; // hex
373
+				$data['ident'] = $line[2]; // ident
374
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
375
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
376
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
377
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
378
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
379
+				$data['verticalrate'] = ''; // vertical rate
380
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
381
+				$data['emergency'] = ''; // emergency
382
+			$data['datetime'] = date('Y-m-d H:i:s');
383
+			$data['format_source'] = 'deltadbtxt';
384
+				$data['id_source'] = $id_source;
385
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
386
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
387
+				$SI->add($data);
388
+			unset($data);
389
+			}
390
+			}
391
+			$last_exec[$id]['last'] = time();
392 392
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
393
-	    date_default_timezone_set('CET');
394
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
395
-	    date_default_timezone_set('UTC');
396
-	    if ($buffer != '') $reset = 0;
397
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
398
-	    $buffer = explode('\n',$buffer);
399
-	    foreach ($buffer as $line) {
393
+		date_default_timezone_set('CET');
394
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
395
+		date_default_timezone_set('UTC');
396
+		if ($buffer != '') $reset = 0;
397
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
398
+		$buffer = explode('\n',$buffer);
399
+		foreach ($buffer as $line) {
400 400
 		if ($line != '') {
401
-		    echo "'".$line."'\n";
402
-		    $add = false;
403
-		    $ais_data = $AIS->parse_line(trim($line));
404
-		    $data = array();
405
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
406
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
407
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
408
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
409
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
410
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
411
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
412
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
413
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
414
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
415
-		    if (isset($ais_data['timestamp'])) {
401
+			echo "'".$line."'\n";
402
+			$add = false;
403
+			$ais_data = $AIS->parse_line(trim($line));
404
+			$data = array();
405
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
406
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
407
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
408
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
409
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
410
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
411
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
412
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
413
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
414
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
415
+			if (isset($ais_data['timestamp'])) {
416 416
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
417 417
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
418
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
419
-			    $add = true;
418
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
419
+				$add = true;
420 420
 			}
421
-		    } else {
421
+			} else {
422 422
 			$data['datetime'] = date('Y-m-d H:i:s');
423 423
 			$add = true;
424
-		    }
425
-		    $data['format_source'] = 'aisnmeatxt';
426
-    		    $data['id_source'] = $id_source;
427
-		    print_r($data);
428
-		    echo 'Add...'."\n";
429
-		    if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
430
-		    unset($data);
424
+			}
425
+			$data['format_source'] = 'aisnmeatxt';
426
+				$data['id_source'] = $id_source;
427
+			print_r($data);
428
+			echo 'Add...'."\n";
429
+			if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
430
+			unset($data);
431 431
 		}
432
-    	    }
433
-    	    $last_exec[$id]['last'] = time();
432
+			}
433
+			$last_exec[$id]['last'] = time();
434 434
 	} elseif ($value['format'] == 'aisnmeahttp') {
435
-	    $arr = $httpfeeds;
436
-	    $w = $e = null;
435
+		$arr = $httpfeeds;
436
+		$w = $e = null;
437 437
 	    
438
-	    if (isset($arr[$id])) {
439
-	    $nn = stream_select($arr,$w,$e,$timeout);
440
-	    if ($nn > 0) {
438
+		if (isset($arr[$id])) {
439
+		$nn = stream_select($arr,$w,$e,$timeout);
440
+		if ($nn > 0) {
441 441
 		foreach ($httpfeeds as $feed) {
442
-		    $buffer = stream_get_line($feed,2000,"\n");
443
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
444
-		    $buffer = explode('\n',$buffer);
445
-		    foreach ($buffer as $line) {
442
+			$buffer = stream_get_line($feed,2000,"\n");
443
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
444
+			$buffer = explode('\n',$buffer);
445
+			foreach ($buffer as $line) {
446 446
 			if ($line != '') {
447
-			    $ais_data = $AIS->parse_line(trim($line));
448
-			    $data = array();
449
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
450
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
451
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
452
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
453
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
454
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
455
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
456
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
457
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
458
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
459
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
460
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
461
-			    if (isset($ais_data['timestamp'])) {
447
+				$ais_data = $AIS->parse_line(trim($line));
448
+				$data = array();
449
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
450
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
451
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
452
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
453
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
454
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
455
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
456
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
457
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
458
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
459
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
460
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
461
+				if (isset($ais_data['timestamp'])) {
462 462
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
463
-			    } else {
463
+				} else {
464 464
 				$data['datetime'] = date('Y-m-d H:i:s');
465
-			    }
466
-			    $data['format_source'] = 'aisnmeahttp';
467
-			    $data['id_source'] = $id_source;
468
-			    if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
469
-			    unset($data);
465
+				}
466
+				$data['format_source'] = 'aisnmeahttp';
467
+				$data['id_source'] = $id_source;
468
+				if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
469
+				unset($data);
470 470
 			}
471
-		    }
471
+			}
472
+		}
472 473
 		}
473 474
 		}
474
-	    }
475 475
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
476
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
477
-	    if ($buffer != '') {
476
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
477
+		if ($buffer != '') {
478 478
 		//echo $buffer;
479 479
 		$all_data = json_decode($buffer,true);
480 480
 		//print_r($all_data);
481 481
 		if (isset($all_data[0]['DATA'])) {
482 482
 		foreach ($all_data[0]['DATA'] as $line) {
483
-		    if ($line != '') {
483
+			if ($line != '') {
484 484
 			$data = array();
485 485
 			$data['ident'] = $line['NAME'];
486 486
 			$data['mmsi'] = $line['MMSI'];
@@ -496,87 +496,87 @@  discard block
 block discarded – undo
496 496
 			$data['id_source'] = $id_source;
497 497
 			$MI->add($data);
498 498
 			unset($data);
499
-		    }
499
+			}
500 500
 		}
501 501
 		}
502 502
 		
503
-	    }
504
-    	    $last_exec[$id]['last'] = time();
503
+		}
504
+			$last_exec[$id]['last'] = time();
505 505
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
506
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
507
-	    if ($buffer != '') {
506
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
507
+		if ($buffer != '') {
508 508
 		$all_data = json_decode($buffer,true);
509 509
 		if (isset($all_data[0]['mmsi'])) {
510
-		    foreach ($all_data as $line) {
510
+			foreach ($all_data as $line) {
511 511
 			if ($line != '') {
512
-			    $data = array();
513
-			    $data['ident'] = $line['shipname'];
514
-			    $data['callsign'] = $line['callsign'];
515
-			    $data['mmsi'] = $line['mmsi'];
516
-			    $data['speed'] = $line['sog'];
517
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
518
-			    $data['latitude'] = $line['latitude'];
519
-			    $data['longitude'] = $line['longitude'];
520
-			    $data['type_id'] = $line['shiptype'];
521
-			    $data['arrival_code'] = $line['destination'];
522
-			    $data['datetime'] = $line['time'];
523
-			    $data['format_source'] = 'boatbeaconapp';
524
-			    $data['id_source'] = $id_source;
525
-			    $MI->add($data);
526
-			    unset($data);
512
+				$data = array();
513
+				$data['ident'] = $line['shipname'];
514
+				$data['callsign'] = $line['callsign'];
515
+				$data['mmsi'] = $line['mmsi'];
516
+				$data['speed'] = $line['sog'];
517
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
518
+				$data['latitude'] = $line['latitude'];
519
+				$data['longitude'] = $line['longitude'];
520
+				$data['type_id'] = $line['shiptype'];
521
+				$data['arrival_code'] = $line['destination'];
522
+				$data['datetime'] = $line['time'];
523
+				$data['format_source'] = 'boatbeaconapp';
524
+				$data['id_source'] = $id_source;
525
+				$MI->add($data);
526
+				unset($data);
527
+			}
527 528
 			}
528
-		    }
529 529
 		}
530 530
 		
531
-	    }
532
-    	    $last_exec[$id]['last'] = time();
531
+		}
532
+			$last_exec[$id]['last'] = time();
533 533
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
534
-	    echo 'download...';
535
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
536
-	    echo 'done !'."\n";
537
-	    if ($buffer != '') $reset = 0;
538
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539
-	    $buffer = explode('\n',$buffer);
540
-	    foreach ($buffer as $line) {
534
+		echo 'download...';
535
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
536
+		echo 'done !'."\n";
537
+		if ($buffer != '') $reset = 0;
538
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539
+		$buffer = explode('\n',$buffer);
540
+		foreach ($buffer as $line) {
541 541
 		if ($line != '') {
542
-		    $data = array();
543
-		    $data['mmsi'] = (int)substr($line,0,9);
544
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
545
-		    //$data['status'] = substr($line,21,2);
546
-		    //$data['type'] = substr($line,24,3);
547
-		    $data['latitude'] = substr($line,29,9);
548
-		    $data['longitude'] = substr($line,41,9);
549
-		    $data['speed'] = round(substr($line,51,5));
550
-		    //$data['course'] = substr($line,57,5);
551
-		    $data['heading'] = round(substr($line,63,3));
552
-		    //$data['draft'] = substr($line,67,4);
553
-		    //$data['length'] = substr($line,72,3);
554
-		    //$data['beam'] = substr($line,76,2);
555
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
556
-		    //$data['callsign'] = trim(substr($line,100,7);
557
-		    //$data['dest'] = substr($line,108,20);
558
-		    //$data['etaDate'] = substr($line,129,5);
559
-		    //$data['etaTime'] = substr($line,135,5);
560
-		    $data['format_source'] = 'shipplotter';
561
-    		    $data['id_source'] = $id_source;
562
-		    print_r($data);
563
-		    echo 'Add...'."\n";
564
-		    $MI->add($data);
565
-		    unset($data);
542
+			$data = array();
543
+			$data['mmsi'] = (int)substr($line,0,9);
544
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
545
+			//$data['status'] = substr($line,21,2);
546
+			//$data['type'] = substr($line,24,3);
547
+			$data['latitude'] = substr($line,29,9);
548
+			$data['longitude'] = substr($line,41,9);
549
+			$data['speed'] = round(substr($line,51,5));
550
+			//$data['course'] = substr($line,57,5);
551
+			$data['heading'] = round(substr($line,63,3));
552
+			//$data['draft'] = substr($line,67,4);
553
+			//$data['length'] = substr($line,72,3);
554
+			//$data['beam'] = substr($line,76,2);
555
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
556
+			//$data['callsign'] = trim(substr($line,100,7);
557
+			//$data['dest'] = substr($line,108,20);
558
+			//$data['etaDate'] = substr($line,129,5);
559
+			//$data['etaTime'] = substr($line,135,5);
560
+			$data['format_source'] = 'shipplotter';
561
+				$data['id_source'] = $id_source;
562
+			print_r($data);
563
+			echo 'Add...'."\n";
564
+			$MI->add($data);
565
+			unset($data);
566 566
 		}
567
-    	    }
568
-    	    $last_exec[$id]['last'] = time();
567
+			}
568
+			$last_exec[$id]['last'] = time();
569 569
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
570 570
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
571
-	    //$buffer = $Common->getData($hosts[$id]);
572
-	    $buffer = $Common->getData($value['host']);
573
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
574
-	    $buffer = explode('\n',$buffer);
575
-	    $reset = 0;
576
-	    foreach ($buffer as $line) {
577
-    		if ($line != '') {
578
-    		    $line = explode(':', $line);
579
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
571
+		//$buffer = $Common->getData($hosts[$id]);
572
+		$buffer = $Common->getData($value['host']);
573
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
574
+		$buffer = explode('\n',$buffer);
575
+		$reset = 0;
576
+		foreach ($buffer as $line) {
577
+			if ($line != '') {
578
+				$line = explode(':', $line);
579
+				if (count($line) > 30 && $line[0] != 'callsign') {
580 580
 			$data = array();
581 581
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
582 582
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -589,36 +589,36 @@  discard block
 block discarded – undo
589 589
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
590 590
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
591 591
 			$data['latitude'] = $line[5]; // lat
592
-	        	$data['longitude'] = $line[6]; // long
593
-	        	$data['verticalrate'] = ''; // vertical rate
594
-	        	$data['squawk'] = ''; // squawk
595
-	        	$data['emergency'] = ''; // emergency
596
-	        	$data['waypoints'] = $line[30];
592
+				$data['longitude'] = $line[6]; // long
593
+				$data['verticalrate'] = ''; // vertical rate
594
+				$data['squawk'] = ''; // squawk
595
+				$data['emergency'] = ''; // emergency
596
+				$data['waypoints'] = $line[30];
597 597
 			$data['datetime'] = date('Y-m-d H:i:s');
598 598
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
599 599
 			//if (isset($line[37])) $data['last_update'] = $line[37];
600
-		        $data['departure_airport_icao'] = $line[11];
601
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
602
-		        $data['arrival_airport_icao'] = $line[13];
600
+				$data['departure_airport_icao'] = $line[11];
601
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
602
+				$data['arrival_airport_icao'] = $line[13];
603 603
 			$data['frequency'] = $line[4];
604 604
 			$data['type'] = $line[18];
605 605
 			$data['range'] = $line[19];
606 606
 			if (isset($line[35])) $data['info'] = $line[35];
607
-    			$data['id_source'] = $id_source;
608
-	    		//$data['arrival_airport_time'] = ;
609
-	    		if ($line[9] != '') {
610
-	    		    $aircraft_data = explode('/',$line[9]);
611
-	    		    if (isset($aircraft_data[1])) {
612
-	    			$data['aircraft_icao'] = $aircraft_data[1];
613
-	    		    }
614
-        		}
615
-	    		/*
607
+				$data['id_source'] = $id_source;
608
+				//$data['arrival_airport_time'] = ;
609
+				if ($line[9] != '') {
610
+					$aircraft_data = explode('/',$line[9]);
611
+					if (isset($aircraft_data[1])) {
612
+					$data['aircraft_icao'] = $aircraft_data[1];
613
+					}
614
+				}
615
+				/*
616 616
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
617 617
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
618 618
 	    		*/
619
-	    		$data['format_source'] = $value['format'];
619
+				$data['format_source'] = $value['format'];
620 620
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
621
-    			if ($line[3] == 'PILOT') $SI->add($data);
621
+				if ($line[3] == 'PILOT') $SI->add($data);
622 622
 			elseif ($line[3] == 'ATC') {
623 623
 				//print_r($data);
624 624
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -636,247 +636,247 @@  discard block
 block discarded – undo
636 636
 				if (!isset($data['source_name'])) $data['source_name'] = '';
637 637
 				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']);
638 638
 			}
639
-    			unset($data);
640
-    		    }
641
-    		}
642
-    	    }
643
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
644
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
645
-    	    $last_exec[$id]['last'] = time();
646
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
647
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
648
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
649
-	    if ($buffer != '') {
650
-	    $all_data = json_decode($buffer,true);
651
-	    if (isset($all_data['acList'])) {
639
+				unset($data);
640
+				}
641
+			}
642
+			}
643
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
644
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
645
+			$last_exec[$id]['last'] = time();
646
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
647
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
648
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
649
+		if ($buffer != '') {
650
+		$all_data = json_decode($buffer,true);
651
+		if (isset($all_data['acList'])) {
652 652
 		$reset = 0;
653 653
 		foreach ($all_data['acList'] as $line) {
654
-		    $data = array();
655
-		    $data['hex'] = $line['Icao']; // hex
656
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
657
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
658
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
659
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
660
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
661
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
662
-		    //$data['verticalrate'] = $line['']; // verticale rate
663
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
664
-		    $data['emergency'] = ''; // emergency
665
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
666
-		    /*
654
+			$data = array();
655
+			$data['hex'] = $line['Icao']; // hex
656
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
657
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
658
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
659
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
660
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
661
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
662
+			//$data['verticalrate'] = $line['']; // verticale rate
663
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
664
+			$data['emergency'] = ''; // emergency
665
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
666
+			/*
667 667
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
668 668
 		    else $data['datetime'] = date('Y-m-d H:i:s');
669 669
 		    */
670
-		    $data['datetime'] = date('Y-m-d H:i:s');
671
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
672
-	    	    $data['format_source'] = 'aircraftlistjson';
673
-		    $data['id_source'] = $id_source;
674
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
675
-		    if (isset($data['latitude'])) $SI->add($data);
676
-		    unset($data);
670
+			$data['datetime'] = date('Y-m-d H:i:s');
671
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
672
+				$data['format_source'] = 'aircraftlistjson';
673
+			$data['id_source'] = $id_source;
674
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
675
+			if (isset($data['latitude'])) $SI->add($data);
676
+			unset($data);
677 677
 		}
678
-	    } elseif (is_array($all_data)) {
678
+		} elseif (is_array($all_data)) {
679 679
 		$reset = 0;
680 680
 		foreach ($all_data as $line) {
681
-		    $data = array();
682
-		    $data['hex'] = $line['hex']; // hex
683
-		    $data['ident'] = $line['flight']; // ident
684
-		    $data['altitude'] = $line['altitude']; // altitude
685
-		    $data['speed'] = $line['speed']; // speed
686
-		    $data['heading'] = $line['track']; // heading
687
-		    $data['latitude'] = $line['lat']; // lat
688
-		    $data['longitude'] = $line['lon']; // long
689
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
690
-		    $data['squawk'] = $line['squawk']; // squawk
691
-		    $data['emergency'] = ''; // emergency
692
-		    $data['datetime'] = date('Y-m-d H:i:s');
693
-	    	    $data['format_source'] = 'aircraftlistjson';
694
-    		    $data['id_source'] = $id_source;
695
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
696
-		    $SI->add($data);
697
-		    unset($data);
681
+			$data = array();
682
+			$data['hex'] = $line['hex']; // hex
683
+			$data['ident'] = $line['flight']; // ident
684
+			$data['altitude'] = $line['altitude']; // altitude
685
+			$data['speed'] = $line['speed']; // speed
686
+			$data['heading'] = $line['track']; // heading
687
+			$data['latitude'] = $line['lat']; // lat
688
+			$data['longitude'] = $line['lon']; // long
689
+			$data['verticalrate'] = $line['vrt']; // verticale rate
690
+			$data['squawk'] = $line['squawk']; // squawk
691
+			$data['emergency'] = ''; // emergency
692
+			$data['datetime'] = date('Y-m-d H:i:s');
693
+				$data['format_source'] = 'aircraftlistjson';
694
+				$data['id_source'] = $id_source;
695
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
696
+			$SI->add($data);
697
+			unset($data);
698
+		}
698 699
 		}
699
-	    }
700
-	    }
701
-    	    //$last_exec['aircraftlistjson'] = time();
702
-    	    $last_exec[$id]['last'] = time();
703
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
704
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
705
-	    $buffer = $Common->getData($value['host']);
706
-	    $all_data = json_decode($buffer,true);
707
-	    if (isset($all_data['planes'])) {
700
+		}
701
+			//$last_exec['aircraftlistjson'] = time();
702
+			$last_exec[$id]['last'] = time();
703
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
704
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
705
+		$buffer = $Common->getData($value['host']);
706
+		$all_data = json_decode($buffer,true);
707
+		if (isset($all_data['planes'])) {
708 708
 		$reset = 0;
709 709
 		foreach ($all_data['planes'] as $key => $line) {
710
-		    $data = array();
711
-		    $data['hex'] = $key; // hex
712
-		    $data['ident'] = $line[3]; // ident
713
-		    $data['altitude'] = $line[6]; // altitude
714
-		    $data['speed'] = $line[8]; // speed
715
-		    $data['heading'] = $line[7]; // heading
716
-		    $data['latitude'] = $line[4]; // lat
717
-		    $data['longitude'] = $line[5]; // long
718
-		    //$data['verticalrate'] = $line[]; // verticale rate
719
-		    $data['squawk'] = $line[10]; // squawk
720
-		    $data['emergency'] = ''; // emergency
721
-		    $data['registration'] = $line[2];
722
-		    $data['aircraft_icao'] = $line[0];
723
-		    $deparr = explode('-',$line[1]);
724
-		    if (count($deparr) == 2) {
710
+			$data = array();
711
+			$data['hex'] = $key; // hex
712
+			$data['ident'] = $line[3]; // ident
713
+			$data['altitude'] = $line[6]; // altitude
714
+			$data['speed'] = $line[8]; // speed
715
+			$data['heading'] = $line[7]; // heading
716
+			$data['latitude'] = $line[4]; // lat
717
+			$data['longitude'] = $line[5]; // long
718
+			//$data['verticalrate'] = $line[]; // verticale rate
719
+			$data['squawk'] = $line[10]; // squawk
720
+			$data['emergency'] = ''; // emergency
721
+			$data['registration'] = $line[2];
722
+			$data['aircraft_icao'] = $line[0];
723
+			$deparr = explode('-',$line[1]);
724
+			if (count($deparr) == 2) {
725 725
 			$data['departure_airport_icao'] = $deparr[0];
726 726
 			$data['arrival_airport_icao'] = $deparr[1];
727
-		    }
728
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
729
-	    	    $data['format_source'] = 'planeupdatefaa';
730
-    		    $data['id_source'] = $id_source;
731
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
732
-		    $SI->add($data);
733
-		    unset($data);
727
+			}
728
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
729
+				$data['format_source'] = 'planeupdatefaa';
730
+				$data['id_source'] = $id_source;
731
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
732
+			$SI->add($data);
733
+			unset($data);
734
+		}
734 735
 		}
735
-	    }
736
-    	    //$last_exec['planeupdatefaa'] = time();
737
-    	    $last_exec[$id]['last'] = time();
738
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
739
-	    $buffer = $Common->getData($value['host']);
740
-	    $all_data = json_decode($buffer,true);
741
-	    if (isset($all_data['states'])) {
736
+			//$last_exec['planeupdatefaa'] = time();
737
+			$last_exec[$id]['last'] = time();
738
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
739
+		$buffer = $Common->getData($value['host']);
740
+		$all_data = json_decode($buffer,true);
741
+		if (isset($all_data['states'])) {
742 742
 		$reset = 0;
743 743
 		foreach ($all_data['states'] as $key => $line) {
744
-		    $data = array();
745
-		    $data['hex'] = $line[0]; // hex
746
-		    $data['ident'] = trim($line[1]); // ident
747
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
748
-		    $data['speed'] = round($line[9]*1.94384); // speed
749
-		    $data['heading'] = round($line[10]); // heading
750
-		    $data['latitude'] = $line[5]; // lat
751
-		    $data['longitude'] = $line[6]; // long
752
-		    $data['verticalrate'] = $line[11]; // verticale rate
753
-		    //$data['squawk'] = $line[10]; // squawk
754
-		    //$data['emergency'] = ''; // emergency
755
-		    //$data['registration'] = $line[2];
756
-		    //$data['aircraft_icao'] = $line[0];
757
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
758
-	    	    $data['format_source'] = 'opensky';
759
-    		    $data['id_source'] = $id_source;
760
-		    $SI->add($data);
761
-		    unset($data);
744
+			$data = array();
745
+			$data['hex'] = $line[0]; // hex
746
+			$data['ident'] = trim($line[1]); // ident
747
+			$data['altitude'] = round($line[7]*3.28084); // altitude
748
+			$data['speed'] = round($line[9]*1.94384); // speed
749
+			$data['heading'] = round($line[10]); // heading
750
+			$data['latitude'] = $line[5]; // lat
751
+			$data['longitude'] = $line[6]; // long
752
+			$data['verticalrate'] = $line[11]; // verticale rate
753
+			//$data['squawk'] = $line[10]; // squawk
754
+			//$data['emergency'] = ''; // emergency
755
+			//$data['registration'] = $line[2];
756
+			//$data['aircraft_icao'] = $line[0];
757
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
758
+				$data['format_source'] = 'opensky';
759
+				$data['id_source'] = $id_source;
760
+			$SI->add($data);
761
+			unset($data);
762
+		}
762 763
 		}
763
-	    }
764
-    	    //$last_exec['planeupdatefaa'] = time();
765
-    	    $last_exec[$id]['last'] = time();
766
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
767
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
768
-	    //$buffer = $Common->getData($hosts[$id]);
769
-	    $buffer = $Common->getData($value['host']);
770
-	    $all_data = json_decode($buffer,true);
771
-	    if (!empty($all_data)) $reset = 0;
772
-	    foreach ($all_data as $key => $line) {
764
+			//$last_exec['planeupdatefaa'] = time();
765
+			$last_exec[$id]['last'] = time();
766
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
767
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
768
+		//$buffer = $Common->getData($hosts[$id]);
769
+		$buffer = $Common->getData($value['host']);
770
+		$all_data = json_decode($buffer,true);
771
+		if (!empty($all_data)) $reset = 0;
772
+		foreach ($all_data as $key => $line) {
773 773
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
774
-		    $data = array();
775
-		    $data['hex'] = $line[0];
776
-		    $data['ident'] = $line[16]; //$line[13]
777
-	    	    $data['altitude'] = $line[4]; // altitude
778
-	    	    $data['speed'] = $line[5]; // speed
779
-	    	    $data['heading'] = $line[3]; // heading
780
-	    	    $data['latitude'] = $line[1]; // lat
781
-	    	    $data['longitude'] = $line[2]; // long
782
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
783
-	    	    $data['squawk'] = $line[6]; // squawk
784
-	    	    $data['aircraft_icao'] = $line[8];
785
-	    	    $data['registration'] = $line[9];
786
-		    $data['departure_airport_iata'] = $line[11];
787
-		    $data['arrival_airport_iata'] = $line[12];
788
-	    	    $data['emergency'] = ''; // emergency
789
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
790
-	    	    $data['format_source'] = 'fr24json';
791
-    		    $data['id_source'] = $id_source;
792
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
793
-		    $SI->add($data);
794
-		    unset($data);
774
+			$data = array();
775
+			$data['hex'] = $line[0];
776
+			$data['ident'] = $line[16]; //$line[13]
777
+				$data['altitude'] = $line[4]; // altitude
778
+				$data['speed'] = $line[5]; // speed
779
+				$data['heading'] = $line[3]; // heading
780
+				$data['latitude'] = $line[1]; // lat
781
+				$data['longitude'] = $line[2]; // long
782
+				$data['verticalrate'] = $line[15]; // verticale rate
783
+				$data['squawk'] = $line[6]; // squawk
784
+				$data['aircraft_icao'] = $line[8];
785
+				$data['registration'] = $line[9];
786
+			$data['departure_airport_iata'] = $line[11];
787
+			$data['arrival_airport_iata'] = $line[12];
788
+				$data['emergency'] = ''; // emergency
789
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
790
+				$data['format_source'] = 'fr24json';
791
+				$data['id_source'] = $id_source;
792
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
793
+			$SI->add($data);
794
+			unset($data);
795
+		}
795 796
 		}
796
-	    }
797
-    	    //$last_exec['fr24json'] = time();
798
-    	    $last_exec[$id]['last'] = time();
799
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
800
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
801
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
802
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
803
-	    //echo $buffer;
804
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
805
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
806
-	    $all_data = json_decode($buffer,true);
807
-	    if (json_last_error() != JSON_ERROR_NONE) {
797
+			//$last_exec['fr24json'] = time();
798
+			$last_exec[$id]['last'] = time();
799
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
800
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
801
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
802
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
803
+		//echo $buffer;
804
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
805
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
806
+		$all_data = json_decode($buffer,true);
807
+		if (json_last_error() != JSON_ERROR_NONE) {
808 808
 		die(json_last_error_msg());
809
-	    }
810
-	    if (isset($all_data['mrkrs'])) {
809
+		}
810
+		if (isset($all_data['mrkrs'])) {
811 811
 		$reset = 0;
812 812
 		foreach ($all_data['mrkrs'] as $key => $line) {
813
-		    if (isset($line['inf'])) {
813
+			if (isset($line['inf'])) {
814 814
 			$data = array();
815 815
 			$data['hex'] = $line['inf']['ia'];
816 816
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
817
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
818
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
819
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
820
-	    		$data['latitude'] = $line['pt'][0]; // lat
821
-	    		$data['longitude'] = $line['pt'][1]; // long
822
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
823
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
824
-	    		//$data['aircraft_icao'] = $line[8];
825
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
817
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
818
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
819
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
820
+				$data['latitude'] = $line['pt'][0]; // lat
821
+				$data['longitude'] = $line['pt'][1]; // long
822
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
823
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
824
+				//$data['aircraft_icao'] = $line[8];
825
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
826 826
 			//$data['departure_airport_iata'] = $line[11];
827 827
 			//$data['arrival_airport_iata'] = $line[12];
828
-	    		//$data['emergency'] = ''; // emergency
828
+				//$data['emergency'] = ''; // emergency
829 829
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
830
-	    		$data['format_source'] = 'radarvirtueljson';
831
-    			$data['id_source'] = $id_source;
830
+				$data['format_source'] = 'radarvirtueljson';
831
+				$data['id_source'] = $id_source;
832 832
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
833 833
 			$SI->add($data);
834 834
 			unset($data);
835
-		    }
835
+			}
836 836
 		}
837
-	    }
838
-    	    //$last_exec['radarvirtueljson'] = time();
839
-    	    $last_exec[$id]['last'] = time();
840
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
841
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
842
-	    //$buffer = $Common->getData($hosts[$id]);
843
-	    $buffer = $Common->getData($value['host'].'?'.time());
844
-	    $all_data = json_decode(utf8_encode($buffer),true);
837
+		}
838
+			//$last_exec['radarvirtueljson'] = time();
839
+			$last_exec[$id]['last'] = time();
840
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
841
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
842
+		//$buffer = $Common->getData($hosts[$id]);
843
+		$buffer = $Common->getData($value['host'].'?'.time());
844
+		$all_data = json_decode(utf8_encode($buffer),true);
845 845
 	    
846
-	    if (isset($all_data['pireps'])) {
846
+		if (isset($all_data['pireps'])) {
847 847
 		$reset = 0;
848
-	        foreach ($all_data['pireps'] as $line) {
849
-		    $data = array();
850
-		    $data['id'] = $line['id'];
851
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
852
-		    $data['ident'] = $line['callsign']; // ident
853
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
854
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
855
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
856
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
857
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
858
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
859
-		    $data['latitude'] = $line['lat']; // lat
860
-		    $data['longitude'] = $line['lon']; // long
861
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
862
-		    //$data['squawk'] = $line['squawk']; // squawk
863
-		    //$data['emergency'] = ''; // emergency
864
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
865
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
866
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
867
-		    //$data['arrival_airport_time'] = $line['arrtime'];
868
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
869
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
870
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
871
-		    else $data['info'] = '';
872
-		    $data['format_source'] = 'pireps';
873
-    		    $data['id_source'] = $id_source;
874
-		    $data['datetime'] = date('Y-m-d H:i:s');
875
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
876
-		    if ($line['icon'] == 'plane') {
848
+			foreach ($all_data['pireps'] as $line) {
849
+			$data = array();
850
+			$data['id'] = $line['id'];
851
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
852
+			$data['ident'] = $line['callsign']; // ident
853
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
854
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
855
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
856
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
857
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
858
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
859
+			$data['latitude'] = $line['lat']; // lat
860
+			$data['longitude'] = $line['lon']; // long
861
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
862
+			//$data['squawk'] = $line['squawk']; // squawk
863
+			//$data['emergency'] = ''; // emergency
864
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
865
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
866
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
867
+			//$data['arrival_airport_time'] = $line['arrtime'];
868
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
869
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
870
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
871
+			else $data['info'] = '';
872
+			$data['format_source'] = 'pireps';
873
+				$data['id_source'] = $id_source;
874
+			$data['datetime'] = date('Y-m-d H:i:s');
875
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
876
+			if ($line['icon'] == 'plane') {
877 877
 			$SI->add($data);
878
-		    //    print_r($data);
879
-    		    } elseif ($line['icon'] == 'ct') {
878
+			//    print_r($data);
879
+				} elseif ($line['icon'] == 'ct') {
880 880
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
881 881
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
882 882
 			$typec = substr($data['ident'],-3);
@@ -891,190 +891,190 @@  discard block
 block discarded – undo
891 891
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
892 892
 			else $data['type'] = 'Observer';
893 893
 			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']);
894
-		    }
895
-		    unset($data);
894
+			}
895
+			unset($data);
896 896
 		}
897
-	    }
898
-    	    //$last_exec['pirepsjson'] = time();
899
-    	    $last_exec[$id]['last'] = time();
900
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
901
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
902
-	    //$buffer = $Common->getData($hosts[$id]);
903
-	    if ($globalDebug) echo 'Get Data...'."\n";
904
-	    $buffer = $Common->getData($value['host']);
905
-	    $all_data = json_decode($buffer,true);
906
-	    if ($buffer != '' && is_array($all_data)) {
897
+		}
898
+			//$last_exec['pirepsjson'] = time();
899
+			$last_exec[$id]['last'] = time();
900
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
901
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
902
+		//$buffer = $Common->getData($hosts[$id]);
903
+		if ($globalDebug) echo 'Get Data...'."\n";
904
+		$buffer = $Common->getData($value['host']);
905
+		$all_data = json_decode($buffer,true);
906
+		if ($buffer != '' && is_array($all_data)) {
907 907
 		$reset = 0;
908 908
 		foreach ($all_data as $line) {
909
-	    	    $data = array();
910
-	    	    //$data['id'] = $line['id']; // id not usable
911
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
912
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
913
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
914
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
915
-	    	    $data['ident'] = $line['flightnum']; // ident
916
-	    	    $data['altitude'] = $line['alt']; // altitude
917
-	    	    $data['speed'] = $line['gs']; // speed
918
-	    	    $data['heading'] = $line['heading']; // heading
919
-	    	    $data['latitude'] = $line['lat']; // lat
920
-	    	    $data['longitude'] = $line['lng']; // long
921
-	    	    $data['verticalrate'] = ''; // verticale rate
922
-	    	    $data['squawk'] = ''; // squawk
923
-	    	    $data['emergency'] = ''; // emergency
924
-	    	    //$data['datetime'] = $line['lastupdate'];
925
-	    	    $data['last_update'] = $line['lastupdate'];
926
-		    $data['datetime'] = date('Y-m-d H:i:s');
927
-	    	    $data['departure_airport_icao'] = $line['depicao'];
928
-	    	    $data['departure_airport_time'] = $line['deptime'];
929
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
930
-    		    $data['arrival_airport_time'] = $line['arrtime'];
931
-    		    $data['registration'] = $line['aircraft'];
932
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
933
-		    if (isset($line['aircraftname'])) {
909
+				$data = array();
910
+				//$data['id'] = $line['id']; // id not usable
911
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
912
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
913
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
914
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
915
+				$data['ident'] = $line['flightnum']; // ident
916
+				$data['altitude'] = $line['alt']; // altitude
917
+				$data['speed'] = $line['gs']; // speed
918
+				$data['heading'] = $line['heading']; // heading
919
+				$data['latitude'] = $line['lat']; // lat
920
+				$data['longitude'] = $line['lng']; // long
921
+				$data['verticalrate'] = ''; // verticale rate
922
+				$data['squawk'] = ''; // squawk
923
+				$data['emergency'] = ''; // emergency
924
+				//$data['datetime'] = $line['lastupdate'];
925
+				$data['last_update'] = $line['lastupdate'];
926
+			$data['datetime'] = date('Y-m-d H:i:s');
927
+				$data['departure_airport_icao'] = $line['depicao'];
928
+				$data['departure_airport_time'] = $line['deptime'];
929
+				$data['arrival_airport_icao'] = $line['arricao'];
930
+				$data['arrival_airport_time'] = $line['arrtime'];
931
+				$data['registration'] = $line['aircraft'];
932
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
933
+			if (isset($line['aircraftname'])) {
934 934
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
935 935
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
936
-	    		$aircraft_data = explode('-',$line['aircraftname']);
937
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
938
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
939
-	    		else {
940
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
941
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
942
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
943
-	    		}
944
-	    	    }
945
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
946
-    		    $data['id_source'] = $id_source;
947
-	    	    $data['format_source'] = 'phpvmacars';
948
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
949
-		    $SI->add($data);
950
-		    unset($data);
936
+				$aircraft_data = explode('-',$line['aircraftname']);
937
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
938
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
939
+				else {
940
+					$aircraft_data = explode(' ',$line['aircraftname']);
941
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
942
+					else $data['aircraft_icao'] = $line['aircraftname'];
943
+				}
944
+				}
945
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
946
+				$data['id_source'] = $id_source;
947
+				$data['format_source'] = 'phpvmacars';
948
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
949
+			$SI->add($data);
950
+			unset($data);
951 951
 		}
952 952
 		if ($globalDebug) echo 'No more data...'."\n";
953 953
 		unset($buffer);
954 954
 		unset($all_data);
955
-	    }
956
-    	    //$last_exec['phpvmacars'] = time();
957
-    	    $last_exec[$id]['last'] = time();
958
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
959
-	    //$buffer = $Common->getData($hosts[$id]);
960
-	    if ($globalDebug) echo 'Get Data...'."\n";
961
-	    $buffer = $Common->getData($value['host']);
962
-	    $all_data = json_decode($buffer,true);
963
-	    if ($buffer != '' && is_array($all_data)) {
955
+		}
956
+			//$last_exec['phpvmacars'] = time();
957
+			$last_exec[$id]['last'] = time();
958
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
959
+		//$buffer = $Common->getData($hosts[$id]);
960
+		if ($globalDebug) echo 'Get Data...'."\n";
961
+		$buffer = $Common->getData($value['host']);
962
+		$all_data = json_decode($buffer,true);
963
+		if ($buffer != '' && is_array($all_data)) {
964 964
 		$reset = 0;
965 965
 		foreach ($all_data as $line) {
966
-	    	    $data = array();
967
-	    	    //$data['id'] = $line['id']; // id not usable
968
-	    	    $data['id'] = trim($line['flight_id']);
969
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
970
-	    	    $data['pilot_name'] = $line['pilot_name'];
971
-	    	    $data['pilot_id'] = $line['pilot_id'];
972
-	    	    $data['ident'] = trim($line['callsign']); // ident
973
-	    	    $data['altitude'] = $line['altitude']; // altitude
974
-	    	    $data['speed'] = $line['gs']; // speed
975
-	    	    $data['heading'] = $line['heading']; // heading
976
-	    	    $data['latitude'] = $line['latitude']; // lat
977
-	    	    $data['longitude'] = $line['longitude']; // long
978
-	    	    $data['verticalrate'] = ''; // verticale rate
979
-	    	    $data['squawk'] = ''; // squawk
980
-	    	    $data['emergency'] = ''; // emergency
981
-	    	    //$data['datetime'] = $line['lastupdate'];
982
-	    	    $data['last_update'] = $line['last_update'];
983
-		    $data['datetime'] = date('Y-m-d H:i:s');
984
-	    	    $data['departure_airport_icao'] = $line['departure'];
985
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
986
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
987
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
988
-    		    //$data['registration'] = $line['aircraft'];
989
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
990
-	    	    $data['aircraft_icao'] = $line['plane_type'];
991
-    		    $data['id_source'] = $id_source;
992
-	    	    $data['format_source'] = 'vam';
993
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
994
-		    $SI->add($data);
995
-		    unset($data);
966
+				$data = array();
967
+				//$data['id'] = $line['id']; // id not usable
968
+				$data['id'] = trim($line['flight_id']);
969
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
970
+				$data['pilot_name'] = $line['pilot_name'];
971
+				$data['pilot_id'] = $line['pilot_id'];
972
+				$data['ident'] = trim($line['callsign']); // ident
973
+				$data['altitude'] = $line['altitude']; // altitude
974
+				$data['speed'] = $line['gs']; // speed
975
+				$data['heading'] = $line['heading']; // heading
976
+				$data['latitude'] = $line['latitude']; // lat
977
+				$data['longitude'] = $line['longitude']; // long
978
+				$data['verticalrate'] = ''; // verticale rate
979
+				$data['squawk'] = ''; // squawk
980
+				$data['emergency'] = ''; // emergency
981
+				//$data['datetime'] = $line['lastupdate'];
982
+				$data['last_update'] = $line['last_update'];
983
+			$data['datetime'] = date('Y-m-d H:i:s');
984
+				$data['departure_airport_icao'] = $line['departure'];
985
+				//$data['departure_airport_time'] = $line['departure_time'];
986
+				$data['arrival_airport_icao'] = $line['arrival'];
987
+				//$data['arrival_airport_time'] = $line['arrival_time'];
988
+				//$data['registration'] = $line['aircraft'];
989
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
990
+				$data['aircraft_icao'] = $line['plane_type'];
991
+				$data['id_source'] = $id_source;
992
+				$data['format_source'] = 'vam';
993
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
994
+			$SI->add($data);
995
+			unset($data);
996 996
 		}
997 997
 		if ($globalDebug) echo 'No more data...'."\n";
998 998
 		unset($buffer);
999 999
 		unset($all_data);
1000
-	    }
1001
-    	    //$last_exec['phpvmacars'] = time();
1002
-    	    $last_exec[$id]['last'] = time();
1000
+		}
1001
+			//$last_exec['phpvmacars'] = time();
1002
+			$last_exec[$id]['last'] = time();
1003 1003
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1004 1004
 	} 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' || $value['format'] == 'vrstcp') {
1005
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1006
-    	    //$last_exec[$id]['last'] = time();
1005
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1006
+			//$last_exec[$id]['last'] = time();
1007 1007
 
1008
-	    //$read = array( $sockets[$id] );
1009
-	    $read = $sockets;
1010
-	    $write = NULL;
1011
-	    $e = NULL;
1012
-	    $n = socket_select($read, $write, $e, $timeout);
1013
-	    if ($e != NULL) var_dump($e);
1014
-	    if ($n > 0) {
1008
+		//$read = array( $sockets[$id] );
1009
+		$read = $sockets;
1010
+		$write = NULL;
1011
+		$e = NULL;
1012
+		$n = socket_select($read, $write, $e, $timeout);
1013
+		if ($e != NULL) var_dump($e);
1014
+		if ($n > 0) {
1015 1015
 		$reset = 0;
1016 1016
 		foreach ($read as $nb => $r) {
1017
-		    //$value = $formats[$nb];
1018
-		    $format = $globalSources[$nb]['format'];
1019
-        	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3' || $format == 'vrstcp') {
1020
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1021
-        	    } else {
1022
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1023
-	    	    }
1024
-        	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1025
-        	    //echo $buffer."\n";
1026
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1027
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1028
-		    $error = false;
1029
-		    //$SI::del();
1030
-		    if ($format == 'vrstcp') {
1017
+			//$value = $formats[$nb];
1018
+			$format = $globalSources[$nb]['format'];
1019
+				if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3' || $format == 'vrstcp') {
1020
+				$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1021
+				} else {
1022
+					$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1023
+				}
1024
+				//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1025
+				//echo $buffer."\n";
1026
+			// lets play nice and handle signals such as ctrl-c/kill properly
1027
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1028
+			$error = false;
1029
+			//$SI::del();
1030
+			if ($format == 'vrstcp') {
1031 1031
 			$buffer = explode('},{',$buffer);
1032
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1033
-		    // SBS format is CSV format
1034
-		    if ($buffer != '') {
1032
+			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1033
+			// SBS format is CSV format
1034
+			if ($buffer != '') {
1035 1035
 			$tt[$format] = 0;
1036 1036
 			if ($format == 'acarssbs3') {
1037
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1038
-			    $ACARS->add(trim($buffer));
1039
-			    $ACARS->deleteLiveAcarsData();
1037
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1038
+				$ACARS->add(trim($buffer));
1039
+				$ACARS->deleteLiveAcarsData();
1040 1040
 			} elseif ($format == 'raw') {
1041
-			    // AVR format
1042
-			    $data = $SBS->parse($buffer);
1043
-			    if (is_array($data)) {
1041
+				// AVR format
1042
+				$data = $SBS->parse($buffer);
1043
+				if (is_array($data)) {
1044 1044
 				$data['datetime'] = date('Y-m-d H:i:s');
1045 1045
 				$data['format_source'] = 'raw';
1046 1046
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1047
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1048
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1049
-                            }
1050
-                        } elseif ($format == 'ais') {
1051
-			    $ais_data = $AIS->parse_line(trim($buffer));
1052
-			    $data = array();
1053
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1054
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1055
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1056
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1057
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1058
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1059
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1060
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1061
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1062
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1063
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1064
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1047
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1048
+								if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1049
+							}
1050
+						} elseif ($format == 'ais') {
1051
+				$ais_data = $AIS->parse_line(trim($buffer));
1052
+				$data = array();
1053
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1054
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1055
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1056
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1057
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1058
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1059
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1060
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1061
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1062
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1063
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1064
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1065 1065
 
1066
-			    if (isset($ais_data['timestamp'])) {
1066
+				if (isset($ais_data['timestamp'])) {
1067 1067
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1068
-			    } else {
1068
+				} else {
1069 1069
 				$data['datetime'] = date('Y-m-d H:i:s');
1070
-			    }
1071
-			    $data['format_source'] = 'aisnmea';
1072
-    			    $data['id_source'] = $id_source;
1073
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1074
-			    unset($data);
1075
-                        } elseif ($format == 'flightgearsp') {
1076
-                    	    //echo $buffer."\n";
1077
-                    	    if (strlen($buffer) > 5) {
1070
+				}
1071
+				$data['format_source'] = 'aisnmea';
1072
+					$data['id_source'] = $id_source;
1073
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1074
+				unset($data);
1075
+						} elseif ($format == 'flightgearsp') {
1076
+							//echo $buffer."\n";
1077
+							if (strlen($buffer) > 5) {
1078 1078
 				$line = explode(',',$buffer);
1079 1079
 				$data = array();
1080 1080
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1090,37 +1090,37 @@  discard block
 block discarded – undo
1090 1090
 				$data['format_source'] = 'flightgearsp';
1091 1091
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1092 1092
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1093
-			    }
1094
-                        } elseif ($format == 'acars') {
1095
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1096
-			    $ACARS->add(trim($buffer));
1097
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1098
-			    $ACARS->deleteLiveAcarsData();
1093
+				}
1094
+						} elseif ($format == 'acars') {
1095
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1096
+				$ACARS->add(trim($buffer));
1097
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1098
+				$ACARS->deleteLiveAcarsData();
1099 1099
 			} elseif ($format == 'flightgearmp') {
1100
-			    if (substr($buffer,0,1) != '#') {
1100
+				if (substr($buffer,0,1) != '#') {
1101 1101
 				$data = array();
1102 1102
 				//echo $buffer."\n";
1103 1103
 				$line = explode(' ',$buffer);
1104 1104
 				if (count($line) == 11) {
1105
-				    $userserver = explode('@',$line[0]);
1106
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1107
-				    $data['ident'] = $userserver[0];
1108
-				    $data['registration'] = $userserver[0];
1109
-				    $data['latitude'] = $line[4];
1110
-				    $data['longitude'] = $line[5];
1111
-				    $data['altitude'] = $line[6];
1112
-				    $data['datetime'] = date('Y-m-d H:i:s');
1113
-				    $aircraft_type = $line[10];
1114
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1115
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1116
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1105
+					$userserver = explode('@',$line[0]);
1106
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1107
+					$data['ident'] = $userserver[0];
1108
+					$data['registration'] = $userserver[0];
1109
+					$data['latitude'] = $line[4];
1110
+					$data['longitude'] = $line[5];
1111
+					$data['altitude'] = $line[6];
1112
+					$data['datetime'] = date('Y-m-d H:i:s');
1113
+					$aircraft_type = $line[10];
1114
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1115
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1116
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1117
+				}
1117 1118
 				}
1118
-			    }
1119 1119
 			} elseif ($format == 'beast') {
1120
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1121
-			    die;
1120
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1121
+				die;
1122 1122
 			} elseif ($format == 'vrstcp') {
1123
-			    foreach($buffer as $all_data) {
1123
+				foreach($buffer as $all_data) {
1124 1124
 				$line = json_decode('{'.$all_data.'}',true);
1125 1125
 				$data = array();
1126 1126
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1140,100 +1140,100 @@  discard block
 block discarded – undo
1140 1140
 				*/
1141 1141
 				$data['datetime'] = date('Y-m-d H:i:s');
1142 1142
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1143
-		    		$data['format_source'] = 'vrstcp';
1143
+					$data['format_source'] = 'vrstcp';
1144 1144
 				$data['id_source'] = $id_source;
1145 1145
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1146 1146
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1147 1147
 				unset($data);
1148
-			    }
1148
+				}
1149 1149
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1150
-			    $line = explode("\t", $buffer);
1151
-			    for($k = 0; $k < count($line); $k=$k+2) {
1150
+				$line = explode("\t", $buffer);
1151
+				for($k = 0; $k < count($line); $k=$k+2) {
1152 1152
 				$key = $line[$k];
1153
-			        $lined[$key] = $line[$k+1];
1154
-			    }
1155
-    			    if (count($lined) > 3) {
1156
-    				$data['hex'] = $lined['hexid'];
1157
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1158
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1159
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1160
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1161
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1162
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1163
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1164
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1165
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1166
-    				$data['id_source'] = $id_source;
1167
-    				$data['format_source'] = 'tsv';
1168
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1169
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1170
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1171
-    				unset($lined);
1172
-    				unset($data);
1173
-    			    } else $error = true;
1153
+					$lined[$key] = $line[$k+1];
1154
+				}
1155
+					if (count($lined) > 3) {
1156
+					$data['hex'] = $lined['hexid'];
1157
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1158
+					$data['datetime'] = date('Y-m-d H:i:s');;
1159
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1160
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1161
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1162
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1163
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1164
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1165
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1166
+					$data['id_source'] = $id_source;
1167
+					$data['format_source'] = 'tsv';
1168
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1169
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1170
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1171
+					unset($lined);
1172
+					unset($data);
1173
+					} else $error = true;
1174 1174
 			} elseif ($format == 'aprs' && $use_aprs) {
1175
-			    if ($aprs_connect == 0) {
1175
+				if ($aprs_connect == 0) {
1176 1176
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1177 1177
 				$aprs_connect = 1;
1178
-			    }
1178
+				}
1179 1179
 			    
1180
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1180
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1181 1181
 				$aprs_last_tx = time();
1182 1182
 				$data_aprs = "# Keep alive";
1183 1183
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1184
-			    }
1184
+				}
1185 1185
 			    
1186
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1187
-			    //echo 'APRS data : '.$buffer."\n";
1188
-			    $buffer = str_replace('APRS <- ','',$buffer);
1189
-			    $buffer = str_replace('APRS -> ','',$buffer);
1190
-			    //echo $buffer."\n";
1191
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1186
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1187
+				//echo 'APRS data : '.$buffer."\n";
1188
+				$buffer = str_replace('APRS <- ','',$buffer);
1189
+				$buffer = str_replace('APRS -> ','',$buffer);
1190
+				//echo $buffer."\n";
1191
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1192 1192
 				$line = $APRS->parse($buffer);
1193 1193
 				//print_r($line);
1194 1194
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1195 1195
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']))) {
1196
-				    $aprs_last_tx = time();
1197
-				    $data = array();
1198
-				    //print_r($line);
1199
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1200
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1201
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1202
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1203
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1204
-				    $data['latitude'] = $line['latitude'];
1205
-				    $data['longitude'] = $line['longitude'];
1206
-				    //$data['verticalrate'] = $line[16];
1207
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1208
-				    else $data['speed'] = 0;
1209
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1210
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1211
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1212
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1213
-				    //else $data['heading'] = 0;
1214
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1215
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1216
-    				    $data['id_source'] = $id_source;
1217
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1218
-				    else $data['format_source'] = 'aprs';
1219
-				    $data['source_name'] = $line['source'];
1220
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1221
-				    else $data['source_type'] = 'flarm';
1222
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1223
-				    $currentdate = date('Y-m-d H:i:s');
1224
-				    $aprsdate = strtotime($data['datetime']);
1225
-				    // Accept data if time <= system time + 20s
1226
-				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1196
+					$aprs_last_tx = time();
1197
+					$data = array();
1198
+					//print_r($line);
1199
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1200
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1201
+					else $data['datetime'] = date('Y-m-d H:i:s');
1202
+					//$data['datetime'] = date('Y-m-d H:i:s');
1203
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1204
+					$data['latitude'] = $line['latitude'];
1205
+					$data['longitude'] = $line['longitude'];
1206
+					//$data['verticalrate'] = $line[16];
1207
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1208
+					else $data['speed'] = 0;
1209
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1210
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1211
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1212
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
1213
+					//else $data['heading'] = 0;
1214
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1215
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1216
+						$data['id_source'] = $id_source;
1217
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1218
+					else $data['format_source'] = 'aprs';
1219
+					$data['source_name'] = $line['source'];
1220
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1221
+					else $data['source_type'] = 'flarm';
1222
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1223
+					$currentdate = date('Y-m-d H:i:s');
1224
+					$aprsdate = strtotime($data['datetime']);
1225
+					// Accept data if time <= system time + 20s
1226
+					if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1227 1227
 					$send = $SI->add($data);
1228
-				    } elseif (isset($line['stealth'])) {
1228
+					} elseif (isset($line['stealth'])) {
1229 1229
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1230 1230
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1231
-				    //} 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')) {
1232
-				    } 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') {
1231
+					//} 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')) {
1232
+					} 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') {
1233 1233
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1234 1234
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1235
-				    }
1236
-				    unset($data);
1235
+					}
1236
+					unset($data);
1237 1237
 				} 
1238 1238
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1239 1239
 					echo '!! Weather Station not yet supported'."\n";
@@ -1243,12 +1243,12 @@  discard block
 block discarded – undo
1243 1243
 				}
1244 1244
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1245 1245
 				//elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1246
-			    }
1246
+				}
1247 1247
 			} else {
1248
-			    $line = explode(',', $buffer);
1249
-    			    if (count($line) > 20) {
1250
-    			    	$data['hex'] = $line[4];
1251
-    				/*
1248
+				$line = explode(',', $buffer);
1249
+					if (count($line) > 20) {
1250
+						$data['hex'] = $line[4];
1251
+					/*
1252 1252
     				$data['datetime'] = $line[6].' '.$line[7];
1253 1253
     					date_default_timezone_set($globalTimezone);
1254 1254
     					$datetime = new DateTime($data['datetime']);
@@ -1256,29 +1256,29 @@  discard block
 block discarded – undo
1256 1256
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1257 1257
     					date_default_timezone_set('UTC');
1258 1258
     				*/
1259
-    				// Force datetime to current UTC datetime
1260
-    				date_default_timezone_set('UTC');
1261
-    				$data['datetime'] = date('Y-m-d H:i:s');
1262
-    				$data['ident'] = trim($line[10]);
1263
-    				$data['latitude'] = $line[14];
1264
-    				$data['longitude'] = $line[15];
1265
-    				$data['verticalrate'] = $line[16];
1266
-    				$data['emergency'] = $line[20];
1267
-    				$data['speed'] = $line[12];
1268
-    				$data['squawk'] = $line[17];
1269
-    				$data['altitude'] = $line[11];
1270
-    				$data['heading'] = $line[13];
1271
-    				$data['ground'] = $line[21];
1272
-    				$data['emergency'] = $line[19];
1273
-    				$data['format_source'] = 'sbs';
1259
+					// Force datetime to current UTC datetime
1260
+					date_default_timezone_set('UTC');
1261
+					$data['datetime'] = date('Y-m-d H:i:s');
1262
+					$data['ident'] = trim($line[10]);
1263
+					$data['latitude'] = $line[14];
1264
+					$data['longitude'] = $line[15];
1265
+					$data['verticalrate'] = $line[16];
1266
+					$data['emergency'] = $line[20];
1267
+					$data['speed'] = $line[12];
1268
+					$data['squawk'] = $line[17];
1269
+					$data['altitude'] = $line[11];
1270
+					$data['heading'] = $line[13];
1271
+					$data['ground'] = $line[21];
1272
+					$data['emergency'] = $line[19];
1273
+					$data['format_source'] = 'sbs';
1274 1274
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1275
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1276
-    				$data['id_source'] = $id_source;
1277
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1278
-    				else $error = true;
1279
-    				unset($data);
1280
-    			    } else $error = true;
1281
-			    if ($error) {
1275
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1276
+					$data['id_source'] = $id_source;
1277
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1278
+					else $error = true;
1279
+					unset($data);
1280
+					} else $error = true;
1281
+				if ($error) {
1282 1282
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1283 1283
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1284 1284
 				} else {
@@ -1294,13 +1294,13 @@  discard block
 block discarded – undo
1294 1294
 					connect_all($sourceer);
1295 1295
 					$sourceer = array();
1296 1296
 				}
1297
-			    }
1297
+				}
1298 1298
 			}
1299 1299
 			// Sleep for xxx microseconds
1300 1300
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1301
-		    } else {
1301
+			} else {
1302 1302
 			if ($format == 'flightgearmp') {
1303
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1303
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1304 1304
 				//@socket_close($r);
1305 1305
 				sleep($globalMinFetch);
1306 1306
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1309,9 +1309,9 @@  discard block
 block discarded – undo
1309 1309
 				break;
1310 1310
 				
1311 1311
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1312
-			    if (isset($tt[$format])) $tt[$format]++;
1313
-			    else $tt[$format] = 0;
1314
-			    if ($tt[$format] > 30) {
1312
+				if (isset($tt[$format])) $tt[$format]++;
1313
+				else $tt[$format] = 0;
1314
+				if ($tt[$format] > 30) {
1315 1315
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1316 1316
 				//@socket_close($r);
1317 1317
 				sleep(2);
@@ -1322,23 +1322,23 @@  discard block
 block discarded – undo
1322 1322
 				//connect_all($globalSources);
1323 1323
 				$tt[$format]=0;
1324 1324
 				break;
1325
-			    }
1325
+				}
1326
+			}
1326 1327
 			}
1327
-		    }
1328 1328
 		}
1329
-	    } else {
1329
+		} else {
1330 1330
 		$error = socket_strerror(socket_last_error());
1331 1331
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1332 1332
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1333 1333
 			if (isset($globalDebug)) echo "Restarting...\n";
1334 1334
 			// Restart the script if possible
1335 1335
 			if (is_array($sockets)) {
1336
-			    if ($globalDebug) echo "Shutdown all sockets...";
1336
+				if ($globalDebug) echo "Shutdown all sockets...";
1337 1337
 			    
1338
-			    foreach ($sockets as $sock) {
1338
+				foreach ($sockets as $sock) {
1339 1339
 				@socket_shutdown($sock,2);
1340 1340
 				@socket_close($sock);
1341
-			    }
1341
+				}
1342 1342
 			    
1343 1343
 			}
1344 1344
 			if ($globalDebug) echo "Restart all connections...";
@@ -1349,13 +1349,13 @@  discard block
 block discarded – undo
1349 1349
 			if ($reset > 40) exit('Too many attempts...');
1350 1350
 			connect_all($globalSources);
1351 1351
 		}
1352
-	    }
1352
+		}
1353 1353
 	}
1354 1354
 	if ($globalDaemon === false) {
1355
-	    if ($globalDebug) echo 'Check all...'."\n";
1356
-	    $SI->checkAll();
1355
+		if ($globalDebug) echo 'Check all...'."\n";
1356
+		$SI->checkAll();
1357
+	}
1357 1358
 	}
1358
-    }
1359 1359
 }
1360 1360
 
1361 1361
 ?>
Please login to merge, or discard this patch.
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -45,11 +45,11 @@  discard block
 block discarded – undo
45 45
 	    die;
46 46
 	}
47 47
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
48
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
48
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
49 49
     }
50 50
 }
51 51
 
52
-$options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::'));
52
+$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::', 'aprsserverssid::', 'aprsserverpass::'));
53 53
 //if (isset($options['s'])) $hosts = array($options['s']);
54 54
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 55
 if (isset($options['s'])) {
@@ -67,27 +67,27 @@  discard block
 block discarded – undo
67 67
 else $id_source = 1;
68 68
 if (isset($globalServer) && $globalServer) {
69 69
     if ($globalDebug) echo "Using Server Mode\n";
70
-    $SI=new SpotterServer();
70
+    $SI = new SpotterServer();
71 71
 /*
72 72
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
73 73
     $SI = new adsb2aprs();
74 74
     $SI->connect();
75 75
 */
76
-} else $SI=new SpotterImport($Connection->db);
76
+} else $SI = new SpotterImport($Connection->db);
77 77
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
78 78
 if (isset($globalMarine) && $globalMarine) {
79 79
     $AIS = new AIS();
80 80
     $MI = new MarineImport($Connection->db);
81 81
 }
82 82
 //$APRS=new APRS($Connection->db);
83
-$SBS=new SBS();
84
-$ACARS=new ACARS($Connection->db);
85
-$Common=new Common();
83
+$SBS = new SBS();
84
+$ACARS = new ACARS($Connection->db);
85
+$Common = new Common();
86 86
 date_default_timezone_set('UTC');
87 87
 //$servertz = system('date +%Z');
88 88
 // signal handler - playing nice with sockets and dump1090
89 89
 if (function_exists('pcntl_fork')) {
90
-    pcntl_signal(SIGINT,  function() {
90
+    pcntl_signal(SIGINT, function() {
91 91
         global $sockets;
92 92
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
93 93
         die("Bye!\n");
@@ -103,35 +103,35 @@  discard block
 block discarded – undo
103 103
 
104 104
 function connect_all($hosts) {
105 105
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
106
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
106
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
107 107
     $reset++;
108 108
     if ($globalDebug) echo 'Connect to all...'."\n";
109 109
     foreach ($hosts as $id => $value) {
110 110
 	$host = $value['host'];
111 111
 	$globalSources[$id]['last_exec'] = 0;
112 112
 	// Here we check type of source(s)
113
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
114
-            if (preg_match('/deltadb.txt$/i',$host)) {
113
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
114
+            if (preg_match('/deltadb.txt$/i', $host)) {
115 115
         	//$formats[$id] = 'deltadbtxt';
116 116
         	$globalSources[$id]['format'] = 'deltadbtxt';
117 117
         	//$last_exec['deltadbtxt'] = 0;
118 118
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
119
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
119
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
120 120
         	//$formats[$id] = 'vatsimtxt';
121 121
         	$globalSources[$id]['format'] = 'vatsimtxt';
122 122
         	//$last_exec['vatsimtxt'] = 0;
123 123
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
124
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
124
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
125 125
         	//$formats[$id] = 'aircraftlistjson';
126 126
         	$globalSources[$id]['format'] = 'aircraftlistjson';
127 127
         	//$last_exec['aircraftlistjson'] = 0;
128 128
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
129
-    	    } else if (preg_match('/opensky/i',$host)) {
129
+    	    } else if (preg_match('/opensky/i', $host)) {
130 130
         	//$formats[$id] = 'aircraftlistjson';
131 131
         	$globalSources[$id]['format'] = 'opensky';
132 132
         	//$last_exec['aircraftlistjson'] = 0;
133 133
         	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
134
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
134
+    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) {
135 135
         	//$formats[$id] = 'radarvirtueljson';
136 136
         	$globalSources[$id]['format'] = 'radarvirtueljson';
137 137
         	//$last_exec['radarvirtueljson'] = 0;
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
141 141
         	    exit(0);
142 142
         	}
143
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
143
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
144 144
         	//$formats[$id] = 'planeupdatefaa';
145 145
         	$globalSources[$id]['format'] = 'planeupdatefaa';
146 146
         	//$last_exec['planeupdatefaa'] = 0;
@@ -149,26 +149,26 @@  discard block
 block discarded – undo
149 149
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
150 150
         	    exit(0);
151 151
         	}
152
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
152
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
153 153
         	//$formats[$id] = 'phpvmacars';
154 154
         	$globalSources[$id]['format'] = 'phpvmacars';
155 155
         	//$last_exec['phpvmacars'] = 0;
156 156
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
157
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
157
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
158 158
         	//$formats[$id] = 'phpvmacars';
159 159
         	$globalSources[$id]['format'] = 'vam';
160 160
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
161
-            } else if (preg_match('/whazzup/i',$host)) {
161
+            } else if (preg_match('/whazzup/i', $host)) {
162 162
         	//$formats[$id] = 'whazzup';
163 163
         	$globalSources[$id]['format'] = 'whazzup';
164 164
         	//$last_exec['whazzup'] = 0;
165 165
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
166
-            } else if (preg_match('/recentpireps/i',$host)) {
166
+            } else if (preg_match('/recentpireps/i', $host)) {
167 167
         	//$formats[$id] = 'pirepsjson';
168 168
         	$globalSources[$id]['format'] = 'pirepsjson';
169 169
         	//$last_exec['pirepsjson'] = 0;
170 170
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
171
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
171
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
172 172
         	//$formats[$id] = 'fr24json';
173 173
         	$globalSources[$id]['format'] = 'fr24json';
174 174
         	//$last_exec['fr24json'] = 0;
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
178 178
         	    exit(0);
179 179
         	}
180
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
180
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
181 181
         	//$formats[$id] = 'fr24json';
182 182
         	$globalSources[$id]['format'] = 'myshiptracking';
183 183
         	//$last_exec['fr24json'] = 0;
@@ -187,22 +187,22 @@  discard block
 block discarded – undo
187 187
         	    exit(0);
188 188
         	}
189 189
             //} else if (preg_match('/10001/',$host)) {
190
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
190
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
191 191
         	//$formats[$id] = 'tsv';
192 192
         	$globalSources[$id]['format'] = 'tsv';
193 193
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
194 194
             }
195
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
195
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
196 196
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
197
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
197
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
198 198
     		    if ($idf !== false) {
199 199
     			$httpfeeds[$id] = $idf;
200 200
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
201 201
     		    }
202 202
     		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
203 203
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
204
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
205
-	    $hostport = explode(':',$host);
204
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
205
+	    $hostport = explode(':', $host);
206 206
 	    if (isset($hostport[1])) {
207 207
 		$port = $hostport[1];
208 208
 		$hostn = $hostport[0];
@@ -212,19 +212,19 @@  discard block
 block discarded – undo
212 212
 	    }
213 213
 	    $Common = new Common();
214 214
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
215
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
215
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
216 216
     	    } else {
217
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
217
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
218 218
 	    }
219 219
 	    if ($s) {
220 220
     	        $sockets[$id] = $s;
221 221
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
222
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
222
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
223 223
 			//$formats[$id] = 'aprs';
224 224
 			$globalSources[$id]['format'] = 'aprs';
225 225
 			//$aprs_connect = 0;
226 226
 			//$use_aprs = true;
227
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
227
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
228 228
 			$globalSources[$id]['format'] = 'vrstcp';
229 229
     		    } elseif ($port == '10001') {
230 230
         		//$formats[$id] = 'tsv';
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
264 264
 else $timeout = 20;
265 265
 $errno = '';
266
-$errstr='';
266
+$errstr = '';
267 267
 
268 268
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
269 269
 /* Initiate connections to all the hosts simultaneously */
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 //connect_all($globalSources);
272 272
 
273 273
 if (isset($globalProxy) && $globalProxy) {
274
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
274
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
275 275
 } else {
276 276
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
277 277
 }
@@ -298,16 +298,16 @@  discard block
 block discarded – undo
298 298
 
299 299
 if ($use_aprs) {
300 300
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
301
-	$APRS=new APRS();
301
+	$APRS = new APRS();
302 302
 	$aprs_connect = 0;
303 303
 	$aprs_keep = 120;
304 304
 	$aprs_last_tx = time();
305 305
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
306
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
306
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
307 307
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
308
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
308
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
309 309
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
310
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
310
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
311 311
 	if ($aprs_full) $aprs_filter = '';
312 312
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
313 313
 	else $aprs_pass = '-1';
@@ -322,12 +322,12 @@  discard block
 block discarded – undo
322 322
 sleep(1);
323 323
 if ($globalDebug) echo "SCAN MODE \n\n";
324 324
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
325
-$endtime = time()+$globalCronEnd;
325
+$endtime = time() + $globalCronEnd;
326 326
 $i = 1;
327 327
 $tt = array();
328 328
 // Delete all ATC
329 329
 if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
330
-	$ATC=new ATC($Connection->db);
330
+	$ATC = new ATC($Connection->db);
331 331
 }
332 332
 if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
333 333
 	$ATC->deleteAll();
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 
336 336
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
337 337
 while ($i > 0) {
338
-    if (!$globalDaemon) $i = $endtime-time();
338
+    if (!$globalDaemon) $i = $endtime - time();
339 339
     // Delete old ATC
340 340
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
341 341
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 	}
351 351
 	if ($max != $globalMinFetch) {
352 352
 	    if ($globalDebug) echo 'Sleeping...'."\n";
353
-	    sleep($globalMinFetch-$max+2);
353
+	    sleep($globalMinFetch - $max + 2);
354 354
 	}
355 355
     }
356 356
 
@@ -363,8 +363,8 @@  discard block
 block discarded – undo
363 363
 	    //$buffer = $Common->getData($hosts[$id]);
364 364
 	    $buffer = $Common->getData($value['host']);
365 365
 	    if ($buffer != '') $reset = 0;
366
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
367
-	    $buffer = explode('\n',$buffer);
366
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
367
+	    $buffer = explode('\n', $buffer);
368 368
 	    foreach ($buffer as $line) {
369 369
     		if ($line != '' && count($line) > 7) {
370 370
     		    $line = explode(',', $line);
@@ -391,11 +391,11 @@  discard block
 block discarded – undo
391 391
     	    $last_exec[$id]['last'] = time();
392 392
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
393 393
 	    date_default_timezone_set('CET');
394
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
394
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
395 395
 	    date_default_timezone_set('UTC');
396 396
 	    if ($buffer != '') $reset = 0;
397
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
398
-	    $buffer = explode('\n',$buffer);
397
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
398
+	    $buffer = explode('\n', $buffer);
399 399
 	    foreach ($buffer as $line) {
400 400
 		if ($line != '') {
401 401
 		    echo "'".$line."'\n";
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
414 414
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
415 415
 		    if (isset($ais_data['timestamp'])) {
416
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
416
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
417 417
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
418 418
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
419 419
 			    $add = true;
@@ -436,12 +436,12 @@  discard block
 block discarded – undo
436 436
 	    $w = $e = null;
437 437
 	    
438 438
 	    if (isset($arr[$id])) {
439
-	    $nn = stream_select($arr,$w,$e,$timeout);
439
+	    $nn = stream_select($arr, $w, $e, $timeout);
440 440
 	    if ($nn > 0) {
441 441
 		foreach ($httpfeeds as $feed) {
442
-		    $buffer = stream_get_line($feed,2000,"\n");
443
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
444
-		    $buffer = explode('\n',$buffer);
442
+		    $buffer = stream_get_line($feed, 2000, "\n");
443
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
444
+		    $buffer = explode('\n', $buffer);
445 445
 		    foreach ($buffer as $line) {
446 446
 			if ($line != '') {
447 447
 			    $ais_data = $AIS->parse_line(trim($line));
@@ -457,9 +457,9 @@  discard block
 block discarded – undo
457 457
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
458 458
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
459 459
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
460
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
460
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
461 461
 			    if (isset($ais_data['timestamp'])) {
462
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
462
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
463 463
 			    } else {
464 464
 				$data['datetime'] = date('Y-m-d H:i:s');
465 465
 			    }
@@ -473,10 +473,10 @@  discard block
 block discarded – undo
473 473
 		}
474 474
 	    }
475 475
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
476
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
476
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
477 477
 	    if ($buffer != '') {
478 478
 		//echo $buffer;
479
-		$all_data = json_decode($buffer,true);
479
+		$all_data = json_decode($buffer, true);
480 480
 		//print_r($all_data);
481 481
 		if (isset($all_data[0]['DATA'])) {
482 482
 		foreach ($all_data[0]['DATA'] as $line) {
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
 			//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
492 492
 			$data['imo'] = $line['IMO'];
493 493
 			//$data['arrival_code'] = $ais_data['destination'];
494
-			$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
494
+			$data['datetime'] = date('Y-m-d H:i:s', $line['T']);
495 495
 			$data['format_source'] = 'myshiptracking';
496 496
 			$data['id_source'] = $id_source;
497 497
 			$MI->add($data);
@@ -503,9 +503,9 @@  discard block
 block discarded – undo
503 503
 	    }
504 504
     	    $last_exec[$id]['last'] = time();
505 505
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
506
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
506
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
507 507
 	    if ($buffer != '') {
508
-		$all_data = json_decode($buffer,true);
508
+		$all_data = json_decode($buffer, true);
509 509
 		if (isset($all_data[0]['mmsi'])) {
510 510
 		    foreach ($all_data as $line) {
511 511
 			if ($line != '') {
@@ -532,27 +532,27 @@  discard block
 block discarded – undo
532 532
     	    $last_exec[$id]['last'] = time();
533 533
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
534 534
 	    echo 'download...';
535
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
535
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
536 536
 	    echo 'done !'."\n";
537 537
 	    if ($buffer != '') $reset = 0;
538
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539
-	    $buffer = explode('\n',$buffer);
538
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
539
+	    $buffer = explode('\n', $buffer);
540 540
 	    foreach ($buffer as $line) {
541 541
 		if ($line != '') {
542 542
 		    $data = array();
543
-		    $data['mmsi'] = (int)substr($line,0,9);
544
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
543
+		    $data['mmsi'] = (int) substr($line, 0, 9);
544
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
545 545
 		    //$data['status'] = substr($line,21,2);
546 546
 		    //$data['type'] = substr($line,24,3);
547
-		    $data['latitude'] = substr($line,29,9);
548
-		    $data['longitude'] = substr($line,41,9);
549
-		    $data['speed'] = round(substr($line,51,5));
547
+		    $data['latitude'] = substr($line, 29, 9);
548
+		    $data['longitude'] = substr($line, 41, 9);
549
+		    $data['speed'] = round(substr($line, 51, 5));
550 550
 		    //$data['course'] = substr($line,57,5);
551
-		    $data['heading'] = round(substr($line,63,3));
551
+		    $data['heading'] = round(substr($line, 63, 3));
552 552
 		    //$data['draft'] = substr($line,67,4);
553 553
 		    //$data['length'] = substr($line,72,3);
554 554
 		    //$data['beam'] = substr($line,76,2);
555
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
555
+		    $data['ident'] = trim(utf8_encode(substr($line, 79, 20)));
556 556
 		    //$data['callsign'] = trim(substr($line,100,7);
557 557
 		    //$data['dest'] = substr($line,108,20);
558 558
 		    //$data['etaDate'] = substr($line,129,5);
@@ -570,8 +570,8 @@  discard block
 block discarded – undo
570 570
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
571 571
 	    //$buffer = $Common->getData($hosts[$id]);
572 572
 	    $buffer = $Common->getData($value['host']);
573
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
574
-	    $buffer = explode('\n',$buffer);
573
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
574
+	    $buffer = explode('\n', $buffer);
575 575
 	    $reset = 0;
576 576
 	    foreach ($buffer as $line) {
577 577
     		if ($line != '') {
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
583 583
 			$data['pilot_id'] = $line[1];
584 584
 			$data['pilot_name'] = $line[2];
585
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
585
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
586 586
 			$data['ident'] = $line[0]; // ident
587 587
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
588 588
 			$data['speed'] = $line[8]; // speed
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
599 599
 			//if (isset($line[37])) $data['last_update'] = $line[37];
600 600
 		        $data['departure_airport_icao'] = $line[11];
601
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
601
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
602 602
 		        $data['arrival_airport_icao'] = $line[13];
603 603
 			$data['frequency'] = $line[4];
604 604
 			$data['type'] = $line[18];
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
     			$data['id_source'] = $id_source;
608 608
 	    		//$data['arrival_airport_time'] = ;
609 609
 	    		if ($line[9] != '') {
610
-	    		    $aircraft_data = explode('/',$line[9]);
610
+	    		    $aircraft_data = explode('/', $line[9]);
611 611
 	    		    if (isset($aircraft_data[1])) {
612 612
 	    			$data['aircraft_icao'] = $aircraft_data[1];
613 613
 	    		    }
@@ -621,9 +621,9 @@  discard block
 block discarded – undo
621 621
     			if ($line[3] == 'PILOT') $SI->add($data);
622 622
 			elseif ($line[3] == 'ATC') {
623 623
 				//print_r($data);
624
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
625
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
626
-				$typec = substr($data['ident'],-3);
624
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
625
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
626
+				$typec = substr($data['ident'], -3);
627 627
 				if ($typec == 'APP') $data['type'] = 'Approach';
628 628
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
629 629
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
 				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
635 635
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
636 636
 				if (!isset($data['source_name'])) $data['source_name'] = '';
637
-				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']);
637
+				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']);
638 638
 			}
639 639
     			unset($data);
640 640
     		    }
@@ -645,9 +645,9 @@  discard block
 block discarded – undo
645 645
     	    $last_exec[$id]['last'] = time();
646 646
     	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
647 647
     	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
648
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
648
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
649 649
 	    if ($buffer != '') {
650
-	    $all_data = json_decode($buffer,true);
650
+	    $all_data = json_decode($buffer, true);
651 651
 	    if (isset($all_data['acList'])) {
652 652
 		$reset = 0;
653 653
 		foreach ($all_data['acList'] as $line) {
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
704 704
     	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
705 705
 	    $buffer = $Common->getData($value['host']);
706
-	    $all_data = json_decode($buffer,true);
706
+	    $all_data = json_decode($buffer, true);
707 707
 	    if (isset($all_data['planes'])) {
708 708
 		$reset = 0;
709 709
 		foreach ($all_data['planes'] as $key => $line) {
@@ -720,12 +720,12 @@  discard block
 block discarded – undo
720 720
 		    $data['emergency'] = ''; // emergency
721 721
 		    $data['registration'] = $line[2];
722 722
 		    $data['aircraft_icao'] = $line[0];
723
-		    $deparr = explode('-',$line[1]);
723
+		    $deparr = explode('-', $line[1]);
724 724
 		    if (count($deparr) == 2) {
725 725
 			$data['departure_airport_icao'] = $deparr[0];
726 726
 			$data['arrival_airport_icao'] = $deparr[1];
727 727
 		    }
728
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
728
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
729 729
 	    	    $data['format_source'] = 'planeupdatefaa';
730 730
     		    $data['id_source'] = $id_source;
731 731
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
     	    $last_exec[$id]['last'] = time();
738 738
     	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
739 739
 	    $buffer = $Common->getData($value['host']);
740
-	    $all_data = json_decode($buffer,true);
740
+	    $all_data = json_decode($buffer, true);
741 741
 	    if (isset($all_data['states'])) {
742 742
 		$reset = 0;
743 743
 		foreach ($all_data['states'] as $key => $line) {
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
 		    //$data['emergency'] = ''; // emergency
755 755
 		    //$data['registration'] = $line[2];
756 756
 		    //$data['aircraft_icao'] = $line[0];
757
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
757
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
758 758
 	    	    $data['format_source'] = 'opensky';
759 759
     		    $data['id_source'] = $id_source;
760 760
 		    $SI->add($data);
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
     	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
768 768
 	    //$buffer = $Common->getData($hosts[$id]);
769 769
 	    $buffer = $Common->getData($value['host']);
770
-	    $all_data = json_decode($buffer,true);
770
+	    $all_data = json_decode($buffer, true);
771 771
 	    if (!empty($all_data)) $reset = 0;
772 772
 	    foreach ($all_data as $key => $line) {
773 773
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -799,11 +799,11 @@  discard block
 block discarded – undo
799 799
     	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
800 800
     	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
801 801
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
802
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
802
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
803 803
 	    //echo $buffer;
804
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
805
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
806
-	    $all_data = json_decode($buffer,true);
804
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
805
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
806
+	    $all_data = json_decode($buffer, true);
807 807
 	    if (json_last_error() != JSON_ERROR_NONE) {
808 808
 		die(json_last_error_msg());
809 809
 	    }
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
 			//$data['departure_airport_iata'] = $line[11];
827 827
 			//$data['arrival_airport_iata'] = $line[12];
828 828
 	    		//$data['emergency'] = ''; // emergency
829
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
829
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
830 830
 	    		$data['format_source'] = 'radarvirtueljson';
831 831
     			$data['id_source'] = $id_source;
832 832
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -841,14 +841,14 @@  discard block
 block discarded – undo
841 841
     	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
842 842
 	    //$buffer = $Common->getData($hosts[$id]);
843 843
 	    $buffer = $Common->getData($value['host'].'?'.time());
844
-	    $all_data = json_decode(utf8_encode($buffer),true);
844
+	    $all_data = json_decode(utf8_encode($buffer), true);
845 845
 	    
846 846
 	    if (isset($all_data['pireps'])) {
847 847
 		$reset = 0;
848 848
 	        foreach ($all_data['pireps'] as $line) {
849 849
 		    $data = array();
850 850
 		    $data['id'] = $line['id'];
851
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
851
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
852 852
 		    $data['ident'] = $line['callsign']; // ident
853 853
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
854 854
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -877,9 +877,9 @@  discard block
 block discarded – undo
877 877
 			$SI->add($data);
878 878
 		    //    print_r($data);
879 879
     		    } elseif ($line['icon'] == 'ct') {
880
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
881
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
882
-			$typec = substr($data['ident'],-3);
880
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
881
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
882
+			$typec = substr($data['ident'], -3);
883 883
 			$data['type'] = '';
884 884
 			if ($typec == 'APP') $data['type'] = 'Approach';
885 885
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
891 891
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
892 892
 			else $data['type'] = 'Observer';
893
-			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']);
893
+			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']);
894 894
 		    }
895 895
 		    unset($data);
896 896
 		}
@@ -902,14 +902,14 @@  discard block
 block discarded – undo
902 902
 	    //$buffer = $Common->getData($hosts[$id]);
903 903
 	    if ($globalDebug) echo 'Get Data...'."\n";
904 904
 	    $buffer = $Common->getData($value['host']);
905
-	    $all_data = json_decode($buffer,true);
905
+	    $all_data = json_decode($buffer, true);
906 906
 	    if ($buffer != '' && is_array($all_data)) {
907 907
 		$reset = 0;
908 908
 		foreach ($all_data as $line) {
909 909
 	    	    $data = array();
910 910
 	    	    //$data['id'] = $line['id']; // id not usable
911 911
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
912
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
912
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
913 913
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
914 914
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
915 915
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -932,12 +932,12 @@  discard block
 block discarded – undo
932 932
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
933 933
 		    if (isset($line['aircraftname'])) {
934 934
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
935
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
936
-	    		$aircraft_data = explode('-',$line['aircraftname']);
935
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
936
+	    		$aircraft_data = explode('-', $line['aircraftname']);
937 937
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
938 938
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
939 939
 	    		else {
940
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
940
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
941 941
 	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
942 942
 	    		    else $data['aircraft_icao'] = $line['aircraftname'];
943 943
 	    		}
@@ -959,14 +959,14 @@  discard block
 block discarded – undo
959 959
 	    //$buffer = $Common->getData($hosts[$id]);
960 960
 	    if ($globalDebug) echo 'Get Data...'."\n";
961 961
 	    $buffer = $Common->getData($value['host']);
962
-	    $all_data = json_decode($buffer,true);
962
+	    $all_data = json_decode($buffer, true);
963 963
 	    if ($buffer != '' && is_array($all_data)) {
964 964
 		$reset = 0;
965 965
 		foreach ($all_data as $line) {
966 966
 	    	    $data = array();
967 967
 	    	    //$data['id'] = $line['id']; // id not usable
968 968
 	    	    $data['id'] = trim($line['flight_id']);
969
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
969
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
970 970
 	    	    $data['pilot_name'] = $line['pilot_name'];
971 971
 	    	    $data['pilot_id'] = $line['pilot_id'];
972 972
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1017,9 +1017,9 @@  discard block
 block discarded – undo
1017 1017
 		    //$value = $formats[$nb];
1018 1018
 		    $format = $globalSources[$nb]['format'];
1019 1019
         	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3' || $format == 'vrstcp') {
1020
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1020
+        		$buffer = socket_read($r, 6000, PHP_NORMAL_READ);
1021 1021
         	    } else {
1022
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1022
+	    	        $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1023 1023
 	    	    }
1024 1024
         	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1025 1025
         	    //echo $buffer."\n";
@@ -1028,8 +1028,8 @@  discard block
 block discarded – undo
1028 1028
 		    $error = false;
1029 1029
 		    //$SI::del();
1030 1030
 		    if ($format == 'vrstcp') {
1031
-			$buffer = explode('},{',$buffer);
1032
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1031
+			$buffer = explode('},{', $buffer);
1032
+		    } else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1033 1033
 		    // SBS format is CSV format
1034 1034
 		    if ($buffer != '') {
1035 1035
 			$tt[$format] = 0;
@@ -1061,10 +1061,10 @@  discard block
 block discarded – undo
1061 1061
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1062 1062
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1063 1063
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1064
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1064
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1065 1065
 
1066 1066
 			    if (isset($ais_data['timestamp'])) {
1067
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1067
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1068 1068
 			    } else {
1069 1069
 				$data['datetime'] = date('Y-m-d H:i:s');
1070 1070
 			    }
@@ -1075,10 +1075,10 @@  discard block
 block discarded – undo
1075 1075
                         } elseif ($format == 'flightgearsp') {
1076 1076
                     	    //echo $buffer."\n";
1077 1077
                     	    if (strlen($buffer) > 5) {
1078
-				$line = explode(',',$buffer);
1078
+				$line = explode(',', $buffer);
1079 1079
 				$data = array();
1080 1080
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1081
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1081
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1082 1082
 				$data['ident'] = $line[6];
1083 1083
 				$data['aircraft_name'] = $line[7];
1084 1084
 				$data['longitude'] = $line[1];
@@ -1089,21 +1089,21 @@  discard block
 block discarded – undo
1089 1089
 				$data['datetime'] = date('Y-m-d H:i:s');
1090 1090
 				$data['format_source'] = 'flightgearsp';
1091 1091
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1092
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1092
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1093 1093
 			    }
1094 1094
                         } elseif ($format == 'acars') {
1095 1095
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1096 1096
 			    $ACARS->add(trim($buffer));
1097
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1097
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1098 1098
 			    $ACARS->deleteLiveAcarsData();
1099 1099
 			} elseif ($format == 'flightgearmp') {
1100
-			    if (substr($buffer,0,1) != '#') {
1100
+			    if (substr($buffer, 0, 1) != '#') {
1101 1101
 				$data = array();
1102 1102
 				//echo $buffer."\n";
1103
-				$line = explode(' ',$buffer);
1103
+				$line = explode(' ', $buffer);
1104 1104
 				if (count($line) == 11) {
1105
-				    $userserver = explode('@',$line[0]);
1106
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1105
+				    $userserver = explode('@', $line[0]);
1106
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1107 1107
 				    $data['ident'] = $userserver[0];
1108 1108
 				    $data['registration'] = $userserver[0];
1109 1109
 				    $data['latitude'] = $line[4];
@@ -1111,8 +1111,8 @@  discard block
 block discarded – undo
1111 1111
 				    $data['altitude'] = $line[6];
1112 1112
 				    $data['datetime'] = date('Y-m-d H:i:s');
1113 1113
 				    $aircraft_type = $line[10];
1114
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1115
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1114
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1115
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1116 1116
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1117 1117
 				}
1118 1118
 			    }
@@ -1120,8 +1120,8 @@  discard block
 block discarded – undo
1120 1120
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1121 1121
 			    die;
1122 1122
 			} elseif ($format == 'vrstcp') {
1123
-			    foreach($buffer as $all_data) {
1124
-				$line = json_decode('{'.$all_data.'}',true);
1123
+			    foreach ($buffer as $all_data) {
1124
+				$line = json_decode('{'.$all_data.'}', true);
1125 1125
 				$data = array();
1126 1126
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1127 1127
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1146,16 +1146,16 @@  discard block
 block discarded – undo
1146 1146
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1147 1147
 				unset($data);
1148 1148
 			    }
1149
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1149
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1150 1150
 			    $line = explode("\t", $buffer);
1151
-			    for($k = 0; $k < count($line); $k=$k+2) {
1151
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1152 1152
 				$key = $line[$k];
1153
-			        $lined[$key] = $line[$k+1];
1153
+			        $lined[$key] = $line[$k + 1];
1154 1154
 			    }
1155 1155
     			    if (count($lined) > 3) {
1156 1156
     				$data['hex'] = $lined['hexid'];
1157 1157
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1158
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1158
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1159 1159
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1160 1160
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1161 1161
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1173,22 +1173,22 @@  discard block
 block discarded – undo
1173 1173
     			    } else $error = true;
1174 1174
 			} elseif ($format == 'aprs' && $use_aprs) {
1175 1175
 			    if ($aprs_connect == 0) {
1176
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1176
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1177 1177
 				$aprs_connect = 1;
1178 1178
 			    }
1179 1179
 			    
1180
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1180
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1181 1181
 				$aprs_last_tx = time();
1182 1182
 				$data_aprs = "# Keep alive";
1183
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1183
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1184 1184
 			    }
1185 1185
 			    
1186 1186
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1187 1187
 			    //echo 'APRS data : '.$buffer."\n";
1188
-			    $buffer = str_replace('APRS <- ','',$buffer);
1189
-			    $buffer = str_replace('APRS -> ','',$buffer);
1188
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1189
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1190 1190
 			    //echo $buffer."\n";
1191
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1191
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1192 1192
 				$line = $APRS->parse($buffer);
1193 1193
 				//print_r($line);
1194 1194
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
@@ -1197,7 +1197,7 @@  discard block
 block discarded – undo
1197 1197
 				    $data = array();
1198 1198
 				    //print_r($line);
1199 1199
 				    if (isset($line['address'])) $data['hex'] = $line['address'];
1200
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1200
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1201 1201
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1202 1202
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1203 1203
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1223,7 +1223,7 @@  discard block
 block discarded – undo
1223 1223
 				    $currentdate = date('Y-m-d H:i:s');
1224 1224
 				    $aprsdate = strtotime($data['datetime']);
1225 1225
 				    // Accept data if time <= system time + 20s
1226
-				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1226
+				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate) + 20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1227 1227
 					$send = $SI->add($data);
1228 1228
 				    } elseif (isset($line['stealth'])) {
1229 1229
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
@@ -1320,7 +1320,7 @@  discard block
 block discarded – undo
1320 1320
 				connect_all($sourceee);
1321 1321
 				$sourceee = array();
1322 1322
 				//connect_all($globalSources);
1323
-				$tt[$format]=0;
1323
+				$tt[$format] = 0;
1324 1324
 				break;
1325 1325
 			    }
1326 1326
 			}
@@ -1329,14 +1329,14 @@  discard block
 block discarded – undo
1329 1329
 	    } else {
1330 1330
 		$error = socket_strerror(socket_last_error());
1331 1331
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1332
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1332
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1333 1333
 			if (isset($globalDebug)) echo "Restarting...\n";
1334 1334
 			// Restart the script if possible
1335 1335
 			if (is_array($sockets)) {
1336 1336
 			    if ($globalDebug) echo "Shutdown all sockets...";
1337 1337
 			    
1338 1338
 			    foreach ($sockets as $sock) {
1339
-				@socket_shutdown($sock,2);
1339
+				@socket_shutdown($sock, 2);
1340 1340
 				@socket_close($sock);
1341 1341
 			    }
1342 1342
 			    
Please login to merge, or discard this patch.
Braces   +775 added lines, -264 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,22 +63,39 @@  discard block
 block discarded – undo
59 63
     $globalSources = array();
60 64
     $globalSources[] = array('host' => $options['source']);
61 65
 }
62
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
63
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
64
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
65
-if (isset($options['server'])) $globalServer = TRUE;
66
-if (isset($options['idsource'])) $id_source = $options['idsource'];
67
-else $id_source = 1;
66
+if (isset($options['aprsserverssid'])) {
67
+	$globalServerAPRSssid = $options['aprsserverssid'];
68
+}
69
+if (isset($options['aprsserverpass'])) {
70
+	$globalServerAPRSpass = $options['aprsserverpass'];
71
+}
72
+if (isset($options['nodaemon'])) {
73
+	$globalDaemon = FALSE;
74
+}
75
+if (isset($options['server'])) {
76
+	$globalServer = TRUE;
77
+}
78
+if (isset($options['idsource'])) {
79
+	$id_source = $options['idsource'];
80
+} else {
81
+	$id_source = 1;
82
+}
68 83
 if (isset($globalServer) && $globalServer) {
69
-    if ($globalDebug) echo "Using Server Mode\n";
84
+    if ($globalDebug) {
85
+    	echo "Using Server Mode\n";
86
+    }
70 87
     $SI=new SpotterServer();
71 88
 /*
72 89
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
73 90
     $SI = new adsb2aprs();
74 91
     $SI->connect();
75 92
 */
76
-} else $SI=new SpotterImport($Connection->db);
77
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
93
+} else {
94
+	$SI=new SpotterImport($Connection->db);
95
+}
96
+if (isset($globalTracker) && $globalTracker) {
97
+	$TI = new TrackerImport($Connection->db);
98
+}
78 99
 if (isset($globalMarine) && $globalMarine) {
79 100
     $AIS = new AIS();
80 101
     $MI = new MarineImport($Connection->db);
@@ -96,7 +117,9 @@  discard block
 block discarded – undo
96 117
 }
97 118
 
98 119
 // let's try and connect
99
-if ($globalDebug) echo "Connecting...\n";
120
+if ($globalDebug) {
121
+	echo "Connecting...\n";
122
+}
100 123
 $use_aprs = false;
101 124
 $aprs_full = false;
102 125
 $reset = 0;
@@ -105,7 +128,9 @@  discard block
 block discarded – undo
105 128
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
106 129
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
107 130
     $reset++;
108
-    if ($globalDebug) echo 'Connect to all...'."\n";
131
+    if ($globalDebug) {
132
+    	echo 'Connect to all...'."\n";
133
+    }
109 134
     foreach ($hosts as $id => $value) {
110 135
 	$host = $value['host'];
111 136
 	$globalSources[$id]['last_exec'] = 0;
@@ -115,27 +140,37 @@  discard block
 block discarded – undo
115 140
         	//$formats[$id] = 'deltadbtxt';
116 141
         	$globalSources[$id]['format'] = 'deltadbtxt';
117 142
         	//$last_exec['deltadbtxt'] = 0;
118
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
143
+        	if ($globalDebug) {
144
+        		echo "Connect to deltadb source (".$host.")...\n";
145
+        	}
119 146
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
120 147
         	//$formats[$id] = 'vatsimtxt';
121 148
         	$globalSources[$id]['format'] = 'vatsimtxt';
122 149
         	//$last_exec['vatsimtxt'] = 0;
123
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
150
+        	if ($globalDebug) {
151
+        		echo "Connect to vatsim source (".$host.")...\n";
152
+        	}
124 153
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
125 154
         	//$formats[$id] = 'aircraftlistjson';
126 155
         	$globalSources[$id]['format'] = 'aircraftlistjson';
127 156
         	//$last_exec['aircraftlistjson'] = 0;
128
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
157
+        	if ($globalDebug) {
158
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
159
+        	}
129 160
     	    } else if (preg_match('/opensky/i',$host)) {
130 161
         	//$formats[$id] = 'aircraftlistjson';
131 162
         	$globalSources[$id]['format'] = 'opensky';
132 163
         	//$last_exec['aircraftlistjson'] = 0;
133
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
164
+        	if ($globalDebug) {
165
+        		echo "Connect to opensky source (".$host.")...\n";
166
+        	}
134 167
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
135 168
         	//$formats[$id] = 'radarvirtueljson';
136 169
         	$globalSources[$id]['format'] = 'radarvirtueljson';
137 170
         	//$last_exec['radarvirtueljson'] = 0;
138
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
171
+        	if ($globalDebug) {
172
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
173
+        	}
139 174
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
140 175
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
141 176
         	    exit(0);
@@ -144,7 +179,9 @@  discard block
 block discarded – undo
144 179
         	//$formats[$id] = 'planeupdatefaa';
145 180
         	$globalSources[$id]['format'] = 'planeupdatefaa';
146 181
         	//$last_exec['planeupdatefaa'] = 0;
147
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
182
+        	if ($globalDebug) {
183
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
184
+        	}
148 185
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
149 186
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
150 187
         	    exit(0);
@@ -153,26 +190,36 @@  discard block
 block discarded – undo
153 190
         	//$formats[$id] = 'phpvmacars';
154 191
         	$globalSources[$id]['format'] = 'phpvmacars';
155 192
         	//$last_exec['phpvmacars'] = 0;
156
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
193
+        	if ($globalDebug) {
194
+        		echo "Connect to phpvmacars source (".$host.")...\n";
195
+        	}
157 196
             } else if (preg_match('/VAM-json.php$/i',$host)) {
158 197
         	//$formats[$id] = 'phpvmacars';
159 198
         	$globalSources[$id]['format'] = 'vam';
160
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
199
+        	if ($globalDebug) {
200
+        		echo "Connect to Vam source (".$host.")...\n";
201
+        	}
161 202
             } else if (preg_match('/whazzup/i',$host)) {
162 203
         	//$formats[$id] = 'whazzup';
163 204
         	$globalSources[$id]['format'] = 'whazzup';
164 205
         	//$last_exec['whazzup'] = 0;
165
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
206
+        	if ($globalDebug) {
207
+        		echo "Connect to whazzup source (".$host.")...\n";
208
+        	}
166 209
             } else if (preg_match('/recentpireps/i',$host)) {
167 210
         	//$formats[$id] = 'pirepsjson';
168 211
         	$globalSources[$id]['format'] = 'pirepsjson';
169 212
         	//$last_exec['pirepsjson'] = 0;
170
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
213
+        	if ($globalDebug) {
214
+        		echo "Connect to pirepsjson source (".$host.")...\n";
215
+        	}
171 216
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
172 217
         	//$formats[$id] = 'fr24json';
173 218
         	$globalSources[$id]['format'] = 'fr24json';
174 219
         	//$last_exec['fr24json'] = 0;
175
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
220
+        	if ($globalDebug) {
221
+        		echo "Connect to fr24 source (".$host.")...\n";
222
+        	}
176 223
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
177 224
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
178 225
         	    exit(0);
@@ -181,7 +228,9 @@  discard block
 block discarded – undo
181 228
         	//$formats[$id] = 'fr24json';
182 229
         	$globalSources[$id]['format'] = 'myshiptracking';
183 230
         	//$last_exec['fr24json'] = 0;
184
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
231
+        	if ($globalDebug) {
232
+        		echo "Connect to myshiptracking source (".$host.")...\n";
233
+        	}
185 234
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
186 235
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
187 236
         	    exit(0);
@@ -190,17 +239,24 @@  discard block
 block discarded – undo
190 239
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
191 240
         	//$formats[$id] = 'tsv';
192 241
         	$globalSources[$id]['format'] = 'tsv';
193
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
242
+        	if ($globalDebug) {
243
+        		echo "Connect to tsv source (".$host.")...\n";
244
+        	}
194 245
             }
195 246
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
196 247
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
197 248
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
198 249
     		    if ($idf !== false) {
199 250
     			$httpfeeds[$id] = $idf;
200
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
251
+        		if ($globalDebug) {
252
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
253
+        		}
254
+    		    } elseif ($globalDebug) {
255
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
201 256
     		    }
202
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
203
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
257
+    		} elseif ($globalDebug) {
258
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
259
+    		}
204 260
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
205 261
 	    $hostport = explode(':',$host);
206 262
 	    if (isset($hostport[1])) {
@@ -240,17 +296,25 @@  discard block
 block discarded – undo
240 296
         		//$formats[$id] = 'beast';
241 297
         		$globalSources[$id]['format'] = 'beast';
242 298
 		    //} else $formats[$id] = 'sbs';
243
-		    } else $globalSources[$id]['format'] = 'sbs';
299
+		    } else {
300
+		    	$globalSources[$id]['format'] = 'sbs';
301
+		    }
244 302
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
245 303
 		}
246
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
304
+		if ($globalDebug) {
305
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
306
+		}
247 307
             } else {
248
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
308
+		if ($globalDebug) {
309
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
310
+		}
249 311
     	    }
250 312
         }
251 313
     }
252 314
 }
253
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
315
+if (!isset($globalMinFetch)) {
316
+	$globalMinFetch = 15;
317
+}
254 318
 
255 319
 // Initialize all
256 320
 $status = array();
@@ -259,13 +323,19 @@  discard block
 block discarded – undo
259 323
 $formats = array();
260 324
 $last_exec = array();
261 325
 $time = time();
262
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
263
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
264
-else $timeout = 20;
326
+if (isset($globalSourcesTimeout)) {
327
+	$timeout = $globalSourcesTimeOut;
328
+} else if (isset($globalSBS1TimeOut)) {
329
+	$timeout = $globalSBS1TimeOut;
330
+} else {
331
+	$timeout = 20;
332
+}
265 333
 $errno = '';
266 334
 $errstr='';
267 335
 
268
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
336
+if (!isset($globalDaemon)) {
337
+	$globalDaemon = TRUE;
338
+}
269 339
 /* Initiate connections to all the hosts simultaneously */
270 340
 //connect_all($hosts);
271 341
 //connect_all($globalSources);
@@ -291,7 +361,9 @@  discard block
 block discarded – undo
291 361
     if (isset($source['format']) && $source['format'] == 'aprs') {
292 362
 	$aprs_connect = 0;
293 363
 	$use_aprs = true;
294
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
364
+	if (isset($source['port']) && $source['port'] == '10152') {
365
+		$aprs_full = true;
366
+	}
295 367
 	break;
296 368
     }
297 369
 }
@@ -302,26 +374,49 @@  discard block
 block discarded – undo
302 374
 	$aprs_connect = 0;
303 375
 	$aprs_keep = 120;
304 376
 	$aprs_last_tx = time();
305
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
306
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
307
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
308
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
309
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
310
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
311
-	if ($aprs_full) $aprs_filter = '';
312
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
313
-	else $aprs_pass = '-1';
377
+	if (isset($globalAPRSversion)) {
378
+		$aprs_version = $globalAPRSversion;
379
+	} else {
380
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
381
+	}
382
+	if (isset($globalAPRSssid)) {
383
+		$aprs_ssid = $globalAPRSssid;
384
+	} else {
385
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
386
+	}
387
+	if (isset($globalAPRSfilter)) {
388
+		$aprs_filter = $globalAPRSfilter;
389
+	} else {
390
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
391
+	}
392
+	if ($aprs_full) {
393
+		$aprs_filter = '';
394
+	}
395
+	if (isset($globalAPRSpass)) {
396
+		$aprs_pass = $globalAPRSpass;
397
+	} else {
398
+		$aprs_pass = '-1';
399
+	}
314 400
 
315
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
316
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
401
+	if ($aprs_filter != '') {
402
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
403
+	} else {
404
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
405
+	}
317 406
 	echo $aprs_login."\n";
318 407
 }
319 408
 
320 409
 // connected - lets do some work
321
-if ($globalDebug) echo "Connected!\n";
410
+if ($globalDebug) {
411
+	echo "Connected!\n";
412
+}
322 413
 sleep(1);
323
-if ($globalDebug) echo "SCAN MODE \n\n";
324
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
414
+if ($globalDebug) {
415
+	echo "SCAN MODE \n\n";
416
+}
417
+if (!isset($globalCronEnd)) {
418
+	$globalCronEnd = 60;
419
+}
325 420
 $endtime = time()+$globalCronEnd;
326 421
 $i = 1;
327 422
 $tt = array();
@@ -335,10 +430,14 @@  discard block
 block discarded – undo
335 430
 
336 431
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
337 432
 while ($i > 0) {
338
-    if (!$globalDaemon) $i = $endtime-time();
433
+    if (!$globalDaemon) {
434
+    	$i = $endtime-time();
435
+    }
339 436
     // Delete old ATC
340 437
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
341
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
438
+	if ($globalDebug) {
439
+		echo 'Delete old ATC...'."\n";
440
+	}
342 441
         $ATC->deleteOldATC();
343 442
     }
344 443
     
@@ -346,10 +445,14 @@  discard block
 block discarded – undo
346 445
     if (count($last_exec) == count($globalSources)) {
347 446
 	$max = $globalMinFetch;
348 447
 	foreach ($last_exec as $last) {
349
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
448
+	    if ((time() - $last['last']) < $max) {
449
+	    	$max = time() - $last['last'];
450
+	    }
350 451
 	}
351 452
 	if ($max != $globalMinFetch) {
352
-	    if ($globalDebug) echo 'Sleeping...'."\n";
453
+	    if ($globalDebug) {
454
+	    	echo 'Sleeping...'."\n";
455
+	    }
353 456
 	    sleep($globalMinFetch-$max+2);
354 457
 	}
355 458
     }
@@ -358,11 +461,15 @@  discard block
 block discarded – undo
358 461
     //foreach ($formats as $id => $value) {
359 462
     foreach ($globalSources as $id => $value) {
360 463
 	date_default_timezone_set('UTC');
361
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
464
+	if (!isset($last_exec[$id]['last'])) {
465
+		$last_exec[$id]['last'] = 0;
466
+	}
362 467
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
363 468
 	    //$buffer = $Common->getData($hosts[$id]);
364 469
 	    $buffer = $Common->getData($value['host']);
365
-	    if ($buffer != '') $reset = 0;
470
+	    if ($buffer != '') {
471
+	    	$reset = 0;
472
+	    }
366 473
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
367 474
 	    $buffer = explode('\n',$buffer);
368 475
 	    foreach ($buffer as $line) {
@@ -371,19 +478,38 @@  discard block
 block discarded – undo
371 478
 	            $data = array();
372 479
 	            $data['hex'] = $line[1]; // hex
373 480
 	            $data['ident'] = $line[2]; // ident
374
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
375
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
376
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
377
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
378
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
481
+	            if (isset($line[3])) {
482
+	            	$data['altitude'] = $line[3];
483
+	            }
484
+	            // altitude
485
+	            if (isset($line[4])) {
486
+	            	$data['speed'] = $line[4];
487
+	            }
488
+	            // speed
489
+	            if (isset($line[5])) {
490
+	            	$data['heading'] = $line[5];
491
+	            }
492
+	            // heading
493
+	            if (isset($line[6])) {
494
+	            	$data['latitude'] = $line[6];
495
+	            }
496
+	            // lat
497
+	            if (isset($line[7])) {
498
+	            	$data['longitude'] = $line[7];
499
+	            }
500
+	            // long
379 501
 	            $data['verticalrate'] = ''; // vertical rate
380 502
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
381 503
 	            $data['emergency'] = ''; // emergency
382 504
 		    $data['datetime'] = date('Y-m-d H:i:s');
383 505
 		    $data['format_source'] = 'deltadbtxt';
384 506
     		    $data['id_source'] = $id_source;
385
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
386
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
507
+		    if (isset($value['name']) && $value['name'] != '') {
508
+		    	$data['source_name'] = $value['name'];
509
+		    }
510
+		    if (isset($value['sourcestats'])) {
511
+		    	$data['sourcestats'] = $value['sourcestats'];
512
+		    }
387 513
     		    $SI->add($data);
388 514
 		    unset($data);
389 515
     		}
@@ -393,7 +519,9 @@  discard block
 block discarded – undo
393 519
 	    date_default_timezone_set('CET');
394 520
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
395 521
 	    date_default_timezone_set('UTC');
396
-	    if ($buffer != '') $reset = 0;
522
+	    if ($buffer != '') {
523
+	    	$reset = 0;
524
+	    }
397 525
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
398 526
 	    $buffer = explode('\n',$buffer);
399 527
 	    foreach ($buffer as $line) {
@@ -402,16 +530,36 @@  discard block
 block discarded – undo
402 530
 		    $add = false;
403 531
 		    $ais_data = $AIS->parse_line(trim($line));
404 532
 		    $data = array();
405
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
406
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
407
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
408
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
409
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
410
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
411
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
412
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
413
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
414
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
533
+		    if (isset($ais_data['ident'])) {
534
+		    	$data['ident'] = $ais_data['ident'];
535
+		    }
536
+		    if (isset($ais_data['mmsi'])) {
537
+		    	$data['mmsi'] = $ais_data['mmsi'];
538
+		    }
539
+		    if (isset($ais_data['speed'])) {
540
+		    	$data['speed'] = $ais_data['speed'];
541
+		    }
542
+		    if (isset($ais_data['heading'])) {
543
+		    	$data['heading'] = $ais_data['heading'];
544
+		    }
545
+		    if (isset($ais_data['latitude'])) {
546
+		    	$data['latitude'] = $ais_data['latitude'];
547
+		    }
548
+		    if (isset($ais_data['longitude'])) {
549
+		    	$data['longitude'] = $ais_data['longitude'];
550
+		    }
551
+		    if (isset($ais_data['status'])) {
552
+		    	$data['status'] = $ais_data['status'];
553
+		    }
554
+		    if (isset($ais_data['type'])) {
555
+		    	$data['type'] = $ais_data['type'];
556
+		    }
557
+		    if (isset($ais_data['imo'])) {
558
+		    	$data['imo'] = $ais_data['imo'];
559
+		    }
560
+		    if (isset($ais_data['callsign'])) {
561
+		    	$data['callsign'] = $ais_data['callsign'];
562
+		    }
415 563
 		    if (isset($ais_data['timestamp'])) {
416 564
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
417 565
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -426,7 +574,9 @@  discard block
 block discarded – undo
426 574
     		    $data['id_source'] = $id_source;
427 575
 		    print_r($data);
428 576
 		    echo 'Add...'."\n";
429
-		    if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
577
+		    if ($add && $ais_data['mmsi_type'] == 'Ship') {
578
+		    	$MI->add($data);
579
+		    }
430 580
 		    unset($data);
431 581
 		}
432 582
     	    }
@@ -446,18 +596,42 @@  discard block
 block discarded – undo
446 596
 			if ($line != '') {
447 597
 			    $ais_data = $AIS->parse_line(trim($line));
448 598
 			    $data = array();
449
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
450
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
451
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
452
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
453
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
454
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
455
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
456
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
457
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
458
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
459
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
460
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
599
+			    if (isset($ais_data['ident'])) {
600
+			    	$data['ident'] = $ais_data['ident'];
601
+			    }
602
+			    if (isset($ais_data['mmsi'])) {
603
+			    	$data['mmsi'] = $ais_data['mmsi'];
604
+			    }
605
+			    if (isset($ais_data['speed'])) {
606
+			    	$data['speed'] = $ais_data['speed'];
607
+			    }
608
+			    if (isset($ais_data['heading'])) {
609
+			    	$data['heading'] = $ais_data['heading'];
610
+			    }
611
+			    if (isset($ais_data['latitude'])) {
612
+			    	$data['latitude'] = $ais_data['latitude'];
613
+			    }
614
+			    if (isset($ais_data['longitude'])) {
615
+			    	$data['longitude'] = $ais_data['longitude'];
616
+			    }
617
+			    if (isset($ais_data['status'])) {
618
+			    	$data['status'] = $ais_data['status'];
619
+			    }
620
+			    if (isset($ais_data['type'])) {
621
+			    	$data['type'] = $ais_data['type'];
622
+			    }
623
+			    if (isset($ais_data['imo'])) {
624
+			    	$data['imo'] = $ais_data['imo'];
625
+			    }
626
+			    if (isset($ais_data['callsign'])) {
627
+			    	$data['callsign'] = $ais_data['callsign'];
628
+			    }
629
+			    if (isset($ais_data['destination'])) {
630
+			    	$data['arrival_code'] = $ais_data['destination'];
631
+			    }
632
+			    if (isset($ais_data['eta_ts'])) {
633
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
634
+			    }
461 635
 			    if (isset($ais_data['timestamp'])) {
462 636
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
463 637
 			    } else {
@@ -465,7 +639,9 @@  discard block
 block discarded – undo
465 639
 			    }
466 640
 			    $data['format_source'] = 'aisnmeahttp';
467 641
 			    $data['id_source'] = $id_source;
468
-			    if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
642
+			    if ($ais_data['mmsi_type'] == 'Ship') {
643
+			    	$MI->add($data);
644
+			    }
469 645
 			    unset($data);
470 646
 			}
471 647
 		    }
@@ -514,7 +690,9 @@  discard block
 block discarded – undo
514 690
 			    $data['callsign'] = $line['callsign'];
515 691
 			    $data['mmsi'] = $line['mmsi'];
516 692
 			    $data['speed'] = $line['sog'];
517
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
693
+			    if ($line['heading'] != '511') {
694
+			    	$data['heading'] = $line['heading'];
695
+			    }
518 696
 			    $data['latitude'] = $line['latitude'];
519 697
 			    $data['longitude'] = $line['longitude'];
520 698
 			    $data['type_id'] = $line['shiptype'];
@@ -534,7 +712,9 @@  discard block
 block discarded – undo
534 712
 	    echo 'download...';
535 713
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
536 714
 	    echo 'done !'."\n";
537
-	    if ($buffer != '') $reset = 0;
715
+	    if ($buffer != '') {
716
+	    	$reset = 0;
717
+	    }
538 718
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539 719
 	    $buffer = explode('\n',$buffer);
540 720
 	    foreach ($buffer as $line) {
@@ -578,16 +758,28 @@  discard block
 block discarded – undo
578 758
     		    $line = explode(':', $line);
579 759
     		    if (count($line) > 30 && $line[0] != 'callsign') {
580 760
 			$data = array();
581
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
582
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
761
+			if (isset($line[37]) && $line[37] != '') {
762
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
763
+			} else {
764
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
765
+			}
583 766
 			$data['pilot_id'] = $line[1];
584 767
 			$data['pilot_name'] = $line[2];
585 768
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
586 769
 			$data['ident'] = $line[0]; // ident
587
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
770
+			if ($line[7] != '' && $line[7] != 0) {
771
+				$data['altitude'] = $line[7];
772
+			}
773
+			// altitude
588 774
 			$data['speed'] = $line[8]; // speed
589
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
590
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
775
+			if (isset($line[45])) {
776
+				$data['heading'] = $line[45];
777
+			}
778
+			// heading
779
+			elseif (isset($line[38])) {
780
+				$data['heading'] = $line[38];
781
+			}
782
+			// heading
591 783
 			$data['latitude'] = $line[5]; // lat
592 784
 	        	$data['longitude'] = $line[6]; // long
593 785
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -603,7 +795,9 @@  discard block
 block discarded – undo
603 795
 			$data['frequency'] = $line[4];
604 796
 			$data['type'] = $line[18];
605 797
 			$data['range'] = $line[19];
606
-			if (isset($line[35])) $data['info'] = $line[35];
798
+			if (isset($line[35])) {
799
+				$data['info'] = $line[35];
800
+			}
607 801
     			$data['id_source'] = $id_source;
608 802
 	    		//$data['arrival_airport_time'] = ;
609 803
 	    		if ($line[9] != '') {
@@ -617,24 +811,41 @@  discard block
 block discarded – undo
617 811
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
618 812
 	    		*/
619 813
 	    		$data['format_source'] = $value['format'];
620
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
621
-    			if ($line[3] == 'PILOT') $SI->add($data);
622
-			elseif ($line[3] == 'ATC') {
814
+			if (isset($value['name']) && $value['name'] != '') {
815
+				$data['source_name'] = $value['name'];
816
+			}
817
+    			if ($line[3] == 'PILOT') {
818
+    				$SI->add($data);
819
+    			} elseif ($line[3] == 'ATC') {
623 820
 				//print_r($data);
624 821
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
625 822
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
626 823
 				$typec = substr($data['ident'],-3);
627
-				if ($typec == 'APP') $data['type'] = 'Approach';
628
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
629
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
630
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
631
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
632
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
633
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
634
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
635
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
636
-				if (!isset($data['source_name'])) $data['source_name'] = '';
637
-				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']);
824
+				if ($typec == 'APP') {
825
+					$data['type'] = 'Approach';
826
+				} elseif ($typec == 'TWR') {
827
+					$data['type'] = 'Tower';
828
+				} elseif ($typec == 'OBS') {
829
+					$data['type'] = 'Observer';
830
+				} elseif ($typec == 'GND') {
831
+					$data['type'] = 'Ground';
832
+				} elseif ($typec == 'DEL') {
833
+					$data['type'] = 'Delivery';
834
+				} elseif ($typec == 'DEP') {
835
+					$data['type'] = 'Departure';
836
+				} elseif ($typec == 'FSS') {
837
+					$data['type'] = 'Flight Service Station';
838
+				} elseif ($typec == 'CTR') {
839
+					$data['type'] = 'Control Radar or Centre';
840
+				} elseif ($data['type'] == '') {
841
+					$data['type'] = 'Observer';
842
+				}
843
+				if (!isset($data['source_name'])) {
844
+					$data['source_name'] = '';
845
+				}
846
+				if (isset($ATC)) {
847
+					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']);
848
+				}
638 849
 			}
639 850
     			unset($data);
640 851
     		    }
@@ -653,26 +864,55 @@  discard block
 block discarded – undo
653 864
 		foreach ($all_data['acList'] as $line) {
654 865
 		    $data = array();
655 866
 		    $data['hex'] = $line['Icao']; // hex
656
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
657
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
658
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
659
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
660
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
661
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
867
+		    if (isset($line['Call'])) {
868
+		    	$data['ident'] = $line['Call'];
869
+		    }
870
+		    // ident
871
+		    if (isset($line['Alt'])) {
872
+		    	$data['altitude'] = $line['Alt'];
873
+		    }
874
+		    // altitude
875
+		    if (isset($line['Spd'])) {
876
+		    	$data['speed'] = $line['Spd'];
877
+		    }
878
+		    // speed
879
+		    if (isset($line['Trak'])) {
880
+		    	$data['heading'] = $line['Trak'];
881
+		    }
882
+		    // heading
883
+		    if (isset($line['Lat'])) {
884
+		    	$data['latitude'] = $line['Lat'];
885
+		    }
886
+		    // lat
887
+		    if (isset($line['Long'])) {
888
+		    	$data['longitude'] = $line['Long'];
889
+		    }
890
+		    // long
662 891
 		    //$data['verticalrate'] = $line['']; // verticale rate
663
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
892
+		    if (isset($line['Sqk'])) {
893
+		    	$data['squawk'] = $line['Sqk'];
894
+		    }
895
+		    // squawk
664 896
 		    $data['emergency'] = ''; // emergency
665
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
897
+		    if (isset($line['Reg'])) {
898
+		    	$data['registration'] = $line['Reg'];
899
+		    }
666 900
 		    /*
667 901
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
668 902
 		    else $data['datetime'] = date('Y-m-d H:i:s');
669 903
 		    */
670 904
 		    $data['datetime'] = date('Y-m-d H:i:s');
671
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
905
+		    if (isset($line['Type'])) {
906
+		    	$data['aircraft_icao'] = $line['Type'];
907
+		    }
672 908
 	    	    $data['format_source'] = 'aircraftlistjson';
673 909
 		    $data['id_source'] = $id_source;
674
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
675
-		    if (isset($data['latitude'])) $SI->add($data);
910
+		    if (isset($value['name']) && $value['name'] != '') {
911
+		    	$data['source_name'] = $value['name'];
912
+		    }
913
+		    if (isset($data['latitude'])) {
914
+		    	$SI->add($data);
915
+		    }
676 916
 		    unset($data);
677 917
 		}
678 918
 	    } elseif (is_array($all_data)) {
@@ -692,7 +932,9 @@  discard block
 block discarded – undo
692 932
 		    $data['datetime'] = date('Y-m-d H:i:s');
693 933
 	    	    $data['format_source'] = 'aircraftlistjson';
694 934
     		    $data['id_source'] = $id_source;
695
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
935
+		    if (isset($value['name']) && $value['name'] != '') {
936
+		    	$data['source_name'] = $value['name'];
937
+		    }
696 938
 		    $SI->add($data);
697 939
 		    unset($data);
698 940
 		}
@@ -728,7 +970,9 @@  discard block
 block discarded – undo
728 970
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
729 971
 	    	    $data['format_source'] = 'planeupdatefaa';
730 972
     		    $data['id_source'] = $id_source;
731
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
973
+		    if (isset($value['name']) && $value['name'] != '') {
974
+		    	$data['source_name'] = $value['name'];
975
+		    }
732 976
 		    $SI->add($data);
733 977
 		    unset($data);
734 978
 		}
@@ -768,7 +1012,9 @@  discard block
 block discarded – undo
768 1012
 	    //$buffer = $Common->getData($hosts[$id]);
769 1013
 	    $buffer = $Common->getData($value['host']);
770 1014
 	    $all_data = json_decode($buffer,true);
771
-	    if (!empty($all_data)) $reset = 0;
1015
+	    if (!empty($all_data)) {
1016
+	    	$reset = 0;
1017
+	    }
772 1018
 	    foreach ($all_data as $key => $line) {
773 1019
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
774 1020
 		    $data = array();
@@ -789,7 +1035,9 @@  discard block
 block discarded – undo
789 1035
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
790 1036
 	    	    $data['format_source'] = 'fr24json';
791 1037
     		    $data['id_source'] = $id_source;
792
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1038
+		    if (isset($value['name']) && $value['name'] != '') {
1039
+		    	$data['source_name'] = $value['name'];
1040
+		    }
793 1041
 		    $SI->add($data);
794 1042
 		    unset($data);
795 1043
 		}
@@ -813,23 +1061,39 @@  discard block
 block discarded – undo
813 1061
 		    if (isset($line['inf'])) {
814 1062
 			$data = array();
815 1063
 			$data['hex'] = $line['inf']['ia'];
816
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1064
+			if (isset($line['inf']['cs'])) {
1065
+				$data['ident'] = $line['inf']['cs'];
1066
+			}
1067
+			//$line[13]
817 1068
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
818
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
819
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1069
+	    		if (isset($line['inf']['gs'])) {
1070
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1071
+	    		}
1072
+	    		// speed
1073
+	    		if (isset($line['inf']['tr'])) {
1074
+	    			$data['heading'] = $line['inf']['tr'];
1075
+	    		}
1076
+	    		// heading
820 1077
 	    		$data['latitude'] = $line['pt'][0]; // lat
821 1078
 	    		$data['longitude'] = $line['pt'][1]; // long
822 1079
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
823
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1080
+	    		if (isset($line['inf']['sq'])) {
1081
+	    			$data['squawk'] = $line['inf']['sq'];
1082
+	    		}
1083
+	    		// squawk
824 1084
 	    		//$data['aircraft_icao'] = $line[8];
825
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1085
+	    		if (isset($line['inf']['rc'])) {
1086
+	    			$data['registration'] = $line['inf']['rc'];
1087
+	    		}
826 1088
 			//$data['departure_airport_iata'] = $line[11];
827 1089
 			//$data['arrival_airport_iata'] = $line[12];
828 1090
 	    		//$data['emergency'] = ''; // emergency
829 1091
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
830 1092
 	    		$data['format_source'] = 'radarvirtueljson';
831 1093
     			$data['id_source'] = $id_source;
832
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1094
+			if (isset($value['name']) && $value['name'] != '') {
1095
+				$data['source_name'] = $value['name'];
1096
+			}
833 1097
 			$SI->add($data);
834 1098
 			unset($data);
835 1099
 		    }
@@ -850,29 +1114,62 @@  discard block
 block discarded – undo
850 1114
 		    $data['id'] = $line['id'];
851 1115
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
852 1116
 		    $data['ident'] = $line['callsign']; // ident
853
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
854
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
855
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
856
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
857
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
858
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1117
+		    if (isset($line['pilotid'])) {
1118
+		    	$data['pilot_id'] = $line['pilotid'];
1119
+		    }
1120
+		    // pilot id
1121
+		    if (isset($line['name'])) {
1122
+		    	$data['pilot_name'] = $line['name'];
1123
+		    }
1124
+		    // pilot name
1125
+		    if (isset($line['alt'])) {
1126
+		    	$data['altitude'] = $line['alt'];
1127
+		    }
1128
+		    // altitude
1129
+		    if (isset($line['gs'])) {
1130
+		    	$data['speed'] = $line['gs'];
1131
+		    }
1132
+		    // speed
1133
+		    if (isset($line['heading'])) {
1134
+		    	$data['heading'] = $line['heading'];
1135
+		    }
1136
+		    // heading
1137
+		    if (isset($line['route'])) {
1138
+		    	$data['waypoints'] = $line['route'];
1139
+		    }
1140
+		    // route
859 1141
 		    $data['latitude'] = $line['lat']; // lat
860 1142
 		    $data['longitude'] = $line['lon']; // long
861 1143
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
862 1144
 		    //$data['squawk'] = $line['squawk']; // squawk
863 1145
 		    //$data['emergency'] = ''; // emergency
864
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
865
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
866
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1146
+		    if (isset($line['depicao'])) {
1147
+		    	$data['departure_airport_icao'] = $line['depicao'];
1148
+		    }
1149
+		    if (isset($line['deptime'])) {
1150
+		    	$data['departure_airport_time'] = $line['deptime'];
1151
+		    }
1152
+		    if (isset($line['arricao'])) {
1153
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1154
+		    }
867 1155
 		    //$data['arrival_airport_time'] = $line['arrtime'];
868
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
869
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
870
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
871
-		    else $data['info'] = '';
1156
+		    if (isset($line['aircraft'])) {
1157
+		    	$data['aircraft_icao'] = $line['aircraft'];
1158
+		    }
1159
+		    if (isset($line['transponder'])) {
1160
+		    	$data['squawk'] = $line['transponder'];
1161
+		    }
1162
+		    if (isset($line['atis'])) {
1163
+		    	$data['info'] = $line['atis'];
1164
+		    } else {
1165
+		    	$data['info'] = '';
1166
+		    }
872 1167
 		    $data['format_source'] = 'pireps';
873 1168
     		    $data['id_source'] = $id_source;
874 1169
 		    $data['datetime'] = date('Y-m-d H:i:s');
875
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1170
+		    if (isset($value['name']) && $value['name'] != '') {
1171
+		    	$data['source_name'] = $value['name'];
1172
+		    }
876 1173
 		    if ($line['icon'] == 'plane') {
877 1174
 			$SI->add($data);
878 1175
 		    //    print_r($data);
@@ -881,16 +1178,28 @@  discard block
 block discarded – undo
881 1178
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
882 1179
 			$typec = substr($data['ident'],-3);
883 1180
 			$data['type'] = '';
884
-			if ($typec == 'APP') $data['type'] = 'Approach';
885
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
886
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
887
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
888
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
889
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
890
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
891
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
892
-			else $data['type'] = 'Observer';
893
-			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']);
1181
+			if ($typec == 'APP') {
1182
+				$data['type'] = 'Approach';
1183
+			} elseif ($typec == 'TWR') {
1184
+				$data['type'] = 'Tower';
1185
+			} elseif ($typec == 'OBS') {
1186
+				$data['type'] = 'Observer';
1187
+			} elseif ($typec == 'GND') {
1188
+				$data['type'] = 'Ground';
1189
+			} elseif ($typec == 'DEL') {
1190
+				$data['type'] = 'Delivery';
1191
+			} elseif ($typec == 'DEP') {
1192
+				$data['type'] = 'Departure';
1193
+			} elseif ($typec == 'FSS') {
1194
+				$data['type'] = 'Flight Service Station';
1195
+			} elseif ($typec == 'CTR') {
1196
+				$data['type'] = 'Control Radar or Centre';
1197
+			} else {
1198
+				$data['type'] = 'Observer';
1199
+			}
1200
+			if (isset($ATC)) {
1201
+				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']);
1202
+			}
894 1203
 		    }
895 1204
 		    unset($data);
896 1205
 		}
@@ -900,7 +1209,9 @@  discard block
 block discarded – undo
900 1209
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
901 1210
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
902 1211
 	    //$buffer = $Common->getData($hosts[$id]);
903
-	    if ($globalDebug) echo 'Get Data...'."\n";
1212
+	    if ($globalDebug) {
1213
+	    	echo 'Get Data...'."\n";
1214
+	    }
904 1215
 	    $buffer = $Common->getData($value['host']);
905 1216
 	    $all_data = json_decode($buffer,true);
906 1217
 	    if ($buffer != '' && is_array($all_data)) {
@@ -908,10 +1219,16 @@  discard block
 block discarded – undo
908 1219
 		foreach ($all_data as $line) {
909 1220
 	    	    $data = array();
910 1221
 	    	    //$data['id'] = $line['id']; // id not usable
911
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1222
+	    	    if (isset($line['pilotid'])) {
1223
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1224
+	    	    }
912 1225
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
913
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
914
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1226
+	    	    if (isset($line['pilotname'])) {
1227
+	    	    	$data['pilot_name'] = $line['pilotname'];
1228
+	    	    }
1229
+	    	    if (isset($line['pilotid'])) {
1230
+	    	    	$data['pilot_id'] = $line['pilotid'];
1231
+	    	    }
915 1232
 	    	    $data['ident'] = $line['flightnum']; // ident
916 1233
 	    	    $data['altitude'] = $line['alt']; // altitude
917 1234
 	    	    $data['speed'] = $line['gs']; // speed
@@ -929,27 +1246,41 @@  discard block
 block discarded – undo
929 1246
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
930 1247
     		    $data['arrival_airport_time'] = $line['arrtime'];
931 1248
     		    $data['registration'] = $line['aircraft'];
932
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1249
+		    if (isset($line['route'])) {
1250
+		    	$data['waypoints'] = $line['route'];
1251
+		    }
1252
+		    // route
933 1253
 		    if (isset($line['aircraftname'])) {
934 1254
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
935 1255
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
936 1256
 	    		$aircraft_data = explode('-',$line['aircraftname']);
937
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
938
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
939
-	    		else {
1257
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) {
1258
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1259
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) {
1260
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1261
+	    		} else {
940 1262
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
941
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
942
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
1263
+	    		    if (isset($aircraft_data[1])) {
1264
+	    		    	$data['aircraft_icao'] = $aircraft_data[1];
1265
+	    		    } else {
1266
+	    		    	$data['aircraft_icao'] = $line['aircraftname'];
1267
+	    		    }
943 1268
 	    		}
944 1269
 	    	    }
945
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1270
+    		    if (isset($line['route'])) {
1271
+    		    	$data['waypoints'] = $line['route'];
1272
+    		    }
946 1273
     		    $data['id_source'] = $id_source;
947 1274
 	    	    $data['format_source'] = 'phpvmacars';
948
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1275
+		    if (isset($value['name']) && $value['name'] != '') {
1276
+		    	$data['source_name'] = $value['name'];
1277
+		    }
949 1278
 		    $SI->add($data);
950 1279
 		    unset($data);
951 1280
 		}
952
-		if ($globalDebug) echo 'No more data...'."\n";
1281
+		if ($globalDebug) {
1282
+			echo 'No more data...'."\n";
1283
+		}
953 1284
 		unset($buffer);
954 1285
 		unset($all_data);
955 1286
 	    }
@@ -957,7 +1288,9 @@  discard block
 block discarded – undo
957 1288
     	    $last_exec[$id]['last'] = time();
958 1289
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
959 1290
 	    //$buffer = $Common->getData($hosts[$id]);
960
-	    if ($globalDebug) echo 'Get Data...'."\n";
1291
+	    if ($globalDebug) {
1292
+	    	echo 'Get Data...'."\n";
1293
+	    }
961 1294
 	    $buffer = $Common->getData($value['host']);
962 1295
 	    $all_data = json_decode($buffer,true);
963 1296
 	    if ($buffer != '' && is_array($all_data)) {
@@ -986,15 +1319,22 @@  discard block
 block discarded – undo
986 1319
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
987 1320
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
988 1321
     		    //$data['registration'] = $line['aircraft'];
989
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1322
+		    if (isset($line['route'])) {
1323
+		    	$data['waypoints'] = $line['route'];
1324
+		    }
1325
+		    // route
990 1326
 	    	    $data['aircraft_icao'] = $line['plane_type'];
991 1327
     		    $data['id_source'] = $id_source;
992 1328
 	    	    $data['format_source'] = 'vam';
993
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1329
+		    if (isset($value['name']) && $value['name'] != '') {
1330
+		    	$data['source_name'] = $value['name'];
1331
+		    }
994 1332
 		    $SI->add($data);
995 1333
 		    unset($data);
996 1334
 		}
997
-		if ($globalDebug) echo 'No more data...'."\n";
1335
+		if ($globalDebug) {
1336
+			echo 'No more data...'."\n";
1337
+		}
998 1338
 		unset($buffer);
999 1339
 		unset($all_data);
1000 1340
 	    }
@@ -1002,7 +1342,9 @@  discard block
 block discarded – undo
1002 1342
     	    $last_exec[$id]['last'] = time();
1003 1343
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1004 1344
 	} 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' || $value['format'] == 'vrstcp') {
1005
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1345
+	    if (function_exists('pcntl_fork')) {
1346
+	    	pcntl_signal_dispatch();
1347
+	    }
1006 1348
     	    //$last_exec[$id]['last'] = time();
1007 1349
 
1008 1350
 	    //$read = array( $sockets[$id] );
@@ -1010,7 +1352,9 @@  discard block
 block discarded – undo
1010 1352
 	    $write = NULL;
1011 1353
 	    $e = NULL;
1012 1354
 	    $n = socket_select($read, $write, $e, $timeout);
1013
-	    if ($e != NULL) var_dump($e);
1355
+	    if ($e != NULL) {
1356
+	    	var_dump($e);
1357
+	    }
1014 1358
 	    if ($n > 0) {
1015 1359
 		$reset = 0;
1016 1360
 		foreach ($read as $nb => $r) {
@@ -1029,12 +1373,16 @@  discard block
 block discarded – undo
1029 1373
 		    //$SI::del();
1030 1374
 		    if ($format == 'vrstcp') {
1031 1375
 			$buffer = explode('},{',$buffer);
1032
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1376
+		    } else {
1377
+		    	$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1378
+		    }
1033 1379
 		    // SBS format is CSV format
1034 1380
 		    if ($buffer != '') {
1035 1381
 			$tt[$format] = 0;
1036 1382
 			if ($format == 'acarssbs3') {
1037
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1383
+                    	    if ($globalDebug) {
1384
+                    	    	echo 'ACARS : '.$buffer."\n";
1385
+                    	    }
1038 1386
 			    $ACARS->add(trim($buffer));
1039 1387
 			    $ACARS->deleteLiveAcarsData();
1040 1388
 			} elseif ($format == 'raw') {
@@ -1043,25 +1391,55 @@  discard block
 block discarded – undo
1043 1391
 			    if (is_array($data)) {
1044 1392
 				$data['datetime'] = date('Y-m-d H:i:s');
1045 1393
 				$data['format_source'] = 'raw';
1046
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1047
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1048
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1394
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1395
+					$data['source_name'] = $globalSources[$nb]['name'];
1396
+				}
1397
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1398
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1399
+    				}
1400
+                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1401
+                                	$SI->add($data);
1402
+                                }
1049 1403
                             }
1050 1404
                         } elseif ($format == 'ais') {
1051 1405
 			    $ais_data = $AIS->parse_line(trim($buffer));
1052 1406
 			    $data = array();
1053
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1054
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1055
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1056
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1057
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1058
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1059
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1060
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1061
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1062
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1063
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1064
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1407
+			    if (isset($ais_data['ident'])) {
1408
+			    	$data['ident'] = $ais_data['ident'];
1409
+			    }
1410
+			    if (isset($ais_data['mmsi'])) {
1411
+			    	$data['mmsi'] = $ais_data['mmsi'];
1412
+			    }
1413
+			    if (isset($ais_data['speed'])) {
1414
+			    	$data['speed'] = $ais_data['speed'];
1415
+			    }
1416
+			    if (isset($ais_data['heading'])) {
1417
+			    	$data['heading'] = $ais_data['heading'];
1418
+			    }
1419
+			    if (isset($ais_data['latitude'])) {
1420
+			    	$data['latitude'] = $ais_data['latitude'];
1421
+			    }
1422
+			    if (isset($ais_data['longitude'])) {
1423
+			    	$data['longitude'] = $ais_data['longitude'];
1424
+			    }
1425
+			    if (isset($ais_data['status'])) {
1426
+			    	$data['status'] = $ais_data['status'];
1427
+			    }
1428
+			    if (isset($ais_data['type'])) {
1429
+			    	$data['type'] = $ais_data['type'];
1430
+			    }
1431
+			    if (isset($ais_data['imo'])) {
1432
+			    	$data['imo'] = $ais_data['imo'];
1433
+			    }
1434
+			    if (isset($ais_data['callsign'])) {
1435
+			    	$data['callsign'] = $ais_data['callsign'];
1436
+			    }
1437
+			    if (isset($ais_data['destination'])) {
1438
+			    	$data['arrival_code'] = $ais_data['destination'];
1439
+			    }
1440
+			    if (isset($ais_data['eta_ts'])) {
1441
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1442
+			    }
1065 1443
 
1066 1444
 			    if (isset($ais_data['timestamp'])) {
1067 1445
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1070,7 +1448,9 @@  discard block
 block discarded – undo
1070 1448
 			    }
1071 1449
 			    $data['format_source'] = 'aisnmea';
1072 1450
     			    $data['id_source'] = $id_source;
1073
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1451
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1452
+			    	$MI->add($data);
1453
+			    }
1074 1454
 			    unset($data);
1075 1455
                         } elseif ($format == 'flightgearsp') {
1076 1456
                     	    //echo $buffer."\n";
@@ -1088,11 +1468,15 @@  discard block
 block discarded – undo
1088 1468
 				$data['speed'] = round($line[5]*1.94384);
1089 1469
 				$data['datetime'] = date('Y-m-d H:i:s');
1090 1470
 				$data['format_source'] = 'flightgearsp';
1091
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1471
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1472
+					$SI->add($data);
1473
+				}
1092 1474
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1093 1475
 			    }
1094 1476
                         } elseif ($format == 'acars') {
1095
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1477
+                    	    if ($globalDebug) {
1478
+                    	    	echo 'ACARS : '.$buffer."\n";
1479
+                    	    }
1096 1480
 			    $ACARS->add(trim($buffer));
1097 1481
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1098 1482
 			    $ACARS->deleteLiveAcarsData();
@@ -1113,7 +1497,9 @@  discard block
 block discarded – undo
1113 1497
 				    $aircraft_type = $line[10];
1114 1498
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1115 1499
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1116
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1500
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1501
+				    	$SI->add($data);
1502
+				    }
1117 1503
 				}
1118 1504
 			    }
1119 1505
 			} elseif ($format == 'beast') {
@@ -1123,27 +1509,59 @@  discard block
 block discarded – undo
1123 1509
 			    foreach($buffer as $all_data) {
1124 1510
 				$line = json_decode('{'.$all_data.'}',true);
1125 1511
 				$data = array();
1126
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1127
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1128
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1129
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1130
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1131
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1132
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1512
+				if (isset($line['Icao'])) {
1513
+					$data['hex'] = $line['Icao'];
1514
+				}
1515
+				// hex
1516
+				if (isset($line['Call'])) {
1517
+					$data['ident'] = $line['Call'];
1518
+				}
1519
+				// ident
1520
+				if (isset($line['Alt'])) {
1521
+					$data['altitude'] = $line['Alt'];
1522
+				}
1523
+				// altitude
1524
+				if (isset($line['Spd'])) {
1525
+					$data['speed'] = $line['Spd'];
1526
+				}
1527
+				// speed
1528
+				if (isset($line['Trak'])) {
1529
+					$data['heading'] = $line['Trak'];
1530
+				}
1531
+				// heading
1532
+				if (isset($line['Lat'])) {
1533
+					$data['latitude'] = $line['Lat'];
1534
+				}
1535
+				// lat
1536
+				if (isset($line['Long'])) {
1537
+					$data['longitude'] = $line['Long'];
1538
+				}
1539
+				// long
1133 1540
 				//$data['verticalrate'] = $line['']; // verticale rate
1134
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1541
+				if (isset($line['Sqk'])) {
1542
+					$data['squawk'] = $line['Sqk'];
1543
+				}
1544
+				// squawk
1135 1545
 				$data['emergency'] = ''; // emergency
1136
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1546
+				if (isset($line['Reg'])) {
1547
+					$data['registration'] = $line['Reg'];
1548
+				}
1137 1549
 				/*
1138 1550
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1139 1551
 				else $data['datetime'] = date('Y-m-d H:i:s');
1140 1552
 				*/
1141 1553
 				$data['datetime'] = date('Y-m-d H:i:s');
1142
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1554
+				if (isset($line['Type'])) {
1555
+					$data['aircraft_icao'] = $line['Type'];
1556
+				}
1143 1557
 		    		$data['format_source'] = 'vrstcp';
1144 1558
 				$data['id_source'] = $id_source;
1145
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1146
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1559
+				if (isset($value['name']) && $value['name'] != '') {
1560
+					$data['source_name'] = $value['name'];
1561
+				}
1562
+				if (isset($data['latitude']) && isset($data['hex'])) {
1563
+					$SI->add($data);
1564
+				}
1147 1565
 				unset($data);
1148 1566
 			    }
1149 1567
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
@@ -1156,21 +1574,43 @@  discard block
 block discarded – undo
1156 1574
     				$data['hex'] = $lined['hexid'];
1157 1575
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1158 1576
     				$data['datetime'] = date('Y-m-d H:i:s');;
1159
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1160
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1161
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1162
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1163
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1164
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1165
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1577
+    				if (isset($lined['ident'])) {
1578
+    					$data['ident'] = $lined['ident'];
1579
+    				}
1580
+    				if (isset($lined['lat'])) {
1581
+    					$data['latitude'] = $lined['lat'];
1582
+    				}
1583
+    				if (isset($lined['lon'])) {
1584
+    					$data['longitude'] = $lined['lon'];
1585
+    				}
1586
+    				if (isset($lined['speed'])) {
1587
+    					$data['speed'] = $lined['speed'];
1588
+    				}
1589
+    				if (isset($lined['squawk'])) {
1590
+    					$data['squawk'] = $lined['squawk'];
1591
+    				}
1592
+    				if (isset($lined['alt'])) {
1593
+    					$data['altitude'] = $lined['alt'];
1594
+    				}
1595
+    				if (isset($lined['heading'])) {
1596
+    					$data['heading'] = $lined['heading'];
1597
+    				}
1166 1598
     				$data['id_source'] = $id_source;
1167 1599
     				$data['format_source'] = 'tsv';
1168
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1169
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1170
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1600
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1601
+    					$data['source_name'] = $globalSources[$nb]['name'];
1602
+    				}
1603
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1604
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1605
+    				}
1606
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1607
+    					$SI->add($data);
1608
+    				}
1171 1609
     				unset($lined);
1172 1610
     				unset($data);
1173
-    			    } else $error = true;
1611
+    			    } else {
1612
+    			    	$error = true;
1613
+    			    }
1174 1614
 			} elseif ($format == 'aprs' && $use_aprs) {
1175 1615
 			    if ($aprs_connect == 0) {
1176 1616
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1196,49 +1636,82 @@  discard block
 block discarded – undo
1196 1636
 				    $aprs_last_tx = time();
1197 1637
 				    $data = array();
1198 1638
 				    //print_r($line);
1199
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1200
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1201
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1639
+				    if (isset($line['address'])) {
1640
+				    	$data['hex'] = $line['address'];
1641
+				    }
1642
+				    if (isset($line['timestamp'])) {
1643
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1644
+				    } else {
1645
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1646
+				    }
1202 1647
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1203
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1648
+				    if (isset($line['ident'])) {
1649
+				    	$data['ident'] = $line['ident'];
1650
+				    }
1204 1651
 				    $data['latitude'] = $line['latitude'];
1205 1652
 				    $data['longitude'] = $line['longitude'];
1206 1653
 				    //$data['verticalrate'] = $line[16];
1207
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1208
-				    else $data['speed'] = 0;
1209
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1210
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1211
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1212
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1654
+				    if (isset($line['speed'])) {
1655
+				    	$data['speed'] = $line['speed'];
1656
+				    } else {
1657
+				    	$data['speed'] = 0;
1658
+				    }
1659
+				    if (isset($line['altitude'])) {
1660
+				    	$data['altitude'] = $line['altitude'];
1661
+				    }
1662
+				    if (isset($line['comment'])) {
1663
+				    	$data['comment'] = $line['comment'];
1664
+				    }
1665
+				    if (isset($line['symbol'])) {
1666
+				    	$data['type'] = $line['symbol'];
1667
+				    }
1668
+				    if (isset($line['heading'])) {
1669
+				    	$data['heading'] = $line['heading'];
1670
+				    }
1213 1671
 				    //else $data['heading'] = 0;
1214
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1215
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1672
+				    if (isset($line['stealth'])) {
1673
+				    	$data['aircraft_type'] = $line['stealth'];
1674
+				    }
1675
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
1676
+				    	$data['noarchive'] = true;
1677
+				    }
1216 1678
     				    $data['id_source'] = $id_source;
1217
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1218
-				    else $data['format_source'] = 'aprs';
1679
+    				    if (isset($line['format_source'])) {
1680
+    				    	$data['format_source'] = $line['format_source'];
1681
+    				    } else {
1682
+				    	$data['format_source'] = 'aprs';
1683
+				    }
1219 1684
 				    $data['source_name'] = $line['source'];
1220
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1221
-				    else $data['source_type'] = 'flarm';
1222
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1685
+				    if (isset($line['source_type'])) {
1686
+				    	$data['source_type'] = $line['source_type'];
1687
+				    } else {
1688
+				    	$data['source_type'] = 'flarm';
1689
+				    }
1690
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1691
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1692
+    				    }
1223 1693
 				    $currentdate = date('Y-m-d H:i:s');
1224 1694
 				    $aprsdate = strtotime($data['datetime']);
1225 1695
 				    // Accept data if time <= system time + 20s
1226 1696
 				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1227 1697
 					$send = $SI->add($data);
1228 1698
 				    } elseif (isset($line['stealth'])) {
1229
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1230
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1699
+					if ($line['stealth'] != 0) {
1700
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1701
+					} else {
1702
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1703
+					}
1231 1704
 				    //} 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')) {
1232 1705
 				    } 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') {
1233 1706
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1234
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1707
+					if (isset($globalTracker) && $globalTracker) {
1708
+						$send = $TI->add($data);
1709
+					}
1235 1710
 				    }
1236 1711
 				    unset($data);
1237
-				} 
1238
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1712
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1239 1713
 					echo '!! Weather Station not yet supported'."\n";
1240
-				}
1241
-				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')) {
1714
+				} 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')) {
1242 1715
 					echo '!! Car & Trucks not yet supported'."\n";
1243 1716
 				}
1244 1717
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
@@ -1271,25 +1744,42 @@  discard block
 block discarded – undo
1271 1744
     				$data['ground'] = $line[21];
1272 1745
     				$data['emergency'] = $line[19];
1273 1746
     				$data['format_source'] = 'sbs';
1274
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1275
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1747
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1748
+					$data['source_name'] = $globalSources[$nb]['name'];
1749
+				}
1750
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1751
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1752
+    				}
1276 1753
     				$data['id_source'] = $id_source;
1277
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1278
-    				else $error = true;
1754
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1755
+    					$send = $SI->add($data);
1756
+    				} else {
1757
+    					$error = true;
1758
+    				}
1279 1759
     				unset($data);
1280
-    			    } else $error = true;
1760
+    			    } else {
1761
+    			    	$error = true;
1762
+    			    }
1281 1763
 			    if ($error) {
1282 1764
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1283
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1765
+					if ($globalDebug) {
1766
+						echo "Not a message. Ignoring... \n";
1767
+					}
1284 1768
 				} else {
1285
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1769
+					if ($globalDebug) {
1770
+						echo "Wrong line format. Ignoring... \n";
1771
+					}
1286 1772
 					if ($globalDebug) {
1287 1773
 						echo $buffer;
1288 1774
 						print_r($line);
1289 1775
 					}
1290 1776
 					//socket_close($r);
1291
-					if ($globalDebug) echo "Reconnect after an error...\n";
1292
-					if ($format == 'aprs') $aprs_connect = 0;
1777
+					if ($globalDebug) {
1778
+						echo "Reconnect after an error...\n";
1779
+					}
1780
+					if ($format == 'aprs') {
1781
+						$aprs_connect = 0;
1782
+					}
1293 1783
 					$sourceer[$nb] = $globalSources[$nb];
1294 1784
 					connect_all($sourceer);
1295 1785
 					$sourceer = array();
@@ -1297,10 +1787,14 @@  discard block
 block discarded – undo
1297 1787
 			    }
1298 1788
 			}
1299 1789
 			// Sleep for xxx microseconds
1300
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1790
+			if (isset($globalSBSSleep)) {
1791
+				usleep($globalSBSSleep);
1792
+			}
1301 1793
 		    } else {
1302 1794
 			if ($format == 'flightgearmp') {
1303
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1795
+			    	if ($globalDebug) {
1796
+			    		echo "Reconnect FlightGear MP...";
1797
+			    	}
1304 1798
 				//@socket_close($r);
1305 1799
 				sleep($globalMinFetch);
1306 1800
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1309,10 +1803,15 @@  discard block
 block discarded – undo
1309 1803
 				break;
1310 1804
 				
1311 1805
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1312
-			    if (isset($tt[$format])) $tt[$format]++;
1313
-			    else $tt[$format] = 0;
1806
+			    if (isset($tt[$format])) {
1807
+			    	$tt[$format]++;
1808
+			    } else {
1809
+			    	$tt[$format] = 0;
1810
+			    }
1314 1811
 			    if ($tt[$format] > 30) {
1315
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1812
+				if ($globalDebug) {
1813
+					echo "ERROR : Reconnect ".$format."...";
1814
+				}
1316 1815
 				//@socket_close($r);
1317 1816
 				sleep(2);
1318 1817
 				$aprs_connect = 0;
@@ -1329,11 +1828,17 @@  discard block
 block discarded – undo
1329 1828
 	    } else {
1330 1829
 		$error = socket_strerror(socket_last_error());
1331 1830
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1332
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1333
-			if (isset($globalDebug)) echo "Restarting...\n";
1831
+			if ($globalDebug) {
1832
+				echo "ERROR : socket_select give this error ".$error . "\n";
1833
+			}
1834
+			if (isset($globalDebug)) {
1835
+				echo "Restarting...\n";
1836
+			}
1334 1837
 			// Restart the script if possible
1335 1838
 			if (is_array($sockets)) {
1336
-			    if ($globalDebug) echo "Shutdown all sockets...";
1839
+			    if ($globalDebug) {
1840
+			    	echo "Shutdown all sockets...";
1841
+			    }
1337 1842
 			    
1338 1843
 			    foreach ($sockets as $sock) {
1339 1844
 				@socket_shutdown($sock,2);
@@ -1341,18 +1846,24 @@  discard block
 block discarded – undo
1341 1846
 			    }
1342 1847
 			    
1343 1848
 			}
1344
-			if ($globalDebug) echo "Restart all connections...";
1849
+			if ($globalDebug) {
1850
+				echo "Restart all connections...";
1851
+			}
1345 1852
 			sleep(2);
1346 1853
 			$time = time();
1347 1854
 			//connect_all($hosts);
1348 1855
 			$aprs_connect = 0;
1349
-			if ($reset > 40) exit('Too many attempts...');
1856
+			if ($reset > 40) {
1857
+				exit('Too many attempts...');
1858
+			}
1350 1859
 			connect_all($globalSources);
1351 1860
 		}
1352 1861
 	    }
1353 1862
 	}
1354 1863
 	if ($globalDaemon === false) {
1355
-	    if ($globalDebug) echo 'Check all...'."\n";
1864
+	    if ($globalDebug) {
1865
+	    	echo 'Check all...'."\n";
1866
+	    }
1356 1867
 	    $SI->checkAll();
1357 1868
 	}
1358 1869
     }
Please login to merge, or discard this patch.
date.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 require_once(dirname(__FILE__).'/require/settings.php');
3
-$date = filter_input(INPUT_POST,'date',FILTER_SANITIZE_STRING);
3
+$date = filter_input(INPUT_POST, 'date', FILTER_SANITIZE_STRING);
4 4
 if ($date == '') $date = date('Y-m-d');
5 5
 header('Location: '.$globalURL.'/date/'.$date);
6 6
 ?>
7 7
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 require_once(dirname(__FILE__).'/require/settings.php');
3 3
 $date = filter_input(INPUT_POST,'date',FILTER_SANITIZE_STRING);
4
-if ($date == '') $date = date('Y-m-d');
4
+if ($date == '') {
5
+	$date = date('Y-m-d');
6
+}
5 7
 header('Location: '.$globalURL.'/date/'.$date);
6 8
 ?>
7 9
\ No newline at end of file
Please login to merge, or discard this patch.
accident.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 require_once(dirname(__FILE__).'/require/settings.php');
3
-$date = filter_input(INPUT_POST,'date',FILTER_SANITIZE_STRING);
3
+$date = filter_input(INPUT_POST, 'date', FILTER_SANITIZE_STRING);
4 4
 if ($date == '') $date = date('Y-m-d');
5 5
 header('Location: '.$globalURL.'/accident/'.$date);
6 6
 ?>
7 7
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 require_once(dirname(__FILE__).'/require/settings.php');
3 3
 $date = filter_input(INPUT_POST,'date',FILTER_SANITIZE_STRING);
4
-if ($date == '') $date = date('Y-m-d');
4
+if ($date == '') {
5
+	$date = date('Y-m-d');
6
+}
5 7
 header('Location: '.$globalURL.'/accident/'.$date);
6 8
 ?>
7 9
\ No newline at end of file
Please login to merge, or discard this patch.
statistics-fatalities-year.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -19,13 +19,13 @@  discard block
 block discarded – undo
19 19
 print '<div id="chart" class="chart" width="100%"></div><script>';
20 20
 $year_data = '';
21 21
 $year_cnt = '';
22
-foreach($date_array as $year_item)
22
+foreach ($date_array as $year_item)
23 23
 {
24 24
 	$year_data .= '"'.$year_item['year'].'-01-01",';
25 25
 	$year_cnt .= $year_item['count'].',';
26 26
 }
27 27
 $year_data = "['x',".substr($year_data, 0, -1)."]";
28
-$year_cnt = "['flights',".substr($year_cnt,0,-1)."]";
28
+$year_cnt = "['flights',".substr($year_cnt, 0, -1)."]";
29 29
 print 'c3.generate({
30 30
     bindto: "#chart",
31 31
     data: { x: "x",
@@ -35,12 +35,12 @@  discard block
 block discarded – undo
35 35
 
36 36
 if (!empty($date_array))
37 37
 {
38
-	foreach($date_array as $key => $row) {
38
+	foreach ($date_array as $key => $row) {
39 39
 		$years[$key] = $row['year'];
40 40
 		$counts[$key] = $row['count'];
41 41
 	}
42 42
 	//array_multisort($years,SORT_DESC,$date_array);
43
-	array_multisort($counts,SORT_DESC,$date_array);
43
+	array_multisort($counts, SORT_DESC, $date_array);
44 44
 	print '<div class="table-responsive">';
45 45
 	print '<table class="common-date table-striped">';
46 46
 	print '<thead>';
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	print '</thead>';
51 51
 	print '<tbody>';
52 52
 	$i = 1;
53
-	foreach($date_array as $date_item)
53
+	foreach ($date_array as $date_item)
54 54
 	{
55 55
 		print '<tr>';
56 56
 		print '<td><strong>'.$i.'</strong></td>';
Please login to merge, or discard this patch.