Completed
Push — master ( 73f088...7f17b6 )
by Yannick
07:13
created
redirect.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -7,11 +7,11 @@
 block discarded – undo
7 7
 {
8 8
 	$spotter_id = $Spotter->getSpotterIDBasedOnFlightAwareID($_GET['flightaware_id']);
9 9
     
10
-    if ($spotter_id != "")
11
-    {
12
-        header('Location: '.$globalURL.'/flightid/'.$spotter_id);
13
-    } else {
10
+	if ($spotter_id != "")
11
+	{
12
+		header('Location: '.$globalURL.'/flightid/'.$spotter_id);
13
+	} else {
14 14
 	   header('Location: '.$globalURL);
15
-    }
15
+	}
16 16
 }
17 17
 ?>
18 18
\ No newline at end of file
Please login to merge, or discard this patch.
aircraft.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,9 +19,9 @@  discard block
 block discarded – undo
19 19
 	if (empty($aircraft_types) || $aircraft_types[0]['aircraft_name'] == '') $aircraft_types = $Spotter->getAllAircraftTypes();
20 20
 	$previous = null;
21 21
 	print '<div class="alphabet-legend">';
22
-	foreach($aircraft_types as $value) {
22
+	foreach ($aircraft_types as $value) {
23 23
 		$firstLetter = substr($value['aircraft_name'], 0, 1);
24
-		if($previous !== $firstLetter)
24
+		if ($previous !== $firstLetter)
25 25
 		{
26 26
 			if ($previous !== null) print ' | ';
27 27
 			print '<a href="#'.$firstLetter.'">'.$firstLetter.'</a>';
@@ -30,11 +30,11 @@  discard block
 block discarded – undo
30 30
 	}
31 31
 	print '</div>';
32 32
 	$previous = null;
33
-	foreach($aircraft_types as $value) {
33
+	foreach ($aircraft_types as $value) {
34 34
 		$firstLetter = substr($value['aircraft_name'], 0, 1);
35 35
 		if ($firstLetter != "")
36 36
 		{
37
-			if($previous !== $firstLetter)
37
+			if ($previous !== $firstLetter)
38 38
 			{
39 39
 				if ($previous !== null) print '</div>';
40 40
 				print '<a name="'.$firstLetter.'"></a><h4 class="alphabet-header">'.$firstLetter.'</h4><div class="alphabet">';
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,14 +16,18 @@  discard block
 block discarded – undo
16 16
 	print '<h1>'._("Aircrafts Types").'</h1>';
17 17
 
18 18
 	$aircraft_types = $Stats->getAllAircraftTypes();
19
-	if (empty($aircraft_types) || $aircraft_types[0]['aircraft_name'] == '') $aircraft_types = $Spotter->getAllAircraftTypes();
19
+	if (empty($aircraft_types) || $aircraft_types[0]['aircraft_name'] == '') {
20
+		$aircraft_types = $Spotter->getAllAircraftTypes();
21
+	}
20 22
 	$previous = null;
21 23
 	print '<div class="alphabet-legend">';
22 24
 	foreach($aircraft_types as $value) {
23 25
 		$firstLetter = substr($value['aircraft_name'], 0, 1);
24 26
 		if($previous !== $firstLetter)
25 27
 		{
26
-			if ($previous !== null) print ' | ';
28
+			if ($previous !== null) {
29
+				print ' | ';
30
+			}
27 31
 			print '<a href="#'.$firstLetter.'">'.$firstLetter.'</a>';
28 32
 		}
29 33
 		$previous = $firstLetter;
@@ -36,7 +40,9 @@  discard block
 block discarded – undo
36 40
 		{
37 41
 			if($previous !== $firstLetter)
38 42
 			{
39
-				if ($previous !== null) print '</div>';
43
+				if ($previous !== null) {
44
+					print '</div>';
45
+				}
40 46
 				print '<a name="'.$firstLetter.'"></a><h4 class="alphabet-header">'.$firstLetter.'</h4><div class="alphabet">';
41 47
 			}
42 48
 			$previous = $firstLetter;
Please login to merge, or discard this patch.
airline.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 	print '<div class="column">';
15 15
 	print '<h1>'._("Airlines").'</h1>';
16 16
 	if (isset($_POST['airline_type'])) {
17
-		$airline_type = filter_input(INPUT_POST,'airline_type',FILTER_SANITIZE_STRING);
17
+		$airline_type = filter_input(INPUT_POST, 'airline_type', FILTER_SANITIZE_STRING);
18 18
 		//$airline_names = $Spotter->getAllAirlineNames($airline_type);
19 19
 	} else {
20 20
 		//$airline_names = $Spotter->getAllAirlineNames();
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
 	if (isset($_POST['airline_type'])) 
37 37
 	{
38
-		$airline_type = filter_input(INPUT_POST,'airline_type',FILTER_SANITIZE_STRING);
38
+		$airline_type = filter_input(INPUT_POST, 'airline_type', FILTER_SANITIZE_STRING);
39 39
 		$airline_names = $Spotter->getAllAirlineNames($airline_type);
40 40
 	} else {
41 41
 		$Stats = new Stats();
@@ -45,12 +45,12 @@  discard block
 block discarded – undo
45 45
 	}
46 46
 	$previous = null;
47 47
 	print '<div class="alphabet-legend">';
48
-	foreach($airline_names as $value) 
48
+	foreach ($airline_names as $value) 
49 49
 	{
50 50
 		//echo $value['airline_name']."\n";
51 51
 		//echo mb_substr($value['airline_name'],0,1).' - '.$value['airline_name']."\n";
52
-		$firstLetter = mb_strtoupper(mb_substr($value['airline_name'], 0, 1),'UTF-8');
53
-		if($previous !== $firstLetter)
52
+		$firstLetter = mb_strtoupper(mb_substr($value['airline_name'], 0, 1), 'UTF-8');
53
+		if ($previous !== $firstLetter)
54 54
 		{
55 55
 			if ($previous !== null) print ' | ';
56 56
 			print '<a href="#'.$firstLetter.'">'.$firstLetter.'</a>';
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
 	}
60 60
 	print '</div>';
61 61
 	$previous = null;
62
-	foreach($airline_names as $value) {
62
+	foreach ($airline_names as $value) {
63 63
 		$firstLetter = strtoupper(substr($value['airline_name'], 0, 1));
64 64
 		if ($firstLetter != "")
65 65
 		{
66
-			if($previous !== $firstLetter)
66
+			if ($previous !== $firstLetter)
67 67
 			{
68 68
 				if ($previous !== null) print '</div>';
69 69
 				print '<a name="'.$firstLetter.'"></a><h4 class="alphabet-header">'.$firstLetter.'</h4><div class="alphabet">';
Please login to merge, or discard this patch.
Braces   +21 added lines, -7 removed lines patch added patch discarded remove patch
@@ -23,13 +23,21 @@  discard block
 block discarded – undo
23 23
 
24 24
 	print '<div class="select-item"><form action="'.$globalURL.'/airline" method="post"><select name="airline_type" class="selectpicker" data-live-search="true">';
25 25
 	print '<option value="all"';
26
-	if ($airline_type == 'all') print 'selected="selected" ';
26
+	if ($airline_type == 'all') {
27
+		print 'selected="selected" ';
28
+	}
27 29
 	print '>'._("All").'</option><option value="passenger"';
28
-	if ($airline_type == 'passenger') print 'selected="selected" ';
30
+	if ($airline_type == 'passenger') {
31
+		print 'selected="selected" ';
32
+	}
29 33
 	print '>'._("Passenger").'</option><option value="cargo"';
30
-	if ($airline_type == 'cargo') print 'selected="selected" ';
34
+	if ($airline_type == 'cargo') {
35
+		print 'selected="selected" ';
36
+	}
31 37
 	print '>'._("Cargo").'</option><option value="military"';
32
-	if ($airline_type == 'military') print 'selected="selected" ';
38
+	if ($airline_type == 'military') {
39
+		print 'selected="selected" ';
40
+	}
33 41
 	print '>'._("Military").'</option></select>';
34 42
 	print '<button type="submit"><i class="fa fa-angle-double-right"></i></button></form></div>';
35 43
 
@@ -41,7 +49,9 @@  discard block
 block discarded – undo
41 49
 		$Stats = new Stats();
42 50
 		//$airline_names = $Spotter->getAllAirlineNames();
43 51
 		$airline_names = $Stats->getAllAirlineNames();
44
-		if (empty($airline_names)) $airline_names = $Spotter->getAllAirlineNames();
52
+		if (empty($airline_names)) {
53
+			$airline_names = $Spotter->getAllAirlineNames();
54
+		}
45 55
 	}
46 56
 	$previous = null;
47 57
 	print '<div class="alphabet-legend">';
@@ -52,7 +62,9 @@  discard block
 block discarded – undo
52 62
 		$firstLetter = mb_strtoupper(mb_substr($value['airline_name'], 0, 1),'UTF-8');
53 63
 		if($previous !== $firstLetter)
54 64
 		{
55
-			if ($previous !== null) print ' | ';
65
+			if ($previous !== null) {
66
+				print ' | ';
67
+			}
56 68
 			print '<a href="#'.$firstLetter.'">'.$firstLetter.'</a>';
57 69
 		}
58 70
 		$previous = $firstLetter;
@@ -65,7 +77,9 @@  discard block
 block discarded – undo
65 77
 		{
66 78
 			if($previous !== $firstLetter)
67 79
 			{
68
-				if ($previous !== null) print '</div>';
80
+				if ($previous !== null) {
81
+					print '</div>';
82
+				}
69 83
 				print '<a name="'.$firstLetter.'"></a><h4 class="alphabet-header">'.$firstLetter.'</h4><div class="alphabet">';
70 84
 			}
71 85
 			$previous = $firstLetter;
Please login to merge, or discard this patch.
aircraft-statistics-registration.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -6,23 +6,23 @@  discard block
 block discarded – undo
6 6
         header('Location: '.$globalURL.'/aircraft');
7 7
         die();
8 8
 }
9
-$aircraft_type = filter_input(INPUT_GET,'aircraft_type',FILTER_SANITIZE_STRING);
9
+$aircraft_type = filter_input(INPUT_GET, 'aircraft_type', FILTER_SANITIZE_STRING);
10 10
 $Spotter = new Spotter();
11
-$spotter_array = $Spotter->getSpotterDataByAircraft($aircraft_type,"0,1","");
11
+$spotter_array = $Spotter->getSpotterDataByAircraft($aircraft_type, "0,1", "");
12 12
 
13 13
 
14 14
 if (!empty($spotter_array))
15 15
 {
16
-	$title = sprintf(_("Most Common Aircraft by Registration from %s (%s)"),$spotter_array[0]['aircraft_name'],$spotter_array[0]['aircraft_type']);
16
+	$title = sprintf(_("Most Common Aircraft by Registration from %s (%s)"), $spotter_array[0]['aircraft_name'], $spotter_array[0]['aircraft_type']);
17 17
 	require_once('header.php');
18 18
 	print '<div class="select-item">';
19 19
 	print '<form action="'.$globalURL.'/aircraft" method="post">';
20 20
 	print '<select name="aircraft_type" class="selectpicker" data-live-search="true">';
21 21
 	print '<option></option>';
22 22
 	$aircraft_types = $Spotter->getAllAircraftTypes();
23
-	foreach($aircraft_types as $aircraft_type)
23
+	foreach ($aircraft_types as $aircraft_type)
24 24
 	{
25
-		if($aircraft_type == $aircrafttype['aircraft_icao'])
25
+		if ($aircraft_type == $aircrafttype['aircraft_icao'])
26 26
 		{
27 27
 			print '<option value="'.$aircrafttype['aircraft_icao'].'" selected="selected">'.$aircrafttype['aircraft_name'].' ('.$aircrafttype['aircraft_icao'].')</option>';
28 28
 		} else {
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	include('aircraft-sub-menu.php');
49 49
 	print '<div class="column">';
50 50
 	print '<h2>'._("Most Common Aircraft by Registration").'</h2>';
51
-	print '<p>'.sprintf(_("The statistic below shows the most common aircraft by registration of flights from aircraft type <strong>%s (%s)</strong>."),$spotter_array[0]['aircraft_name'],$spotter_array[0]['aircraft_type']).'</p>';
51
+	print '<p>'.sprintf(_("The statistic below shows the most common aircraft by registration of flights from aircraft type <strong>%s (%s)</strong>."), $spotter_array[0]['aircraft_name'], $spotter_array[0]['aircraft_type']).'</p>';
52 52
 
53 53
 	$aircraft_array = $Spotter->countAllAircraftRegistrationByAircraft($aircraft_type);
54 54
 	if (!empty($aircraft_array))
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		print '</thead>';
66 66
 		print '<tbody>';
67 67
 		$i = 1;
68
-		foreach($aircraft_array as $aircraft_item)
68
+		foreach ($aircraft_array as $aircraft_item)
69 69
 		{
70 70
 			print '<tr>';
71 71
 			print '<td><strong>'.$i.'</strong></td>';
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 require_once('require/class.Language.php');
5 5
 
6 6
 if (!isset($_GET['aircraft_type'])) {
7
-        header('Location: '.$globalURL.'/aircraft');
8
-        die();
7
+		header('Location: '.$globalURL.'/aircraft');
8
+		die();
9 9
 }
10 10
 $aircraft_type = filter_input(INPUT_GET,'aircraft_type',FILTER_SANITIZE_STRING);
11 11
 $Spotter = new Spotter();
Please login to merge, or discard this patch.
manufacturer-statistics-aircraft.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
7 7
         die();
8 8
 }
9 9
 $Spotter = new Spotter();
10
-$manufacturer = ucwords(str_replace("-", " ", filter_input(INPUT_GET,'aircraft_manufacturer',FILTER_SANITIZE_STRING)));
11
-$sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING);
12
-$spotter_array = $Spotter->getSpotterDataByManufacturer($manufacturer,"0,1", $sort);
10
+$manufacturer = ucwords(str_replace("-", " ", filter_input(INPUT_GET, 'aircraft_manufacturer', FILTER_SANITIZE_STRING)));
11
+$sort = filter_input(INPUT_GET, 'sort', FILTER_SANITIZE_STRING);
12
+$spotter_array = $Spotter->getSpotterDataByManufacturer($manufacturer, "0,1", $sort);
13 13
 
14 14
 if (!empty($spotter_array))
15 15
 {
16
-	$title = sprintf(_("Most Common Aircraft from %s"),$manufacturer);
16
+	$title = sprintf(_("Most Common Aircraft from %s"), $manufacturer);
17 17
 
18 18
 	require_once('header.php');
19 19
 	print '<div class="select-item">';
@@ -21,9 +21,9 @@  discard block
 block discarded – undo
21 21
 	print '<select name="aircraft_manufacturer" class="selectpicker" data-live-search="true">';
22 22
 	print '<option></option>';
23 23
 	$all_manufacturers = $Spotter->getAllManufacturers();
24
-	foreach($all_manufacturers as $all_manufacturer)
24
+	foreach ($all_manufacturers as $all_manufacturer)
25 25
 	{
26
-		if($_GET['aircraft_manufacturer'] == strtolower(str_replace(" ", "-", $all_manufacturer['aircraft_manufacturer'])))
26
+		if ($_GET['aircraft_manufacturer'] == strtolower(str_replace(" ", "-", $all_manufacturer['aircraft_manufacturer'])))
27 27
 		{
28 28
 			print '<option value="'.strtolower(str_replace(" ", "-", $all_manufacturer['aircraft_manufacturer'])).'" selected="selected">'.$all_manufacturer['aircraft_manufacturer'].'</option>';
29 29
 		} else {
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	include('manufacturer-sub-menu.php');
43 43
 	print '<div class="column">';
44 44
 	print '<h2>'._("Most Common Aircraft").'</h2>';
45
-	print '<p>'.sprintf(_("The statistic below shows the most common aircrafts of flights from <strong>%s</strong>."),$manufacturer).'</p>';
45
+	print '<p>'.sprintf(_("The statistic below shows the most common aircrafts of flights from <strong>%s</strong>."), $manufacturer).'</p>';
46 46
 
47 47
 	$aircraft_array = $Spotter->countAllAircraftTypesByManufacturer($manufacturer);
48 48
 	if (!empty($aircraft_array))
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		print '</thead>';
58 58
 		print '<tbody>';
59 59
 		$i = 1;
60
-		foreach($aircraft_array as $aircraft_item)
60
+		foreach ($aircraft_array as $aircraft_item)
61 61
 		{
62 62
 			print '<tr>';
63 63
 			print '<td><strong>'.$i.'</strong></td>';
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@
 block discarded – undo
3 3
 require_once('require/class.Spotter.php');
4 4
 require_once('require/class.Language.php');
5 5
 if (!isset($_GET['aircraft_manufacturer'])) {
6
-        header('Location: '.$globalURL.'/manufacturer');
7
-        die();
6
+		header('Location: '.$globalURL.'/manufacturer');
7
+		die();
8 8
 }
9 9
 $Spotter = new Spotter();
10 10
 $manufacturer = ucwords(str_replace("-", " ", filter_input(INPUT_GET,'aircraft_manufacturer',FILTER_SANITIZE_STRING)));
Please login to merge, or discard this patch.
scripts/update_db.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
 if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
10 10
 	exec("ps u", $output, $result);
11 11
 	$j = 0;
12
-	foreach ($output AS $line) if(strpos($line, "update_db.php")) $j++;
12
+	foreach ($output AS $line) if (strpos($line, "update_db.php")) $j++;
13 13
 	if ($j > 1) {
14 14
 		echo "Script is already runnning...";
15 15
 		die();
Please login to merge, or discard this patch.
Braces   +16 added lines, -6 removed lines patch added patch discarded remove patch
@@ -9,7 +9,9 @@  discard block
 block discarded – undo
9 9
 if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
10 10
 	exec("ps u", $output, $result);
11 11
 	$j = 0;
12
-	foreach ($output AS $line) if(strpos($line, "update_db.php")) $j++;
12
+	foreach ($output AS $line) {
13
+		if(strpos($line, "update_db.php")) $j++;
14
+	}
13 15
 	if ($j > 1) {
14 16
 		echo "Script is already runnning...";
15 17
 		die();
@@ -22,7 +24,9 @@  discard block
 block discarded – undo
22 24
 	echo "updating NOTAM...";
23 25
 	$update_db->update_notam();
24 26
 	$update_db->insert_last_notam_update();
25
-} elseif (isset($globalDebug) && $globalDebug && isset($globalNOTAM) && $globalNOTAM) echo "NOTAM are only updated once a day.\n";
27
+} elseif (isset($globalDebug) && $globalDebug && isset($globalNOTAM) && $globalNOTAM) {
28
+	echo "NOTAM are only updated once a day.\n";
29
+}
26 30
 
27 31
 if ($update_db->check_last_update() && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) {
28 32
 	$update_db->update_all();
@@ -30,7 +34,9 @@  discard block
 block discarded – undo
30 34
 //	$Spotter = new Spotter();
31 35
 //	$Spotter->updateFieldsFromOtherTables();
32 36
 	$update_db->insert_last_update();
33
-} elseif (isset($globalDebug) && $globalDebug && (!isset($globalphpVMS) || !$globalphpVMS) && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM)) echo "DB are populated with external data only every 15 days ! Files are not updated more often.\n";
37
+} elseif (isset($globalDebug) && $globalDebug && (!isset($globalphpVMS) || !$globalphpVMS) && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM)) {
38
+	echo "DB are populated with external data only every 15 days ! Files are not updated more often.\n";
39
+}
34 40
 
35 41
 
36 42
 if (isset($globalMETAR) && isset($globalMETARcycle) && $globalMETAR && $globalMETARcycle) {
@@ -40,15 +46,19 @@  discard block
 block discarded – undo
40 46
 	if ($METAR->check_last_update()) {
41 47
 		$METAR->addMETARCycle();
42 48
 		$METAR->insert_last_update();
43
-	} else echo "METAR are only updated every hours.\n";
44
-}
49
+	} else {
50
+		echo "METAR are only updated every hours.\n";
51
+	}
52
+	}
45 53
 
46 54
 
47 55
 if (isset($globalOwner) && $globalOwner && $update_db->check_last_owner_update() && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) {
48 56
 	echo "Updating private aircraft's owners...";
49 57
 	$update_db->update_owner();
50 58
 	$update_db->insert_last_owner_update();
51
-} elseif (isset($globalDebug) && $globalDebug && isset($globalOwner) && $globalOwner && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) echo "Owner are only updated every 15 days.\n";
59
+} elseif (isset($globalDebug) && $globalDebug && isset($globalOwner) && $globalOwner && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) {
60
+	echo "Owner are only updated every 15 days.\n";
61
+}
52 62
 
53 63
 if (isset($globalArchiveMonths) && $globalArchiveMonths > 0) {
54 64
 	echo "Updating statistics and archive old data...";
Please login to merge, or discard this patch.
scripts/cron.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,12 +11,12 @@
 block discarded – undo
11 11
 //checks to see if FlightAware import is set
12 12
 if ($globalFlightAware == TRUE)
13 13
 {
14
-    $SpotterLive = new SpotterLive();
15
-    $Spotter = new Spotter();
16
-    //deletes the spotter LIVE data
17
-    $SpotterLive->deleteLiveSpotterData();
14
+	$SpotterLive = new SpotterLive();
15
+	$Spotter = new Spotter();
16
+	//deletes the spotter LIVE data
17
+	$SpotterLive->deleteLiveSpotterData();
18 18
     
19
-    //imports the new data from FlightAware
20
-    $Spotter->importFromFlightAware();
19
+	//imports the new data from FlightAware
20
+	$Spotter->importFromFlightAware();
21 21
 }
22 22
 ?>
23 23
\ No newline at end of file
Please login to merge, or discard this patch.
scripts/daemon-spotter.php 3 patches
Braces   +433 added lines, -151 removed lines patch added patch discarded remove patch
@@ -13,7 +13,9 @@  discard block
 block discarded – undo
13 13
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
14 14
 require_once(dirname(__FILE__).'/../require/class.Common.php');
15 15
 
16
-if (!isset($globalDebug)) $globalDebug = FALSE;
16
+if (!isset($globalDebug)) {
17
+	$globalDebug = FALSE;
18
+}
17 19
 
18 20
 // Check if schema is at latest version
19 21
 $Connection = new Connection();
@@ -43,15 +45,27 @@  discard block
 block discarded – undo
43 45
 $options = getopt('s::',array('source::','server','idsource::'));
44 46
 //if (isset($options['s'])) $hosts = array($options['s']);
45 47
 //elseif (isset($options['source'])) $hosts = array($options['source']);
46
-if (isset($options['s'])) $globalSources[] = array('host' => $options['s']);
47
-elseif (isset($options['source'])) $globalSources[] = array('host' => $options['source']);
48
-if (isset($options['server'])) $globalServer = TRUE;
49
-if (isset($options['idsource'])) $id_source = $options['idsource'];
50
-else $id_source = 1;
48
+if (isset($options['s'])) {
49
+	$globalSources[] = array('host' => $options['s']);
50
+} elseif (isset($options['source'])) {
51
+	$globalSources[] = array('host' => $options['source']);
52
+}
53
+if (isset($options['server'])) {
54
+	$globalServer = TRUE;
55
+}
56
+if (isset($options['idsource'])) {
57
+	$id_source = $options['idsource'];
58
+} else {
59
+	$id_source = 1;
60
+}
51 61
 if (isset($globalServer) && $globalServer) {
52
-    if ($globalDebug) echo "Using Server Mode\n";
62
+    if ($globalDebug) {
63
+    	echo "Using Server Mode\n";
64
+    }
53 65
     $SI=new SpotterServer();
54
-} else $SI=new SpotterImport($Connection->db);
66
+} else {
67
+	$SI=new SpotterImport($Connection->db);
68
+}
55 69
 //$APRS=new APRS($Connection->db);
56 70
 $SBS=new SBS($Connection->db);
57 71
 $Common=new Common();
@@ -68,14 +82,18 @@  discard block
 block discarded – undo
68 82
 }
69 83
 
70 84
 // let's try and connect
71
-if ($globalDebug) echo "Connecting...\n";
85
+if ($globalDebug) {
86
+	echo "Connecting...\n";
87
+}
72 88
 $use_aprs = false;
73 89
 
74 90
 function create_socket($host, $port, &$errno, &$errstr) {
75 91
     $ip = gethostbyname($host);
76 92
     $s = socket_create(AF_INET, SOCK_STREAM, 0);
77 93
     $r = @socket_connect($s, $ip, $port);
78
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
94
+    if (!socket_set_nonblock($s)) {
95
+    	echo "Unable to set nonblock on socket\n";
96
+    }
79 97
     if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
80 98
         return $s;
81 99
     }
@@ -97,22 +115,30 @@  discard block
 block discarded – undo
97 115
         	//$formats[$id] = 'deltadbtxt';
98 116
         	$globalSources[$id]['format'] = 'deltadbtxt';
99 117
         	//$last_exec['deltadbtxt'] = 0;
100
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
118
+        	if ($globalDebug) {
119
+        		echo "Connect to deltadb source (".$host.")...\n";
120
+        	}
101 121
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
102 122
         	//$formats[$id] = 'vatsimtxt';
103 123
         	$globalSources[$id]['format'] = 'vatsimtxt';
104 124
         	//$last_exec['vatsimtxt'] = 0;
105
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
125
+        	if ($globalDebug) {
126
+        		echo "Connect to vatsim source (".$host.")...\n";
127
+        	}
106 128
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
107 129
         	//$formats[$id] = 'aircraftlistjson';
108 130
         	$$globalSources[$id]['format'] = 'aircraftlistjson';
109 131
         	//$last_exec['aircraftlistjson'] = 0;
110
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
132
+        	if ($globalDebug) {
133
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
134
+        	}
111 135
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
112 136
         	//$formats[$id] = 'radarvirtueljson';
113 137
         	$globalSources[$id]['format'] = 'radarvirtueljson';
114 138
         	//$last_exec['radarvirtueljson'] = 0;
115
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
139
+        	if ($globalDebug) {
140
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
141
+        	}
116 142
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
117 143
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
118 144
         	    exit(0);
@@ -121,7 +147,9 @@  discard block
 block discarded – undo
121 147
         	//$formats[$id] = 'planeupdatefaa';
122 148
         	$globalSources[$id]['format'] = 'planeupdatefaa';
123 149
         	//$last_exec['planeupdatefaa'] = 0;
124
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
150
+        	if ($globalDebug) {
151
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
152
+        	}
125 153
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
126 154
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
127 155
         	    exit(0);
@@ -130,22 +158,30 @@  discard block
 block discarded – undo
130 158
         	//$formats[$id] = 'phpvmacars';
131 159
         	$globalSources[$id]['format'] = 'phpvmacars';
132 160
         	//$last_exec['phpvmacars'] = 0;
133
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
161
+        	if ($globalDebug) {
162
+        		echo "Connect to phpvmacars source (".$host.")...\n";
163
+        	}
134 164
             } else if (preg_match('/whazzup/i',$host)) {
135 165
         	//$formats[$id] = 'whazzup';
136 166
         	$globalSources[$id]['format'] = 'whazzup';
137 167
         	//$last_exec['whazzup'] = 0;
138
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
168
+        	if ($globalDebug) {
169
+        		echo "Connect to whazzup source (".$host.")...\n";
170
+        	}
139 171
             } else if (preg_match('/recentpireps/i',$host)) {
140 172
         	//$formats[$id] = 'pirepsjson';
141 173
         	$globalSources[$id]['format'] = 'pirepsjson';
142 174
         	//$last_exec['pirepsjson'] = 0;
143
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
175
+        	if ($globalDebug) {
176
+        		echo "Connect to pirepsjson source (".$host.")...\n";
177
+        	}
144 178
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
145 179
         	//$formats[$id] = 'fr24json';
146 180
         	$globalSources[$id]['format'] = 'fr24json';
147 181
         	//$last_exec['fr24json'] = 0;
148
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
182
+        	if ($globalDebug) {
183
+        		echo "Connect to fr24 source (".$host.")...\n";
184
+        	}
149 185
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
150 186
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151 187
         	    exit(0);
@@ -154,14 +190,21 @@  discard block
 block discarded – undo
154 190
             } else if (preg_match('/10001/',$host) || $globalSources[$id]['port'] == '10001') {
155 191
         	//$formats[$id] = 'tsv';
156 192
         	$globalSources[$id]['format'] = 'tsv';
157
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
193
+        	if ($globalDebug) {
194
+        		echo "Connect to tsv source (".$host.")...\n";
195
+        	}
158 196
             }
159 197
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
160
-        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
+        	if ($globalDebug) {
199
+        		echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
200
+        	}
161 201
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
162 202
 	    $hostport = explode(':',$host);
163
-	    if (isset($hostport[1])) $port = $hostport[1];
164
-	    else $port = $globalSources[$id]['port'];
203
+	    if (isset($hostport[1])) {
204
+	    	$port = $hostport[1];
205
+	    } else {
206
+	    	$port = $globalSources[$id]['port'];
207
+	    }
165 208
     	    $s = create_socket($host,$port, $errno, $errstr);
166 209
 	    if ($s) {
167 210
     	        $sockets[$id] = $s;
@@ -182,17 +225,25 @@  discard block
 block discarded – undo
182 225
         		//$formats[$id] = 'beast';
183 226
         		$globalSources[$id]['format'] = 'beast';
184 227
 		    //} else $formats[$id] = 'sbs';
185
-		    } else $globalSources[$id]['format'] = 'sbs';
228
+		    } else {
229
+		    	$globalSources[$id]['format'] = 'sbs';
230
+		    }
186 231
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
187 232
 		}
188
-		if ($globalDebug) echo 'Connection in progress to '.$host.'('.$globalSources[$id]['format'].')....'."\n";
233
+		if ($globalDebug) {
234
+			echo 'Connection in progress to '.$host.'('.$globalSources[$id]['format'].')....'."\n";
235
+		}
189 236
             } else {
190
-		if ($globalDebug) echo 'Connection failed to '.$host.':'.$port.' : '.$errno.' '.$errstr."\n";
237
+		if ($globalDebug) {
238
+			echo 'Connection failed to '.$host.':'.$port.' : '.$errno.' '.$errstr."\n";
239
+		}
191 240
     	    }
192 241
         }
193 242
     }
194 243
 }
195
-if (!isset($globalMinFetch)) $globalMinFetch = 0;
244
+if (!isset($globalMinFetch)) {
245
+	$globalMinFetch = 0;
246
+}
196 247
 
197 248
 // Initialize all
198 249
 $status = array();
@@ -200,13 +251,19 @@  discard block
 block discarded – undo
200 251
 $formats = array();
201 252
 $last_exec = array();
202 253
 $time = time();
203
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
204
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
205
-else $timeout = 20;
254
+if (isset($globalSourcesTimeout)) {
255
+	$timeout = $globalSourcesTimeOut;
256
+} else if (isset($globalSBS1TimeOut)) {
257
+	$timeout = $globalSBS1TimeOut;
258
+} else {
259
+	$timeout = 20;
260
+}
206 261
 $errno = '';
207 262
 $errstr='';
208 263
 
209
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
264
+if (!isset($globalDaemon)) {
265
+	$globalDaemon = TRUE;
266
+}
210 267
 /* Initiate connections to all the hosts simultaneously */
211 268
 //connect_all($hosts);
212 269
 connect_all($globalSources);
@@ -228,23 +285,41 @@  discard block
 block discarded – undo
228 285
 	$aprs_connect = 0;
229 286
 	$aprs_keep = 240;
230 287
 	$aprs_last_tx = time();
231
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
232
-	else $aprs_version = $globalName.' using FlightAirMap';
288
+	if (isset($globalAPRSversion)) {
289
+		$aprs_version = $globalAPRSversion;
290
+	} else {
291
+		$aprs_version = $globalName.' using FlightAirMap';
292
+	}
233 293
 	//else $aprs_version = 'Perl Example App';
234
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
235
-	else $aprs_ssid = 'FAM';
294
+	if (isset($globalAPRSssid)) {
295
+		$aprs_ssid = $globalAPRSssid;
296
+	} else {
297
+		$aprs_ssid = 'FAM';
298
+	}
236 299
 	//else $aprs_ssid = 'PerlEx';
237
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
238
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
239
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} appid {$aprs_version} filter {$aprs_filter}\n";
240
-	else $aprs_login = "user {$aprs_ssid} appid {$aprs_version}\n";
241
-}
300
+	if (isset($globalAPRSfilter)) {
301
+		$aprs_filter = $globalAPRSfilter;
302
+	} else {
303
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
304
+	}
305
+	if ($aprs_filter != '') {
306
+		$aprs_login = "user {$aprs_ssid} appid {$aprs_version} filter {$aprs_filter}\n";
307
+	} else {
308
+		$aprs_login = "user {$aprs_ssid} appid {$aprs_version}\n";
309
+	}
310
+	}
242 311
 
243 312
 // connected - lets do some work
244
-if ($globalDebug) echo "Connected!\n";
313
+if ($globalDebug) {
314
+	echo "Connected!\n";
315
+}
245 316
 sleep(1);
246
-if ($globalDebug) echo "SCAN MODE \n\n";
247
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
317
+if ($globalDebug) {
318
+	echo "SCAN MODE \n\n";
319
+}
320
+if (!isset($globalCronEnd)) {
321
+	$globalCronEnd = 60;
322
+}
248 323
 $endtime = time()+$globalCronEnd;
249 324
 $i = 1;
250 325
 $tt = 0;
@@ -259,7 +334,9 @@  discard block
 block discarded – undo
259 334
 
260 335
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
261 336
 while ($i > 0) {
262
-    if (!$globalDaemon) $i = $endtime-time();
337
+    if (!$globalDaemon) {
338
+    	$i = $endtime-time();
339
+    }
263 340
     // Delete old ATC
264 341
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
265 342
         $ATC->deleteOldATC();
@@ -289,8 +366,12 @@  discard block
 block discarded – undo
289 366
 		    $data['datetime'] = date('Y-m-d H:i:s');
290 367
 		    $data['format_source'] = 'deltadbtxt';
291 368
     		    $data['id_source'] = $id_source;
292
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
293
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
369
+		    if (isset($value['name']) && $value['name'] != '') {
370
+		    	$data['source_name'] = $value['name'];
371
+		    }
372
+		    if (isset($value['sourcestats'])) {
373
+		    	$data['sourcestats'] = $value['sourcestats'];
374
+		    }
294 375
     		    $SI->add($data);
295 376
 		    unset($data);
296 377
     		}
@@ -312,10 +393,19 @@  discard block
 block discarded – undo
312 393
 			$data['pilot_name'] = $line[2];
313 394
 			$data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT);
314 395
 			$data['ident'] = $line[0]; // ident
315
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
396
+			if ($line[7] != '' && $line[7] != 0) {
397
+				$data['altitude'] = $line[7];
398
+			}
399
+			// altitude
316 400
 			$data['speed'] = $line[8]; // speed
317
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
318
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
401
+			if (isset($line[45])) {
402
+				$data['heading'] = $line[45];
403
+			}
404
+			// heading
405
+			elseif (isset($line[38])) {
406
+				$data['heading'] = $line[38];
407
+			}
408
+			// heading
319 409
 			$data['latitude'] = $line[5]; // lat
320 410
 	        	$data['longitude'] = $line[6]; // long
321 411
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -330,7 +420,9 @@  discard block
 block discarded – undo
330 420
 			$data['frequency'] = $line[4];
331 421
 			$data['type'] = $line[18];
332 422
 			$data['range'] = $line[19];
333
-			if (isset($line[35])) $data['info'] = $line[35];
423
+			if (isset($line[35])) {
424
+				$data['info'] = $line[35];
425
+			}
334 426
     			$data['id_source'] = $id_source;
335 427
 	    		//$data['arrival_airport_time'] = ;
336 428
 	    		if ($line[9] != '') {
@@ -344,22 +436,35 @@  discard block
 block discarded – undo
344 436
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
345 437
 	    		*/
346 438
 	    		$data['format_source'] = $value['format'];
347
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
348
-    			if ($line[3] == 'PILOT') $SI->add($data);
349
-			elseif ($line[3] == 'ATC') {
439
+			if (isset($value['name']) && $value['name'] != '') {
440
+				$data['source_name'] = $value['name'];
441
+			}
442
+    			if ($line[3] == 'PILOT') {
443
+    				$SI->add($data);
444
+    			} elseif ($line[3] == 'ATC') {
350 445
 				//print_r($data);
351 446
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
352 447
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
353 448
 				$typec = substr($data['ident'],-3);
354
-				if ($typec == 'APP') $data['type'] = 'Approach';
355
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
356
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
357
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
358
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
359
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
360
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
361
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
362
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
449
+				if ($typec == 'APP') {
450
+					$data['type'] = 'Approach';
451
+				} elseif ($typec == 'TWR') {
452
+					$data['type'] = 'Tower';
453
+				} elseif ($typec == 'OBS') {
454
+					$data['type'] = 'Observer';
455
+				} elseif ($typec == 'GND') {
456
+					$data['type'] = 'Ground';
457
+				} elseif ($typec == 'DEL') {
458
+					$data['type'] = 'Delivery';
459
+				} elseif ($typec == 'DEP') {
460
+					$data['type'] = 'Departure';
461
+				} elseif ($typec == 'FSS') {
462
+					$data['type'] = 'Flight Service Station';
463
+				} elseif ($typec == 'CTR') {
464
+					$data['type'] = 'Control Radar or Centre';
465
+				} elseif ($data['type'] == '') {
466
+					$data['type'] = 'Observer';
467
+				}
363 468
 				
364 469
 				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']);
365 470
 			}
@@ -379,26 +484,55 @@  discard block
 block discarded – undo
379 484
 		foreach ($all_data['acList'] as $line) {
380 485
 		    $data = array();
381 486
 		    $data['hex'] = $line['Icao']; // hex
382
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
383
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
384
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
385
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
386
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
387
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
487
+		    if (isset($line['Call'])) {
488
+		    	$data['ident'] = $line['Call'];
489
+		    }
490
+		    // ident
491
+		    if (isset($line['Alt'])) {
492
+		    	$data['altitude'] = $line['Alt'];
493
+		    }
494
+		    // altitude
495
+		    if (isset($line['Spd'])) {
496
+		    	$data['speed'] = $line['Spd'];
497
+		    }
498
+		    // speed
499
+		    if (isset($line['Trak'])) {
500
+		    	$data['heading'] = $line['Trak'];
501
+		    }
502
+		    // heading
503
+		    if (isset($line['Lat'])) {
504
+		    	$data['latitude'] = $line['Lat'];
505
+		    }
506
+		    // lat
507
+		    if (isset($line['Long'])) {
508
+		    	$data['longitude'] = $line['Long'];
509
+		    }
510
+		    // long
388 511
 		    //$data['verticalrate'] = $line['']; // verticale rate
389
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
512
+		    if (isset($line['Sqk'])) {
513
+		    	$data['squawk'] = $line['Sqk'];
514
+		    }
515
+		    // squawk
390 516
 		    $data['emergency'] = ''; // emergency
391
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
517
+		    if (isset($line['Reg'])) {
518
+		    	$data['registration'] = $line['Reg'];
519
+		    }
392 520
 		    /*
393 521
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
394 522
 		    else $data['datetime'] = date('Y-m-d H:i:s');
395 523
 		    */
396 524
 		    $data['datetime'] = date('Y-m-d H:i:s');
397
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
525
+		    if (isset($line['Type'])) {
526
+		    	$data['aircraft_icao'] = $line['Type'];
527
+		    }
398 528
 	    	    $data['format_source'] = 'aircraftlistjson';
399 529
 		    $data['id_source'] = $id_source;
400
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
401
-		    if (isset($data['datetime'])) $SI->add($data);
530
+		    if (isset($value['name']) && $value['name'] != '') {
531
+		    	$data['source_name'] = $value['name'];
532
+		    }
533
+		    if (isset($data['datetime'])) {
534
+		    	$SI->add($data);
535
+		    }
402 536
 		    unset($data);
403 537
 		}
404 538
 	    } else {
@@ -417,7 +551,9 @@  discard block
 block discarded – undo
417 551
 		    $data['datetime'] = date('Y-m-d H:i:s');
418 552
 	    	    $data['format_source'] = 'aircraftlistjson';
419 553
     		    $data['id_source'] = $id_source;
420
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
554
+		    if (isset($value['name']) && $value['name'] != '') {
555
+		    	$data['source_name'] = $value['name'];
556
+		    }
421 557
 		    $SI->add($data);
422 558
 		    unset($data);
423 559
 		}
@@ -452,7 +588,9 @@  discard block
 block discarded – undo
452 588
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
453 589
 	    	    $data['format_source'] = 'planeupdatefaa';
454 590
     		    $data['id_source'] = $id_source;
455
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
591
+		    if (isset($value['name']) && $value['name'] != '') {
592
+		    	$data['source_name'] = $value['name'];
593
+		    }
456 594
 		    $SI->add($data);
457 595
 		    unset($data);
458 596
 		}
@@ -484,7 +622,9 @@  discard block
 block discarded – undo
484 622
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
485 623
 	    	    $data['format_source'] = 'fr24json';
486 624
     		    $data['id_source'] = $id_source;
487
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
625
+		    if (isset($value['name']) && $value['name'] != '') {
626
+		    	$data['source_name'] = $value['name'];
627
+		    }
488 628
 		    $SI->add($data);
489 629
 		    unset($data);
490 630
 		}
@@ -507,23 +647,39 @@  discard block
 block discarded – undo
507 647
 		    if (isset($line['inf'])) {
508 648
 			$data = array();
509 649
 			$data['hex'] = $line['inf']['ia'];
510
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
650
+			if (isset($line['inf']['cs'])) {
651
+				$data['ident'] = $line['inf']['cs'];
652
+			}
653
+			//$line[13]
511 654
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
512
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
513
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
655
+	    		if (isset($line['inf']['gs'])) {
656
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
657
+	    		}
658
+	    		// speed
659
+	    		if (isset($line['inf']['tr'])) {
660
+	    			$data['heading'] = $line['inf']['tr'];
661
+	    		}
662
+	    		// heading
514 663
 	    		$data['latitude'] = $line['pt'][0]; // lat
515 664
 	    		$data['longitude'] = $line['pt'][1]; // long
516 665
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
517
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
666
+	    		if (isset($line['inf']['sq'])) {
667
+	    			$data['squawk'] = $line['inf']['sq'];
668
+	    		}
669
+	    		// squawk
518 670
 	    		//$data['aircraft_icao'] = $line[8];
519
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
671
+	    		if (isset($line['inf']['rc'])) {
672
+	    			$data['registration'] = $line['inf']['rc'];
673
+	    		}
520 674
 			//$data['departure_airport_iata'] = $line[11];
521 675
 			//$data['arrival_airport_iata'] = $line[12];
522 676
 	    		//$data['emergency'] = ''; // emergency
523 677
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
524 678
 	    		$data['format_source'] = 'radarvirtueljson';
525 679
     			$data['id_source'] = $id_source;
526
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
680
+			if (isset($value['name']) && $value['name'] != '') {
681
+				$data['source_name'] = $value['name'];
682
+			}
527 683
 			$SI->add($data);
528 684
 			unset($data);
529 685
 		    }
@@ -542,29 +698,62 @@  discard block
 block discarded – undo
542 698
 		    $data = array();
543 699
 		    $data['hex'] = str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT);
544 700
 		    $data['ident'] = $line['callsign']; // ident
545
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
546
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
547
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
548
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
549
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
550
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
701
+		    if (isset($line['pilotid'])) {
702
+		    	$data['pilot_id'] = $line['pilotid'];
703
+		    }
704
+		    // pilot id
705
+		    if (isset($line['name'])) {
706
+		    	$data['pilot_name'] = $line['name'];
707
+		    }
708
+		    // pilot name
709
+		    if (isset($line['alt'])) {
710
+		    	$data['altitude'] = $line['alt'];
711
+		    }
712
+		    // altitude
713
+		    if (isset($line['gs'])) {
714
+		    	$data['speed'] = $line['gs'];
715
+		    }
716
+		    // speed
717
+		    if (isset($line['heading'])) {
718
+		    	$data['heading'] = $line['heading'];
719
+		    }
720
+		    // heading
721
+		    if (isset($line['route'])) {
722
+		    	$data['waypoints'] = $line['route'];
723
+		    }
724
+		    // route
551 725
 		    $data['latitude'] = $line['lat']; // lat
552 726
 		    $data['longitude'] = $line['lon']; // long
553 727
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
554 728
 		    //$data['squawk'] = $line['squawk']; // squawk
555 729
 		    //$data['emergency'] = ''; // emergency
556
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
557
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
558
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
730
+		    if (isset($line['depicao'])) {
731
+		    	$data['departure_airport_icao'] = $line['depicao'];
732
+		    }
733
+		    if (isset($line['deptime'])) {
734
+		    	$data['departure_airport_time'] = $line['deptime'];
735
+		    }
736
+		    if (isset($line['arricao'])) {
737
+		    	$data['arrival_airport_icao'] = $line['arricao'];
738
+		    }
559 739
 		    //$data['arrival_airport_time'] = $line['arrtime'];
560
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
561
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
562
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
563
-		    else $data['info'] = '';
740
+		    if (isset($line['aircraft'])) {
741
+		    	$data['aircraft_icao'] = $line['aircraft'];
742
+		    }
743
+		    if (isset($line['transponder'])) {
744
+		    	$data['squawk'] = $line['transponder'];
745
+		    }
746
+		    if (isset($line['atis'])) {
747
+		    	$data['info'] = $line['atis'];
748
+		    } else {
749
+		    	$data['info'] = '';
750
+		    }
564 751
 		    $data['format_source'] = 'pireps';
565 752
     		    $data['id_source'] = $id_source;
566 753
 		    $data['datetime'] = date('Y-m-d H:i:s');
567
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
754
+		    if (isset($value['name']) && $value['name'] != '') {
755
+		    	$data['source_name'] = $value['name'];
756
+		    }
568 757
 		    if ($line['icon'] == 'plane') {
569 758
 			$SI->add($data);
570 759
 		    //    print_r($data);
@@ -573,15 +762,25 @@  discard block
 block discarded – undo
573 762
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
574 763
 			$typec = substr($data['ident'],-3);
575 764
 			$data['type'] = '';
576
-			if ($typec == 'APP') $data['type'] = 'Approach';
577
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
578
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
579
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
580
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
581
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
582
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
583
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
584
-			else $data['type'] = 'Observer';
765
+			if ($typec == 'APP') {
766
+				$data['type'] = 'Approach';
767
+			} elseif ($typec == 'TWR') {
768
+				$data['type'] = 'Tower';
769
+			} elseif ($typec == 'OBS') {
770
+				$data['type'] = 'Observer';
771
+			} elseif ($typec == 'GND') {
772
+				$data['type'] = 'Ground';
773
+			} elseif ($typec == 'DEL') {
774
+				$data['type'] = 'Delivery';
775
+			} elseif ($typec == 'DEP') {
776
+				$data['type'] = 'Departure';
777
+			} elseif ($typec == 'FSS') {
778
+				$data['type'] = 'Flight Service Station';
779
+			} elseif ($typec == 'CTR') {
780
+				$data['type'] = 'Control Radar or Centre';
781
+			} else {
782
+				$data['type'] = 'Observer';
783
+			}
585 784
 			echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name']);
586 785
 		    }
587 786
 		    unset($data);
@@ -599,8 +798,12 @@  discard block
 block discarded – undo
599 798
 	    	    $data = array();
600 799
 	    	    //$data['id'] = $line['id']; // id not usable
601 800
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
602
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
603
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
801
+	    	    if (isset($line['pilotname'])) {
802
+	    	    	$data['pilot_name'] = $line['pilotname'];
803
+	    	    }
804
+	    	    if (isset($line['pilotid'])) {
805
+	    	    	$data['pilot_id'] = $line['pilotid'];
806
+	    	    }
604 807
 	    	    $data['ident'] = $line['flightnum']; // ident
605 808
 	    	    $data['altitude'] = $line['alt']; // altitude
606 809
 	    	    $data['speed'] = $line['gs']; // speed
@@ -617,23 +820,35 @@  discard block
 block discarded – undo
617 820
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
618 821
     		    $data['arrival_airport_time'] = $line['arrtime'];
619 822
     		    $data['registration'] = $line['aircraft'];
620
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
823
+		    if (isset($line['route'])) {
824
+		    	$data['waypoints'] = $line['route'];
825
+		    }
826
+		    // route
621 827
 		    if (isset($line['aircraftname'])) {
622 828
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
623 829
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
624 830
 	    		$aircraft_data = explode('-',$line['aircraftname']);
625
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
626
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
627
-	    		else {
831
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) {
832
+	    			$data['aircraft_icao'] = $aircraft_data[0];
833
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) {
834
+	    			$data['aircraft_icao'] = $aircraft_data[1];
835
+	    		} else {
628 836
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
629
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
630
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
837
+	    		    if (isset($aircraft_data[1])) {
838
+	    		    	$data['aircraft_icao'] = $aircraft_data[1];
839
+	    		    } else {
840
+	    		    	$data['aircraft_icao'] = $line['aircraftname'];
841
+	    		    }
631 842
 	    		}
632 843
 	    	    }
633
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
844
+    		    if (isset($line['route'])) {
845
+    		    	$data['waypoints'] = $line['route'];
846
+    		    }
634 847
     		    $data['id_source'] = $id_source;
635 848
 	    	    $data['format_source'] = 'phpvmacars';
636
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
849
+		    if (isset($value['name']) && $value['name'] != '') {
850
+		    	$data['source_name'] = $value['name'];
851
+		    }
637 852
 		    $SI->add($data);
638 853
 		    unset($data);
639 854
 		}
@@ -642,14 +857,18 @@  discard block
 block discarded – undo
642 857
     	    $value['last_exec'] = time();
643 858
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
644 859
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast') {
645
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
860
+	    if (function_exists('pcntl_fork')) {
861
+	    	pcntl_signal_dispatch();
862
+	    }
646 863
 
647 864
 	    //$read = array( $sockets[$id] );
648 865
 	    $read = $sockets;
649 866
 	    $write = NULL;
650 867
 	    $e = NULL;
651 868
 	    $n = socket_select($read, $write, $e, $timeout);
652
-	    if ($e != NULL) var_dump($e);
869
+	    if ($e != NULL) {
870
+	    	var_dump($e);
871
+	    }
653 872
 	    if ($n > 0) {
654 873
 		foreach ($read as $nb => $r) {
655 874
 		    //$value = $formats[$nb];
@@ -671,8 +890,12 @@  discard block
 block discarded – undo
671 890
 			    if (is_array($data)) {
672 891
 				$data['datetime'] = date('Y-m-d H:i:s');
673 892
 				$data['format_source'] = 'raw';
674
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
675
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
893
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
894
+					$data['source_name'] = $globalSources[$nb]['name'];
895
+				}
896
+    				if (isset($globalSources[$nb]['sourcestats'])) {
897
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
898
+    				}
676 899
                                 $SI->add($data);
677 900
                             }
678 901
 			} elseif ($format == 'beast') {
@@ -688,21 +911,41 @@  discard block
 block discarded – undo
688 911
     				$data['hex'] = $lined['hexid'];
689 912
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
690 913
     				$data['datetime'] = date('Y-m-d H:i:s');;
691
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
692
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
693
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
694
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
695
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
696
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
697
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
914
+    				if (isset($lined['ident'])) {
915
+    					$data['ident'] = $lined['ident'];
916
+    				}
917
+    				if (isset($lined['lat'])) {
918
+    					$data['latitude'] = $lined['lat'];
919
+    				}
920
+    				if (isset($lined['lon'])) {
921
+    					$data['longitude'] = $lined['lon'];
922
+    				}
923
+    				if (isset($lined['speed'])) {
924
+    					$data['speed'] = $lined['speed'];
925
+    				}
926
+    				if (isset($lined['squawk'])) {
927
+    					$data['squawk'] = $lined['squawk'];
928
+    				}
929
+    				if (isset($lined['alt'])) {
930
+    					$data['altitude'] = $lined['alt'];
931
+    				}
932
+    				if (isset($lined['heading'])) {
933
+    					$data['heading'] = $lined['heading'];
934
+    				}
698 935
     				$data['id_source'] = $id_source;
699 936
     				$data['format_source'] = 'tsv';
700
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
701
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
937
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
938
+    					$data['source_name'] = $globalSources[$nb]['name'];
939
+    				}
940
+    				if (isset($globalSources[$nb]['sourcestats'])) {
941
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
942
+    				}
702 943
     				$SI->add($data);
703 944
     				unset($lined);
704 945
     				unset($data);
705
-    			    } else $error = true;
946
+    			    } else {
947
+    			    	$error = true;
948
+    			    }
706 949
 			} elseif ($format == 'aprs' && $use_aprs) {
707 950
 			    if ($aprs_connect == 0) {
708 951
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -726,29 +969,44 @@  discard block
 block discarded – undo
726 969
 				    $data['latitude'] = $line['latitude'];
727 970
 				    $data['longitude'] = $line['longitude'];
728 971
 				    //$data['verticalrate'] = $line[16];
729
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
730
-				    else $data['speed'] = 0;
972
+				    if (isset($line['speed'])) {
973
+				    	$data['speed'] = $line['speed'];
974
+				    } else {
975
+				    	$data['speed'] = 0;
976
+				    }
731 977
 				    $data['altitude'] = $line['altitude'];
732
-				    if (isset($line['course'])) $data['heading'] = $line['course'];
978
+				    if (isset($line['course'])) {
979
+				    	$data['heading'] = $line['course'];
980
+				    }
733 981
 				    //else $data['heading'] = 0;
734 982
 				    $data['aircraft_type'] = $line['stealth'];
735
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
983
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
984
+				    	$data['noarchive'] = true;
985
+				    }
736 986
     				    $data['id_source'] = $id_source;
737 987
 				    $data['format_source'] = 'aprs';
738 988
 				    $data['source_name'] = $line['source'];
739
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
989
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
990
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
991
+    				    }
740 992
 				    $currentdate = date('Y-m-d H:i:s');
741 993
 				    $aprsdate = strtotime($data['datetime']);
742 994
 				    // Accept data if time <= system time + 20s
743
-				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20)) $send = $SI->add($data);
744
-				    else {
745
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
746
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
995
+				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20)) {
996
+				    	$send = $SI->add($data);
997
+				    } else {
998
+					if ($line['stealth'] != 0) {
999
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1000
+					} else {
1001
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1002
+					}
747 1003
 				    }
748 1004
 				    unset($data);
749 1005
 				} 
750 1006
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
751
-				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1007
+				elseif ($line == true && $globalDebug) {
1008
+					echo '!! Failed : '.$buffer."!!\n";
1009
+				}
752 1010
 			    }
753 1011
 			} else {
754 1012
 			    $line = explode(',', $buffer);
@@ -776,33 +1034,49 @@  discard block
 block discarded – undo
776 1034
     				$data['ground'] = $line[21];
777 1035
     				$data['emergency'] = $line[19];
778 1036
     				$data['format_source'] = 'sbs';
779
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
780
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1037
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1038
+					$data['source_name'] = $globalSources[$nb]['name'];
1039
+				}
1040
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1041
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1042
+    				}
781 1043
     				$data['id_source'] = $id_source;
782 1044
     				$send = $SI->add($data);
783 1045
     				unset($data);
784
-    			    } else $error = true;
1046
+    			    } else {
1047
+    			    	$error = true;
1048
+    			    }
785 1049
 			    if ($error) {
786 1050
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
787
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1051
+					if ($globalDebug) {
1052
+						echo "Not a message. Ignoring... \n";
1053
+					}
788 1054
 				} else {
789
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1055
+					if ($globalDebug) {
1056
+						echo "Wrong line format. Ignoring... \n";
1057
+					}
790 1058
 					if ($globalDebug) {
791 1059
 						echo $buffer;
792 1060
 						print_r($line);
793 1061
 					}
794 1062
 					//socket_close($r);
795
-					if ($globalDebug) echo "Reconnect after an error...\n";
1063
+					if ($globalDebug) {
1064
+						echo "Reconnect after an error...\n";
1065
+					}
796 1066
 					connect_all($globalSources);
797 1067
 				}
798 1068
 			    }
799 1069
 			}
800 1070
 			// Sleep for xxx microseconds
801
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1071
+			if (isset($globalSBSSleep)) {
1072
+				usleep($globalSBSSleep);
1073
+			}
802 1074
 		    } else {
803 1075
 			$tt++;
804 1076
 			if ($tt > 30) {
805
-			    if ($globalDebug)echo "ERROR : Reconnect...";
1077
+			    if ($globalDebug) {
1078
+			    	echo "ERROR : Reconnect...";
1079
+			    }
806 1080
 			    //@socket_close($r);
807 1081
 			    sleep(2);
808 1082
 			    connect_all($globalSources);
@@ -813,12 +1087,18 @@  discard block
 block discarded – undo
813 1087
 		}
814 1088
 	    } else {
815 1089
 		$error = socket_strerror(socket_last_error());
816
-		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1090
+		if ($globalDebug) {
1091
+			echo "ERROR : socket_select give this error ".$error . "\n";
1092
+		}
817 1093
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) || time() - $time >= $timeout) {
818
-			if (isset($globalDebug)) echo "Restarting...\n";
1094
+			if (isset($globalDebug)) {
1095
+				echo "Restarting...\n";
1096
+			}
819 1097
 			// Restart the script if possible
820 1098
 			if (is_array($sockets)) {
821
-			    if ($globalDebug) echo "Shutdown all sockets...";
1099
+			    if ($globalDebug) {
1100
+			    	echo "Shutdown all sockets...";
1101
+			    }
822 1102
 			    
823 1103
 			    foreach ($sockets as $sock) {
824 1104
 				@socket_shutdown($sock,2);
@@ -826,7 +1106,9 @@  discard block
 block discarded – undo
826 1106
 			    }
827 1107
 			    
828 1108
 			}
829
-			    if ($globalDebug) echo "Restart all connections...";
1109
+			    if ($globalDebug) {
1110
+			    	echo "Restart all connections...";
1111
+			    }
830 1112
 			    sleep(2);
831 1113
 			    $time = time();
832 1114
 			    //connect_all($hosts);
Please login to merge, or discard this patch.
Indentation   +551 added lines, -551 removed lines patch added patch discarded remove patch
@@ -18,26 +18,26 @@  discard block
 block discarded – undo
18 18
 // Check if schema is at latest version
19 19
 $Connection = new Connection();
20 20
 if ($Connection->latest() === false) {
21
-    echo "You MUST update to latest schema. Run install/index.php";
22
-    exit();
21
+	echo "You MUST update to latest schema. Run install/index.php";
22
+	exit();
23 23
 }
24 24
 
25 25
 
26 26
 // This is to be compatible with old version of settings.php
27 27
 if (!isset($globalSources)) {
28
-    if (isset($globalSBS1Hosts)) {
29
-        //$hosts = $globalSBS1Hosts;
30
-        foreach ($globalSBS1Hosts as $host) {
31
-	    $globalSources[] = array('host' => $host);
32
-    	}
33
-    } else {
34
-        if (!isset($globalSBS1Host)) {
35
-	    echo '$globalSBS1Host MUST be defined !';
36
-	    die;
28
+	if (isset($globalSBS1Hosts)) {
29
+		//$hosts = $globalSBS1Hosts;
30
+		foreach ($globalSBS1Hosts as $host) {
31
+		$globalSources[] = array('host' => $host);
32
+		}
33
+	} else {
34
+		if (!isset($globalSBS1Host)) {
35
+		echo '$globalSBS1Host MUST be defined !';
36
+		die;
37 37
 	}
38 38
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
39 39
 	$globalSources[] = array('host' => $globalSBS1Host.':'.$globalSBS1Port);
40
-    }
40
+	}
41 41
 }
42 42
 
43 43
 $options = getopt('s::',array('source::','server','idsource::'));
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 if (isset($options['idsource'])) $id_source = $options['idsource'];
50 50
 else $id_source = 1;
51 51
 if (isset($globalServer) && $globalServer) {
52
-    if ($globalDebug) echo "Using Server Mode\n";
53
-    $SI=new SpotterServer();
52
+	if ($globalDebug) echo "Using Server Mode\n";
53
+	$SI=new SpotterServer();
54 54
 } else $SI=new SpotterImport($Connection->db);
55 55
 //$APRS=new APRS($Connection->db);
56 56
 $SBS=new SBS($Connection->db);
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
 //$servertz = system('date +%Z');
60 60
 // signal handler - playing nice with sockets and dump1090
61 61
 if (function_exists('pcntl_fork')) {
62
-    pcntl_signal(SIGINT,  function($signo) {
63
-        global $sockets;
64
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
65
-        die("Bye!\n");
66
-    });
67
-    pcntl_signal_dispatch();
62
+	pcntl_signal(SIGINT,  function($signo) {
63
+		global $sockets;
64
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
65
+		die("Bye!\n");
66
+	});
67
+	pcntl_signal_dispatch();
68 68
 }
69 69
 
70 70
 // let's try and connect
@@ -72,125 +72,125 @@  discard block
 block discarded – undo
72 72
 $use_aprs = false;
73 73
 
74 74
 function create_socket($host, $port, &$errno, &$errstr) {
75
-    $ip = gethostbyname($host);
76
-    $s = socket_create(AF_INET, SOCK_STREAM, 0);
77
-    $r = @socket_connect($s, $ip, $port);
78
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
79
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
80
-        return $s;
81
-    }
82
-    $errno = socket_last_error($s);
83
-    $errstr = socket_strerror($errno);
84
-    socket_close($s);
85
-    return false;
75
+	$ip = gethostbyname($host);
76
+	$s = socket_create(AF_INET, SOCK_STREAM, 0);
77
+	$r = @socket_connect($s, $ip, $port);
78
+	if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
79
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
80
+		return $s;
81
+	}
82
+	$errno = socket_last_error($s);
83
+	$errstr = socket_strerror($errno);
84
+	socket_close($s);
85
+	return false;
86 86
 }
87 87
 
88 88
 function connect_all($hosts) {
89
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
90
-    global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
91
-    foreach ($hosts as $id => $value) {
89
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
90
+	global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
91
+	foreach ($hosts as $id => $value) {
92 92
 	$host = $value['host'];
93 93
 	$globalSources[$id]['last_exec'] = 0;
94 94
 	// Here we check type of source(s)
95 95
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
96
-            if (preg_match('/deltadb.txt$/i',$host)) {
97
-        	//$formats[$id] = 'deltadbtxt';
98
-        	$globalSources[$id]['format'] = 'deltadbtxt';
99
-        	//$last_exec['deltadbtxt'] = 0;
100
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
101
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
102
-        	//$formats[$id] = 'vatsimtxt';
103
-        	$globalSources[$id]['format'] = 'vatsimtxt';
104
-        	//$last_exec['vatsimtxt'] = 0;
105
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
106
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
107
-        	//$formats[$id] = 'aircraftlistjson';
108
-        	$$globalSources[$id]['format'] = 'aircraftlistjson';
109
-        	//$last_exec['aircraftlistjson'] = 0;
110
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
111
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
112
-        	//$formats[$id] = 'radarvirtueljson';
113
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
114
-        	//$last_exec['radarvirtueljson'] = 0;
115
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
116
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
117
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
118
-        	    exit(0);
119
-        	}
120
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
121
-        	//$formats[$id] = 'planeupdatefaa';
122
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
123
-        	//$last_exec['planeupdatefaa'] = 0;
124
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
125
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
126
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
127
-        	    exit(0);
128
-        	}
129
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
130
-        	//$formats[$id] = 'phpvmacars';
131
-        	$globalSources[$id]['format'] = 'phpvmacars';
132
-        	//$last_exec['phpvmacars'] = 0;
133
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
134
-            } else if (preg_match('/whazzup/i',$host)) {
135
-        	//$formats[$id] = 'whazzup';
136
-        	$globalSources[$id]['format'] = 'whazzup';
137
-        	//$last_exec['whazzup'] = 0;
138
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
139
-            } else if (preg_match('/recentpireps/i',$host)) {
140
-        	//$formats[$id] = 'pirepsjson';
141
-        	$globalSources[$id]['format'] = 'pirepsjson';
142
-        	//$last_exec['pirepsjson'] = 0;
143
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
144
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
145
-        	//$formats[$id] = 'fr24json';
146
-        	$globalSources[$id]['format'] = 'fr24json';
147
-        	//$last_exec['fr24json'] = 0;
148
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
149
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
150
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151
-        	    exit(0);
152
-        	}
153
-            //} else if (preg_match('/10001/',$host)) {
154
-            } else if (preg_match('/10001/',$host) || $globalSources[$id]['port'] == '10001') {
155
-        	//$formats[$id] = 'tsv';
156
-        	$globalSources[$id]['format'] = 'tsv';
157
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
158
-            }
159
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
160
-        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
161
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
162
-	    $hostport = explode(':',$host);
163
-	    if (isset($hostport[1])) $port = $hostport[1];
164
-	    else $port = $globalSources[$id]['port'];
165
-    	    $s = create_socket($host,$port, $errno, $errstr);
166
-	    if ($s) {
167
-    	        $sockets[$id] = $s;
168
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
169
-		    if (preg_match('/aprs/',$host)) {
96
+			if (preg_match('/deltadb.txt$/i',$host)) {
97
+			//$formats[$id] = 'deltadbtxt';
98
+			$globalSources[$id]['format'] = 'deltadbtxt';
99
+			//$last_exec['deltadbtxt'] = 0;
100
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
101
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
102
+			//$formats[$id] = 'vatsimtxt';
103
+			$globalSources[$id]['format'] = 'vatsimtxt';
104
+			//$last_exec['vatsimtxt'] = 0;
105
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
106
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
107
+			//$formats[$id] = 'aircraftlistjson';
108
+			$$globalSources[$id]['format'] = 'aircraftlistjson';
109
+			//$last_exec['aircraftlistjson'] = 0;
110
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
111
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
112
+			//$formats[$id] = 'radarvirtueljson';
113
+			$globalSources[$id]['format'] = 'radarvirtueljson';
114
+			//$last_exec['radarvirtueljson'] = 0;
115
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
116
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
117
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
118
+				exit(0);
119
+			}
120
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
121
+			//$formats[$id] = 'planeupdatefaa';
122
+			$globalSources[$id]['format'] = 'planeupdatefaa';
123
+			//$last_exec['planeupdatefaa'] = 0;
124
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
125
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
126
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
127
+				exit(0);
128
+			}
129
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
130
+			//$formats[$id] = 'phpvmacars';
131
+			$globalSources[$id]['format'] = 'phpvmacars';
132
+			//$last_exec['phpvmacars'] = 0;
133
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
134
+			} else if (preg_match('/whazzup/i',$host)) {
135
+			//$formats[$id] = 'whazzup';
136
+			$globalSources[$id]['format'] = 'whazzup';
137
+			//$last_exec['whazzup'] = 0;
138
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
139
+			} else if (preg_match('/recentpireps/i',$host)) {
140
+			//$formats[$id] = 'pirepsjson';
141
+			$globalSources[$id]['format'] = 'pirepsjson';
142
+			//$last_exec['pirepsjson'] = 0;
143
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
144
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
145
+			//$formats[$id] = 'fr24json';
146
+			$globalSources[$id]['format'] = 'fr24json';
147
+			//$last_exec['fr24json'] = 0;
148
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
149
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
150
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151
+				exit(0);
152
+			}
153
+			//} else if (preg_match('/10001/',$host)) {
154
+			} else if (preg_match('/10001/',$host) || $globalSources[$id]['port'] == '10001') {
155
+			//$formats[$id] = 'tsv';
156
+			$globalSources[$id]['format'] = 'tsv';
157
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
158
+			}
159
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
160
+			if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
161
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
162
+		$hostport = explode(':',$host);
163
+		if (isset($hostport[1])) $port = $hostport[1];
164
+		else $port = $globalSources[$id]['port'];
165
+			$s = create_socket($host,$port, $errno, $errstr);
166
+		if ($s) {
167
+				$sockets[$id] = $s;
168
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
169
+			if (preg_match('/aprs/',$host)) {
170 170
 			//$formats[$id] = 'aprs';
171 171
 			$globalSources[$id]['format'] = 'aprs';
172 172
 			//$aprs_connect = 0;
173 173
 			//$use_aprs = true;
174
-    		    } elseif ($port == '10001') {
175
-        		//$formats[$id] = 'tsv';
176
-        		$globalSources[$id]['format'] = 'tsv';
177
-		    } elseif ($port == '30002') {
178
-        		//$formats[$id] = 'raw';
179
-        		$globalSources[$id]['format'] = 'raw';
180
-		    } elseif ($port == '30005') {
174
+				} elseif ($port == '10001') {
175
+				//$formats[$id] = 'tsv';
176
+				$globalSources[$id]['format'] = 'tsv';
177
+			} elseif ($port == '30002') {
178
+				//$formats[$id] = 'raw';
179
+				$globalSources[$id]['format'] = 'raw';
180
+			} elseif ($port == '30005') {
181 181
 			// Not yet supported
182
-        		//$formats[$id] = 'beast';
183
-        		$globalSources[$id]['format'] = 'beast';
184
-		    //} else $formats[$id] = 'sbs';
185
-		    } else $globalSources[$id]['format'] = 'sbs';
186
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
182
+				//$formats[$id] = 'beast';
183
+				$globalSources[$id]['format'] = 'beast';
184
+			//} else $formats[$id] = 'sbs';
185
+			} else $globalSources[$id]['format'] = 'sbs';
186
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
187 187
 		}
188 188
 		if ($globalDebug) echo 'Connection in progress to '.$host.'('.$globalSources[$id]['format'].')....'."\n";
189
-            } else {
189
+			} else {
190 190
 		if ($globalDebug) echo 'Connection failed to '.$host.':'.$port.' : '.$errno.' '.$errstr."\n";
191
-    	    }
192
-        }
193
-    }
191
+			}
192
+		}
193
+	}
194 194
 }
195 195
 if (!isset($globalMinFetch)) $globalMinFetch = 0;
196 196
 
@@ -213,13 +213,13 @@  discard block
 block discarded – undo
213 213
 
214 214
 // APRS Configuration
215 215
 foreach ($globalSources as $key => $source) {
216
-    if (isset($source['format']) && $source['format'] == 'aprs') {
216
+	if (isset($source['format']) && $source['format'] == 'aprs') {
217 217
 	$aprs_connect = 0;
218 218
 	$use_aprs = true;
219 219
 	break;
220
-    } elseif (!isset($source['format'])) {
221
-        $globalSources[$key]['format'] = 'auto';
222
-    }
220
+	} elseif (!isset($source['format'])) {
221
+		$globalSources[$key]['format'] = 'auto';
222
+	}
223 223
 }
224 224
 
225 225
 if ($use_aprs) {
@@ -259,53 +259,53 @@  discard block
 block discarded – undo
259 259
 
260 260
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
261 261
 while ($i > 0) {
262
-    if (!$globalDaemon) $i = $endtime-time();
263
-    // Delete old ATC
264
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
265
-        $ATC->deleteOldATC();
266
-    }
267
-    //foreach ($formats as $id => $value) {
268
-    foreach ($globalSources as $id => $value) {
262
+	if (!$globalDaemon) $i = $endtime-time();
263
+	// Delete old ATC
264
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
265
+		$ATC->deleteOldATC();
266
+	}
267
+	//foreach ($formats as $id => $value) {
268
+	foreach ($globalSources as $id => $value) {
269 269
 	//if ($value == 'deltadbtxt' && (time() - $last_exec['deltadbtxt'] > $globalMinFetch)) {
270 270
 	if ($value['format'] == 'deltadbtxt' && (time() - $value['last_exec'] > $globalMinFetch)) {
271
-	    //$buffer = $Common->getData($hosts[$id]);
272
-	    $buffer = $Common->getData($value['host']);
273
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
274
-	    $buffer = explode('\n',$buffer);
275
-	    foreach ($buffer as $line) {
276
-    		if ($line != '') {
277
-    		    $line = explode(',', $line);
278
-	            $data = array();
279
-	            $data['hex'] = $line[1]; // hex
280
-	            $data['ident'] = $line[2]; // ident
281
-	            $data['altitude'] = $line[3]; // altitude
282
-	            $data['speed'] = $line[4]; // speed
283
-	            $data['heading'] = $line[5]; // heading
284
-	            $data['latitude'] = $line[6]; // lat
285
-	            $data['longitude'] = $line[7]; // long
286
-	            $data['verticalrate'] = ''; // vertical rate
287
-	            $data['squawk'] = ''; // squawk
288
-	            $data['emergency'] = ''; // emergency
289
-		    $data['datetime'] = date('Y-m-d H:i:s');
290
-		    $data['format_source'] = 'deltadbtxt';
291
-    		    $data['id_source'] = $id_source;
292
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
293
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
294
-    		    $SI->add($data);
295
-		    unset($data);
296
-    		}
297
-    	    }
298
-    	    $value['last_exec'] = time();
271
+		//$buffer = $Common->getData($hosts[$id]);
272
+		$buffer = $Common->getData($value['host']);
273
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
274
+		$buffer = explode('\n',$buffer);
275
+		foreach ($buffer as $line) {
276
+			if ($line != '') {
277
+				$line = explode(',', $line);
278
+				$data = array();
279
+				$data['hex'] = $line[1]; // hex
280
+				$data['ident'] = $line[2]; // ident
281
+				$data['altitude'] = $line[3]; // altitude
282
+				$data['speed'] = $line[4]; // speed
283
+				$data['heading'] = $line[5]; // heading
284
+				$data['latitude'] = $line[6]; // lat
285
+				$data['longitude'] = $line[7]; // long
286
+				$data['verticalrate'] = ''; // vertical rate
287
+				$data['squawk'] = ''; // squawk
288
+				$data['emergency'] = ''; // emergency
289
+			$data['datetime'] = date('Y-m-d H:i:s');
290
+			$data['format_source'] = 'deltadbtxt';
291
+				$data['id_source'] = $id_source;
292
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
293
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
294
+				$SI->add($data);
295
+			unset($data);
296
+			}
297
+			}
298
+			$value['last_exec'] = time();
299 299
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
300 300
 	} elseif (($value['format'] == 'whazzup' && (time() - $value['last_exec'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $value['last_exec'] > $globalMinFetch))) {
301
-	    //$buffer = $Common->getData($hosts[$id]);
302
-	    $buffer = $Common->getData($value['host']);
303
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
304
-	    $buffer = explode('\n',$buffer);
305
-	    foreach ($buffer as $line) {
306
-    		if ($line != '') {
307
-    		    $line = explode(':', $line);
308
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
301
+		//$buffer = $Common->getData($hosts[$id]);
302
+		$buffer = $Common->getData($value['host']);
303
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
304
+		$buffer = explode('\n',$buffer);
305
+		foreach ($buffer as $line) {
306
+			if ($line != '') {
307
+				$line = explode(':', $line);
308
+				if (count($line) > 30 && $line[0] != 'callsign') {
309 309
 			$data = array();
310 310
 			$data['id'] = $line[1].'-'.$line[0];
311 311
 			$data['pilot_id'] = $line[1];
@@ -317,35 +317,35 @@  discard block
 block discarded – undo
317 317
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
318 318
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
319 319
 			$data['latitude'] = $line[5]; // lat
320
-	        	$data['longitude'] = $line[6]; // long
321
-	        	$data['verticalrate'] = ''; // vertical rate
322
-	        	$data['squawk'] = ''; // squawk
323
-	        	$data['emergency'] = ''; // emergency
324
-	        	$data['waypoints'] = $line[30];
320
+				$data['longitude'] = $line[6]; // long
321
+				$data['verticalrate'] = ''; // vertical rate
322
+				$data['squawk'] = ''; // squawk
323
+				$data['emergency'] = ''; // emergency
324
+				$data['waypoints'] = $line[30];
325 325
 			$data['datetime'] = date('Y-m-d H:i:s');
326 326
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
327
-		        $data['departure_airport_icao'] = $line[11];
328
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
329
-		        $data['arrival_airport_icao'] = $line[13];
327
+				$data['departure_airport_icao'] = $line[11];
328
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
329
+				$data['arrival_airport_icao'] = $line[13];
330 330
 			$data['frequency'] = $line[4];
331 331
 			$data['type'] = $line[18];
332 332
 			$data['range'] = $line[19];
333 333
 			if (isset($line[35])) $data['info'] = $line[35];
334
-    			$data['id_source'] = $id_source;
335
-	    		//$data['arrival_airport_time'] = ;
336
-	    		if ($line[9] != '') {
337
-	    		    $aircraft_data = explode('/',$line[9]);
338
-	    		    if (isset($aircraft_data[1])) {
339
-	    			$data['aircraft_icao'] = $aircraft_data[1];
340
-	    		    }
341
-        		}
342
-	    		/*
334
+				$data['id_source'] = $id_source;
335
+				//$data['arrival_airport_time'] = ;
336
+				if ($line[9] != '') {
337
+					$aircraft_data = explode('/',$line[9]);
338
+					if (isset($aircraft_data[1])) {
339
+					$data['aircraft_icao'] = $aircraft_data[1];
340
+					}
341
+				}
342
+				/*
343 343
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
344 344
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
345 345
 	    		*/
346
-	    		$data['format_source'] = $value['format'];
346
+				$data['format_source'] = $value['format'];
347 347
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
348
-    			if ($line[3] == 'PILOT') $SI->add($data);
348
+				if ($line[3] == 'PILOT') $SI->add($data);
349 349
 			elseif ($line[3] == 'ATC') {
350 350
 				//print_r($data);
351 351
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -363,212 +363,212 @@  discard block
 block discarded – undo
363 363
 				
364 364
 				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']);
365 365
 			}
366
-    			unset($data);
367
-    		    }
368
-    		}
369
-    	    }
370
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
371
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
372
-    	    $value['last_exec'] = time();
373
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
374
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
375
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
376
-	    if ($buffer != '') {
377
-	    $all_data = json_decode($buffer,true);
378
-	    if (isset($all_data['acList'])) {
366
+				unset($data);
367
+				}
368
+			}
369
+			}
370
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
371
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
372
+			$value['last_exec'] = time();
373
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
374
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
375
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
376
+		if ($buffer != '') {
377
+		$all_data = json_decode($buffer,true);
378
+		if (isset($all_data['acList'])) {
379 379
 		foreach ($all_data['acList'] as $line) {
380
-		    $data = array();
381
-		    $data['hex'] = $line['Icao']; // hex
382
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
383
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
384
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
385
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
386
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
387
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
388
-		    //$data['verticalrate'] = $line['']; // verticale rate
389
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
390
-		    $data['emergency'] = ''; // emergency
391
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
392
-		    /*
380
+			$data = array();
381
+			$data['hex'] = $line['Icao']; // hex
382
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
383
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
384
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
385
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
386
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
387
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
388
+			//$data['verticalrate'] = $line['']; // verticale rate
389
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
390
+			$data['emergency'] = ''; // emergency
391
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
392
+			/*
393 393
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
394 394
 		    else $data['datetime'] = date('Y-m-d H:i:s');
395 395
 		    */
396
-		    $data['datetime'] = date('Y-m-d H:i:s');
397
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
398
-	    	    $data['format_source'] = 'aircraftlistjson';
399
-		    $data['id_source'] = $id_source;
400
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
401
-		    if (isset($data['datetime'])) $SI->add($data);
402
-		    unset($data);
396
+			$data['datetime'] = date('Y-m-d H:i:s');
397
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
398
+				$data['format_source'] = 'aircraftlistjson';
399
+			$data['id_source'] = $id_source;
400
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
401
+			if (isset($data['datetime'])) $SI->add($data);
402
+			unset($data);
403 403
 		}
404
-	    } else {
404
+		} else {
405 405
 		foreach ($all_data as $line) {
406
-		    $data = array();
407
-		    $data['hex'] = $line['hex']; // hex
408
-		    $data['ident'] = $line['flight']; // ident
409
-		    $data['altitude'] = $line['altitude']; // altitude
410
-		    $data['speed'] = $line['speed']; // speed
411
-		    $data['heading'] = $line['track']; // heading
412
-		    $data['latitude'] = $line['lat']; // lat
413
-		    $data['longitude'] = $line['lon']; // long
414
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
415
-		    $data['squawk'] = $line['squawk']; // squawk
416
-		    $data['emergency'] = ''; // emergency
417
-		    $data['datetime'] = date('Y-m-d H:i:s');
418
-	    	    $data['format_source'] = 'aircraftlistjson';
419
-    		    $data['id_source'] = $id_source;
420
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
421
-		    $SI->add($data);
422
-		    unset($data);
406
+			$data = array();
407
+			$data['hex'] = $line['hex']; // hex
408
+			$data['ident'] = $line['flight']; // ident
409
+			$data['altitude'] = $line['altitude']; // altitude
410
+			$data['speed'] = $line['speed']; // speed
411
+			$data['heading'] = $line['track']; // heading
412
+			$data['latitude'] = $line['lat']; // lat
413
+			$data['longitude'] = $line['lon']; // long
414
+			$data['verticalrate'] = $line['vrt']; // verticale rate
415
+			$data['squawk'] = $line['squawk']; // squawk
416
+			$data['emergency'] = ''; // emergency
417
+			$data['datetime'] = date('Y-m-d H:i:s');
418
+				$data['format_source'] = 'aircraftlistjson';
419
+				$data['id_source'] = $id_source;
420
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
421
+			$SI->add($data);
422
+			unset($data);
423
+		}
423 424
 		}
424
-	    }
425
-	    }
426
-    	    //$last_exec['aircraftlistjson'] = time();
427
-    	    $value['last_exec'] = time();
428
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
429
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $value['last_exec'] > $globalMinFetch)) {
430
-	    $buffer = $Common->getData($value['host']);
431
-	    $all_data = json_decode($buffer,true);
432
-	    if (isset($all_data['planes'])) {
425
+		}
426
+			//$last_exec['aircraftlistjson'] = time();
427
+			$value['last_exec'] = time();
428
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
429
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $value['last_exec'] > $globalMinFetch)) {
430
+		$buffer = $Common->getData($value['host']);
431
+		$all_data = json_decode($buffer,true);
432
+		if (isset($all_data['planes'])) {
433 433
 		foreach ($all_data['planes'] as $key => $line) {
434
-		    $data = array();
435
-		    $data['hex'] = $key; // hex
436
-		    $data['ident'] = $line[3]; // ident
437
-		    $data['altitude'] = $line[6]; // altitude
438
-		    $data['speed'] = $line[8]; // speed
439
-		    $data['heading'] = $line[7]; // heading
440
-		    $data['latitude'] = $line[4]; // lat
441
-		    $data['longitude'] = $line[5]; // long
442
-		    //$data['verticalrate'] = $line[]; // verticale rate
443
-		    $data['squawk'] = $line[10]; // squawk
444
-		    $data['emergency'] = ''; // emergency
445
-		    $data['registration'] = $line[2];
446
-		    $data['aircraft_icao'] = $line[0];
447
-		    $deparr = explode('-',$line[1]);
448
-		    if (count($deparr) == 2) {
434
+			$data = array();
435
+			$data['hex'] = $key; // hex
436
+			$data['ident'] = $line[3]; // ident
437
+			$data['altitude'] = $line[6]; // altitude
438
+			$data['speed'] = $line[8]; // speed
439
+			$data['heading'] = $line[7]; // heading
440
+			$data['latitude'] = $line[4]; // lat
441
+			$data['longitude'] = $line[5]; // long
442
+			//$data['verticalrate'] = $line[]; // verticale rate
443
+			$data['squawk'] = $line[10]; // squawk
444
+			$data['emergency'] = ''; // emergency
445
+			$data['registration'] = $line[2];
446
+			$data['aircraft_icao'] = $line[0];
447
+			$deparr = explode('-',$line[1]);
448
+			if (count($deparr) == 2) {
449 449
 			$data['departure_airport_icao'] = $deparr[0];
450 450
 			$data['arrival_airport_icao'] = $deparr[1];
451
-		    }
452
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
453
-	    	    $data['format_source'] = 'planeupdatefaa';
454
-    		    $data['id_source'] = $id_source;
455
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
456
-		    $SI->add($data);
457
-		    unset($data);
451
+			}
452
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
453
+				$data['format_source'] = 'planeupdatefaa';
454
+				$data['id_source'] = $id_source;
455
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
456
+			$SI->add($data);
457
+			unset($data);
458 458
 		}
459
-	    }
460
-    	    //$last_exec['planeupdatefaa'] = time();
461
-    	    $value['last_exec'] = time();
462
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
463
-    	} elseif ($value['format'] == 'fr24json' && (time() - $value['last_exec'] > $globalMinFetch)) {
464
-	    //$buffer = $Common->getData($hosts[$id]);
465
-	    $buffer = $Common->getData($value['host']);
466
-	    $all_data = json_decode($buffer,true);
467
-	    foreach ($all_data as $key => $line) {
459
+		}
460
+			//$last_exec['planeupdatefaa'] = time();
461
+			$value['last_exec'] = time();
462
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
463
+		} elseif ($value['format'] == 'fr24json' && (time() - $value['last_exec'] > $globalMinFetch)) {
464
+		//$buffer = $Common->getData($hosts[$id]);
465
+		$buffer = $Common->getData($value['host']);
466
+		$all_data = json_decode($buffer,true);
467
+		foreach ($all_data as $key => $line) {
468 468
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
469
-		    $data = array();
470
-		    $data['hex'] = $line[0];
471
-		    $data['ident'] = $line[16]; //$line[13]
472
-	    	    $data['altitude'] = $line[4]; // altitude
473
-	    	    $data['speed'] = $line[5]; // speed
474
-	    	    $data['heading'] = $line[3]; // heading
475
-	    	    $data['latitude'] = $line[1]; // lat
476
-	    	    $data['longitude'] = $line[2]; // long
477
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
478
-	    	    $data['squawk'] = $line[6]; // squawk
479
-	    	    $data['aircraft_icao'] = $line[8];
480
-	    	    $data['registration'] = $line[9];
481
-		    $data['departure_airport_iata'] = $line[11];
482
-		    $data['arrival_airport_iata'] = $line[12];
483
-	    	    $data['emergency'] = ''; // emergency
484
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
485
-	    	    $data['format_source'] = 'fr24json';
486
-    		    $data['id_source'] = $id_source;
487
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
488
-		    $SI->add($data);
489
-		    unset($data);
469
+			$data = array();
470
+			$data['hex'] = $line[0];
471
+			$data['ident'] = $line[16]; //$line[13]
472
+				$data['altitude'] = $line[4]; // altitude
473
+				$data['speed'] = $line[5]; // speed
474
+				$data['heading'] = $line[3]; // heading
475
+				$data['latitude'] = $line[1]; // lat
476
+				$data['longitude'] = $line[2]; // long
477
+				$data['verticalrate'] = $line[15]; // verticale rate
478
+				$data['squawk'] = $line[6]; // squawk
479
+				$data['aircraft_icao'] = $line[8];
480
+				$data['registration'] = $line[9];
481
+			$data['departure_airport_iata'] = $line[11];
482
+			$data['arrival_airport_iata'] = $line[12];
483
+				$data['emergency'] = ''; // emergency
484
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
485
+				$data['format_source'] = 'fr24json';
486
+				$data['id_source'] = $id_source;
487
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
488
+			$SI->add($data);
489
+			unset($data);
490
+		}
490 491
 		}
491
-	    }
492
-    	    //$last_exec['fr24json'] = time();
493
-    	    $value['last_exec'] = time();
494
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
495
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $value['last_exec'] > $globalMinFetch)) {
496
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
497
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
498
-	    //echo $buffer;
499
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
500
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
501
-	    $all_data = json_decode($buffer,true);
502
-	    if (json_last_error() != JSON_ERROR_NONE) {
492
+			//$last_exec['fr24json'] = time();
493
+			$value['last_exec'] = time();
494
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
495
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $value['last_exec'] > $globalMinFetch)) {
496
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
497
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
498
+		//echo $buffer;
499
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
500
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
501
+		$all_data = json_decode($buffer,true);
502
+		if (json_last_error() != JSON_ERROR_NONE) {
503 503
 		die(json_last_error_msg());
504
-	    }
505
-	    if (isset($all_data['mrkrs'])) {
504
+		}
505
+		if (isset($all_data['mrkrs'])) {
506 506
 		foreach ($all_data['mrkrs'] as $key => $line) {
507
-		    if (isset($line['inf'])) {
507
+			if (isset($line['inf'])) {
508 508
 			$data = array();
509 509
 			$data['hex'] = $line['inf']['ia'];
510 510
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
511
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
512
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
513
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
514
-	    		$data['latitude'] = $line['pt'][0]; // lat
515
-	    		$data['longitude'] = $line['pt'][1]; // long
516
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
517
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
518
-	    		//$data['aircraft_icao'] = $line[8];
519
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
511
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
512
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
513
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
514
+				$data['latitude'] = $line['pt'][0]; // lat
515
+				$data['longitude'] = $line['pt'][1]; // long
516
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
517
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
518
+				//$data['aircraft_icao'] = $line[8];
519
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
520 520
 			//$data['departure_airport_iata'] = $line[11];
521 521
 			//$data['arrival_airport_iata'] = $line[12];
522
-	    		//$data['emergency'] = ''; // emergency
522
+				//$data['emergency'] = ''; // emergency
523 523
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
524
-	    		$data['format_source'] = 'radarvirtueljson';
525
-    			$data['id_source'] = $id_source;
524
+				$data['format_source'] = 'radarvirtueljson';
525
+				$data['id_source'] = $id_source;
526 526
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
527 527
 			$SI->add($data);
528 528
 			unset($data);
529
-		    }
529
+			}
530
+		}
530 531
 		}
531
-	    }
532
-    	    //$last_exec['radarvirtueljson'] = time();
533
-    	    $value['last_exec'] = time();
534
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
535
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
536
-	    //$buffer = $Common->getData($hosts[$id]);
537
-	    $buffer = $Common->getData($value['host']);
538
-	    $all_data = json_decode(utf8_encode($buffer),true);
532
+			//$last_exec['radarvirtueljson'] = time();
533
+			$value['last_exec'] = time();
534
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
535
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
536
+		//$buffer = $Common->getData($hosts[$id]);
537
+		$buffer = $Common->getData($value['host']);
538
+		$all_data = json_decode(utf8_encode($buffer),true);
539 539
 	    
540
-	    if (isset($all_data['pireps'])) {
541
-	        foreach ($all_data['pireps'] as $line) {
542
-		    $data = array();
543
-		    $data['hex'] = str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT);
544
-		    $data['ident'] = $line['callsign']; // ident
545
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
546
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
547
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
548
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
549
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
550
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
551
-		    $data['latitude'] = $line['lat']; // lat
552
-		    $data['longitude'] = $line['lon']; // long
553
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
554
-		    //$data['squawk'] = $line['squawk']; // squawk
555
-		    //$data['emergency'] = ''; // emergency
556
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
557
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
558
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
559
-		    //$data['arrival_airport_time'] = $line['arrtime'];
560
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
561
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
562
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
563
-		    else $data['info'] = '';
564
-		    $data['format_source'] = 'pireps';
565
-    		    $data['id_source'] = $id_source;
566
-		    $data['datetime'] = date('Y-m-d H:i:s');
567
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
568
-		    if ($line['icon'] == 'plane') {
540
+		if (isset($all_data['pireps'])) {
541
+			foreach ($all_data['pireps'] as $line) {
542
+			$data = array();
543
+			$data['hex'] = str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT);
544
+			$data['ident'] = $line['callsign']; // ident
545
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
546
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
547
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
548
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
549
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
550
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
551
+			$data['latitude'] = $line['lat']; // lat
552
+			$data['longitude'] = $line['lon']; // long
553
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
554
+			//$data['squawk'] = $line['squawk']; // squawk
555
+			//$data['emergency'] = ''; // emergency
556
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
557
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
558
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
559
+			//$data['arrival_airport_time'] = $line['arrtime'];
560
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
561
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
562
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
563
+			else $data['info'] = '';
564
+			$data['format_source'] = 'pireps';
565
+				$data['id_source'] = $id_source;
566
+			$data['datetime'] = date('Y-m-d H:i:s');
567
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
568
+			if ($line['icon'] == 'plane') {
569 569
 			$SI->add($data);
570
-		    //    print_r($data);
571
-    		    } elseif ($line['icon'] == 'ct') {
570
+			//    print_r($data);
571
+				} elseif ($line['icon'] == 'ct') {
572 572
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
573 573
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
574 574
 			$typec = substr($data['ident'],-3);
@@ -583,178 +583,178 @@  discard block
 block discarded – undo
583 583
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
584 584
 			else $data['type'] = 'Observer';
585 585
 			echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name']);
586
-		    }
587
-		    unset($data);
586
+			}
587
+			unset($data);
588
+		}
588 589
 		}
589
-	    }
590
-    	    //$last_exec['pirepsjson'] = time();
591
-    	    $value['last_exec'] = time();
592
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
593
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $value['last_exec'] > $globalMinFetch)) {
594
-	    //$buffer = $Common->getData($hosts[$id]);
595
-	    $buffer = $Common->getData($value['host']);
596
-	    $all_data = json_decode($buffer,true);
597
-	    if ($buffer != '' && is_array($all_data)) {
590
+			//$last_exec['pirepsjson'] = time();
591
+			$value['last_exec'] = time();
592
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
593
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $value['last_exec'] > $globalMinFetch)) {
594
+		//$buffer = $Common->getData($hosts[$id]);
595
+		$buffer = $Common->getData($value['host']);
596
+		$all_data = json_decode($buffer,true);
597
+		if ($buffer != '' && is_array($all_data)) {
598 598
 		foreach ($all_data as $line) {
599
-	    	    $data = array();
600
-	    	    //$data['id'] = $line['id']; // id not usable
601
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
602
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
603
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
604
-	    	    $data['ident'] = $line['flightnum']; // ident
605
-	    	    $data['altitude'] = $line['alt']; // altitude
606
-	    	    $data['speed'] = $line['gs']; // speed
607
-	    	    $data['heading'] = $line['heading']; // heading
608
-	    	    $data['latitude'] = $line['lat']; // lat
609
-	    	    $data['longitude'] = $line['lng']; // long
610
-	    	    $data['verticalrate'] = ''; // verticale rate
611
-	    	    $data['squawk'] = ''; // squawk
612
-	    	    $data['emergency'] = ''; // emergency
613
-	    	    //$data['datetime'] = $line['lastupdate'];
614
-		    $data['datetime'] = date('Y-m-d H:i:s');
615
-	    	    $data['departure_airport_icao'] = $line['depicao'];
616
-	    	    $data['departure_airport_time'] = $line['deptime'];
617
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
618
-    		    $data['arrival_airport_time'] = $line['arrtime'];
619
-    		    $data['registration'] = $line['aircraft'];
620
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
621
-		    if (isset($line['aircraftname'])) {
599
+				$data = array();
600
+				//$data['id'] = $line['id']; // id not usable
601
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
602
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
603
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
604
+				$data['ident'] = $line['flightnum']; // ident
605
+				$data['altitude'] = $line['alt']; // altitude
606
+				$data['speed'] = $line['gs']; // speed
607
+				$data['heading'] = $line['heading']; // heading
608
+				$data['latitude'] = $line['lat']; // lat
609
+				$data['longitude'] = $line['lng']; // long
610
+				$data['verticalrate'] = ''; // verticale rate
611
+				$data['squawk'] = ''; // squawk
612
+				$data['emergency'] = ''; // emergency
613
+				//$data['datetime'] = $line['lastupdate'];
614
+			$data['datetime'] = date('Y-m-d H:i:s');
615
+				$data['departure_airport_icao'] = $line['depicao'];
616
+				$data['departure_airport_time'] = $line['deptime'];
617
+				$data['arrival_airport_icao'] = $line['arricao'];
618
+				$data['arrival_airport_time'] = $line['arrtime'];
619
+				$data['registration'] = $line['aircraft'];
620
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
621
+			if (isset($line['aircraftname'])) {
622 622
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
623 623
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
624
-	    		$aircraft_data = explode('-',$line['aircraftname']);
625
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
626
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
627
-	    		else {
628
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
629
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
630
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
631
-	    		}
632
-	    	    }
633
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
634
-    		    $data['id_source'] = $id_source;
635
-	    	    $data['format_source'] = 'phpvmacars';
636
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
637
-		    $SI->add($data);
638
-		    unset($data);
624
+				$aircraft_data = explode('-',$line['aircraftname']);
625
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
626
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
627
+				else {
628
+					$aircraft_data = explode(' ',$line['aircraftname']);
629
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
630
+					else $data['aircraft_icao'] = $line['aircraftname'];
631
+				}
632
+				}
633
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
634
+				$data['id_source'] = $id_source;
635
+				$data['format_source'] = 'phpvmacars';
636
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
637
+			$SI->add($data);
638
+			unset($data);
639
+		}
639 640
 		}
640
-	    }
641
-    	    //$last_exec['phpvmacars'] = time();
642
-    	    $value['last_exec'] = time();
641
+			//$last_exec['phpvmacars'] = time();
642
+			$value['last_exec'] = time();
643 643
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
644 644
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast') {
645
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
645
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
646 646
 
647
-	    //$read = array( $sockets[$id] );
648
-	    $read = $sockets;
649
-	    $write = NULL;
650
-	    $e = NULL;
651
-	    $n = socket_select($read, $write, $e, $timeout);
652
-	    if ($e != NULL) var_dump($e);
653
-	    if ($n > 0) {
647
+		//$read = array( $sockets[$id] );
648
+		$read = $sockets;
649
+		$write = NULL;
650
+		$e = NULL;
651
+		$n = socket_select($read, $write, $e, $timeout);
652
+		if ($e != NULL) var_dump($e);
653
+		if ($n > 0) {
654 654
 		foreach ($read as $nb => $r) {
655
-		    //$value = $formats[$nb];
656
-		    $format = $globalSources[$nb]['format'];
657
-        	    $buffer = socket_read($r, 6000,PHP_NORMAL_READ);
658
-        	    //echo $buffer."\n";
659
-		    // lets play nice and handle signals such as ctrl-c/kill properly
660
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
661
-		    $dataFound = false;
662
-		    $error = false;
663
-		    //$SI::del();
664
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
665
-		    // SBS format is CSV format
666
-		    if ($buffer != '') {
655
+			//$value = $formats[$nb];
656
+			$format = $globalSources[$nb]['format'];
657
+				$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
658
+				//echo $buffer."\n";
659
+			// lets play nice and handle signals such as ctrl-c/kill properly
660
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
661
+			$dataFound = false;
662
+			$error = false;
663
+			//$SI::del();
664
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
665
+			// SBS format is CSV format
666
+			if ($buffer != '') {
667 667
 			$tt = 0;
668 668
 			if ($format == 'raw') {
669
-			    // AVR format
670
-			    $data = $SBS->parse($buffer);
671
-			    if (is_array($data)) {
669
+				// AVR format
670
+				$data = $SBS->parse($buffer);
671
+				if (is_array($data)) {
672 672
 				$data['datetime'] = date('Y-m-d H:i:s');
673 673
 				$data['format_source'] = 'raw';
674 674
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
675
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
676
-                                $SI->add($data);
677
-                            }
675
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
676
+								$SI->add($data);
677
+							}
678 678
 			} elseif ($format == 'beast') {
679
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
680
-			    die;
679
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
680
+				die;
681 681
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
682
-			    $line = explode("\t", $buffer);
683
-			    for($k = 0; $k < count($line); $k=$k+2) {
682
+				$line = explode("\t", $buffer);
683
+				for($k = 0; $k < count($line); $k=$k+2) {
684 684
 				$key = $line[$k];
685
-			        $lined[$key] = $line[$k+1];
686
-			    }
687
-    			    if (count($lined) > 3) {
688
-    				$data['hex'] = $lined['hexid'];
689
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
690
-    				$data['datetime'] = date('Y-m-d H:i:s');;
691
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
692
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
693
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
694
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
695
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
696
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
697
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
698
-    				$data['id_source'] = $id_source;
699
-    				$data['format_source'] = 'tsv';
700
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
701
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
702
-    				$SI->add($data);
703
-    				unset($lined);
704
-    				unset($data);
705
-    			    } else $error = true;
685
+					$lined[$key] = $line[$k+1];
686
+				}
687
+					if (count($lined) > 3) {
688
+					$data['hex'] = $lined['hexid'];
689
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
690
+					$data['datetime'] = date('Y-m-d H:i:s');;
691
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
692
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
693
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
694
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
695
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
696
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
697
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
698
+					$data['id_source'] = $id_source;
699
+					$data['format_source'] = 'tsv';
700
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
701
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
702
+					$SI->add($data);
703
+					unset($lined);
704
+					unset($data);
705
+					} else $error = true;
706 706
 			} elseif ($format == 'aprs' && $use_aprs) {
707
-			    if ($aprs_connect == 0) {
707
+				if ($aprs_connect == 0) {
708 708
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
709 709
 				$aprs_connect = 1;
710
-			    }
711
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
710
+				}
711
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
712 712
 				$aprs_last_tx = time();
713 713
 				$data_aprs = "# Keep alive";
714 714
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
715
-			    }
716
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
717
-			    if (substr($buffer,0,1) != '#') {
715
+				}
716
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
717
+				if (substr($buffer,0,1) != '#') {
718 718
 				$line = $APRS->parse($buffer);
719 719
 				if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
720
-				    $data = array();
721
-				    //print_r($line);
722
-				    $data['hex'] = $line['address'];
723
-				    $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
724
-				    //$data['datetime'] = date('Y-m-d H:i:s');
725
-				    $data['ident'] = $line['ident'];
726
-				    $data['latitude'] = $line['latitude'];
727
-				    $data['longitude'] = $line['longitude'];
728
-				    //$data['verticalrate'] = $line[16];
729
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
730
-				    else $data['speed'] = 0;
731
-				    $data['altitude'] = $line['altitude'];
732
-				    if (isset($line['course'])) $data['heading'] = $line['course'];
733
-				    //else $data['heading'] = 0;
734
-				    $data['aircraft_type'] = $line['stealth'];
735
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
736
-    				    $data['id_source'] = $id_source;
737
-				    $data['format_source'] = 'aprs';
738
-				    $data['source_name'] = $line['source'];
739
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
740
-				    $currentdate = date('Y-m-d H:i:s');
741
-				    $aprsdate = strtotime($data['datetime']);
742
-				    // Accept data if time <= system time + 20s
743
-				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20)) $send = $SI->add($data);
744
-				    else {
720
+					$data = array();
721
+					//print_r($line);
722
+					$data['hex'] = $line['address'];
723
+					$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
724
+					//$data['datetime'] = date('Y-m-d H:i:s');
725
+					$data['ident'] = $line['ident'];
726
+					$data['latitude'] = $line['latitude'];
727
+					$data['longitude'] = $line['longitude'];
728
+					//$data['verticalrate'] = $line[16];
729
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
730
+					else $data['speed'] = 0;
731
+					$data['altitude'] = $line['altitude'];
732
+					if (isset($line['course'])) $data['heading'] = $line['course'];
733
+					//else $data['heading'] = 0;
734
+					$data['aircraft_type'] = $line['stealth'];
735
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
736
+						$data['id_source'] = $id_source;
737
+					$data['format_source'] = 'aprs';
738
+					$data['source_name'] = $line['source'];
739
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
740
+					$currentdate = date('Y-m-d H:i:s');
741
+					$aprsdate = strtotime($data['datetime']);
742
+					// Accept data if time <= system time + 20s
743
+					if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20)) $send = $SI->add($data);
744
+					else {
745 745
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
746 746
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
747
-				    }
748
-				    unset($data);
747
+					}
748
+					unset($data);
749 749
 				} 
750 750
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
751 751
 				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
752
-			    }
752
+				}
753 753
 			} else {
754
-			    $line = explode(',', $buffer);
755
-    			    if (count($line) > 20) {
756
-    			    	$data['hex'] = $line[4];
757
-    				/*
754
+				$line = explode(',', $buffer);
755
+					if (count($line) > 20) {
756
+						$data['hex'] = $line[4];
757
+					/*
758 758
     				$data['datetime'] = $line[6].' '.$line[7];
759 759
     					date_default_timezone_set($globalTimezone);
760 760
     					$datetime = new DateTime($data['datetime']);
@@ -762,27 +762,27 @@  discard block
 block discarded – undo
762 762
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
763 763
     					date_default_timezone_set('UTC');
764 764
     				*/
765
-    				// Force datetime to current UTC datetime
766
-    				$data['datetime'] = date('Y-m-d H:i:s');
767
-    				$data['ident'] = trim($line[10]);
768
-    				$data['latitude'] = $line[14];
769
-    				$data['longitude'] = $line[15];
770
-    				$data['verticalrate'] = $line[16];
771
-    				$data['emergency'] = $line[20];
772
-    				$data['speed'] = $line[12];
773
-    				$data['squawk'] = $line[17];
774
-    				$data['altitude'] = $line[11];
775
-    				$data['heading'] = $line[13];
776
-    				$data['ground'] = $line[21];
777
-    				$data['emergency'] = $line[19];
778
-    				$data['format_source'] = 'sbs';
765
+					// Force datetime to current UTC datetime
766
+					$data['datetime'] = date('Y-m-d H:i:s');
767
+					$data['ident'] = trim($line[10]);
768
+					$data['latitude'] = $line[14];
769
+					$data['longitude'] = $line[15];
770
+					$data['verticalrate'] = $line[16];
771
+					$data['emergency'] = $line[20];
772
+					$data['speed'] = $line[12];
773
+					$data['squawk'] = $line[17];
774
+					$data['altitude'] = $line[11];
775
+					$data['heading'] = $line[13];
776
+					$data['ground'] = $line[21];
777
+					$data['emergency'] = $line[19];
778
+					$data['format_source'] = 'sbs';
779 779
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
780
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
781
-    				$data['id_source'] = $id_source;
782
-    				$send = $SI->add($data);
783
-    				unset($data);
784
-    			    } else $error = true;
785
-			    if ($error) {
780
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
781
+					$data['id_source'] = $id_source;
782
+					$send = $SI->add($data);
783
+					unset($data);
784
+					} else $error = true;
785
+				if ($error) {
786 786
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
787 787
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
788 788
 				} else {
@@ -795,50 +795,50 @@  discard block
 block discarded – undo
795 795
 					if ($globalDebug) echo "Reconnect after an error...\n";
796 796
 					connect_all($globalSources);
797 797
 				}
798
-			    }
798
+				}
799 799
 			}
800 800
 			// Sleep for xxx microseconds
801 801
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
802
-		    } else {
802
+			} else {
803 803
 			$tt++;
804 804
 			if ($tt > 30) {
805
-			    if ($globalDebug)echo "ERROR : Reconnect...";
806
-			    //@socket_close($r);
807
-			    sleep(2);
808
-			    connect_all($globalSources);
809
-			    break;
810
-			    $tt = 0;
805
+				if ($globalDebug)echo "ERROR : Reconnect...";
806
+				//@socket_close($r);
807
+				sleep(2);
808
+				connect_all($globalSources);
809
+				break;
810
+				$tt = 0;
811
+			}
811 812
 			}
812
-		    }
813 813
 		}
814
-	    } else {
814
+		} else {
815 815
 		$error = socket_strerror(socket_last_error());
816 816
 		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
817 817
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) || time() - $time >= $timeout) {
818 818
 			if (isset($globalDebug)) echo "Restarting...\n";
819 819
 			// Restart the script if possible
820 820
 			if (is_array($sockets)) {
821
-			    if ($globalDebug) echo "Shutdown all sockets...";
821
+				if ($globalDebug) echo "Shutdown all sockets...";
822 822
 			    
823
-			    foreach ($sockets as $sock) {
823
+				foreach ($sockets as $sock) {
824 824
 				@socket_shutdown($sock,2);
825 825
 				@socket_close($sock);
826
-			    }
826
+				}
827 827
 			    
828 828
 			}
829
-			    if ($globalDebug) echo "Restart all connections...";
830
-			    sleep(2);
831
-			    $time = time();
832
-			    //connect_all($hosts);
833
-			    connect_all($globalSources);
829
+				if ($globalDebug) echo "Restart all connections...";
830
+				sleep(2);
831
+				$time = time();
832
+				//connect_all($hosts);
833
+				connect_all($globalSources);
834 834
 
835 835
 		}
836
-	    }
836
+		}
837 837
 	}
838 838
 	if ($globalDaemon == false) {
839
-	    $SI->checkAll();
839
+		$SI->checkAll();
840
+	}
840 841
 	}
841
-    }
842 842
 }
843 843
 
844 844
 ?>
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     }
41 41
 }
42 42
 
43
-$options = getopt('s::',array('source::','server','idsource::'));
43
+$options = getopt('s::', array('source::', 'server', 'idsource::'));
44 44
 //if (isset($options['s'])) $hosts = array($options['s']);
45 45
 //elseif (isset($options['source'])) $hosts = array($options['source']);
46 46
 if (isset($options['s'])) $globalSources[] = array('host' => $options['s']);
@@ -50,16 +50,16 @@  discard block
 block discarded – undo
50 50
 else $id_source = 1;
51 51
 if (isset($globalServer) && $globalServer) {
52 52
     if ($globalDebug) echo "Using Server Mode\n";
53
-    $SI=new SpotterServer();
54
-} else $SI=new SpotterImport($Connection->db);
53
+    $SI = new SpotterServer();
54
+} else $SI = new SpotterImport($Connection->db);
55 55
 //$APRS=new APRS($Connection->db);
56
-$SBS=new SBS($Connection->db);
57
-$Common=new Common();
56
+$SBS = new SBS($Connection->db);
57
+$Common = new Common();
58 58
 date_default_timezone_set('UTC');
59 59
 //$servertz = system('date +%Z');
60 60
 // signal handler - playing nice with sockets and dump1090
61 61
 if (function_exists('pcntl_fork')) {
62
-    pcntl_signal(SIGINT,  function($signo) {
62
+    pcntl_signal(SIGINT, function($signo) {
63 63
         global $sockets;
64 64
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
65 65
         die("Bye!\n");
@@ -87,28 +87,28 @@  discard block
 block discarded – undo
87 87
 
88 88
 function connect_all($hosts) {
89 89
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
90
-    global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
90
+    global $sockets, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs;
91 91
     foreach ($hosts as $id => $value) {
92 92
 	$host = $value['host'];
93 93
 	$globalSources[$id]['last_exec'] = 0;
94 94
 	// Here we check type of source(s)
95
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
96
-            if (preg_match('/deltadb.txt$/i',$host)) {
95
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
96
+            if (preg_match('/deltadb.txt$/i', $host)) {
97 97
         	//$formats[$id] = 'deltadbtxt';
98 98
         	$globalSources[$id]['format'] = 'deltadbtxt';
99 99
         	//$last_exec['deltadbtxt'] = 0;
100 100
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
101
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
101
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
102 102
         	//$formats[$id] = 'vatsimtxt';
103 103
         	$globalSources[$id]['format'] = 'vatsimtxt';
104 104
         	//$last_exec['vatsimtxt'] = 0;
105 105
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
106
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
106
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
107 107
         	//$formats[$id] = 'aircraftlistjson';
108 108
         	$$globalSources[$id]['format'] = 'aircraftlistjson';
109 109
         	//$last_exec['aircraftlistjson'] = 0;
110 110
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
111
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
111
+    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) {
112 112
         	//$formats[$id] = 'radarvirtueljson';
113 113
         	$globalSources[$id]['format'] = 'radarvirtueljson';
114 114
         	//$last_exec['radarvirtueljson'] = 0;
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
118 118
         	    exit(0);
119 119
         	}
120
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
120
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
121 121
         	//$formats[$id] = 'planeupdatefaa';
122 122
         	$globalSources[$id]['format'] = 'planeupdatefaa';
123 123
         	//$last_exec['planeupdatefaa'] = 0;
@@ -126,22 +126,22 @@  discard block
 block discarded – undo
126 126
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
127 127
         	    exit(0);
128 128
         	}
129
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
129
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
130 130
         	//$formats[$id] = 'phpvmacars';
131 131
         	$globalSources[$id]['format'] = 'phpvmacars';
132 132
         	//$last_exec['phpvmacars'] = 0;
133 133
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
134
-            } else if (preg_match('/whazzup/i',$host)) {
134
+            } else if (preg_match('/whazzup/i', $host)) {
135 135
         	//$formats[$id] = 'whazzup';
136 136
         	$globalSources[$id]['format'] = 'whazzup';
137 137
         	//$last_exec['whazzup'] = 0;
138 138
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
139
-            } else if (preg_match('/recentpireps/i',$host)) {
139
+            } else if (preg_match('/recentpireps/i', $host)) {
140 140
         	//$formats[$id] = 'pirepsjson';
141 141
         	$globalSources[$id]['format'] = 'pirepsjson';
142 142
         	//$last_exec['pirepsjson'] = 0;
143 143
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
144
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
144
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
145 145
         	//$formats[$id] = 'fr24json';
146 146
         	$globalSources[$id]['format'] = 'fr24json';
147 147
         	//$last_exec['fr24json'] = 0;
@@ -151,22 +151,22 @@  discard block
 block discarded – undo
151 151
         	    exit(0);
152 152
         	}
153 153
             //} else if (preg_match('/10001/',$host)) {
154
-            } else if (preg_match('/10001/',$host) || $globalSources[$id]['port'] == '10001') {
154
+            } else if (preg_match('/10001/', $host) || $globalSources[$id]['port'] == '10001') {
155 155
         	//$formats[$id] = 'tsv';
156 156
         	$globalSources[$id]['format'] = 'tsv';
157 157
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
158 158
             }
159
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
159
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
160 160
         	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
161
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
162
-	    $hostport = explode(':',$host);
161
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
162
+	    $hostport = explode(':', $host);
163 163
 	    if (isset($hostport[1])) $port = $hostport[1];
164 164
 	    else $port = $globalSources[$id]['port'];
165
-    	    $s = create_socket($host,$port, $errno, $errstr);
165
+    	    $s = create_socket($host, $port, $errno, $errstr);
166 166
 	    if ($s) {
167 167
     	        $sockets[$id] = $s;
168 168
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
169
-		    if (preg_match('/aprs/',$host)) {
169
+		    if (preg_match('/aprs/', $host)) {
170 170
 			//$formats[$id] = 'aprs';
171 171
 			$globalSources[$id]['format'] = 'aprs';
172 172
 			//$aprs_connect = 0;
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
205 205
 else $timeout = 20;
206 206
 $errno = '';
207
-$errstr='';
207
+$errstr = '';
208 208
 
209 209
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
210 210
 /* Initiate connections to all the hosts simultaneously */
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 
225 225
 if ($use_aprs) {
226 226
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
227
-	$APRS=new APRS($Connection->db);
227
+	$APRS = new APRS($Connection->db);
228 228
 	$aprs_connect = 0;
229 229
 	$aprs_keep = 240;
230 230
 	$aprs_last_tx = time();
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 	else $aprs_ssid = 'FAM';
236 236
 	//else $aprs_ssid = 'PerlEx';
237 237
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
238
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
238
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
239 239
 	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} appid {$aprs_version} filter {$aprs_filter}\n";
240 240
 	else $aprs_login = "user {$aprs_ssid} appid {$aprs_version}\n";
241 241
 }
@@ -245,13 +245,13 @@  discard block
 block discarded – undo
245 245
 sleep(1);
246 246
 if ($globalDebug) echo "SCAN MODE \n\n";
247 247
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
248
-$endtime = time()+$globalCronEnd;
248
+$endtime = time() + $globalCronEnd;
249 249
 $i = 1;
250 250
 $tt = 0;
251 251
 
252 252
 // Delete all ATC
253 253
 if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
254
-	$ATC=new ATC($Connection->db);
254
+	$ATC = new ATC($Connection->db);
255 255
 }
256 256
 if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
257 257
 	$ATC->deleteAll();
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 
260 260
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
261 261
 while ($i > 0) {
262
-    if (!$globalDaemon) $i = $endtime-time();
262
+    if (!$globalDaemon) $i = $endtime - time();
263 263
     // Delete old ATC
264 264
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
265 265
         $ATC->deleteOldATC();
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
 	if ($value['format'] == 'deltadbtxt' && (time() - $value['last_exec'] > $globalMinFetch)) {
271 271
 	    //$buffer = $Common->getData($hosts[$id]);
272 272
 	    $buffer = $Common->getData($value['host']);
273
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
274
-	    $buffer = explode('\n',$buffer);
273
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
274
+	    $buffer = explode('\n', $buffer);
275 275
 	    foreach ($buffer as $line) {
276 276
     		if ($line != '') {
277 277
     		    $line = explode(',', $line);
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
 	} elseif (($value['format'] == 'whazzup' && (time() - $value['last_exec'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $value['last_exec'] > $globalMinFetch))) {
301 301
 	    //$buffer = $Common->getData($hosts[$id]);
302 302
 	    $buffer = $Common->getData($value['host']);
303
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
304
-	    $buffer = explode('\n',$buffer);
303
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
304
+	    $buffer = explode('\n', $buffer);
305 305
 	    foreach ($buffer as $line) {
306 306
     		if ($line != '') {
307 307
     		    $line = explode(':', $line);
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 			$data['id'] = $line[1].'-'.$line[0];
311 311
 			$data['pilot_id'] = $line[1];
312 312
 			$data['pilot_name'] = $line[2];
313
-			$data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT);
313
+			$data['hex'] = str_pad(dechex($line[1]), 6, '000000', STR_PAD_LEFT);
314 314
 			$data['ident'] = $line[0]; // ident
315 315
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
316 316
 			$data['speed'] = $line[8]; // speed
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 			$data['datetime'] = date('Y-m-d H:i:s');
326 326
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
327 327
 		        $data['departure_airport_icao'] = $line[11];
328
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
328
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
329 329
 		        $data['arrival_airport_icao'] = $line[13];
330 330
 			$data['frequency'] = $line[4];
331 331
 			$data['type'] = $line[18];
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
     			$data['id_source'] = $id_source;
335 335
 	    		//$data['arrival_airport_time'] = ;
336 336
 	    		if ($line[9] != '') {
337
-	    		    $aircraft_data = explode('/',$line[9]);
337
+	    		    $aircraft_data = explode('/', $line[9]);
338 338
 	    		    if (isset($aircraft_data[1])) {
339 339
 	    			$data['aircraft_icao'] = $aircraft_data[1];
340 340
 	    		    }
@@ -348,9 +348,9 @@  discard block
 block discarded – undo
348 348
     			if ($line[3] == 'PILOT') $SI->add($data);
349 349
 			elseif ($line[3] == 'ATC') {
350 350
 				//print_r($data);
351
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
352
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
353
-				$typec = substr($data['ident'],-3);
351
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
352
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
353
+				$typec = substr($data['ident'], -3);
354 354
 				if ($typec == 'APP') $data['type'] = 'Approach';
355 355
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
356 356
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
362 362
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
363 363
 				
364
-				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']);
364
+				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']);
365 365
 			}
366 366
     			unset($data);
367 367
     		    }
@@ -372,9 +372,9 @@  discard block
 block discarded – undo
372 372
     	    $value['last_exec'] = time();
373 373
     	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
374 374
     	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
375
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
375
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
376 376
 	    if ($buffer != '') {
377
-	    $all_data = json_decode($buffer,true);
377
+	    $all_data = json_decode($buffer, true);
378 378
 	    if (isset($all_data['acList'])) {
379 379
 		foreach ($all_data['acList'] as $line) {
380 380
 		    $data = array();
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
429 429
     	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $value['last_exec'] > $globalMinFetch)) {
430 430
 	    $buffer = $Common->getData($value['host']);
431
-	    $all_data = json_decode($buffer,true);
431
+	    $all_data = json_decode($buffer, true);
432 432
 	    if (isset($all_data['planes'])) {
433 433
 		foreach ($all_data['planes'] as $key => $line) {
434 434
 		    $data = array();
@@ -444,12 +444,12 @@  discard block
 block discarded – undo
444 444
 		    $data['emergency'] = ''; // emergency
445 445
 		    $data['registration'] = $line[2];
446 446
 		    $data['aircraft_icao'] = $line[0];
447
-		    $deparr = explode('-',$line[1]);
447
+		    $deparr = explode('-', $line[1]);
448 448
 		    if (count($deparr) == 2) {
449 449
 			$data['departure_airport_icao'] = $deparr[0];
450 450
 			$data['arrival_airport_icao'] = $deparr[1];
451 451
 		    }
452
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
452
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
453 453
 	    	    $data['format_source'] = 'planeupdatefaa';
454 454
     		    $data['id_source'] = $id_source;
455 455
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
     	} elseif ($value['format'] == 'fr24json' && (time() - $value['last_exec'] > $globalMinFetch)) {
464 464
 	    //$buffer = $Common->getData($hosts[$id]);
465 465
 	    $buffer = $Common->getData($value['host']);
466
-	    $all_data = json_decode($buffer,true);
466
+	    $all_data = json_decode($buffer, true);
467 467
 	    foreach ($all_data as $key => $line) {
468 468
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
469 469
 		    $data = array();
@@ -494,11 +494,11 @@  discard block
 block discarded – undo
494 494
     	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
495 495
     	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $value['last_exec'] > $globalMinFetch)) {
496 496
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
497
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
497
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
498 498
 	    //echo $buffer;
499
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
500
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
501
-	    $all_data = json_decode($buffer,true);
499
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
500
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
501
+	    $all_data = json_decode($buffer, true);
502 502
 	    if (json_last_error() != JSON_ERROR_NONE) {
503 503
 		die(json_last_error_msg());
504 504
 	    }
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
 			//$data['departure_airport_iata'] = $line[11];
521 521
 			//$data['arrival_airport_iata'] = $line[12];
522 522
 	    		//$data['emergency'] = ''; // emergency
523
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
523
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
524 524
 	    		$data['format_source'] = 'radarvirtueljson';
525 525
     			$data['id_source'] = $id_source;
526 526
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -535,12 +535,12 @@  discard block
 block discarded – undo
535 535
     	} elseif ($value['format'] == 'pirepsjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
536 536
 	    //$buffer = $Common->getData($hosts[$id]);
537 537
 	    $buffer = $Common->getData($value['host']);
538
-	    $all_data = json_decode(utf8_encode($buffer),true);
538
+	    $all_data = json_decode(utf8_encode($buffer), true);
539 539
 	    
540 540
 	    if (isset($all_data['pireps'])) {
541 541
 	        foreach ($all_data['pireps'] as $line) {
542 542
 		    $data = array();
543
-		    $data['hex'] = str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT);
543
+		    $data['hex'] = str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT);
544 544
 		    $data['ident'] = $line['callsign']; // ident
545 545
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
546 546
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -569,9 +569,9 @@  discard block
 block discarded – undo
569 569
 			$SI->add($data);
570 570
 		    //    print_r($data);
571 571
     		    } elseif ($line['icon'] == 'ct') {
572
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
573
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
574
-			$typec = substr($data['ident'],-3);
572
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
573
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
574
+			$typec = substr($data['ident'], -3);
575 575
 			$data['type'] = '';
576 576
 			if ($typec == 'APP') $data['type'] = 'Approach';
577 577
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
583 583
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
584 584
 			else $data['type'] = 'Observer';
585
-			echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name']);
585
+			echo $ATC->add($data['ident'], '', $data['latitude'], $data['longitude'], '0', $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name']);
586 586
 		    }
587 587
 		    unset($data);
588 588
 		}
@@ -593,12 +593,12 @@  discard block
 block discarded – undo
593 593
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $value['last_exec'] > $globalMinFetch)) {
594 594
 	    //$buffer = $Common->getData($hosts[$id]);
595 595
 	    $buffer = $Common->getData($value['host']);
596
-	    $all_data = json_decode($buffer,true);
596
+	    $all_data = json_decode($buffer, true);
597 597
 	    if ($buffer != '' && is_array($all_data)) {
598 598
 		foreach ($all_data as $line) {
599 599
 	    	    $data = array();
600 600
 	    	    //$data['id'] = $line['id']; // id not usable
601
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
601
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
602 602
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
603 603
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
604 604
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -620,12 +620,12 @@  discard block
 block discarded – undo
620 620
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
621 621
 		    if (isset($line['aircraftname'])) {
622 622
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
623
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
624
-	    		$aircraft_data = explode('-',$line['aircraftname']);
623
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
624
+	    		$aircraft_data = explode('-', $line['aircraftname']);
625 625
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
626 626
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
627 627
 	    		else {
628
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
628
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
629 629
 	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
630 630
 	    		    else $data['aircraft_icao'] = $line['aircraftname'];
631 631
 	    		}
@@ -654,14 +654,14 @@  discard block
 block discarded – undo
654 654
 		foreach ($read as $nb => $r) {
655 655
 		    //$value = $formats[$nb];
656 656
 		    $format = $globalSources[$nb]['format'];
657
-        	    $buffer = socket_read($r, 6000,PHP_NORMAL_READ);
657
+        	    $buffer = socket_read($r, 6000, PHP_NORMAL_READ);
658 658
         	    //echo $buffer."\n";
659 659
 		    // lets play nice and handle signals such as ctrl-c/kill properly
660 660
 		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
661 661
 		    $dataFound = false;
662 662
 		    $error = false;
663 663
 		    //$SI::del();
664
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
664
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
665 665
 		    // SBS format is CSV format
666 666
 		    if ($buffer != '') {
667 667
 			$tt = 0;
@@ -678,16 +678,16 @@  discard block
 block discarded – undo
678 678
 			} elseif ($format == 'beast') {
679 679
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
680 680
 			    die;
681
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
681
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
682 682
 			    $line = explode("\t", $buffer);
683
-			    for($k = 0; $k < count($line); $k=$k+2) {
683
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
684 684
 				$key = $line[$k];
685
-			        $lined[$key] = $line[$k+1];
685
+			        $lined[$key] = $line[$k + 1];
686 686
 			    }
687 687
     			    if (count($lined) > 3) {
688 688
     				$data['hex'] = $lined['hexid'];
689 689
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
690
-    				$data['datetime'] = date('Y-m-d H:i:s');;
690
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
691 691
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
692 692
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
693 693
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -705,22 +705,22 @@  discard block
 block discarded – undo
705 705
     			    } else $error = true;
706 706
 			} elseif ($format == 'aprs' && $use_aprs) {
707 707
 			    if ($aprs_connect == 0) {
708
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
708
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
709 709
 				$aprs_connect = 1;
710 710
 			    }
711
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
711
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
712 712
 				$aprs_last_tx = time();
713 713
 				$data_aprs = "# Keep alive";
714
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
714
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
715 715
 			    }
716 716
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
717
-			    if (substr($buffer,0,1) != '#') {
717
+			    if (substr($buffer, 0, 1) != '#') {
718 718
 				$line = $APRS->parse($buffer);
719 719
 				if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
720 720
 				    $data = array();
721 721
 				    //print_r($line);
722 722
 				    $data['hex'] = $line['address'];
723
-				    $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
723
+				    $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
724 724
 				    //$data['datetime'] = date('Y-m-d H:i:s');
725 725
 				    $data['ident'] = $line['ident'];
726 726
 				    $data['latitude'] = $line['latitude'];
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
 				    $currentdate = date('Y-m-d H:i:s');
741 741
 				    $aprsdate = strtotime($data['datetime']);
742 742
 				    // Accept data if time <= system time + 20s
743
-				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20)) $send = $SI->add($data);
743
+				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate) + 20)) $send = $SI->add($data);
744 744
 				    else {
745 745
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
746 746
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
 		}
814 814
 	    } else {
815 815
 		$error = socket_strerror(socket_last_error());
816
-		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
816
+		if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
817 817
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) || time() - $time >= $timeout) {
818 818
 			if (isset($globalDebug)) echo "Restarting...\n";
819 819
 			// Restart the script if possible
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
 			    if ($globalDebug) echo "Shutdown all sockets...";
822 822
 			    
823 823
 			    foreach ($sockets as $sock) {
824
-				@socket_shutdown($sock,2);
824
+				@socket_shutdown($sock, 2);
825 825
 				@socket_close($sock);
826 826
 			    }
827 827
 			    
Please login to merge, or discard this patch.
scripts/check_data.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@
 block discarded – undo
5 5
 */
6 6
 require_once(dirname(__FILE__).'/../require/settings.php');
7 7
 if ($globalInstalled) {
8
-    echo '$globalInstalled must be set to FALSE in require/settings.php';
9
-    exit;
8
+	echo '$globalInstalled must be set to FALSE in require/settings.php';
9
+	exit;
10 10
 }
11 11
 
12 12
 require_once('../require/class.Connection.php');
Please login to merge, or discard this patch.