Completed
Push — master ( b7c521...b3c778 )
by Yannick
06:35
created
redirect.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@
 block discarded – undo
5 5
 $Spotter = new Spotter();
6 6
 if ($_GET['flightaware_id'] != "")
7 7
 {
8
-	$flightaware_id = filter_input(INPUT_GET,'flightaware_id',FILTER_SANITIZE_STRING);
8
+	$flightaware_id = filter_input(INPUT_GET, 'flightaware_id', FILTER_SANITIZE_STRING);
9 9
 	$spotter_id = $Spotter->getSpotterIDBasedOnFlightAwareID($flightaware_id);
10 10
     
11 11
     if ($spotter_id != "")
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -8,11 +8,11 @@
 block discarded – undo
8 8
 	$flightaware_id = filter_input(INPUT_GET,'flightaware_id',FILTER_SANITIZE_STRING);
9 9
 	$spotter_id = $Spotter->getSpotterIDBasedOnFlightAwareID($flightaware_id);
10 10
     
11
-    if ($spotter_id != "")
12
-    {
13
-        header('Location: '.$globalURL.'/flightid/'.$spotter_id);
14
-    } else {
11
+	if ($spotter_id != "")
12
+	{
13
+		header('Location: '.$globalURL.'/flightid/'.$spotter_id);
14
+	} else {
15 15
 	   header('Location: '.$globalURL);
16
-    }
16
+	}
17 17
 }
18 18
 ?>
19 19
\ No newline at end of file
Please login to merge, or discard this patch.
upcoming.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
 require_once('header.php');
8 8
 
9 9
 //calculuation for the pagination
10
-if(!isset($_GET['limit']))
10
+if (!isset($_GET['limit']))
11 11
 {
12 12
 	$limit_start = 0;
13 13
 	$limit_end = 25;
14 14
 	$absolute_difference = 25;
15
-}  else {
15
+} else {
16 16
 	$limit_explode = explode(",", $_GET['limit']);
17 17
 	$limit_start = $limit_explode[0];
18 18
 	$limit_end = $limit_explode[1];
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 print '<div class="table column">';	
36 36
 print '<p>'._("This page shows all upcoming flights within the next 3 hours calculated using historical data, based on the number of same flights on the current day of the week &amp; current time. This does not take into account real-time delays and other factors.").'</p>';
37 37
 
38
-$sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING);
38
+$sort = filter_input(INPUT_GET, 'sort', FILTER_SANITIZE_STRING);
39 39
 if ($sort != '') {
40 40
 	$spotter_array = $Spotter->getUpcomingFlights($limit_start.",".$absolute_difference, $sort);
41 41
 } else {
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 	$limit_start = 0;
13 13
 	$limit_end = 25;
14 14
 	$absolute_difference = 25;
15
-}  else {
15
+} else {
16 16
 	$limit_explode = explode(",", $_GET['limit']);
17 17
 	$limit_start = $limit_explode[0];
18 18
 	$limit_end = $limit_explode[1];
Please login to merge, or discard this patch.
date-statistics-airline.php 2 patches
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,8 +6,11 @@
 block discarded – undo
6 6
 $Spotter = new Spotter();
7 7
 $sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING);
8 8
 $date = filter_input(INPUT_GET,'date',FILTER_SANITIZE_STRING);
9
-if (isset($_GET['date'])) $spotter_array = $Spotter->getSpotterDataByDate($date,"0,1", $sort);
10
-else $spotter_array = '';
9
+if (isset($_GET['date'])) {
10
+	$spotter_array = $Spotter->getSpotterDataByDate($date,"0,1", $sort);
11
+} else {
12
+	$spotter_array = '';
13
+}
11 14
 
12 15
 if (!empty($spotter_array))
13 16
 {
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -4,14 +4,14 @@  discard block
 block discarded – undo
4 4
 require_once('require/class.Language.php');
5 5
 
6 6
 $Spotter = new Spotter();
7
-$sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING);
8
-$date = filter_input(INPUT_GET,'date',FILTER_SANITIZE_STRING);
9
-if (isset($_GET['date'])) $spotter_array = $Spotter->getSpotterDataByDate($date,"0,1", $sort);
7
+$sort = filter_input(INPUT_GET, 'sort', FILTER_SANITIZE_STRING);
8
+$date = filter_input(INPUT_GET, 'date', FILTER_SANITIZE_STRING);
9
+if (isset($_GET['date'])) $spotter_array = $Spotter->getSpotterDataByDate($date, "0,1", $sort);
10 10
 else $spotter_array = '';
11 11
 
12 12
 if (!empty($spotter_array))
13 13
 {
14
-	$title = sprintf(_("Most Common Airlines on %s"),date("l F j, Y", strtotime($spotter_array[0]['date_iso_8601'])));
14
+	$title = sprintf(_("Most Common Airlines on %s"), date("l F j, Y", strtotime($spotter_array[0]['date_iso_8601'])));
15 15
 
16 16
 	require_once('header.php');
17 17
 	print '<div class="select-item">';
@@ -29,13 +29,13 @@  discard block
 block discarded – undo
29 29
 	print '<script type="text/javascript">$(function () { $("#datepicker").datetimepicker({ format: "YYYY-MM-DD", defaultDate: "'.$date.'" }); }); </script>';
30 30
 	print '<br />';
31 31
 	print '<div class="info column">';
32
-	print '<h1>'.sprintf(_("Flights from %s"),date("l F j, Y", strtotime($spotter_array[0]['date_iso_8601']))).'</h1>';
32
+	print '<h1>'.sprintf(_("Flights from %s"), date("l F j, Y", strtotime($spotter_array[0]['date_iso_8601']))).'</h1>';
33 33
 	print '</div>';
34 34
 
35 35
 	include('date-sub-menu.php');
36 36
 	print '<div class="column">';
37 37
 	print '<h2>'._("Most Common Airlines").'</h2>';
38
-	print '<p>'.sprintf(_("The statistic below shows the most common airlines of flights on <strong>%s</strong>."),date("l F j, Y", strtotime($spotter_array[0]['date_iso_8601']))).'</p>';
38
+	print '<p>'.sprintf(_("The statistic below shows the most common airlines of flights on <strong>%s</strong>."), date("l F j, Y", strtotime($spotter_array[0]['date_iso_8601']))).'</p>';
39 39
 
40 40
 	$airline_array = $Spotter->countAllAirlinesByDate($date);
41 41
 	if (!empty($airline_array))
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 		print '</thead>';
53 53
 		print '<tbody>';
54 54
 		$i = 1;
55
-		foreach($airline_array as $airline_item)
55
+		foreach ($airline_array as $airline_item)
56 56
 		{
57 57
 			print '<tr>';
58 58
 			print '<td><strong>'.$i.'</strong></td>';
Please login to merge, or discard this patch.
date-statistics-airline-country.php 2 patches
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -8,8 +8,11 @@
 block discarded – undo
8 8
 $date = filter_input(INPUT_GET,'date',FILTER_SANITIZE_STRING);
9 9
 
10 10
 $Spotter = new Spotter();
11
-if (isset($_GET['date'])) $spotter_array = $Spotter->getSpotterDataByDate($date,"0,1", $sort);
12
-else $spotter_array = array();
11
+if (isset($_GET['date'])) {
12
+	$spotter_array = $Spotter->getSpotterDataByDate($date,"0,1", $sort);
13
+} else {
14
+	$spotter_array = array();
15
+}
13 16
 
14 17
 if (!empty($spotter_array))
15 18
 {
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -3,16 +3,16 @@  discard block
 block discarded – undo
3 3
 require_once('require/class.Spotter.php');
4 4
 require_once('require/class.Language.php');
5 5
 
6
-$sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING);
7
-$date = filter_input(INPUT_GET,'date',FILTER_SANITIZE_STRING);
6
+$sort = filter_input(INPUT_GET, 'sort', FILTER_SANITIZE_STRING);
7
+$date = filter_input(INPUT_GET, 'date', FILTER_SANITIZE_STRING);
8 8
 
9 9
 $Spotter = new Spotter();
10
-if (isset($_GET['date'])) $spotter_array = $Spotter->getSpotterDataByDate($date,"0,1", $sort);
10
+if (isset($_GET['date'])) $spotter_array = $Spotter->getSpotterDataByDate($date, "0,1", $sort);
11 11
 else $spotter_array = array();
12 12
 
13 13
 if (!empty($spotter_array))
14 14
 {
15
-	$title = sprintf(_("Most Common Airlines by Country on %s"),date("l F j, Y", strtotime($spotter_array[0]['date_iso_8601'])));
15
+	$title = sprintf(_("Most Common Airlines by Country on %s"), date("l F j, Y", strtotime($spotter_array[0]['date_iso_8601'])));
16 16
 	require_once('header.php');
17 17
 	print '<div class="select-item">';
18 18
 	print '<form action="'.$globalURL.'/date" method="post" class="form-inline">';
@@ -29,13 +29,13 @@  discard block
 block discarded – undo
29 29
 	print '<script type="text/javascript">$(function () { $("#datepicker").datetimepicker({ format: "YYYY-MM-DD", defaultDate: "'.$date.'" }); }); </script>';
30 30
 	print '<br />';
31 31
 	print '<div class="info column">';
32
-	print '<h1>'.sprintf(_("Flights from %s"),date("l F j, Y", strtotime($spotter_array[0]['date_iso_8601']))).'</h1>';
32
+	print '<h1>'.sprintf(_("Flights from %s"), date("l F j, Y", strtotime($spotter_array[0]['date_iso_8601']))).'</h1>';
33 33
 	print '</div>';
34 34
 
35 35
 	include('date-sub-menu.php');
36 36
 	print '<div class="column">';
37 37
 	print '<h2>'._("Most Common Airlines by Country").'</h2>';
38
-	print '<p>'.sprintf(_("The statistic below shows the most common airlines by Country of origin of flights on <strong>%s</strong>."),date("l F j, Y", strtotime($spotter_array[0]['date_iso_8601']))).'</p>';
38
+	print '<p>'.sprintf(_("The statistic below shows the most common airlines by Country of origin of flights on <strong>%s</strong>."), date("l F j, Y", strtotime($spotter_array[0]['date_iso_8601']))).'</p>';
39 39
 
40 40
 	$airline_array = $Spotter->countAllAirlineCountriesByDate($date);
41 41
 	print '<script type="text/javascript" src="https://www.google.com/jsapi"></script>';
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
             var data = google.visualization.arrayToDataTable([
48 48
             	["'._("Country").'", "'._("# of times").'"], ';
49 49
 	$country_data = '';
50
-	foreach($airline_array as $airline_item)
50
+	foreach ($airline_array as $airline_item)
51 51
 	{
52 52
 		$country_data .= '[ "'.$airline_item['airline_country'].'",'.$airline_item['airline_country_count'].'],';
53 53
 	}
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 		print '</thead>';
82 82
 		print '<tbody>';
83 83
 		$i = 1;
84
-		foreach($airline_array as $airline_item)
84
+		foreach ($airline_array as $airline_item)
85 85
 		{
86 86
 			print '<tr>';
87 87
 			print '<td><strong>'.$i.'</strong></td>';
Please login to merge, or discard this patch.
incident-latest.php 2 patches
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -38,8 +38,12 @@
 block discarded – undo
38 38
 if (!empty($spotter_array) && $spotter_array[0]['query_number_rows'] != 0) {
39 39
 	include('table-output.php');
40 40
 	print '<div class="pagination">';
41
-	if ($limit_previous_1 >= 0) print '<a href="'.$page_url.'/'.$limit_previous_1.','.$limit_previous_2.'">&laquo;'._("Previous Page").'</a>';
42
-	if ($spotter_array[0]['query_number_rows'] == $absolute_difference) print '<a href="'.$page_url.'/'.$limit_end.','.$limit_next.'">'._("Next Page").'&raquo;</a>';
41
+	if ($limit_previous_1 >= 0) {
42
+		print '<a href="'.$page_url.'/'.$limit_previous_1.','.$limit_previous_2.'">&laquo;'._("Previous Page").'</a>';
43
+	}
44
+	if ($spotter_array[0]['query_number_rows'] == $absolute_difference) {
45
+		print '<a href="'.$page_url.'/'.$limit_end.','.$limit_next.'">'._("Next Page").'&raquo;</a>';
46
+	}
43 47
 	print '</div>';
44 48
 }
45 49
 print '</div>';
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
 $page_url = $globalURL.'/accident-latest';
10 10
 
11
-if(!isset($_GET['limit']))
11
+if (!isset($_GET['limit']))
12 12
 {
13 13
 	$limit_start = 0;
14 14
 	$limit_end = 25;
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 
35 35
 print '<div class="table column">';
36 36
 print '<p>'._("The table below shows the latest Incidents.").'</p>';
37
-$spotter_array = $Accident->getAccidentData($limit_start.",".$absolute_difference,'incident');
37
+$spotter_array = $Accident->getAccidentData($limit_start.",".$absolute_difference, 'incident');
38 38
 //print_r($spotter_array);
39 39
 if (!empty($spotter_array) && $spotter_array[0]['query_number_rows'] != 0) {
40 40
 	include('table-output.php');
Please login to merge, or discard this patch.
require/class.METAR.php 3 patches
Indentation   +261 added lines, -261 removed lines patch added patch discarded remove patch
@@ -7,109 +7,109 @@  discard block
 block discarded – undo
7 7
 	public $db;
8 8
 	
9 9
 	protected $texts = Array(
10
-	    'MI' => 'Shallow',
11
-	    'PR' => 'Partial',
12
-	    'BC' => 'Low drifting',
13
-	    'BL' => 'Blowing',
14
-	    'SH' => 'Showers',
15
-	    'TS' => 'Thunderstorm',
16
-	    'FZ' => 'Freezing',
17
-	    'DZ' => 'Drizzle',
18
-	    'RA' => 'Rain',
19
-	    'SN' => 'Snow',
20
-	    'SG' => 'Snow Grains',
21
-	    'IC' => 'Ice crystals',
22
-	    'PL' => 'Ice pellets',
23
-	    'GR' => 'Hail',
24
-	    'GS' => 'Small hail',
25
-	    'UP' => 'Unknown',
26
-	    'BR' => 'Mist',
27
-	    'FG' => 'Fog',
28
-	    'FU' => 'Smoke',
29
-	    'VA' => 'Volcanic ash',
30
-	    'DU' => 'Widespread dust',
31
-	    'SA' => 'Sand',
32
-	    'HZ' => 'Haze',
33
-	    'PY' => 'Spray',
34
-	    'PO' => 'Well developed dust / sand whirls',
35
-	    'SQ' => 'Squalls',
36
-	    'FC' => 'Funnel clouds inc tornadoes or waterspouts',
37
-	    'SS' => 'Sandstorm',
38
-	    'DS' => 'Duststorm'
10
+		'MI' => 'Shallow',
11
+		'PR' => 'Partial',
12
+		'BC' => 'Low drifting',
13
+		'BL' => 'Blowing',
14
+		'SH' => 'Showers',
15
+		'TS' => 'Thunderstorm',
16
+		'FZ' => 'Freezing',
17
+		'DZ' => 'Drizzle',
18
+		'RA' => 'Rain',
19
+		'SN' => 'Snow',
20
+		'SG' => 'Snow Grains',
21
+		'IC' => 'Ice crystals',
22
+		'PL' => 'Ice pellets',
23
+		'GR' => 'Hail',
24
+		'GS' => 'Small hail',
25
+		'UP' => 'Unknown',
26
+		'BR' => 'Mist',
27
+		'FG' => 'Fog',
28
+		'FU' => 'Smoke',
29
+		'VA' => 'Volcanic ash',
30
+		'DU' => 'Widespread dust',
31
+		'SA' => 'Sand',
32
+		'HZ' => 'Haze',
33
+		'PY' => 'Spray',
34
+		'PO' => 'Well developed dust / sand whirls',
35
+		'SQ' => 'Squalls',
36
+		'FC' => 'Funnel clouds inc tornadoes or waterspouts',
37
+		'SS' => 'Sandstorm',
38
+		'DS' => 'Duststorm'
39 39
 	);
40 40
 	
41 41
 	public function __construct($dbc = null) {
42
-                $Connection = new Connection($dbc);
43
-                $this->db = $Connection->db;
44
-        }
42
+				$Connection = new Connection($dbc);
43
+				$this->db = $Connection->db;
44
+		}
45 45
 
46
-       public static function check_last_update() {
47
-    		global $globalDBdriver;
48
-    		if ($globalDBdriver == 'mysql') {
46
+	   public static function check_last_update() {
47
+			global $globalDBdriver;
48
+			if ($globalDBdriver == 'mysql') {
49 49
 			$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_metar' AND value > DATE_SUB(NOW(), INTERVAL 20 MINUTE)";
50 50
 		} else {
51 51
 			$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_metar' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '20 MINUTES'";
52 52
 		}
53
-                try {
54
-                        $Connection = new Connection();
55
-                        $sth = $Connection->db->prepare($query);
56
-                        $sth->execute();
57
-                } catch(PDOException $e) {
58
-                        return "error : ".$e->getMessage();
59
-                }
60
-                $row = $sth->fetch(PDO::FETCH_ASSOC);
61
-                $sth->closeCursor();
62
-                if ($row['nb'] > 0) return false;
63
-                else return true;
64
-        }
53
+				try {
54
+						$Connection = new Connection();
55
+						$sth = $Connection->db->prepare($query);
56
+						$sth->execute();
57
+				} catch(PDOException $e) {
58
+						return "error : ".$e->getMessage();
59
+				}
60
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
61
+				$sth->closeCursor();
62
+				if ($row['nb'] > 0) return false;
63
+				else return true;
64
+		}
65 65
 
66
-        public static function insert_last_update() {
67
-                $query = "DELETE FROM config WHERE name = 'last_update_metar';
66
+		public static function insert_last_update() {
67
+				$query = "DELETE FROM config WHERE name = 'last_update_metar';
68 68
                         INSERT INTO config (name,value) VALUES ('last_update_metar',NOW());";
69
-                try {
70
-                        $Connection = new Connection();
71
-                        $sth = $Connection->db->prepare($query);
72
-                        $sth->execute();
73
-                } catch(PDOException $e) {
74
-                        return "error : ".$e->getMessage();
75
-                }
76
-        }
69
+				try {
70
+						$Connection = new Connection();
71
+						$sth = $Connection->db->prepare($query);
72
+						$sth->execute();
73
+				} catch(PDOException $e) {
74
+						return "error : ".$e->getMessage();
75
+				}
76
+		}
77 77
 
78 78
 
79 79
         
80
-        public function parse($data) {
81
-    		//$data = str_replace(array('\n','\r','\r','\n'),'',$data);
82
-    		$codes = implode('|', array_keys($this->texts));
83
-    		$regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#';
84
-    		//$pieces = explode(' ',$data);
85
-    		$pieces = preg_split('/\s/',$data);
86
-    		$pos = 0;
87
-    		if ($pieces[0] == 'METAR') $pos++;
88
-    		elseif ($pieces[0] == 'SPECI') $pos++;
89
-    		if (strlen($pieces[$pos]) != 4) $pos++;
90
-    		$result = array();
91
-    		$result['location'] = $pieces[$pos];
92
-    		$pos++;
93
-    		$result['dayofmonth'] = substr($pieces[$pos],0,2);
94
-    		$result['time'] = substr($pieces[$pos],2,4);
95
-    		$c = count($pieces);
96
-    		for($pos++; $pos < $c; $pos++) {
97
-    			$piece = $pieces[$pos];
98
-    			if ($piece == 'RMK') break;
99
-    			if ($piece == 'AUTO') $result['auto'] = true;
100
-    			if ($piece == 'COR') $result['correction'] = true;
101
-    			// Wind Speed
102
-    			if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) {
103
-    				$result['wind']['direction'] = (float)$matches[1];
80
+		public function parse($data) {
81
+			//$data = str_replace(array('\n','\r','\r','\n'),'',$data);
82
+			$codes = implode('|', array_keys($this->texts));
83
+			$regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#';
84
+			//$pieces = explode(' ',$data);
85
+			$pieces = preg_split('/\s/',$data);
86
+			$pos = 0;
87
+			if ($pieces[0] == 'METAR') $pos++;
88
+			elseif ($pieces[0] == 'SPECI') $pos++;
89
+			if (strlen($pieces[$pos]) != 4) $pos++;
90
+			$result = array();
91
+			$result['location'] = $pieces[$pos];
92
+			$pos++;
93
+			$result['dayofmonth'] = substr($pieces[$pos],0,2);
94
+			$result['time'] = substr($pieces[$pos],2,4);
95
+			$c = count($pieces);
96
+			for($pos++; $pos < $c; $pos++) {
97
+				$piece = $pieces[$pos];
98
+				if ($piece == 'RMK') break;
99
+				if ($piece == 'AUTO') $result['auto'] = true;
100
+				if ($piece == 'COR') $result['correction'] = true;
101
+				// Wind Speed
102
+				if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) {
103
+					$result['wind']['direction'] = (float)$matches[1];
104 104
 				$result['wind']['unit'] = $matches[4];
105
-    				if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2);
106
-    				elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2);
107
-    				elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2);
105
+					if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2);
106
+					elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2);
107
+					elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2);
108 108
 				$result['wind']['gust'] = (float)$matches[3];
109 109
 				$result['wind']['unit'] = $matches[4];
110 110
 				$result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0;
111 111
 				$result['wind']['max_variation'] = array_key_exists(6,$matches) ? $matches[6] : 0;
112
-    			}
112
+				}
113 113
 
114 114
 /*    			if (preg_match('#^([0-9]{3})([0-9]{2})(G([0-9]{2}))?(KT|MPS)$#', $piece, $matches)) {
115 115
     				$result['wind_direction'] = (float)$matches[1];
@@ -126,35 +126,35 @@  discard block
 block discarded – undo
126 126
     				}
127 127
     			}
128 128
     			*/
129
-    			// Temperature
130
-    			if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) {
131
-    				$temp = (float)$matches[1];
129
+				// Temperature
130
+				if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) {
131
+					$temp = (float)$matches[1];
132 132
 				if ($matches[1]{0} == 'M') {
133 133
 					$temp = ((float)substr($matches[1], 1)) * -1;
134 134
 				}
135
-    				$result['temperature'] = $temp;
136
-    				$dew = (float)$matches[2];
135
+					$result['temperature'] = $temp;
136
+					$dew = (float)$matches[2];
137 137
 				if ($matches[2]{0} == 'M') {
138 138
 					$dew = ((float)substr($matches[2], 1)) * -1;
139 139
 				}
140 140
 				$result['dew'] = $dew;
141
-    			}
142
-    			// QNH
143
-    			if (preg_match('#^(A|Q)([0-9]{4})$#', $piece, $matches)) {
144
-    			// #^(Q|A)(////|[0-9]{4})( )#
145
-    				if ($matches[1] == 'Q') {
146
-    					// hPa
147
-    					$result['QNH'] = $matches[2];
148
-    				} else {
149
-    					// inHg
150
-    					$result['QNH'] = round(($matches[2] / 100)*33.86389,2);
151 141
 				}
152
-    				/*
142
+				// QNH
143
+				if (preg_match('#^(A|Q)([0-9]{4})$#', $piece, $matches)) {
144
+				// #^(Q|A)(////|[0-9]{4})( )#
145
+					if ($matches[1] == 'Q') {
146
+						// hPa
147
+						$result['QNH'] = $matches[2];
148
+					} else {
149
+						// inHg
150
+						$result['QNH'] = round(($matches[2] / 100)*33.86389,2);
151
+				}
152
+					/*
153 153
     				$result['QNH'] = $matches[1] == 'Q' ? $matches[2] : ($matches[2] / 100);
154 154
     				$result['QNH_format'] = $matches[1] == 'Q' ? 'hPa' : 'inHg';
155 155
     				*/
156
-    			}
157
-                     /*
156
+				}
157
+					 /*
158 158
     			// Wind Direction
159 159
     			if (preg_match('#^([0-9]{3})V([0-9]{3})$#', $piece, $matches)) {
160 160
     				$result['wind_direction'] = $matches[1];
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
     				$result['speed_variable'] = $matches[1];
166 166
     			}
167 167
     			*/
168
-    			// Visibility
169
-    			if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) {
170
-    				if (isset($matches[3]) && strlen($matches[3]) > 0) {
168
+				// Visibility
169
+				if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) {
170
+					if (isset($matches[3]) && strlen($matches[3]) > 0) {
171 171
 					$result['visibility'] = (float)$matches[3] * 1609.34;
172 172
 				} else {
173 173
 					if ($matches[1] == '9999') {
@@ -180,28 +180,28 @@  discard block
 block discarded – undo
180 180
 					$result['visibility'] = '> 10000';
181 181
 					$result['weather'] = "CAVOK";
182 182
 				}
183
-    			}
184
-    			// Cloud Coverage
185
-    			if (preg_match('#^(SKC|CLR|FEW|SCT|BKN|OVC|VV)([0-9]{3})(CB|TCU|CU|CI)?$#', $piece, $matches)) {
186
-    				//$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : '');
187
-    				$type = $matches[1];
188
-    				$cloud = array();
189
-    				if ($type == 'SKC') $cloud['type'] = 'No cloud/Sky clear';
190
-    				elseif ($type == 'CLR') $cloud['type'] = 'No cloud below 12,000ft (3700m)';
191
-    				elseif ($type == 'NSC') $cloud['type'] = 'No significant cloud';
192
-    				elseif ($type == 'FEW') $cloud['type'] = 'Few';
193
-    				elseif ($type == 'SCT') $cloud['type'] = 'Scattered';
194
-    				elseif ($type == 'BKN') $cloud['type'] = 'Broken';
195
-    				elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage';
196
-    				elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility';
197
-    				$cloud['type_code'] = $type;
198
-    				$cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048);
199
-    				$cloud['significant'] = isset($matches[3]) ? $matches[3] : '';
200
-    				$result['cloud'][] = $cloud;
201
-    			}
202
-    			// RVR
203
-    			 if (preg_match('#^(R.+)/([M|P])?(\d{4})(?:V(\d+)|[UDN])?(FT)?$#', $piece, $matches)) {
204
-    				$rvr = array();
183
+				}
184
+				// Cloud Coverage
185
+				if (preg_match('#^(SKC|CLR|FEW|SCT|BKN|OVC|VV)([0-9]{3})(CB|TCU|CU|CI)?$#', $piece, $matches)) {
186
+					//$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : '');
187
+					$type = $matches[1];
188
+					$cloud = array();
189
+					if ($type == 'SKC') $cloud['type'] = 'No cloud/Sky clear';
190
+					elseif ($type == 'CLR') $cloud['type'] = 'No cloud below 12,000ft (3700m)';
191
+					elseif ($type == 'NSC') $cloud['type'] = 'No significant cloud';
192
+					elseif ($type == 'FEW') $cloud['type'] = 'Few';
193
+					elseif ($type == 'SCT') $cloud['type'] = 'Scattered';
194
+					elseif ($type == 'BKN') $cloud['type'] = 'Broken';
195
+					elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage';
196
+					elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility';
197
+					$cloud['type_code'] = $type;
198
+					$cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048);
199
+					$cloud['significant'] = isset($matches[3]) ? $matches[3] : '';
200
+					$result['cloud'][] = $cloud;
201
+				}
202
+				// RVR
203
+				 if (preg_match('#^(R.+)/([M|P])?(\d{4})(?:V(\d+)|[UDN])?(FT)?$#', $piece, $matches)) {
204
+					$rvr = array();
205 205
 				$rvr['runway'] = $matches[1];
206 206
 				$rvr['assessment'] = $matches[2];
207 207
 				$rvr['rvr'] = $matches[3];
@@ -210,33 +210,33 @@  discard block
 block discarded – undo
210 210
 				$result['RVR'] = $rvr;
211 211
 			}
212 212
     			
213
-    			//if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
214
-    			if (preg_match('#^R(\d{2}[LRC]?)/([\d/])([\d/])([\d/]{2})([\d/]{2})$#', $piece, $matches)) {
215
-    				//print_r($matches);
216
-    				// https://github.com/davidmegginson/metar-taf/blob/master/Metar.php
217
-    				$result['RVR']['runway'] = $matches[1];
218
-        			$result['RVR']['deposits'] = $matches[2];
219
-        			$result['RVR']['extent'] = $matches[3];
220
-        			$result['RVR']['depth'] = $matches[4];
221
-        			$result['RVR']['friction'] = $matches[5];
222
-    			}
223
-    			if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
224
-    				//echo $piece;
225
-    				//print_r($matches);
226
-    				if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
227
-    				else $range = array('exact' => (float)$matches[2], 'unit' => 'M');
213
+				//if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
214
+				if (preg_match('#^R(\d{2}[LRC]?)/([\d/])([\d/])([\d/]{2})([\d/]{2})$#', $piece, $matches)) {
215
+					//print_r($matches);
216
+					// https://github.com/davidmegginson/metar-taf/blob/master/Metar.php
217
+					$result['RVR']['runway'] = $matches[1];
218
+					$result['RVR']['deposits'] = $matches[2];
219
+					$result['RVR']['extent'] = $matches[3];
220
+					$result['RVR']['depth'] = $matches[4];
221
+					$result['RVR']['friction'] = $matches[5];
222
+				}
223
+				if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
224
+					//echo $piece;
225
+					//print_r($matches);
226
+					if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
227
+					else $range = array('exact' => (float)$matches[2], 'unit' => 'M');
228 228
 				if (isset($matches[3])) {
229 229
 					$range = Array(
230
-					    'from' => (float)$matches[2],
231
-					    'to'   => (float)$matches[4],
232
-					    'unit' => $matches[5] ? 'FT' : 'M'
230
+						'from' => (float)$matches[2],
231
+						'to'   => (float)$matches[4],
232
+						'unit' => $matches[5] ? 'FT' : 'M'
233 233
 					);
234 234
 				}
235 235
 				$result['RVR'] = $matches[1];
236 236
 				$result['RVR_range'] = $range;
237
-    			}
238
-    			// Weather
239
-    			if (preg_match($regWeather, $piece, $matches)) {
237
+				}
238
+				// Weather
239
+				if (preg_match($regWeather, $piece, $matches)) {
240 240
 				$text = Array();
241 241
 				switch ($matches[1]) {
242 242
 					case '+':
@@ -259,35 +259,35 @@  discard block
 block discarded – undo
259 259
 				}
260 260
 				if (!isset($result['weather'])) $result['weather'] = implode(' ', $text);
261 261
 				else $result['weather'] = $result['weather'].' / '.implode(' ', $text);
262
-    			}
263
-    		}
264
-    		return $result;
262
+				}
263
+			}
264
+			return $result;
265 265
         
266
-        }
266
+		}
267 267
         
268 268
 	public function getMETAR($icao) {
269
-    		global $globalMETARcycle, $globalDBdriver;
270
-    		if (isset($globalMETARcycle) && $globalMETARcycle) {
271
-            		$query = "SELECT * FROM metar WHERE metar_location = :icao";
272
-                } else {
273
-            		if ($globalDBdriver == 'mysql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1";
274
-            		else $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1";
275
-                }
276
-                $query_values = array(':icao' => $icao);
277
-                 try {
278
-                        $sth = $this->db->prepare($query);
279
-                        $sth->execute($query_values);
280
-                } catch(PDOException $e) {
281
-                        return "error : ".$e->getMessage();
282
-                }
283
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
284
-                if ((!isset($globalMETARcycle) || $globalMETARcycle === false) && count($all) == 0) {
285
-            		$all = $this->downloadMETAR($icao);
286
-                }
287
-                return $all;
288
-        }
269
+			global $globalMETARcycle, $globalDBdriver;
270
+			if (isset($globalMETARcycle) && $globalMETARcycle) {
271
+					$query = "SELECT * FROM metar WHERE metar_location = :icao";
272
+				} else {
273
+					if ($globalDBdriver == 'mysql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1";
274
+					else $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1";
275
+				}
276
+				$query_values = array(':icao' => $icao);
277
+				 try {
278
+						$sth = $this->db->prepare($query);
279
+						$sth->execute($query_values);
280
+				} catch(PDOException $e) {
281
+						return "error : ".$e->getMessage();
282
+				}
283
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
284
+				if ((!isset($globalMETARcycle) || $globalMETARcycle === false) && count($all) == 0) {
285
+					$all = $this->downloadMETAR($icao);
286
+				}
287
+				return $all;
288
+		}
289 289
 
290
-       public function addMETAR($location,$metar,$date) {
290
+	   public function addMETAR($location,$metar,$date) {
291 291
 		global $globalDBdriver;
292 292
 		$date = date('Y-m-d H:i:s',strtotime($date));
293 293
 		if ($globalDBdriver == 'mysql') {
@@ -295,104 +295,104 @@  discard block
 block discarded – undo
295 295
 		} else {
296 296
 			$query = "UPDATE metar SET metar_date = :date, metar = metar WHERE metar_location = :location;INSERT INTO metar (metar_location,metar_date,metar) SELECT :location,:date,:metar WHERE NOT EXISTS (SELECT 1 FROM metar WHERE metar_location = :location);";
297 297
 		}
298
-                $query_values = array(':location' => $location,':date' => $date,':metar' => utf8_encode($metar));
299
-                 try {
300
-                        $sth = $this->db->prepare($query);
301
-                        $sth->execute($query_values);
302
-                } catch(PDOException $e) {
303
-                        return "error : ".$e->getMessage();
304
-                }
305
-        }
298
+				$query_values = array(':location' => $location,':date' => $date,':metar' => utf8_encode($metar));
299
+				 try {
300
+						$sth = $this->db->prepare($query);
301
+						$sth->execute($query_values);
302
+				} catch(PDOException $e) {
303
+						return "error : ".$e->getMessage();
304
+				}
305
+		}
306 306
 
307
-       public function deleteMETAR($id) {
308
-                $query = "DELETE FROM metar WHERE id = :id";
309
-                $query_values = array(':id' => $id);
310
-                 try {
311
-                        $sth = $this->db->prepare($query);
312
-                        $sth->execute($query_values);
313
-                } catch(PDOException $e) {
314
-                        return "error : ".$e->getMessage();
315
-                }
316
-        }
317
-       public function deleteAllMETARLocation() {
318
-                $query = "DELETE FROM metar";
319
-                 try {
320
-                        $sth = $this->db->prepare($query);
321
-                        $sth->execute();
322
-                } catch(PDOException $e) {
323
-                        return "error : ".$e->getMessage();
324
-                }
325
-        }
307
+	   public function deleteMETAR($id) {
308
+				$query = "DELETE FROM metar WHERE id = :id";
309
+				$query_values = array(':id' => $id);
310
+				 try {
311
+						$sth = $this->db->prepare($query);
312
+						$sth->execute($query_values);
313
+				} catch(PDOException $e) {
314
+						return "error : ".$e->getMessage();
315
+				}
316
+		}
317
+	   public function deleteAllMETARLocation() {
318
+				$query = "DELETE FROM metar";
319
+				 try {
320
+						$sth = $this->db->prepare($query);
321
+						$sth->execute();
322
+				} catch(PDOException $e) {
323
+						return "error : ".$e->getMessage();
324
+				}
325
+		}
326 326
         
327
-        public function addMETARCycle() {
328
-    		global $globalDebug, $globalIVAO;
329
-    		if (isset($globalDebug) && $globalDebug) echo "Downloading METAR cycle...";
330
-    		date_default_timezone_set("UTC");
331
-    		$Common = new Common();
332
-    		if (isset($globalIVAO) && $globalIVAO) {
333
-        		//$cycle = $Common->getData('http://wx.ivao.aero/metar.php');
327
+		public function addMETARCycle() {
328
+			global $globalDebug, $globalIVAO;
329
+			if (isset($globalDebug) && $globalDebug) echo "Downloading METAR cycle...";
330
+			date_default_timezone_set("UTC");
331
+			$Common = new Common();
332
+			if (isset($globalIVAO) && $globalIVAO) {
333
+				//$cycle = $Common->getData('http://wx.ivao.aero/metar.php');
334 334
 			$Common->download('http://wx.ivao.aero/metar.php',dirname(__FILE__).'/../install/tmp/ivaometar.txt');
335
-    			$handle = fopen(dirname(__FILE__).'/../install/tmp/ivaometar.txt',"r");
336
-    		} else {
335
+				$handle = fopen(dirname(__FILE__).'/../install/tmp/ivaometar.txt',"r");
336
+			} else {
337 337
 			//$cycle = $Common->getData('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT');
338 338
 			$Common->download('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT',dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT');
339
-    			$handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT',"r");
340
-    		}
341
-    		if ($handle) {
339
+				$handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT',"r");
340
+			}
341
+			if ($handle) {
342 342
 			if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB...";
343 343
 			$date = '';
344
-    			//foreach(explode("\n",$cycle) as $line) {
345
-	    		while(($line = fgets($handle,4096)) !== false) {
344
+				//foreach(explode("\n",$cycle) as $line) {
345
+				while(($line = fgets($handle,4096)) !== false) {
346 346
 				if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) {
347 347
 					$date = $line;
348
-    				} elseif ($line != '') {
349
-    				    //$this->parse($line);
350
-    				    if ($date == '') $date = date('Y/m/d H:m');
351
-        			    $pos = 0;
352
-        			    $pieces = preg_split('/\s/',$line);
353
-        			    if ($pieces[0] == 'METAR') $pos++;
354
-        			    if (strlen($pieces[$pos]) != 4) $pos++;
355
-		        	    $location = $pieces[$pos];
356
-        	        	    echo $this->addMETAR($location,$line,$date);
357
-    				}
358
-    			}
359
-    			fclose($handle);
360
-    		}
361
-    		if (isset($globalDebug) && $globalDebug) echo "Done\n";
348
+					} elseif ($line != '') {
349
+						//$this->parse($line);
350
+						if ($date == '') $date = date('Y/m/d H:m');
351
+						$pos = 0;
352
+						$pieces = preg_split('/\s/',$line);
353
+						if ($pieces[0] == 'METAR') $pos++;
354
+						if (strlen($pieces[$pos]) != 4) $pos++;
355
+						$location = $pieces[$pos];
356
+							echo $this->addMETAR($location,$line,$date);
357
+					}
358
+				}
359
+				fclose($handle);
360
+			}
361
+			if (isset($globalDebug) && $globalDebug) echo "Done\n";
362 362
         
363
-        }
364
-        public function downloadMETAR($icao) {
365
-    		global $globalMETARurl;
366
-    		if ($globalMETARurl == '') return array();
367
-    		date_default_timezone_set("UTC");
368
-    		$Common = new Common();
369
-    		$url = str_replace('{icao}',$icao,$globalMETARurl);
370
-    		$cycle = $Common->getData($url);
371
-    		$date = '';
372
-    		foreach(explode("\n",$cycle) as $line) {
373
-    			if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) {
374
-    				//echo "date : ".$line."\n";
375
-    				$date = $line;
376
-    			} 
377
-    			if ($line != '') {
378
-    			    //$this->parse($line);
379
-    			    //echo $line;
380
-    			    if ($date == '') $date = date('Y/m/d H:m');
381
-    			    $pos = 0;
382
-    			    $pieces = preg_split('/\s/',$line);
383
-    			    if ($pieces[0] == 'METAR') $pos++;
384
-    			    if (strlen($pieces[$pos]) != 4) $pos++;
385
-	        	    $location = $pieces[$pos];
386
-	        	    if (strlen($location == 4)) {
387
-	        		$this->addMETAR($location,$line,$date);
388
-	        		return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line));
389
-	        	    } else return array();
390
-    			}
391
-    			//echo $line."\n";
392
-    		}
393
-    		return array();
363
+		}
364
+		public function downloadMETAR($icao) {
365
+			global $globalMETARurl;
366
+			if ($globalMETARurl == '') return array();
367
+			date_default_timezone_set("UTC");
368
+			$Common = new Common();
369
+			$url = str_replace('{icao}',$icao,$globalMETARurl);
370
+			$cycle = $Common->getData($url);
371
+			$date = '';
372
+			foreach(explode("\n",$cycle) as $line) {
373
+				if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) {
374
+					//echo "date : ".$line."\n";
375
+					$date = $line;
376
+				} 
377
+				if ($line != '') {
378
+					//$this->parse($line);
379
+					//echo $line;
380
+					if ($date == '') $date = date('Y/m/d H:m');
381
+					$pos = 0;
382
+					$pieces = preg_split('/\s/',$line);
383
+					if ($pieces[0] == 'METAR') $pos++;
384
+					if (strlen($pieces[$pos]) != 4) $pos++;
385
+					$location = $pieces[$pos];
386
+					if (strlen($location == 4)) {
387
+					$this->addMETAR($location,$line,$date);
388
+					return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line));
389
+					} else return array();
390
+				}
391
+				//echo $line."\n";
392
+			}
393
+			return array();
394 394
         
395
-        }
395
+		}
396 396
 }
397 397
 /*
398 398
 $METAR = new METAR();
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
                         $Connection = new Connection();
55 55
                         $sth = $Connection->db->prepare($query);
56 56
                         $sth->execute();
57
-                } catch(PDOException $e) {
57
+                } catch (PDOException $e) {
58 58
                         return "error : ".$e->getMessage();
59 59
                 }
60 60
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
                         $Connection = new Connection();
71 71
                         $sth = $Connection->db->prepare($query);
72 72
                         $sth->execute();
73
-                } catch(PDOException $e) {
73
+                } catch (PDOException $e) {
74 74
                         return "error : ".$e->getMessage();
75 75
                 }
76 76
         }
@@ -80,9 +80,9 @@  discard block
 block discarded – undo
80 80
         public function parse($data) {
81 81
     		//$data = str_replace(array('\n','\r','\r','\n'),'',$data);
82 82
     		$codes = implode('|', array_keys($this->texts));
83
-    		$regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#';
83
+    		$regWeather = '#^(\+|\-|VC)?('.$codes.')('.$codes.')?$#';
84 84
     		//$pieces = explode(' ',$data);
85
-    		$pieces = preg_split('/\s/',$data);
85
+    		$pieces = preg_split('/\s/', $data);
86 86
     		$pos = 0;
87 87
     		if ($pieces[0] == 'METAR') $pos++;
88 88
     		elseif ($pieces[0] == 'SPECI') $pos++;
@@ -90,25 +90,25 @@  discard block
 block discarded – undo
90 90
     		$result = array();
91 91
     		$result['location'] = $pieces[$pos];
92 92
     		$pos++;
93
-    		$result['dayofmonth'] = substr($pieces[$pos],0,2);
94
-    		$result['time'] = substr($pieces[$pos],2,4);
93
+    		$result['dayofmonth'] = substr($pieces[$pos], 0, 2);
94
+    		$result['time'] = substr($pieces[$pos], 2, 4);
95 95
     		$c = count($pieces);
96
-    		for($pos++; $pos < $c; $pos++) {
96
+    		for ($pos++; $pos < $c; $pos++) {
97 97
     			$piece = $pieces[$pos];
98 98
     			if ($piece == 'RMK') break;
99 99
     			if ($piece == 'AUTO') $result['auto'] = true;
100 100
     			if ($piece == 'COR') $result['correction'] = true;
101 101
     			// Wind Speed
102 102
     			if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) {
103
-    				$result['wind']['direction'] = (float)$matches[1];
103
+    				$result['wind']['direction'] = (float) $matches[1];
104 104
 				$result['wind']['unit'] = $matches[4];
105
-    				if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2);
106
-    				elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2);
107
-    				elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2);
108
-				$result['wind']['gust'] = (float)$matches[3];
105
+    				if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float) $matches[2])*0.51444444444, 2);
106
+    				elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float) $matches[2])*1000, 2);
107
+    				elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float) $matches[2]), 2);
108
+				$result['wind']['gust'] = (float) $matches[3];
109 109
 				$result['wind']['unit'] = $matches[4];
110
-				$result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0;
111
-				$result['wind']['max_variation'] = array_key_exists(6,$matches) ? $matches[6] : 0;
110
+				$result['wind']['min_variation'] = array_key_exists(5, $matches) ? $matches[5] : 0;
111
+				$result['wind']['max_variation'] = array_key_exists(6, $matches) ? $matches[6] : 0;
112 112
     			}
113 113
 
114 114
 /*    			if (preg_match('#^([0-9]{3})([0-9]{2})(G([0-9]{2}))?(KT|MPS)$#', $piece, $matches)) {
@@ -128,14 +128,14 @@  discard block
 block discarded – undo
128 128
     			*/
129 129
     			// Temperature
130 130
     			if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) {
131
-    				$temp = (float)$matches[1];
131
+    				$temp = (float) $matches[1];
132 132
 				if ($matches[1]{0} == 'M') {
133
-					$temp = ((float)substr($matches[1], 1)) * -1;
133
+					$temp = ((float) substr($matches[1], 1))*-1;
134 134
 				}
135 135
     				$result['temperature'] = $temp;
136
-    				$dew = (float)$matches[2];
136
+    				$dew = (float) $matches[2];
137 137
 				if ($matches[2]{0} == 'M') {
138
-					$dew = ((float)substr($matches[2], 1)) * -1;
138
+					$dew = ((float) substr($matches[2], 1))*-1;
139 139
 				}
140 140
 				$result['dew'] = $dew;
141 141
     			}
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
     					$result['QNH'] = $matches[2];
148 148
     				} else {
149 149
     					// inHg
150
-    					$result['QNH'] = round(($matches[2] / 100)*33.86389,2);
150
+    					$result['QNH'] = round(($matches[2]/100)*33.86389, 2);
151 151
 				}
152 152
     				/*
153 153
     				$result['QNH'] = $matches[1] == 'Q' ? $matches[2] : ($matches[2] / 100);
@@ -168,12 +168,12 @@  discard block
 block discarded – undo
168 168
     			// Visibility
169 169
     			if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) {
170 170
     				if (isset($matches[3]) && strlen($matches[3]) > 0) {
171
-					$result['visibility'] = (float)$matches[3] * 1609.34;
171
+					$result['visibility'] = (float) $matches[3]*1609.34;
172 172
 				} else {
173 173
 					if ($matches[1] == '9999') {
174 174
 						$result['visibility'] = '> 10000';
175 175
 					} else {
176
-						$result['visibility'] = (float)$matches[1];
176
+						$result['visibility'] = (float) $matches[1];
177 177
 					}
178 178
 				}
179 179
 				if (preg_match('#^CAVOK$#', $piece, $matches)) {
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
     				elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage';
196 196
     				elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility';
197 197
     				$cloud['type_code'] = $type;
198
-    				$cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048);
198
+    				$cloud['level'] = round(((float) $matches[2])*100*0.3048);
199 199
     				$cloud['significant'] = isset($matches[3]) ? $matches[3] : '';
200 200
     				$result['cloud'][] = $cloud;
201 201
     			}
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
 				$rvr['runway'] = $matches[1];
206 206
 				$rvr['assessment'] = $matches[2];
207 207
 				$rvr['rvr'] = $matches[3];
208
-				$rvr['rvr_max'] = array_key_exists(4,$matches) ? $matches[4] : 0;
209
-				$rvr['unit'] = array_key_exists(5,$matches) ? $matches[5] : '';
208
+				$rvr['rvr_max'] = array_key_exists(4, $matches) ? $matches[4] : 0;
209
+				$rvr['unit'] = array_key_exists(5, $matches) ? $matches[5] : '';
210 210
 				$result['RVR'] = $rvr;
211 211
 			}
212 212
     			
@@ -223,12 +223,12 @@  discard block
 block discarded – undo
223 223
     			if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
224 224
     				//echo $piece;
225 225
     				//print_r($matches);
226
-    				if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
227
-    				else $range = array('exact' => (float)$matches[2], 'unit' => 'M');
226
+    				if (isset($matches[5])) $range = array('exact' => (float) $matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
227
+    				else $range = array('exact' => (float) $matches[2], 'unit' => 'M');
228 228
 				if (isset($matches[3])) {
229 229
 					$range = Array(
230
-					    'from' => (float)$matches[2],
231
-					    'to'   => (float)$matches[4],
230
+					    'from' => (float) $matches[2],
231
+					    'to'   => (float) $matches[4],
232 232
 					    'unit' => $matches[5] ? 'FT' : 'M'
233 233
 					);
234 234
 				}
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
                  try {
278 278
                         $sth = $this->db->prepare($query);
279 279
                         $sth->execute($query_values);
280
-                } catch(PDOException $e) {
280
+                } catch (PDOException $e) {
281 281
                         return "error : ".$e->getMessage();
282 282
                 }
283 283
                 $all = $sth->fetchAll(PDO::FETCH_ASSOC);
@@ -287,19 +287,19 @@  discard block
 block discarded – undo
287 287
                 return $all;
288 288
         }
289 289
 
290
-       public function addMETAR($location,$metar,$date) {
290
+       public function addMETAR($location, $metar, $date) {
291 291
 		global $globalDBdriver;
292
-		$date = date('Y-m-d H:i:s',strtotime($date));
292
+		$date = date('Y-m-d H:i:s', strtotime($date));
293 293
 		if ($globalDBdriver == 'mysql') {
294 294
 			$query = "INSERT INTO metar (metar_location,metar_date,metar) VALUES (:location,:date,:metar) ON DUPLICATE KEY UPDATE metar_date = :date, metar = :metar";
295 295
 		} else {
296 296
 			$query = "UPDATE metar SET metar_date = :date, metar = metar WHERE metar_location = :location;INSERT INTO metar (metar_location,metar_date,metar) SELECT :location,:date,:metar WHERE NOT EXISTS (SELECT 1 FROM metar WHERE metar_location = :location);";
297 297
 		}
298
-                $query_values = array(':location' => $location,':date' => $date,':metar' => utf8_encode($metar));
298
+                $query_values = array(':location' => $location, ':date' => $date, ':metar' => utf8_encode($metar));
299 299
                  try {
300 300
                         $sth = $this->db->prepare($query);
301 301
                         $sth->execute($query_values);
302
-                } catch(PDOException $e) {
302
+                } catch (PDOException $e) {
303 303
                         return "error : ".$e->getMessage();
304 304
                 }
305 305
         }
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
                  try {
311 311
                         $sth = $this->db->prepare($query);
312 312
                         $sth->execute($query_values);
313
-                } catch(PDOException $e) {
313
+                } catch (PDOException $e) {
314 314
                         return "error : ".$e->getMessage();
315 315
                 }
316 316
         }
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
                  try {
320 320
                         $sth = $this->db->prepare($query);
321 321
                         $sth->execute();
322
-                } catch(PDOException $e) {
322
+                } catch (PDOException $e) {
323 323
                         return "error : ".$e->getMessage();
324 324
                 }
325 325
         }
@@ -331,29 +331,29 @@  discard block
 block discarded – undo
331 331
     		$Common = new Common();
332 332
     		if (isset($globalIVAO) && $globalIVAO) {
333 333
         		//$cycle = $Common->getData('http://wx.ivao.aero/metar.php');
334
-			$Common->download('http://wx.ivao.aero/metar.php',dirname(__FILE__).'/../install/tmp/ivaometar.txt');
335
-    			$handle = fopen(dirname(__FILE__).'/../install/tmp/ivaometar.txt',"r");
334
+			$Common->download('http://wx.ivao.aero/metar.php', dirname(__FILE__).'/../install/tmp/ivaometar.txt');
335
+    			$handle = fopen(dirname(__FILE__).'/../install/tmp/ivaometar.txt', "r");
336 336
     		} else {
337 337
 			//$cycle = $Common->getData('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT');
338
-			$Common->download('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT',dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT');
339
-    			$handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT',"r");
338
+			$Common->download('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT', dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT');
339
+    			$handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT', "r");
340 340
     		}
341 341
     		if ($handle) {
342 342
 			if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB...";
343 343
 			$date = '';
344 344
     			//foreach(explode("\n",$cycle) as $line) {
345
-	    		while(($line = fgets($handle,4096)) !== false) {
346
-				if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) {
345
+	    		while (($line = fgets($handle, 4096)) !== false) {
346
+				if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) {
347 347
 					$date = $line;
348 348
     				} elseif ($line != '') {
349 349
     				    //$this->parse($line);
350 350
     				    if ($date == '') $date = date('Y/m/d H:m');
351 351
         			    $pos = 0;
352
-        			    $pieces = preg_split('/\s/',$line);
352
+        			    $pieces = preg_split('/\s/', $line);
353 353
         			    if ($pieces[0] == 'METAR') $pos++;
354 354
         			    if (strlen($pieces[$pos]) != 4) $pos++;
355 355
 		        	    $location = $pieces[$pos];
356
-        	        	    echo $this->addMETAR($location,$line,$date);
356
+        	        	    echo $this->addMETAR($location, $line, $date);
357 357
     				}
358 358
     			}
359 359
     			fclose($handle);
@@ -366,11 +366,11 @@  discard block
 block discarded – undo
366 366
     		if ($globalMETARurl == '') return array();
367 367
     		date_default_timezone_set("UTC");
368 368
     		$Common = new Common();
369
-    		$url = str_replace('{icao}',$icao,$globalMETARurl);
369
+    		$url = str_replace('{icao}', $icao, $globalMETARurl);
370 370
     		$cycle = $Common->getData($url);
371 371
     		$date = '';
372
-    		foreach(explode("\n",$cycle) as $line) {
373
-    			if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) {
372
+    		foreach (explode("\n", $cycle) as $line) {
373
+    			if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) {
374 374
     				//echo "date : ".$line."\n";
375 375
     				$date = $line;
376 376
     			} 
@@ -379,12 +379,12 @@  discard block
 block discarded – undo
379 379
     			    //echo $line;
380 380
     			    if ($date == '') $date = date('Y/m/d H:m');
381 381
     			    $pos = 0;
382
-    			    $pieces = preg_split('/\s/',$line);
382
+    			    $pieces = preg_split('/\s/', $line);
383 383
     			    if ($pieces[0] == 'METAR') $pos++;
384 384
     			    if (strlen($pieces[$pos]) != 4) $pos++;
385 385
 	        	    $location = $pieces[$pos];
386 386
 	        	    if (strlen($location == 4)) {
387
-	        		$this->addMETAR($location,$line,$date);
387
+	        		$this->addMETAR($location, $line, $date);
388 388
 	        		return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line));
389 389
 	        	    } else return array();
390 390
     			}
Please login to merge, or discard this patch.
Braces   +94 added lines, -36 removed lines patch added patch discarded remove patch
@@ -59,8 +59,11 @@  discard block
 block discarded – undo
59 59
                 }
60 60
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
61 61
                 $sth->closeCursor();
62
-                if ($row['nb'] > 0) return false;
63
-                else return true;
62
+                if ($row['nb'] > 0) {
63
+                	return false;
64
+                } else {
65
+                	return true;
66
+                }
64 67
         }
65 68
 
66 69
         public static function insert_last_update() {
@@ -84,9 +87,14 @@  discard block
 block discarded – undo
84 87
     		//$pieces = explode(' ',$data);
85 88
     		$pieces = preg_split('/\s/',$data);
86 89
     		$pos = 0;
87
-    		if ($pieces[0] == 'METAR') $pos++;
88
-    		elseif ($pieces[0] == 'SPECI') $pos++;
89
-    		if (strlen($pieces[$pos]) != 4) $pos++;
90
+    		if ($pieces[0] == 'METAR') {
91
+    			$pos++;
92
+    		} elseif ($pieces[0] == 'SPECI') {
93
+    			$pos++;
94
+    		}
95
+    		if (strlen($pieces[$pos]) != 4) {
96
+    			$pos++;
97
+    		}
90 98
     		$result = array();
91 99
     		$result['location'] = $pieces[$pos];
92 100
     		$pos++;
@@ -95,16 +103,26 @@  discard block
 block discarded – undo
95 103
     		$c = count($pieces);
96 104
     		for($pos++; $pos < $c; $pos++) {
97 105
     			$piece = $pieces[$pos];
98
-    			if ($piece == 'RMK') break;
99
-    			if ($piece == 'AUTO') $result['auto'] = true;
100
-    			if ($piece == 'COR') $result['correction'] = true;
106
+    			if ($piece == 'RMK') {
107
+    				break;
108
+    			}
109
+    			if ($piece == 'AUTO') {
110
+    				$result['auto'] = true;
111
+    			}
112
+    			if ($piece == 'COR') {
113
+    				$result['correction'] = true;
114
+    			}
101 115
     			// Wind Speed
102 116
     			if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) {
103 117
     				$result['wind']['direction'] = (float)$matches[1];
104 118
 				$result['wind']['unit'] = $matches[4];
105
-    				if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2);
106
-    				elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2);
107
-    				elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2);
119
+    				if ($result['wind']['unit'] == 'KT') {
120
+    					$result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2);
121
+    				} elseif ($result['wind']['unit'] == 'KPH') {
122
+    					$result['wind']['speed'] = round(((float)$matches[2])*1000,2);
123
+    				} elseif ($result['wind']['unit'] == 'MPS') {
124
+    					$result['wind']['speed'] = round(((float)$matches[2]),2);
125
+    				}
108 126
 				$result['wind']['gust'] = (float)$matches[3];
109 127
 				$result['wind']['unit'] = $matches[4];
110 128
 				$result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0;
@@ -186,14 +204,23 @@  discard block
 block discarded – undo
186 204
     				//$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : '');
187 205
     				$type = $matches[1];
188 206
     				$cloud = array();
189
-    				if ($type == 'SKC') $cloud['type'] = 'No cloud/Sky clear';
190
-    				elseif ($type == 'CLR') $cloud['type'] = 'No cloud below 12,000ft (3700m)';
191
-    				elseif ($type == 'NSC') $cloud['type'] = 'No significant cloud';
192
-    				elseif ($type == 'FEW') $cloud['type'] = 'Few';
193
-    				elseif ($type == 'SCT') $cloud['type'] = 'Scattered';
194
-    				elseif ($type == 'BKN') $cloud['type'] = 'Broken';
195
-    				elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage';
196
-    				elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility';
207
+    				if ($type == 'SKC') {
208
+    					$cloud['type'] = 'No cloud/Sky clear';
209
+    				} elseif ($type == 'CLR') {
210
+    					$cloud['type'] = 'No cloud below 12,000ft (3700m)';
211
+    				} elseif ($type == 'NSC') {
212
+    					$cloud['type'] = 'No significant cloud';
213
+    				} elseif ($type == 'FEW') {
214
+    					$cloud['type'] = 'Few';
215
+    				} elseif ($type == 'SCT') {
216
+    					$cloud['type'] = 'Scattered';
217
+    				} elseif ($type == 'BKN') {
218
+    					$cloud['type'] = 'Broken';
219
+    				} elseif ($type == 'OVC') {
220
+    					$cloud['type'] = 'Overcast/Full cloud coverage';
221
+    				} elseif ($type == 'VV') {
222
+    					$cloud['type'] = 'Vertical visibility';
223
+    				}
197 224
     				$cloud['type_code'] = $type;
198 225
     				$cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048);
199 226
     				$cloud['significant'] = isset($matches[3]) ? $matches[3] : '';
@@ -223,8 +250,11 @@  discard block
 block discarded – undo
223 250
     			if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
224 251
     				//echo $piece;
225 252
     				//print_r($matches);
226
-    				if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
227
-    				else $range = array('exact' => (float)$matches[2], 'unit' => 'M');
253
+    				if (isset($matches[5])) {
254
+    					$range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
255
+    				} else {
256
+    					$range = array('exact' => (float)$matches[2], 'unit' => 'M');
257
+    				}
228 258
 				if (isset($matches[3])) {
229 259
 					$range = Array(
230 260
 					    'from' => (float)$matches[2],
@@ -257,8 +287,11 @@  discard block
 block discarded – undo
257 287
 				if (isset($matches[3])) {
258 288
 					$text[] = $this->texts[$matches[3]];
259 289
 				}
260
-				if (!isset($result['weather'])) $result['weather'] = implode(' ', $text);
261
-				else $result['weather'] = $result['weather'].' / '.implode(' ', $text);
290
+				if (!isset($result['weather'])) {
291
+					$result['weather'] = implode(' ', $text);
292
+				} else {
293
+					$result['weather'] = $result['weather'].' / '.implode(' ', $text);
294
+				}
262 295
     			}
263 296
     		}
264 297
     		return $result;
@@ -270,8 +303,11 @@  discard block
 block discarded – undo
270 303
     		if (isset($globalMETARcycle) && $globalMETARcycle) {
271 304
             		$query = "SELECT * FROM metar WHERE metar_location = :icao";
272 305
                 } else {
273
-            		if ($globalDBdriver == 'mysql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1";
274
-            		else $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1";
306
+            		if ($globalDBdriver == 'mysql') {
307
+            			$query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1";
308
+            		} else {
309
+            			$query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1";
310
+            		}
275 311
                 }
276 312
                 $query_values = array(':icao' => $icao);
277 313
                  try {
@@ -326,7 +362,9 @@  discard block
 block discarded – undo
326 362
         
327 363
         public function addMETARCycle() {
328 364
     		global $globalDebug, $globalIVAO;
329
-    		if (isset($globalDebug) && $globalDebug) echo "Downloading METAR cycle...";
365
+    		if (isset($globalDebug) && $globalDebug) {
366
+    			echo "Downloading METAR cycle...";
367
+    		}
330 368
     		date_default_timezone_set("UTC");
331 369
     		$Common = new Common();
332 370
     		if (isset($globalIVAO) && $globalIVAO) {
@@ -339,7 +377,9 @@  discard block
 block discarded – undo
339 377
     			$handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT',"r");
340 378
     		}
341 379
     		if ($handle) {
342
-			if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB...";
380
+			if (isset($globalDebug) && $globalDebug) {
381
+				echo "Done - Updating DB...";
382
+			}
343 383
 			$date = '';
344 384
     			//foreach(explode("\n",$cycle) as $line) {
345 385
 	    		while(($line = fgets($handle,4096)) !== false) {
@@ -347,23 +387,33 @@  discard block
 block discarded – undo
347 387
 					$date = $line;
348 388
     				} elseif ($line != '') {
349 389
     				    //$this->parse($line);
350
-    				    if ($date == '') $date = date('Y/m/d H:m');
390
+    				    if ($date == '') {
391
+    				    	$date = date('Y/m/d H:m');
392
+    				    }
351 393
         			    $pos = 0;
352 394
         			    $pieces = preg_split('/\s/',$line);
353
-        			    if ($pieces[0] == 'METAR') $pos++;
354
-        			    if (strlen($pieces[$pos]) != 4) $pos++;
395
+        			    if ($pieces[0] == 'METAR') {
396
+        			    	$pos++;
397
+        			    }
398
+        			    if (strlen($pieces[$pos]) != 4) {
399
+        			    	$pos++;
400
+        			    }
355 401
 		        	    $location = $pieces[$pos];
356 402
         	        	    echo $this->addMETAR($location,$line,$date);
357 403
     				}
358 404
     			}
359 405
     			fclose($handle);
360 406
     		}
361
-    		if (isset($globalDebug) && $globalDebug) echo "Done\n";
407
+    		if (isset($globalDebug) && $globalDebug) {
408
+    			echo "Done\n";
409
+    		}
362 410
         
363 411
         }
364 412
         public function downloadMETAR($icao) {
365 413
     		global $globalMETARurl;
366
-    		if ($globalMETARurl == '') return array();
414
+    		if ($globalMETARurl == '') {
415
+    			return array();
416
+    		}
367 417
     		date_default_timezone_set("UTC");
368 418
     		$Common = new Common();
369 419
     		$url = str_replace('{icao}',$icao,$globalMETARurl);
@@ -377,16 +427,24 @@  discard block
 block discarded – undo
377 427
     			if ($line != '') {
378 428
     			    //$this->parse($line);
379 429
     			    //echo $line;
380
-    			    if ($date == '') $date = date('Y/m/d H:m');
430
+    			    if ($date == '') {
431
+    			    	$date = date('Y/m/d H:m');
432
+    			    }
381 433
     			    $pos = 0;
382 434
     			    $pieces = preg_split('/\s/',$line);
383
-    			    if ($pieces[0] == 'METAR') $pos++;
384
-    			    if (strlen($pieces[$pos]) != 4) $pos++;
435
+    			    if ($pieces[0] == 'METAR') {
436
+    			    	$pos++;
437
+    			    }
438
+    			    if (strlen($pieces[$pos]) != 4) {
439
+    			    	$pos++;
440
+    			    }
385 441
 	        	    $location = $pieces[$pos];
386 442
 	        	    if (strlen($location == 4)) {
387 443
 	        		$this->addMETAR($location,$line,$date);
388 444
 	        		return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line));
389
-	        	    } else return array();
445
+	        	    } else {
446
+	        	    	return array();
447
+	        	    }
390 448
     			}
391 449
     			//echo $line."\n";
392 450
     		}
Please login to merge, or discard this patch.
require/class.SpotterImport.php 4 patches
Spacing   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -29,18 +29,18 @@  discard block
 block discarded – undo
29 29
 	$currentdate = date('Y-m-d');
30 30
 	$sourcestat = $Stats->getStatsSource($currentdate);
31 31
 	if (!empty($sourcestat)) {
32
-	    foreach($sourcestat as $srcst) {
32
+	    foreach ($sourcestat as $srcst) {
33 33
 	    	$type = $srcst['stats_type'];
34 34
 		if ($type == 'polar' || $type == 'hist') {
35 35
 		    $source = $srcst['source_name'];
36 36
 		    $data = $srcst['source_data'];
37
-		    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
37
+		    $this->stats[$currentdate][$source][$type] = json_decode($data, true);
38 38
 	        }
39 39
 	    }
40 40
 	}
41 41
     }
42 42
 
43
-    public function get_Schedule($id,$ident) {
43
+    public function get_Schedule($id, $ident) {
44 44
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
45 45
 	// Get schedule here, so it's done only one time
46 46
 	
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 		$schedule = $Schedule->fetchSchedule($operator);
66 66
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
67 67
 		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
68
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
69
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
68
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $schedule['DepartureTime']));
69
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $schedule['ArrivalTime']));
70 70
 		    // Should also check if route schedule = route from DB
71 71
 		    if ($schedule['DepartureAirportIATA'] != '') {
72 72
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 			    }
87 87
 			}
88 88
 		    }
89
-		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
89
+		    $Schedule->addSchedule($operator, $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time'], $schedule['Source']);
90 90
 		}
91 91
 	    } else $scheduleexist = true;
92 92
 	} else $scheduleexist = true;
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
        if ($scheduleexist) {
95 95
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
96 96
     		$sch = $Schedule->getSchedule($operator);
97
-		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
97
+		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport' => $sch['arrival_airport_icao'], 'departure_airport' => $sch['departure_airport_icao'], 'departure_airport_time' => $sch['departure_airport_time'], 'arrival_airport_time' => $sch['arrival_airport_time']));
98 98
        }
99 99
 	$Spotter->db = null;
100 100
 	$Schedule->db = null;
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 		//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
121 121
     		$Spotter = new Spotter($this->db);
122 122
         	$real_arrival = $this->arrival($key);
123
-        	$Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
123
+        	$Spotter->updateLatestSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $real_arrival['airport_icao'], $real_arrival['airport_time']);
124 124
             }
125 125
 	}
126 126
     }
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
         $airport_time = '';
134 134
         if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
135 135
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
136
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
136
+	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $globalClosestMinDist);
137 137
     	    if (isset($closestAirports[0])) {
138 138
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
139 139
         	    $airport_icao = $closestAirports[0]['icao'];
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
         		    break;
149 149
         		}
150 150
         	    }
151
-        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
151
+        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude'] + 5000))) {
152 152
         		$airport_icao = $closestAirports[0]['icao'];
153 153
         		$airport_time = $this->all_flights[$key]['datetime'];
154 154
         	} else {
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
         } else {
162 162
         	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
163 163
         }
164
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
164
+        return array('airport_icao' => $airport_icao, 'airport_time' => $airport_time);
165 165
     }
166 166
 
167 167
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
173 173
 	foreach ($this->all_flights as $key => $flight) {
174 174
     	    if (isset($flight['lastupdate'])) {
175
-        	if ($flight['lastupdate'] < (time()-3000)) {
175
+        	if ($flight['lastupdate'] < (time() - 3000)) {
176 176
             	    if (isset($this->all_flights[$key]['id'])) {
177 177
             		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
178 178
 			/*
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
             		$real_arrival = $this->arrival($key);
184 184
             		$Spotter = new Spotter($this->db);
185 185
             		if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
186
-				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
186
+				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $real_arrival['airport_icao'], $real_arrival['airport_time']);
187 187
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
188 188
 			}
189 189
 			// Put in archive
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 	$send = false;
220 220
 	
221 221
 	// SBS format is CSV format
222
-	if(is_array($line) && isset($line['hex'])) {
222
+	if (is_array($line) && isset($line['hex'])) {
223 223
 	    //print_r($line);
224 224
   	    if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) {
225 225
 
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 		//print_r($this->all_flights);
254 254
 		if (!isset($this->all_flights[$id]['hex']) && ctype_xdigit($hex)) {
255 255
 		    $this->all_flights[$id] = array('hex' => $hex);
256
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
256
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
257 257
 		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
258 258
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
259 259
 		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 			$Spotter = new Spotter($this->db);
264 264
 			$aircraft_icao = $Spotter->getAllAircraftType($hex);
265 265
 			$Spotter->db = null;
266
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
266
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
267 267
 
268 268
 			if ($aircraft_icao == '' && isset($line['aircraft_type'])) {
269 269
 			    if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
@@ -271,32 +271,32 @@  discard block
 block discarded – undo
271 271
 			    elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
272 272
 			    elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
273 273
 			}
274
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
274
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
275 275
 		    } else if (isset($line['aircraft_name'])) {
276 276
 			// Get aircraft ICAO from aircraft name
277 277
 			$Spotter = new Spotter($this->db);
278 278
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
279 279
 			$Spotter->db = null;
280
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
281
-			else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
282
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
283
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true));
284
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
280
+			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
281
+			else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => 'NA'));
282
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $line['aircraft_icao']));
283
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => '', 'departure_airport' => '', 'arrival_airport' => '', 'latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'altitude_real' => '', 'heading' => '', 'departure_airport_time' => '', 'arrival_airport_time' => '', 'squawk' => '', 'route_stop' => '', 'registration' => '', 'pilot_id' => '', 'pilot_name' => '', 'waypoints' => '', 'ground' => '0', 'format_source' => '', 'source_name' => '', 'over_country' => '', 'verticalrate' => '', 'noarchive' => false, 'putinarchive' => true));
284
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('lastupdate' => time()));
285 285
 		    if (!isset($line['id'])) {
286 286
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
287 287
 //			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
288 288
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
289
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
289
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
290 290
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
291
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
291
+		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
292 292
 
293 293
 		    if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n";
294 294
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
295 295
 		}
296 296
 		
297
-		if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
297
+		if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/', $line['datetime'])) {
298 298
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
299
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
299
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => $line['datetime']));
300 300
 		    } else {
301 301
 				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
302 302
 				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
@@ -307,23 +307,23 @@  discard block
 block discarded – undo
307 307
 				*/
308 308
 				return '';
309 309
 		    }
310
-		} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
310
+		} else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => date('Y-m-d H:i:s')));
311 311
 
312 312
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
313
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
313
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('registration' => $line['registration']));
314 314
 		}
315 315
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
316
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
316
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('waypoints' => $line['waypoints']));
317 317
 		}
318 318
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
319
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
319
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_id' => $line['pilot_id']));
320 320
 		}
321 321
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
322
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
322
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_name' => $line['pilot_name']));
323 323
 		}
324 324
  
325 325
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
326
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
326
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident'])));
327 327
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
328 328
 			$timeelapsed = microtime(true);
329 329
             		$Spotter = new Spotter($this->db);
@@ -333,10 +333,10 @@  discard block
 block discarded – undo
333 333
 			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
334 334
 			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
335 335
 			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
336
-            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
336
+            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $fromsource);
337 337
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
338 338
 			$Spotter->db = null;
339
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
339
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
340 340
 		    }
341 341
 
342 342
 /*
@@ -347,24 +347,24 @@  discard block
 block discarded – undo
347 347
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
348 348
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
349 349
   */
350
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
350
+		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
351 351
 
352 352
 		    //$putinarchive = true;
353 353
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
354
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
354
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $line['departure_airport_time']));
355 355
 		    }
356 356
 		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
357
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
357
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $line['arrival_airport_time']));
358 358
 		    }
359 359
 		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
360
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
360
+		    		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $line['departure_airport_icao'], 'arrival_airport' => $line['arrival_airport_icao'], 'route_stop' => ''));
361 361
 		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
362 362
 				$timeelapsed = microtime(true);
363 363
 				$Spotter = new Spotter($this->db);
364 364
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
365 365
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
366
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
367
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
366
+		    		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $line['departure_airport_icao'], 'arrival_airport' => $line['arrival_airport_icao'], 'route_stop' => ''));
367
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
368 368
 
369 369
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
370 370
 			$timeelapsed = microtime(true);
@@ -377,34 +377,34 @@  discard block
 block discarded – undo
377 377
 				$Translation->db = null;
378 378
 			}
379 379
 			$Spotter->db = null;
380
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
380
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
381 381
 
382 382
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
383 383
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
384 384
 			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
385 385
 				//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop']));
386
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
386
+		    		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $route['fromairport_icao'], 'arrival_airport' => $route['toairport_icao'], 'route_stop' => $route['routestop']));
387 387
 		    	    }
388 388
 			}
389 389
 			if (!isset($globalFork)) $globalFork = TRUE;
390 390
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
391
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
391
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id, trim($line['ident']));
392 392
 			}
393 393
 		    }
394 394
 		}
395 395
 
396 396
 		if (isset($line['speed']) && $line['speed'] != '') {
397 397
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
398
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
399
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
398
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($line['speed'])));
399
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed_fromsrc' => true));
400 400
 		    //$dataFound = true;
401 401
 		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
402
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
402
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm');
403 403
 		    if ($distance > 1000 && $distance < 10000) {
404 404
 		    // use datetime
405 405
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
406 406
 			$speed = $speed*3.6;
407
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
407
+			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($speed)));
408 408
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
409 409
 		    }
410 410
 		}
@@ -412,11 +412,11 @@  discard block
 block discarded – undo
412 412
 
413 413
 
414 414
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
415
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
415
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time() - $this->all_flights[$id]['time_last_coord']);
416 416
 	    	    else unset($timediff);
417
-	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 800 || ($timediff > 10 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
417
+	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 800 || ($timediff > 10 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')))) {
418 418
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
419
-			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
419
+			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'], $this->all_flights[$id]['archive_longitude'], $this->all_flights[$id]['livedb_latitude'], $this->all_flights[$id]['livedb_longitude'], $line['latitude'], $line['longitude'])) {
420 420
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
421 421
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
422 422
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -424,10 +424,10 @@  discard block
 block discarded – undo
424 424
 				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
425 425
 				$timeelapsed = microtime(true);
426 426
 				$Spotter = new Spotter($this->db);
427
-				$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
427
+				$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
428 428
 				if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
429 429
 				$Spotter->db = null;
430
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
430
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
431 431
 				$this->tmd = 0;
432 432
 				if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
433 433
 			    }
@@ -436,13 +436,13 @@  discard block
 block discarded – undo
436 436
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
437 437
 			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
438 438
 				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
439
-				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
439
+				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude'] - $line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
440 440
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
441 441
 				    $dataFound = true;
442 442
 				    $this->all_flights[$id]['time_last_coord'] = time();
443 443
 				}
444 444
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
445
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
445
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('latitude' => $line['latitude']));
446 446
 				/*
447 447
 				if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) {
448 448
 				    $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -460,13 +460,13 @@  discard block
 block discarded – undo
460 460
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
461 461
 			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
462 462
 				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
463
-				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
463
+				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude'] - $line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
464 464
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
465 465
 				    $dataFound = true;
466 466
 				    $this->all_flights[$id]['time_last_coord'] = time();
467 467
 				}
468 468
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
469
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
469
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('longitude' => $line['longitude']));
470 470
 				/*
471 471
 				if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) {
472 472
 				    $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
@@ -484,45 +484,45 @@  discard block
 block discarded – undo
484 484
 		    } else if ($globalDebug && $timediff > 20) {
485 485
 			$this->tmd = $this->tmd + 1;
486 486
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
487
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
488
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
487
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')."m -";
488
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
489 489
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
490 490
 		    }
491 491
 		}
492 492
 		if (isset($line['last_update']) && $line['last_update'] != '') {
493 493
 		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
494
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
494
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('last_update' => $line['last_update']));
495 495
 		}
496 496
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
497
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
497
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('verticalrate' => $line['verticalrate']));
498 498
 		    //$dataFound = true;
499 499
 		}
500 500
 		if (isset($line['format_source']) && $line['format_source'] != '') {
501
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
501
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('format_source' => $line['format_source']));
502 502
 		}
503 503
 		if (isset($line['source_name']) && $line['source_name'] != '') {
504
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
504
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_name' => $line['source_name']));
505 505
 		}
506 506
 		if (isset($line['emergency']) && $line['emergency'] != '') {
507
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
507
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('emergency' => $line['emergency']));
508 508
 		    //$dataFound = true;
509 509
 		}
510 510
 		if (isset($line['ground']) && $line['ground'] != '') {
511 511
 		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
512 512
 			// Here we force archive of flight because after ground it's a new one (or should be)
513
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
514
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
515
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
516
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
517
-			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
513
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
514
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
515
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
516
+		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
517
+			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
518 518
 		    }
519 519
 		    if ($line['ground'] != 1) $line['ground'] = 0;
520
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
520
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ground' => $line['ground']));
521 521
 		    //$dataFound = true;
522 522
 		}
523 523
 		if (isset($line['squawk']) && $line['squawk'] != '') {
524 524
 		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
525
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
525
+			    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
526 526
 			    $highlight = '';
527 527
 			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
528 528
 			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
@@ -530,48 +530,48 @@  discard block
 block discarded – undo
530 530
 			    if ($highlight != '') {
531 531
 				$timeelapsed = microtime(true);
532 532
 				$Spotter = new Spotter($this->db);
533
-				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
533
+				$Spotter->setHighlightFlight($this->all_flights[$id]['id'], $highlight);
534 534
 				$Spotter->db = null;
535
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
535
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
536 536
 
537 537
 				$this->all_flights[$id]['putinarchive'] = true;
538 538
 				//$putinarchive = true;
539 539
 				//$highlight = '';
540 540
 			    }
541 541
 			    
542
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
542
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
543 543
 		    //$dataFound = true;
544 544
 		}
545 545
 
546 546
 		if (isset($line['altitude']) && $line['altitude'] != '') {
547 547
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
548
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 2) $this->all_flights[$id]['putinarchive'] = true;
549
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
550
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
548
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100) - $this->all_flights[$id]['altitude']) > 2) $this->all_flights[$id]['putinarchive'] = true;
549
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude' => round($line['altitude']/100)));
550
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_real' => $line['altitude']));
551 551
 			//$dataFound = true;
552 552
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
553 553
   		}
554 554
 
555 555
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
556
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
556
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('noarchive' => true));
557 557
 		}
558 558
 		
559 559
 		if (isset($line['heading']) && $line['heading'] != '') {
560
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true;
561
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
562
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
560
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading'] - round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true;
561
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($line['heading'])));
562
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading_fromsrc' => true));
563 563
 		    //$dataFound = true;
564 564
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
565
-  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
566
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
567
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true;
565
+  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'], $this->all_flights[$id]['archive_longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
566
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($heading)));
567
+		    if (abs($this->all_flights[$id]['heading'] - round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true;
568 568
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
569 569
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
570 570
   		    // If not enough messages and ACARS set heading to 0
571
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
571
+  		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => 0));
572 572
   		}
573
-		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
574
-		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
573
+		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
574
+		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
575 575
 
576 576
 //		print_r($this->all_flights[$id]);
577 577
 		//gets the callsign from the last hour
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 		if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
582 582
 		    $this->all_flights[$id]['lastupdate'] = time();
583 583
 		    if ($this->all_flights[$id]['addedSpotter'] == 0) {
584
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
584
+		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == '' || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
585 585
 			    //print_r($this->all_flights);
586 586
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
587 587
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
@@ -591,61 +591,61 @@  discard block
 block discarded – undo
591 591
 				$SpotterLive = new SpotterLive($this->db);
592 592
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
593 593
 				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
594
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
594
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
595 595
 				} elseif (isset($line['id'])) {
596 596
 				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
597
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
597
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
598 598
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
599 599
 				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
600
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
600
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
601 601
 				} else $recent_ident = '';
602
-				$SpotterLive->db=null;
602
+				$SpotterLive->db = null;
603 603
 
604 604
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
605 605
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
606 606
 			    } else {
607 607
 				$recent_ident = '';
608
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
608
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 0));
609 609
 			    }
610 610
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
611
-			    if($recent_ident == "")
611
+			    if ($recent_ident == "")
612 612
 			    {
613 613
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
614 614
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
615 615
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
616 616
 				//adds the spotter data for the archive
617 617
 				$ignoreImport = false;
618
-				foreach($globalAirportIgnore as $airportIgnore) {
618
+				foreach ($globalAirportIgnore as $airportIgnore) {
619 619
 				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
620 620
 					$ignoreImport = true;
621 621
 				    }
622 622
 				}
623 623
 				if (count($globalAirportAccept) > 0) {
624 624
 				    $ignoreImport = true;
625
-				    foreach($globalAirportIgnore as $airportIgnore) {
625
+				    foreach ($globalAirportIgnore as $airportIgnore) {
626 626
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
627 627
 					    $ignoreImport = false;
628 628
 					}
629 629
 				    }
630 630
 				}
631 631
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
632
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
633
-					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
632
+				    foreach ($globalAirlineIgnore as $airlineIgnore) {
633
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) {
634 634
 					    $ignoreImport = true;
635 635
 					}
636 636
 				    }
637 637
 				}
638 638
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
639 639
 				    $ignoreImport = true;
640
-				    foreach($globalAirlineAccept as $airlineAccept) {
641
-					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
640
+				    foreach ($globalAirlineAccept as $airlineAccept) {
641
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) {
642 642
 					    $ignoreImport = false;
643 643
 					}
644 644
 				    }
645 645
 				}
646 646
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
647 647
 				    $ignoreImport = true;
648
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
648
+				    foreach ($globalPilotIdAccept as $pilotIdAccept) {
649 649
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
650 650
 					    $ignoreImport = false;
651 651
 					}
@@ -657,27 +657,27 @@  discard block
 block discarded – undo
657 657
 				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
658 658
 				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
659 659
 				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
660
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
660
+				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
661 661
 				    $timeelapsed = microtime(true);
662 662
 				    $Spotter = new Spotter($this->db);
663
-				    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name']);
663
+				    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $highlight, $this->all_flights[$id]['hex'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name']);
664 664
 				    $Spotter->db = null;
665 665
 				    if ($globalDebug && isset($result)) echo $result."\n";
666
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
666
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
667 667
 				    
668 668
 				    // Add source stat in DB
669 669
 				    $Stats = new Stats($this->db);
670 670
 				    if (!empty($this->stats)) {
671 671
 					if ($globalDebug) echo 'Add source stats : ';
672
-				        foreach($this->stats as $date => $data) {
673
-					    foreach($data as $source => $sourced) {
672
+				        foreach ($this->stats as $date => $data) {
673
+					    foreach ($data as $source => $sourced) {
674 674
 					        //print_r($sourced);
675
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
676
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
675
+				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar', $date);
676
+				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist', $date);
677 677
 				    		if (isset($sourced['msg'])) {
678 678
 				    		    if (time() - $sourced['msg']['date'] > 10) {
679 679
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
680
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
680
+				    		        echo $Stats->addStatSource($nbmsg, $source, 'msg', $date);
681 681
 			    			        unset($this->stats[$date][$source]['msg']);
682 682
 			    			    }
683 683
 			    			}
@@ -713,18 +713,18 @@  discard block
 block discarded – undo
713 713
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
714 714
 				    $SpotterLive = new SpotterLive($this->db);
715 715
 				    $SpotterLive->deleteLiveSpotterData();
716
-				    $SpotterLive->db=null;
716
+				    $SpotterLive->db = null;
717 717
 				    if ($globalDebug) echo " Done\n";
718 718
 				    $this->last_delete = time();
719 719
 				}
720 720
 			    } else {
721
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) {
721
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) {
722 722
 				    $this->all_flights[$id]['id'] = $recent_ident;
723 723
 				    $this->all_flights[$id]['addedSpotter'] = 1;
724 724
 				}
725 725
 				if (isset($globalDaemon) && !$globalDaemon) {
726 726
 					$Spotter = new Spotter($this->db);
727
-					$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
727
+					$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time']);
728 728
 					$Spotter->db = null;
729 729
 				}
730 730
 				
@@ -748,37 +748,37 @@  discard block
 block discarded – undo
748 748
 		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
749 749
 		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
750 750
 
751
-		    foreach($globalAirportIgnore as $airportIgnore) {
751
+		    foreach ($globalAirportIgnore as $airportIgnore) {
752 752
 		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
753 753
 			    $ignoreImport = true;
754 754
 			}
755 755
 		    }
756 756
 		    if (count($globalAirportAccept) > 0) {
757 757
 		        $ignoreImport = true;
758
-		        foreach($globalAirportIgnore as $airportIgnore) {
758
+		        foreach ($globalAirportIgnore as $airportIgnore) {
759 759
 			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
760 760
 				$ignoreImport = false;
761 761
 			    }
762 762
 			}
763 763
 		    }
764 764
 		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
765
-			foreach($globalAirlineIgnore as $airlineIgnore) {
766
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
765
+			foreach ($globalAirlineIgnore as $airlineIgnore) {
766
+			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) {
767 767
 				$ignoreImport = true;
768 768
 			    }
769 769
 			}
770 770
 		    }
771 771
 		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
772 772
 			$ignoreImport = true;
773
-			foreach($globalAirlineAccept as $airlineAccept) {
774
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
773
+			foreach ($globalAirlineAccept as $airlineAccept) {
774
+			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) {
775 775
 				$ignoreImport = false;
776 776
 			    }
777 777
 			}
778 778
 		    }
779 779
 		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
780 780
 			$ignoreImport = true;
781
-			foreach($globalPilotIdAccept as $pilotIdAccept) {
781
+			foreach ($globalPilotIdAccept as $pilotIdAccept) {
782 782
 			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
783 783
 			        $ignoreImport = false;
784 784
 			    }
@@ -786,13 +786,13 @@  discard block
 block discarded – undo
786 786
 		    }
787 787
 
788 788
 		    if (!$ignoreImport) {
789
-			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
789
+			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
790 790
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
791 791
 				$timeelapsed = microtime(true);
792 792
 				$SpotterLive = new SpotterLive($this->db);
793
-				$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
793
+				$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $this->all_flights[$id]['hex'], $this->all_flights[$id]['putinarchive'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['over_country']);
794 794
 				$SpotterLive->db = null;
795
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
795
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
796 796
 
797 797
 				// Put statistics in $this->stats variable
798 798
 				//if ($line['format_source'] != 'aprs') {
@@ -810,19 +810,19 @@  discard block
 block discarded – undo
810 810
 							$latitude = $globalCenterLatitude;
811 811
 							$longitude = $globalCenterLongitude;
812 812
 						}
813
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
813
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
814 814
 					} else {
815 815
 						$latitude = $this->source_location[$source]['latitude'];
816 816
 						$longitude = $this->source_location[$source]['longitude'];
817 817
 					}
818
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
818
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
819 819
 					//$stats_heading = $stats_heading%22.5;
820 820
 					$stats_heading = round($stats_heading/22.5);
821
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
821
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
822 822
 					$current_date = date('Y-m-d');
823 823
 					if ($stats_heading == 16) $stats_heading = 0;
824 824
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
825
-						for ($i=0;$i<=15;$i++) {
825
+						for ($i = 0; $i <= 15; $i++) {
826 826
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
827 827
 						}
828 828
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -837,9 +837,9 @@  discard block
 block discarded – undo
837 837
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
838 838
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
839 839
 						    end($this->stats[$current_date][$source]['hist']);
840
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
840
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
841 841
 						} else $mini = 0;
842
-						for ($i=$mini;$i<=$distance;$i+=10) {
842
+						for ($i = $mini; $i <= $distance; $i += 10) {
843 843
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
844 844
 						}
845 845
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
 				if ($this->all_flights[$id]['putinarchive']) $send = true;
853 853
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
854 854
 				if ($globalDebug) echo $result."\n";
855
-			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
855
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n";
856 856
 			//$this->del();
857 857
 			
858 858
 			
Please login to merge, or discard this patch.
Indentation   +354 added lines, -354 removed lines patch added patch discarded remove patch
@@ -9,16 +9,16 @@  discard block
 block discarded – undo
9 9
 require_once(dirname(__FILE__).'/class.Source.php');
10 10
 
11 11
 class SpotterImport {
12
-    private $all_flights = array();
13
-    private $last_delete_hourly = 0;
14
-    private $last_delete = 0;
15
-    private $stats = array();
16
-    private $tmd = 0;
17
-    private $source_location = array();
18
-    public $db = null;
19
-    public $nb = 0;
20
-
21
-    public function __construct($dbc = null) {
12
+	private $all_flights = array();
13
+	private $last_delete_hourly = 0;
14
+	private $last_delete = 0;
15
+	private $stats = array();
16
+	private $tmd = 0;
17
+	private $source_location = array();
18
+	public $db = null;
19
+	public $nb = 0;
20
+
21
+	public function __construct($dbc = null) {
22 22
 	global $globalBeta;
23 23
 	$Connection = new Connection($dbc);
24 24
 	$this->db = $Connection->db();
@@ -29,18 +29,18 @@  discard block
 block discarded – undo
29 29
 	$currentdate = date('Y-m-d');
30 30
 	$sourcestat = $Stats->getStatsSource($currentdate);
31 31
 	if (!empty($sourcestat)) {
32
-	    foreach($sourcestat as $srcst) {
33
-	    	$type = $srcst['stats_type'];
32
+		foreach($sourcestat as $srcst) {
33
+			$type = $srcst['stats_type'];
34 34
 		if ($type == 'polar' || $type == 'hist') {
35
-		    $source = $srcst['source_name'];
36
-		    $data = $srcst['source_data'];
37
-		    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
38
-	        }
39
-	    }
35
+			$source = $srcst['source_name'];
36
+			$data = $srcst['source_data'];
37
+			$this->stats[$currentdate][$source][$type] = json_decode($data,true);
38
+			}
39
+		}
40
+	}
40 41
 	}
41
-    }
42 42
 
43
-    public function get_Schedule($id,$ident) {
43
+	public function get_Schedule($id,$ident) {
44 44
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
45 45
 	// Get schedule here, so it's done only one time
46 46
 	
@@ -60,42 +60,42 @@  discard block
 block discarded – undo
60 60
 	$operator = $Spotter->getOperator($ident);
61 61
 	$scheduleexist = false;
62 62
 	if ($Schedule->checkSchedule($operator) == 0) {
63
-	    $operator = $Translation->checkTranslation($ident);
64
-	    if ($Schedule->checkSchedule($operator) == 0) {
63
+		$operator = $Translation->checkTranslation($ident);
64
+		if ($Schedule->checkSchedule($operator) == 0) {
65 65
 		$schedule = $Schedule->fetchSchedule($operator);
66 66
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
67
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
68
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
69
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
70
-		    // Should also check if route schedule = route from DB
71
-		    if ($schedule['DepartureAirportIATA'] != '') {
67
+			if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
68
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
69
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
70
+			// Should also check if route schedule = route from DB
71
+			if ($schedule['DepartureAirportIATA'] != '') {
72 72
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
73
-			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
74
-			    if (trim($airport_icao) != '') {
73
+				$airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
74
+				if (trim($airport_icao) != '') {
75 75
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
76 76
 				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
77
-			    }
77
+				}
78
+			}
78 79
 			}
79
-		    }
80
-		    if ($schedule['ArrivalAirportIATA'] != '') {
80
+			if ($schedule['ArrivalAirportIATA'] != '') {
81 81
 			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) {
82
-			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
83
-			    if (trim($airport_icao) != '') {
82
+				$airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
83
+				if (trim($airport_icao) != '') {
84 84
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
85 85
 				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
86
-			    }
86
+				}
87
+			}
87 88
 			}
88
-		    }
89
-		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
89
+			$Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
90 90
 		}
91
-	    } else $scheduleexist = true;
91
+		} else $scheduleexist = true;
92 92
 	} else $scheduleexist = true;
93 93
 	// close connection, at least one way will work ?
94
-       if ($scheduleexist) {
94
+	   if ($scheduleexist) {
95 95
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
96
-    		$sch = $Schedule->getSchedule($operator);
96
+			$sch = $Schedule->getSchedule($operator);
97 97
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
98
-       }
98
+	   }
99 99
 	$Spotter->db = null;
100 100
 	$Schedule->db = null;
101 101
 	$Translation->db = null;
@@ -110,92 +110,92 @@  discard block
 block discarded – undo
110 110
 	}
111 111
 	  */
112 112
 	}
113
-    }
113
+	}
114 114
 
115
-    public function checkAll() {
115
+	public function checkAll() {
116 116
 	global $globalDebug;
117 117
 	if ($globalDebug) echo "Update last seen flights data...\n";
118 118
 	foreach ($this->all_flights as $key => $flight) {
119
-	    if (isset($this->all_flights[$key]['id'])) {
119
+		if (isset($this->all_flights[$key]['id'])) {
120 120
 		//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
121
-    		$Spotter = new Spotter($this->db);
122
-        	$real_arrival = $this->arrival($key);
123
-        	$Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
124
-            }
121
+			$Spotter = new Spotter($this->db);
122
+			$real_arrival = $this->arrival($key);
123
+			$Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
124
+			}
125
+	}
125 126
 	}
126
-    }
127 127
 
128
-    public function arrival($key) {
128
+	public function arrival($key) {
129 129
 	global $globalClosestMinDist, $globalDebug;
130 130
 	if ($globalDebug) echo 'Update arrival...'."\n";
131 131
 	$Spotter = new Spotter($this->db);
132
-        $airport_icao = '';
133
-        $airport_time = '';
134
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
132
+		$airport_icao = '';
133
+		$airport_time = '';
134
+		if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
135 135
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
136
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
137
-    	    if (isset($closestAirports[0])) {
138
-        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
139
-        	    $airport_icao = $closestAirports[0]['icao'];
140
-        	    $airport_time = $this->all_flights[$key]['datetime'];
141
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
142
-        	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
143
-        	    foreach ($closestAirports as $airport) {
144
-        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
145
-        		    $airport_icao = $airport['icao'];
146
-        		    $airport_time = $this->all_flights[$key]['datetime'];
147
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
148
-        		    break;
149
-        		}
150
-        	    }
151
-        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
152
-        		$airport_icao = $closestAirports[0]['icao'];
153
-        		$airport_time = $this->all_flights[$key]['datetime'];
154
-        	} else {
155
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
156
-        	}
157
-    	    } else {
158
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
159
-    	    }
160
-
161
-        } else {
162
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
163
-        }
164
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
165
-    }
166
-
167
-
168
-
169
-    public function del() {
136
+		$closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
137
+			if (isset($closestAirports[0])) {
138
+			if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
139
+				$airport_icao = $closestAirports[0]['icao'];
140
+				$airport_time = $this->all_flights[$key]['datetime'];
141
+				if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
142
+			} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
143
+				foreach ($closestAirports as $airport) {
144
+				if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
145
+					$airport_icao = $airport['icao'];
146
+					$airport_time = $this->all_flights[$key]['datetime'];
147
+					if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
148
+					break;
149
+				}
150
+				}
151
+			} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
152
+				$airport_icao = $closestAirports[0]['icao'];
153
+				$airport_time = $this->all_flights[$key]['datetime'];
154
+			} else {
155
+				if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
156
+			}
157
+			} else {
158
+				if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
159
+			}
160
+
161
+		} else {
162
+			if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
163
+		}
164
+		return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
165
+	}
166
+
167
+
168
+
169
+	public function del() {
170 170
 	global $globalDebug;
171 171
 	// Delete old infos
172 172
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
173 173
 	foreach ($this->all_flights as $key => $flight) {
174
-    	    if (isset($flight['lastupdate'])) {
175
-        	if ($flight['lastupdate'] < (time()-3000)) {
176
-            	    if (isset($this->all_flights[$key]['id'])) {
177
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
174
+			if (isset($flight['lastupdate'])) {
175
+			if ($flight['lastupdate'] < (time()-3000)) {
176
+					if (isset($this->all_flights[$key]['id'])) {
177
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
178 178
 			/*
179 179
 			$SpotterLive = new SpotterLive();
180 180
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
181 181
 			$SpotterLive->db = null;
182 182
 			*/
183
-            		$real_arrival = $this->arrival($key);
184
-            		$Spotter = new Spotter($this->db);
185
-            		if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
183
+					$real_arrival = $this->arrival($key);
184
+					$Spotter = new Spotter($this->db);
185
+					if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
186 186
 				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
187 187
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
188 188
 			}
189 189
 			// Put in archive
190 190
 //			$Spotter->db = null;
191
-            	    }
192
-            	    unset($this->all_flights[$key]);
193
-    	        }
194
-	    }
195
-        }
196
-    }
197
-
198
-    public function add($line) {
191
+					}
192
+					unset($this->all_flights[$key]);
193
+				}
194
+		}
195
+		}
196
+	}
197
+
198
+	public function add($line) {
199 199
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights;
200 200
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
201 201
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
@@ -220,18 +220,18 @@  discard block
 block discarded – undo
220 220
 	
221 221
 	// SBS format is CSV format
222 222
 	if(is_array($line) && isset($line['hex'])) {
223
-	    //print_r($line);
224
-  	    if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) {
223
+		//print_r($line);
224
+  		if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) {
225 225
 
226 226
 		// Increment message number
227 227
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
228
-		    $current_date = date('Y-m-d');
229
-		    $source = $line['source_name'];
230
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
231
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
232
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
233
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
234
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
228
+			$current_date = date('Y-m-d');
229
+			$source = $line['source_name'];
230
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
231
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
232
+				$this->stats[$current_date][$source]['msg']['date'] = time();
233
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
234
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
235 235
 		}
236 236
 		
237 237
 		/*
@@ -247,17 +247,17 @@  discard block
 block discarded – undo
247 247
 		//$this->db = $dbc;
248 248
 
249 249
 		$hex = trim($line['hex']);
250
-	        if (!isset($line['id'])) $id = trim($line['hex']);
251
-	        else $id = trim($line['id']);
250
+			if (!isset($line['id'])) $id = trim($line['hex']);
251
+			else $id = trim($line['id']);
252 252
 		
253 253
 		//print_r($this->all_flights);
254 254
 		if (!isset($this->all_flights[$id]['hex']) && ctype_xdigit($hex)) {
255
-		    $this->all_flights[$id] = array('hex' => $hex);
256
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
257
-		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
255
+			$this->all_flights[$id] = array('hex' => $hex);
256
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
257
+			//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
258 258
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
259
-		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
260
-		    if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????')) {
259
+			//} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
260
+			if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????')) {
261 261
 
262 262
 			$timeelapsed = microtime(true);
263 263
 			$Spotter = new Spotter($this->db);
@@ -266,38 +266,38 @@  discard block
 block discarded – undo
266 266
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
267 267
 
268 268
 			if ($aircraft_icao == '' && isset($line['aircraft_type'])) {
269
-			    if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
270
-			    elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
271
-			    elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
272
-			    elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
269
+				if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
270
+				elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
271
+				elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
272
+				elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
273 273
 			}
274 274
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
275
-		    } else if (isset($line['aircraft_name'])) {
275
+			} else if (isset($line['aircraft_name'])) {
276 276
 			// Get aircraft ICAO from aircraft name
277 277
 			$Spotter = new Spotter($this->db);
278 278
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
279 279
 			$Spotter->db = null;
280 280
 			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
281 281
 			else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
282
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
283
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true));
284
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
285
-		    if (!isset($line['id'])) {
282
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
283
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true));
284
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
285
+			if (!isset($line['id'])) {
286 286
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
287 287
 //			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
288 288
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
289 289
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
290
-		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
291
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
290
+				//else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
291
+			 } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
292 292
 
293
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n";
294
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
293
+			if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n";
294
+			if ($globalAllFlights !== FALSE) $dataFound = true;
295 295
 		}
296 296
 		
297 297
 		if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
298
-		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
298
+			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
299 299
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
300
-		    } else {
300
+			} else {
301 301
 				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
302 302
 				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
303 303
 				/*
@@ -306,38 +306,38 @@  discard block
 block discarded – undo
306 306
 				print_r($line);
307 307
 				*/
308 308
 				return '';
309
-		    }
309
+			}
310 310
 		} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
311 311
 
312 312
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
313
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
313
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
314 314
 		}
315 315
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
316
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
316
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
317 317
 		}
318 318
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
319
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
319
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
320 320
 		}
321 321
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
322
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
322
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
323 323
 		}
324 324
  
325 325
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
326
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
327
-		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
326
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
327
+			if ($this->all_flights[$id]['addedSpotter'] == 1) {
328 328
 			$timeelapsed = microtime(true);
329
-            		$Spotter = new Spotter($this->db);
330
-            		$fromsource = NULL;
331
-            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
332
-            		elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
329
+					$Spotter = new Spotter($this->db);
330
+					$fromsource = NULL;
331
+					if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
332
+					elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
333 333
 			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
334 334
 			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
335 335
 			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
336
-            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
336
+					$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
337 337
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
338 338
 			$Spotter->db = null;
339 339
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
340
-		    }
340
+			}
341 341
 
342 342
 /*
343 343
 		    if (!isset($line['id'])) {
@@ -347,26 +347,26 @@  discard block
 block discarded – undo
347 347
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
348 348
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
349 349
   */
350
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
350
+			if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
351 351
 
352
-		    //$putinarchive = true;
353
-		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
352
+			//$putinarchive = true;
353
+			if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
354 354
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
355
-		    }
356
-		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
355
+			}
356
+			if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
357 357
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
358
-		    }
359
-		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
360
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
361
-		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
358
+			}
359
+			if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
360
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
361
+			} elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
362 362
 				$timeelapsed = microtime(true);
363 363
 				$Spotter = new Spotter($this->db);
364 364
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
365 365
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
366
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
366
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
367 367
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
368 368
 
369
-		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
369
+			} elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
370 370
 			$timeelapsed = microtime(true);
371 371
 			$Spotter = new Spotter($this->db);
372 372
 			$route = $Spotter->getRouteInfo(trim($line['ident']));
@@ -380,43 +380,43 @@  discard block
 block discarded – undo
380 380
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
381 381
 
382 382
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
383
-			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
384
-			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
383
+				//if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
384
+				if ($route['fromairport_icao'] != $route['toairport_icao']) {
385 385
 				//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop']));
386
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
387
-		    	    }
386
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
387
+					}
388 388
 			}
389 389
 			if (!isset($globalFork)) $globalFork = TRUE;
390 390
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
391 391
 				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
392 392
 			}
393
-		    }
393
+			}
394 394
 		}
395 395
 
396 396
 		if (isset($line['speed']) && $line['speed'] != '') {
397 397
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
398
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
399
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
400
-		    //$dataFound = true;
398
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
399
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
400
+			//$dataFound = true;
401 401
 		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
402
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
403
-		    if ($distance > 1000 && $distance < 10000) {
404
-		    // use datetime
402
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
403
+			if ($distance > 1000 && $distance < 10000) {
404
+			// use datetime
405 405
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
406 406
 			$speed = $speed*3.6;
407 407
 			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
408 408
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
409
-		    }
409
+			}
410 410
 		}
411 411
 
412 412
 
413 413
 
414
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
415
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
416
-	    	    else unset($timediff);
417
-	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 800 || ($timediff > 10 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
414
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
415
+				if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
416
+				else unset($timediff);
417
+				if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 800 || ($timediff > 10 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
418 418
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
419
-			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
419
+				if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
420 420
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
421 421
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
422 422
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -430,16 +430,16 @@  discard block
 block discarded – undo
430 430
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
431 431
 				$this->tmd = 0;
432 432
 				if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
433
-			    }
433
+				}
434 434
 			}
435 435
 
436 436
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
437
-			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
437
+				//if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
438 438
 				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
439 439
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
440
-				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
441
-				    $dataFound = true;
442
-				    $this->all_flights[$id]['time_last_coord'] = time();
440
+					$this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
441
+					$dataFound = true;
442
+					$this->all_flights[$id]['time_last_coord'] = time();
443 443
 				}
444 444
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
445 445
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
@@ -450,20 +450,20 @@  discard block
 block discarded – undo
450 450
 				    //$putinarchive = true;
451 451
 				}
452 452
 				*/
453
-			    /*
453
+				/*
454 454
 			    } elseif (isset($this->all_flights[$id]['latitude'])) {
455 455
 				if ($globalDebug) echo '!!! Strange latitude value - diff : '.abs($this->all_flights[$id]['latitude']-$line['latitude']).'- previous lat : '.$this->all_flights[$id]['latitude'].'- new lat : '.$line['latitude']."\n";
456 456
 			    }
457 457
 			    */
458 458
 			}
459 459
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
460
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
461
-			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
460
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
461
+				//if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
462 462
 				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
463 463
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
464
-				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
465
-				    $dataFound = true;
466
-				    $this->all_flights[$id]['time_last_coord'] = time();
464
+					$this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
465
+					$dataFound = true;
466
+					$this->all_flights[$id]['time_last_coord'] = time();
467 467
 				}
468 468
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
469 469
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
@@ -481,53 +481,53 @@  discard block
 block discarded – undo
481 481
 			    */
482 482
 			}
483 483
 
484
-		    } else if ($globalDebug && $timediff > 20) {
484
+			} else if ($globalDebug && $timediff > 20) {
485 485
 			$this->tmd = $this->tmd + 1;
486 486
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
487 487
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
488 488
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
489 489
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
490
-		    }
490
+			}
491 491
 		}
492 492
 		if (isset($line['last_update']) && $line['last_update'] != '') {
493
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
494
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
493
+			if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
494
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
495 495
 		}
496 496
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
497
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
498
-		    //$dataFound = true;
497
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
498
+			//$dataFound = true;
499 499
 		}
500 500
 		if (isset($line['format_source']) && $line['format_source'] != '') {
501
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
501
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
502 502
 		}
503 503
 		if (isset($line['source_name']) && $line['source_name'] != '') {
504
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
504
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
505 505
 		}
506 506
 		if (isset($line['emergency']) && $line['emergency'] != '') {
507
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
508
-		    //$dataFound = true;
507
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
508
+			//$dataFound = true;
509 509
 		}
510 510
 		if (isset($line['ground']) && $line['ground'] != '') {
511
-		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
511
+			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
512 512
 			// Here we force archive of flight because after ground it's a new one (or should be)
513 513
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
514 514
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
515 515
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
516
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
516
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
517 517
 			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
518
-		    }
519
-		    if ($line['ground'] != 1) $line['ground'] = 0;
520
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
521
-		    //$dataFound = true;
518
+			}
519
+			if ($line['ground'] != 1) $line['ground'] = 0;
520
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
521
+			//$dataFound = true;
522 522
 		}
523 523
 		if (isset($line['squawk']) && $line['squawk'] != '') {
524
-		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
525
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
526
-			    $highlight = '';
527
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
528
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
529
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
530
-			    if ($highlight != '') {
524
+			if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
525
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
526
+				$highlight = '';
527
+				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
528
+				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
529
+				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
530
+				if ($highlight != '') {
531 531
 				$timeelapsed = microtime(true);
532 532
 				$Spotter = new Spotter($this->db);
533 533
 				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
@@ -537,38 +537,38 @@  discard block
 block discarded – undo
537 537
 				$this->all_flights[$id]['putinarchive'] = true;
538 538
 				//$putinarchive = true;
539 539
 				//$highlight = '';
540
-			    }
540
+				}
541 541
 			    
542
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
543
-		    //$dataFound = true;
542
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
543
+			//$dataFound = true;
544 544
 		}
545 545
 
546 546
 		if (isset($line['altitude']) && $line['altitude'] != '') {
547
-		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
547
+			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
548 548
 			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 2) $this->all_flights[$id]['putinarchive'] = true;
549 549
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
550 550
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
551 551
 			//$dataFound = true;
552
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
552
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
553 553
   		}
554 554
 
555 555
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
556
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
556
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
557 557
 		}
558 558
 		
559 559
 		if (isset($line['heading']) && $line['heading'] != '') {
560
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true;
561
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
562
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
563
-		    //$dataFound = true;
560
+			if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true;
561
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
562
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
563
+			//$dataFound = true;
564 564
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
565
-  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
566
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
567
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true;
568
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
565
+  			$heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
566
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
567
+			if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true;
568
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
569 569
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
570
-  		    // If not enough messages and ACARS set heading to 0
571
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
570
+  			// If not enough messages and ACARS set heading to 0
571
+  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
572 572
   		}
573 573
 		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
574 574
 		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
@@ -579,119 +579,119 @@  discard block
 block discarded – undo
579 579
 		//if ($dataFound == true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
580 580
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
581 581
 		if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
582
-		    $this->all_flights[$id]['lastupdate'] = time();
583
-		    if ($this->all_flights[$id]['addedSpotter'] == 0) {
584
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
585
-			    //print_r($this->all_flights);
586
-			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
587
-			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
588
-			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
582
+			$this->all_flights[$id]['lastupdate'] = time();
583
+			if ($this->all_flights[$id]['addedSpotter'] == 0) {
584
+				if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
585
+				//print_r($this->all_flights);
586
+				//echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
587
+				//$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
588
+				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
589 589
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
590 590
 				$timeelapsed = microtime(true);
591 591
 				$SpotterLive = new SpotterLive($this->db);
592 592
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
593
-				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
594
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
593
+					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
594
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
595 595
 				} elseif (isset($line['id'])) {
596
-				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
597
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
596
+					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
597
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
598 598
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
599
-				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
600
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
599
+					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
600
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
601 601
 				} else $recent_ident = '';
602 602
 				$SpotterLive->db=null;
603 603
 
604 604
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
605 605
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
606
-			    } else {
606
+				} else {
607 607
 				$recent_ident = '';
608 608
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
609
-			    }
610
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
611
-			    if($recent_ident == "")
612
-			    {
609
+				}
610
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
611
+				if($recent_ident == "")
612
+				{
613 613
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
614 614
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
615 615
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
616 616
 				//adds the spotter data for the archive
617 617
 				$ignoreImport = false;
618 618
 				foreach($globalAirportIgnore as $airportIgnore) {
619
-				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
619
+					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
620 620
 					$ignoreImport = true;
621
-				    }
621
+					}
622 622
 				}
623 623
 				if (count($globalAirportAccept) > 0) {
624
-				    $ignoreImport = true;
625
-				    foreach($globalAirportIgnore as $airportIgnore) {
624
+					$ignoreImport = true;
625
+					foreach($globalAirportIgnore as $airportIgnore) {
626 626
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
627
-					    $ignoreImport = false;
627
+						$ignoreImport = false;
628
+					}
628 629
 					}
629
-				    }
630 630
 				}
631 631
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
632
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
632
+					foreach($globalAirlineIgnore as $airlineIgnore) {
633 633
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
634
-					    $ignoreImport = true;
634
+						$ignoreImport = true;
635
+					}
635 636
 					}
636
-				    }
637 637
 				}
638 638
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
639
-				    $ignoreImport = true;
640
-				    foreach($globalAirlineAccept as $airlineAccept) {
639
+					$ignoreImport = true;
640
+					foreach($globalAirlineAccept as $airlineAccept) {
641 641
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
642
-					    $ignoreImport = false;
642
+						$ignoreImport = false;
643
+					}
643 644
 					}
644
-				    }
645 645
 				}
646 646
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
647
-				    $ignoreImport = true;
648
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
647
+					$ignoreImport = true;
648
+					foreach($globalPilotIdAccept as $pilotIdAccept) {
649 649
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
650
-					    $ignoreImport = false;
650
+						$ignoreImport = false;
651
+					}
651 652
 					}
652
-				    }
653 653
 				}
654 654
 				
655 655
 				if (!$ignoreImport) {
656
-				    $highlight = '';
657
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
658
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
659
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
660
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
661
-				    $timeelapsed = microtime(true);
662
-				    $Spotter = new Spotter($this->db);
663
-				    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name']);
664
-				    $Spotter->db = null;
665
-				    if ($globalDebug && isset($result)) echo $result."\n";
666
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
656
+					$highlight = '';
657
+					if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
658
+					if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
659
+					if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
660
+					if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
661
+					$timeelapsed = microtime(true);
662
+					$Spotter = new Spotter($this->db);
663
+					$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name']);
664
+					$Spotter->db = null;
665
+					if ($globalDebug && isset($result)) echo $result."\n";
666
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
667 667
 				    
668
-				    // Add source stat in DB
669
-				    $Stats = new Stats($this->db);
670
-				    if (!empty($this->stats)) {
668
+					// Add source stat in DB
669
+					$Stats = new Stats($this->db);
670
+					if (!empty($this->stats)) {
671 671
 					if ($globalDebug) echo 'Add source stats : ';
672
-				        foreach($this->stats as $date => $data) {
673
-					    foreach($data as $source => $sourced) {
674
-					        //print_r($sourced);
675
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
676
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
677
-				    		if (isset($sourced['msg'])) {
678
-				    		    if (time() - $sourced['msg']['date'] > 10) {
679
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
680
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
681
-			    			        unset($this->stats[$date][$source]['msg']);
682
-			    			    }
683
-			    			}
684
-			    		    }
685
-			    		    if ($date != date('Y-m-d')) {
686
-			    			unset($this->stats[$date]);
687
-			    		    }
688
-				    	}
689
-				    	if ($globalDebug) echo 'Done'."\n";
690
-
691
-				    }
692
-				    $Stats->db = null;
672
+						foreach($this->stats as $date => $data) {
673
+						foreach($data as $source => $sourced) {
674
+							//print_r($sourced);
675
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
676
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
677
+							if (isset($sourced['msg'])) {
678
+								if (time() - $sourced['msg']['date'] > 10) {
679
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
680
+									echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
681
+									unset($this->stats[$date][$source]['msg']);
682
+								}
683
+							}
684
+							}
685
+							if ($date != date('Y-m-d')) {
686
+							unset($this->stats[$date]);
687
+							}
688
+						}
689
+						if ($globalDebug) echo 'Done'."\n";
690
+
691
+					}
692
+					$Stats->db = null;
693 693
 				    
694
-				    $this->del();
694
+					$this->del();
695 695
 				} elseif ($globalDebug) echo 'Ignore data'."\n";
696 696
 				//$ignoreImport = false;
697 697
 				$this->all_flights[$id]['addedSpotter'] = 1;
@@ -709,18 +709,18 @@  discard block
 block discarded – undo
709 709
 			*/
710 710
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
711 711
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
712
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
713
-				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
714
-				    $SpotterLive = new SpotterLive($this->db);
715
-				    $SpotterLive->deleteLiveSpotterData();
716
-				    $SpotterLive->db=null;
717
-				    if ($globalDebug) echo " Done\n";
718
-				    $this->last_delete = time();
712
+					if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
713
+					//SpotterLive->deleteLiveSpotterDataNotUpdated();
714
+					$SpotterLive = new SpotterLive($this->db);
715
+					$SpotterLive->deleteLiveSpotterData();
716
+					$SpotterLive->db=null;
717
+					if ($globalDebug) echo " Done\n";
718
+					$this->last_delete = time();
719 719
 				}
720
-			    } else {
720
+				} else {
721 721
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) {
722
-				    $this->all_flights[$id]['id'] = $recent_ident;
723
-				    $this->all_flights[$id]['addedSpotter'] = 1;
722
+					$this->all_flights[$id]['id'] = $recent_ident;
723
+					$this->all_flights[$id]['addedSpotter'] = 1;
724 724
 				}
725 725
 				if (isset($globalDaemon) && !$globalDaemon) {
726 726
 					$Spotter = new Spotter($this->db);
@@ -728,14 +728,14 @@  discard block
 block discarded – undo
728 728
 					$Spotter->db = null;
729 729
 				}
730 730
 				
731
-			    }
731
+				}
732
+			}
732 733
 			}
733
-		    }
734
-		    //adds the spotter LIVE data
735
-		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
736
-		    //echo "\nAdd in Live !! \n";
737
-		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
738
-		    if ($globalDebug) {
734
+			//adds the spotter LIVE data
735
+			//SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
736
+			//echo "\nAdd in Live !! \n";
737
+			//echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
738
+			if ($globalDebug) {
739 739
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
740 740
 				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
741 741
 				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
@@ -743,49 +743,49 @@  discard block
 block discarded – undo
743 743
 				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
744 744
 				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
745 745
 			}
746
-		    }
747
-		    $ignoreImport = false;
748
-		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
749
-		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
746
+			}
747
+			$ignoreImport = false;
748
+			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
749
+			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
750 750
 
751
-		    foreach($globalAirportIgnore as $airportIgnore) {
752
-		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
753
-			    $ignoreImport = true;
751
+			foreach($globalAirportIgnore as $airportIgnore) {
752
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
753
+				$ignoreImport = true;
754
+			}
754 755
 			}
755
-		    }
756
-		    if (count($globalAirportAccept) > 0) {
757
-		        $ignoreImport = true;
758
-		        foreach($globalAirportIgnore as $airportIgnore) {
759
-			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
756
+			if (count($globalAirportAccept) > 0) {
757
+				$ignoreImport = true;
758
+				foreach($globalAirportIgnore as $airportIgnore) {
759
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
760 760
 				$ignoreImport = false;
761
-			    }
761
+				}
762 762
 			}
763
-		    }
764
-		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
763
+			}
764
+			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
765 765
 			foreach($globalAirlineIgnore as $airlineIgnore) {
766
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
766
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
767 767
 				$ignoreImport = true;
768
-			    }
768
+				}
769 769
 			}
770
-		    }
771
-		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
770
+			}
771
+			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
772 772
 			$ignoreImport = true;
773 773
 			foreach($globalAirlineAccept as $airlineAccept) {
774
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
774
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
775 775
 				$ignoreImport = false;
776
-			    }
776
+				}
777 777
 			}
778
-		    }
779
-		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
778
+			}
779
+			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
780 780
 			$ignoreImport = true;
781 781
 			foreach($globalPilotIdAccept as $pilotIdAccept) {
782
-			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
783
-			        $ignoreImport = false;
784
-			    }
782
+				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
783
+					$ignoreImport = false;
784
+				}
785
+			}
785 786
 			}
786
-		    }
787 787
 
788
-		    if (!$ignoreImport) {
788
+			if (!$ignoreImport) {
789 789
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
790 790
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
791 791
 				$timeelapsed = microtime(true);
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
 					if ($stats_heading == 16) $stats_heading = 0;
824 824
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
825 825
 						for ($i=0;$i<=15;$i++) {
826
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
826
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
827 827
 						}
828 828
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
829 829
 					} else {
@@ -836,11 +836,11 @@  discard block
 block discarded – undo
836 836
 					//var_dump($this->stats);
837 837
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
838 838
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
839
-						    end($this->stats[$current_date][$source]['hist']);
840
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
839
+							end($this->stats[$current_date][$source]['hist']);
840
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
841 841
 						} else $mini = 0;
842 842
 						for ($i=$mini;$i<=$distance;$i+=10) {
843
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
843
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
844 844
 						}
845 845
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
846 846
 					} else {
@@ -857,22 +857,22 @@  discard block
 block discarded – undo
857 857
 			
858 858
 			
859 859
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
860
-			    if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
861
-			    $SpotterLive = new SpotterLive($this->db);
862
-			    $SpotterLive->deleteLiveSpotterDataNotUpdated();
863
-			    $SpotterLive->db = null;
864
-			    //SpotterLive->deleteLiveSpotterData();
865
-			    if ($globalDebug) echo " Done\n";
866
-			    $this->last_delete_hourly = time();
860
+				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
861
+				$SpotterLive = new SpotterLive($this->db);
862
+				$SpotterLive->deleteLiveSpotterDataNotUpdated();
863
+				$SpotterLive->db = null;
864
+				//SpotterLive->deleteLiveSpotterData();
865
+				if ($globalDebug) echo " Done\n";
866
+				$this->last_delete_hourly = time();
867 867
 			}
868 868
 			
869
-		    }
870
-		    //$ignoreImport = false;
869
+			}
870
+			//$ignoreImport = false;
871 871
 		}
872 872
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
873 873
 		if ($send) return $this->all_flights[$id];
874
-	    }
874
+		}
875
+	}
875 876
 	}
876
-    }
877 877
 }
878 878
 ?>
Please login to merge, or discard this patch.
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -40,6 +40,10 @@
 block discarded – undo
40 40
 	}
41 41
     }
42 42
 
43
+    /**
44
+     * @param string $id
45
+     * @param string $ident
46
+     */
43 47
     public function get_Schedule($id,$ident) {
44 48
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
45 49
 	// Get schedule here, so it's done only one time
Please login to merge, or discard this patch.
Braces   +327 added lines, -116 removed lines patch added patch discarded remove patch
@@ -53,7 +53,9 @@  discard block
 block discarded – undo
53 53
 	$dbc = $this->db;
54 54
 	$this->all_flights[$id]['schedule_check'] = true;
55 55
 	if ($globalSchedulesFetch) {
56
-	if ($globalDebug) echo 'Getting schedule info...'."\n";
56
+	if ($globalDebug) {
57
+		echo 'Getting schedule info...'."\n";
58
+	}
57 59
 	$Spotter = new Spotter($dbc);
58 60
 	$Schedule = new Schedule($dbc);
59 61
 	$Translation = new Translation($dbc);
@@ -64,7 +66,9 @@  discard block
 block discarded – undo
64 66
 	    if ($Schedule->checkSchedule($operator) == 0) {
65 67
 		$schedule = $Schedule->fetchSchedule($operator);
66 68
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
67
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
69
+		    if ($globalDebug) {
70
+		    	echo "-> Schedule info for ".$operator." (".$ident.")\n";
71
+		    }
68 72
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
69 73
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
70 74
 		    // Should also check if route schedule = route from DB
@@ -73,7 +77,9 @@  discard block
 block discarded – undo
73 77
 			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
74 78
 			    if (trim($airport_icao) != '') {
75 79
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
76
-				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
80
+				if ($globalDebug) {
81
+					echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
82
+				}
77 83
 			    }
78 84
 			}
79 85
 		    }
@@ -82,17 +88,25 @@  discard block
 block discarded – undo
82 88
 			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
83 89
 			    if (trim($airport_icao) != '') {
84 90
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
85
-				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
91
+				if ($globalDebug) {
92
+					echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
93
+				}
86 94
 			    }
87 95
 			}
88 96
 		    }
89 97
 		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
90 98
 		}
91
-	    } else $scheduleexist = true;
92
-	} else $scheduleexist = true;
99
+	    } else {
100
+	    	$scheduleexist = true;
101
+	    }
102
+	} else {
103
+		$scheduleexist = true;
104
+	}
93 105
 	// close connection, at least one way will work ?
94 106
        if ($scheduleexist) {
95
-		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
107
+		if ($globalDebug) {
108
+			echo "-> get arrival/departure airport info for ".$ident."\n";
109
+		}
96 110
     		$sch = $Schedule->getSchedule($operator);
97 111
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
98 112
        }
@@ -114,7 +128,9 @@  discard block
 block discarded – undo
114 128
 
115 129
     public function checkAll() {
116 130
 	global $globalDebug;
117
-	if ($globalDebug) echo "Update last seen flights data...\n";
131
+	if ($globalDebug) {
132
+		echo "Update last seen flights data...\n";
133
+	}
118 134
 	foreach ($this->all_flights as $key => $flight) {
119 135
 	    if (isset($this->all_flights[$key]['id'])) {
120 136
 		//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
@@ -127,24 +143,32 @@  discard block
 block discarded – undo
127 143
 
128 144
     public function arrival($key) {
129 145
 	global $globalClosestMinDist, $globalDebug;
130
-	if ($globalDebug) echo 'Update arrival...'."\n";
146
+	if ($globalDebug) {
147
+		echo 'Update arrival...'."\n";
148
+	}
131 149
 	$Spotter = new Spotter($this->db);
132 150
         $airport_icao = '';
133 151
         $airport_time = '';
134
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
152
+        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') {
153
+        	$globalClosestMinDist = 50;
154
+        }
135 155
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
136 156
 	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
137 157
     	    if (isset($closestAirports[0])) {
138 158
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
139 159
         	    $airport_icao = $closestAirports[0]['icao'];
140 160
         	    $airport_time = $this->all_flights[$key]['datetime'];
141
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
161
+        	    if ($globalDebug) {
162
+        	    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
163
+        	    }
142 164
         	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
143 165
         	    foreach ($closestAirports as $airport) {
144 166
         		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
145 167
         		    $airport_icao = $airport['icao'];
146 168
         		    $airport_time = $this->all_flights[$key]['datetime'];
147
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
169
+        		    if ($globalDebug) {
170
+        		    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
171
+        		    }
148 172
         		    break;
149 173
         		}
150 174
         	    }
@@ -152,14 +176,20 @@  discard block
 block discarded – undo
152 176
         		$airport_icao = $closestAirports[0]['icao'];
153 177
         		$airport_time = $this->all_flights[$key]['datetime'];
154 178
         	} else {
155
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
179
+        		if ($globalDebug) {
180
+        			echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
181
+        		}
156 182
         	}
157 183
     	    } else {
158
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
184
+    		    if ($globalDebug) {
185
+    		    	echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
186
+    		    }
159 187
     	    }
160 188
 
161 189
         } else {
162
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
190
+        	if ($globalDebug) {
191
+        		echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
192
+        	}
163 193
         }
164 194
         return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
165 195
     }
@@ -169,12 +199,16 @@  discard block
 block discarded – undo
169 199
     public function del() {
170 200
 	global $globalDebug;
171 201
 	// Delete old infos
172
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
202
+	if ($globalDebug) {
203
+		echo 'Delete old values and update latest data...'."\n";
204
+	}
173 205
 	foreach ($this->all_flights as $key => $flight) {
174 206
     	    if (isset($flight['lastupdate'])) {
175 207
         	if ($flight['lastupdate'] < (time()-3000)) {
176 208
             	    if (isset($this->all_flights[$key]['id'])) {
177
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
209
+            		if ($globalDebug) {
210
+            			echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
211
+            		}
178 212
 			/*
179 213
 			$SpotterLive = new SpotterLive();
180 214
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
@@ -184,7 +218,9 @@  discard block
 block discarded – undo
184 218
             		$Spotter = new Spotter($this->db);
185 219
             		if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
186 220
 				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
187
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
221
+				if ($globalDebug && $result != 'success') {
222
+					echo '!!! ERROR : '.$result."\n";
223
+				}
188 224
 			}
189 225
 			// Put in archive
190 226
 //			$Spotter->db = null;
@@ -198,8 +234,10 @@  discard block
 block discarded – undo
198 234
     public function add($line) {
199 235
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights;
200 236
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
201
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
202
-/*
237
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
238
+		$globalCoordMinChange = '0.02';
239
+	}
240
+	/*
203 241
 	$Spotter = new Spotter();
204 242
 	$dbc = $Spotter->db;
205 243
 	$SpotterLive = new SpotterLive($dbc);
@@ -227,11 +265,15 @@  discard block
 block discarded – undo
227 265
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
228 266
 		    $current_date = date('Y-m-d');
229 267
 		    $source = $line['source_name'];
230
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
268
+		    if ($source == '' || $line['format_source'] == 'aprs') {
269
+		    	$source = $line['format_source'];
270
+		    }
231 271
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
232 272
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
233 273
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
234
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
274
+		    } else {
275
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
276
+		    }
235 277
 		}
236 278
 		
237 279
 		/*
@@ -247,8 +289,11 @@  discard block
 block discarded – undo
247 289
 		//$this->db = $dbc;
248 290
 
249 291
 		$hex = trim($line['hex']);
250
-	        if (!isset($line['id'])) $id = trim($line['hex']);
251
-	        else $id = trim($line['id']);
292
+	        if (!isset($line['id'])) {
293
+	        	$id = trim($line['hex']);
294
+	        } else {
295
+	        	$id = trim($line['id']);
296
+	        }
252 297
 		
253 298
 		//print_r($this->all_flights);
254 299
 		if (!isset($this->all_flights[$id]['hex']) && ctype_xdigit($hex)) {
@@ -263,13 +308,20 @@  discard block
 block discarded – undo
263 308
 			$Spotter = new Spotter($this->db);
264 309
 			$aircraft_icao = $Spotter->getAllAircraftType($hex);
265 310
 			$Spotter->db = null;
266
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
311
+			if ($globalDebugTimeElapsed) {
312
+				echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
313
+			}
267 314
 
268 315
 			if ($aircraft_icao == '' && isset($line['aircraft_type'])) {
269
-			    if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
270
-			    elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
271
-			    elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
272
-			    elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
316
+			    if ($line['aircraft_type'] == 'PARA_GLIDER') {
317
+			    	$aircraft_icao = 'GLID';
318
+			    } elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') {
319
+			    	$aircraft_icao = 'UHEL';
320
+			    } elseif ($line['aircraft_type'] == 'TOW_PLANE') {
321
+			    	$aircraft_icao = 'TOWPLANE';
322
+			    } elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') {
323
+			    	$aircraft_icao = 'POWAIRC';
324
+			    }
273 325
 			}
274 326
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
275 327
 		    } else if (isset($line['aircraft_name'])) {
@@ -277,29 +329,47 @@  discard block
 block discarded – undo
277 329
 			$Spotter = new Spotter($this->db);
278 330
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
279 331
 			$Spotter->db = null;
280
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
281
-			else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
282
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
332
+			if ($aircraft_icao != '') {
333
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
334
+			} else {
335
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
336
+			}
337
+		    } else {
338
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
339
+		    }
283 340
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true));
284 341
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
285 342
 		    if (!isset($line['id'])) {
286
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
287
-//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
343
+			if (!isset($globalDaemon)) {
344
+				$globalDaemon = TRUE;
345
+			}
346
+			//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
288 347
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
289
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
348
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
349
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
350
+			}
290 351
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
291
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
352
+		     } else {
353
+		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
354
+		     }
292 355
 
293
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n";
294
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
356
+		    if ($globalDebug) {
357
+		    	echo "*********** New aircraft hex : ".$hex." ***********\n";
358
+		    }
359
+		    if ($globalAllFlights !== FALSE) {
360
+		    	$dataFound = true;
361
+		    }
295 362
 		}
296 363
 		
297 364
 		if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
298 365
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
299 366
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
300 367
 		    } else {
301
-				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
302
-				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
368
+				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
369
+					echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
370
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
371
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
372
+				}
303 373
 				/*
304 374
 				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
305 375
 				print_r($this->all_flights[$id]);
@@ -307,7 +377,9 @@  discard block
 block discarded – undo
307 377
 				*/
308 378
 				return '';
309 379
 		    }
310
-		} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
380
+		} else {
381
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
382
+		}
311 383
 
312 384
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
313 385
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
@@ -328,15 +400,25 @@  discard block
 block discarded – undo
328 400
 			$timeelapsed = microtime(true);
329 401
             		$Spotter = new Spotter($this->db);
330 402
             		$fromsource = NULL;
331
-            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
332
-            		elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
333
-			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
334
-			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
335
-			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
403
+            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') {
404
+            			$fromsource = $globalAirlinesSource;
405
+            		} elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') {
406
+            			$fromsource = 'vatsim';
407
+            		} elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') {
408
+				$fromsource = 'ivao';
409
+			} elseif (isset($globalVATSIM) && $globalVATSIM) {
410
+				$fromsource = 'vatsim';
411
+			} elseif (isset($globalIVAO) && $globalIVAO) {
412
+				$fromsource = 'ivao';
413
+			}
336 414
             		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
337
-			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
415
+			if ($globalDebug && $result != 'success') {
416
+				echo '!!! ERROR : '.$result."\n";
417
+			}
338 418
 			$Spotter->db = null;
339
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
419
+			if ($globalDebugTimeElapsed) {
420
+				echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
421
+			}
340 422
 		    }
341 423
 
342 424
 /*
@@ -347,7 +429,9 @@  discard block
 block discarded – undo
347 429
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
348 430
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
349 431
   */
350
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
432
+		    if (!isset($this->all_flights[$id]['id'])) {
433
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
434
+		    }
351 435
 
352 436
 		    //$putinarchive = true;
353 437
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
@@ -364,7 +448,9 @@  discard block
 block discarded – undo
364 448
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
365 449
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
366 450
 		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
367
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
451
+				if ($globalDebugTimeElapsed) {
452
+					echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
453
+				}
368 454
 
369 455
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
370 456
 			$timeelapsed = microtime(true);
@@ -377,7 +463,9 @@  discard block
 block discarded – undo
377 463
 				$Translation->db = null;
378 464
 			}
379 465
 			$Spotter->db = null;
380
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
466
+			if ($globalDebugTimeElapsed) {
467
+				echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
468
+			}
381 469
 
382 470
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
383 471
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
@@ -386,9 +474,13 @@  discard block
 block discarded – undo
386 474
 		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
387 475
 		    	    }
388 476
 			}
389
-			if (!isset($globalFork)) $globalFork = TRUE;
477
+			if (!isset($globalFork)) {
478
+				$globalFork = TRUE;
479
+			}
390 480
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
391
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
481
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) {
482
+					$this->get_Schedule($id,trim($line['ident']));
483
+				}
392 484
 			}
393 485
 		    }
394 486
 		}
@@ -404,16 +496,23 @@  discard block
 block discarded – undo
404 496
 		    // use datetime
405 497
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
406 498
 			$speed = $speed*3.6;
407
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
408
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
499
+			if ($speed < 1000) {
500
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
501
+			}
502
+  			if ($globalDebug) {
503
+  				echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
504
+  			}
409 505
 		    }
410 506
 		}
411 507
 
412 508
 
413 509
 
414 510
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
415
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
416
-	    	    else unset($timediff);
511
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) {
512
+	    	    	$timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
513
+	    	    } else {
514
+	    	    	unset($timediff);
515
+	    	    }
417 516
 	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 800 || ($timediff > 10 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
418 517
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
419 518
 			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
@@ -421,21 +520,31 @@  discard block
 block discarded – undo
421 520
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
422 521
 				$this->all_flights[$id]['putinarchive'] = true;
423 522
 				
424
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
523
+				if ($globalDebug) {
524
+					echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
525
+				}
425 526
 				$timeelapsed = microtime(true);
426 527
 				$Spotter = new Spotter($this->db);
427 528
 				$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
428
-				if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
529
+				if (!empty($all_country)) {
530
+					$this->all_flights[$id]['over_country'] = $all_country['iso2'];
531
+				}
429 532
 				$Spotter->db = null;
430
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
533
+				if ($globalDebugTimeElapsed) {
534
+					echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
535
+				}
431 536
 				$this->tmd = 0;
432
-				if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
537
+				if ($globalDebug) {
538
+					echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
539
+				}
433 540
 			    }
434 541
 			}
435 542
 
436 543
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
437 544
 			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
438
-				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
545
+				if (!isset($this->all_flights[$id]['archive_latitude'])) {
546
+					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
547
+				}
439 548
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
440 549
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
441 550
 				    $dataFound = true;
@@ -457,9 +566,13 @@  discard block
 block discarded – undo
457 566
 			    */
458 567
 			}
459 568
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
460
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
569
+			    if ($line['longitude'] > 180) {
570
+			    	$line['longitude'] = $line['longitude'] - 360;
571
+			    }
461 572
 			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
462
-				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
573
+				if (!isset($this->all_flights[$id]['archive_longitude'])) {
574
+					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
575
+				}
463 576
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
464 577
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
465 578
 				    $dataFound = true;
@@ -490,7 +603,9 @@  discard block
 block discarded – undo
490 603
 		    }
491 604
 		}
492 605
 		if (isset($line['last_update']) && $line['last_update'] != '') {
493
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
606
+		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) {
607
+		    	$dataFound = true;
608
+		    }
494 609
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
495 610
 		}
496 611
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
@@ -512,11 +627,17 @@  discard block
 block discarded – undo
512 627
 			// Here we force archive of flight because after ground it's a new one (or should be)
513 628
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
514 629
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
515
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
516
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
517
-			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
630
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) {
631
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
632
+			} elseif (isset($line['id'])) {
633
+		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
634
+		        } elseif (isset($this->all_flights[$id]['ident'])) {
635
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
636
+			}
637
+		    }
638
+		    if ($line['ground'] != 1) {
639
+		    	$line['ground'] = 0;
518 640
 		    }
519
-		    if ($line['ground'] != 1) $line['ground'] = 0;
520 641
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
521 642
 		    //$dataFound = true;
522 643
 		}
@@ -524,28 +645,40 @@  discard block
 block discarded – undo
524 645
 		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
525 646
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
526 647
 			    $highlight = '';
527
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
528
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
529
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
648
+			    if ($this->all_flights[$id]['squawk'] == '7500') {
649
+			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
650
+			    }
651
+			    if ($this->all_flights[$id]['squawk'] == '7600') {
652
+			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
653
+			    }
654
+			    if ($this->all_flights[$id]['squawk'] == '7700') {
655
+			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
656
+			    }
530 657
 			    if ($highlight != '') {
531 658
 				$timeelapsed = microtime(true);
532 659
 				$Spotter = new Spotter($this->db);
533 660
 				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
534 661
 				$Spotter->db = null;
535
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
662
+				if ($globalDebugTimeElapsed) {
663
+					echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
664
+				}
536 665
 
537 666
 				$this->all_flights[$id]['putinarchive'] = true;
538 667
 				//$putinarchive = true;
539 668
 				//$highlight = '';
540 669
 			    }
541 670
 			    
542
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
671
+		    } else {
672
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
673
+		    }
543 674
 		    //$dataFound = true;
544 675
 		}
545 676
 
546 677
 		if (isset($line['altitude']) && $line['altitude'] != '') {
547 678
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
548
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 2) $this->all_flights[$id]['putinarchive'] = true;
679
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 2) {
680
+				$this->all_flights[$id]['putinarchive'] = true;
681
+			}
549 682
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
550 683
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
551 684
 			//$dataFound = true;
@@ -557,21 +690,30 @@  discard block
 block discarded – undo
557 690
 		}
558 691
 		
559 692
 		if (isset($line['heading']) && $line['heading'] != '') {
560
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true;
693
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) {
694
+		    	$this->all_flights[$id]['putinarchive'] = true;
695
+		    }
561 696
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
562 697
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
563 698
 		    //$dataFound = true;
564 699
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
565 700
   		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
566 701
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
567
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true;
568
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
702
+		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) {
703
+		    	$this->all_flights[$id]['putinarchive'] = true;
704
+		    }
705
+  		    if ($globalDebug) {
706
+  		    	echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
707
+  		    }
569 708
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
570 709
   		    // If not enough messages and ACARS set heading to 0
571 710
   		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
572 711
   		}
573
-		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
574
-		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
712
+		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) {
713
+			$dataFound = false;
714
+		} elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) {
715
+			$dataFound = false;
716
+		}
575 717
 
576 718
 //		print_r($this->all_flights[$id]);
577 719
 		//gets the callsign from the last hour
@@ -586,23 +728,36 @@  discard block
 block discarded – undo
586 728
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
587 729
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
588 730
 			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
589
-				if ($globalDebug) echo "Check if aircraft is already in DB...";
731
+				if ($globalDebug) {
732
+					echo "Check if aircraft is already in DB...";
733
+				}
590 734
 				$timeelapsed = microtime(true);
591 735
 				$SpotterLive = new SpotterLive($this->db);
592 736
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
593 737
 				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
594
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
738
+				    if ($globalDebugTimeElapsed) {
739
+				    	echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
740
+				    }
595 741
 				} elseif (isset($line['id'])) {
596 742
 				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
597
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
743
+				    if ($globalDebugTimeElapsed) {
744
+				    	echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
745
+				    }
598 746
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
599 747
 				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
600
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
601
-				} else $recent_ident = '';
748
+				    if ($globalDebugTimeElapsed) {
749
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
750
+				    }
751
+				} else {
752
+					$recent_ident = '';
753
+				}
602 754
 				$SpotterLive->db=null;
603 755
 
604
-				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
605
-				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
756
+				if ($globalDebug && $recent_ident == '') {
757
+					echo " Not in DB.\n";
758
+				} elseif ($globalDebug && $recent_ident != '') {
759
+					echo " Already in DB.\n";
760
+				}
606 761
 			    } else {
607 762
 				$recent_ident = '';
608 763
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
@@ -610,7 +765,9 @@  discard block
 block discarded – undo
610 765
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
611 766
 			    if($recent_ident == "")
612 767
 			    {
613
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
768
+				if ($globalDebug) {
769
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
770
+				}
614 771
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
615 772
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
616 773
 				//adds the spotter data for the archive
@@ -654,26 +811,44 @@  discard block
 block discarded – undo
654 811
 				
655 812
 				if (!$ignoreImport) {
656 813
 				    $highlight = '';
657
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
658
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
659
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
660
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
814
+				    if ($this->all_flights[$id]['squawk'] == '7500') {
815
+				    	$highlight = 'Squawk 7500 : Hijack';
816
+				    }
817
+				    if ($this->all_flights[$id]['squawk'] == '7600') {
818
+				    	$highlight = 'Squawk 7600 : Lost Comm (radio failure)';
819
+				    }
820
+				    if ($this->all_flights[$id]['squawk'] == '7700') {
821
+				    	$highlight = 'Squawk 7700 : Emergency';
822
+				    }
823
+				    if (!isset($this->all_flights[$id]['id'])) {
824
+				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
825
+				    }
661 826
 				    $timeelapsed = microtime(true);
662 827
 				    $Spotter = new Spotter($this->db);
663 828
 				    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name']);
664 829
 				    $Spotter->db = null;
665
-				    if ($globalDebug && isset($result)) echo $result."\n";
666
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
830
+				    if ($globalDebug && isset($result)) {
831
+				    	echo $result."\n";
832
+				    }
833
+				    if ($globalDebugTimeElapsed) {
834
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
835
+				    }
667 836
 				    
668 837
 				    // Add source stat in DB
669 838
 				    $Stats = new Stats($this->db);
670 839
 				    if (!empty($this->stats)) {
671
-					if ($globalDebug) echo 'Add source stats : ';
840
+					if ($globalDebug) {
841
+						echo 'Add source stats : ';
842
+					}
672 843
 				        foreach($this->stats as $date => $data) {
673 844
 					    foreach($data as $source => $sourced) {
674 845
 					        //print_r($sourced);
675
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
676
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
846
+				    	        if (isset($sourced['polar'])) {
847
+				    	        	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
848
+				    	        }
849
+				    	        if (isset($sourced['hist'])) {
850
+				    	        	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
851
+				    	        }
677 852
 				    		if (isset($sourced['msg'])) {
678 853
 				    		    if (time() - $sourced['msg']['date'] > 10) {
679 854
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -686,13 +861,17 @@  discard block
 block discarded – undo
686 861
 			    			unset($this->stats[$date]);
687 862
 			    		    }
688 863
 				    	}
689
-				    	if ($globalDebug) echo 'Done'."\n";
864
+				    	if ($globalDebug) {
865
+				    		echo 'Done'."\n";
866
+				    	}
690 867
 
691 868
 				    }
692 869
 				    $Stats->db = null;
693 870
 				    
694 871
 				    $this->del();
695
-				} elseif ($globalDebug) echo 'Ignore data'."\n";
872
+				} elseif ($globalDebug) {
873
+					echo 'Ignore data'."\n";
874
+				}
696 875
 				//$ignoreImport = false;
697 876
 				$this->all_flights[$id]['addedSpotter'] = 1;
698 877
 				//print_r($this->all_flights[$id]);
@@ -709,12 +888,16 @@  discard block
 block discarded – undo
709 888
 			*/
710 889
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
711 890
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
712
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
891
+				    if ($globalDebug) {
892
+				    	echo "---- Deleting Live Spotter data older than 9 hours...";
893
+				    }
713 894
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
714 895
 				    $SpotterLive = new SpotterLive($this->db);
715 896
 				    $SpotterLive->deleteLiveSpotterData();
716 897
 				    $SpotterLive->db=null;
717
-				    if ($globalDebug) echo " Done\n";
898
+				    if ($globalDebug) {
899
+				    	echo " Done\n";
900
+				    }
718 901
 				    $this->last_delete = time();
719 902
 				}
720 903
 			    } else {
@@ -737,11 +920,17 @@  discard block
 block discarded – undo
737 920
 		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
738 921
 		    if ($globalDebug) {
739 922
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
740
-				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
741
-				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
923
+				if (isset($this->all_flights[$id]['source_name'])) {
924
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
925
+				} else {
926
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
927
+				}
742 928
 			} else {
743
-				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
744
-				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
929
+				if (isset($this->all_flights[$id]['source_name'])) {
930
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
931
+				} else {
932
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
933
+				}
745 934
 			}
746 935
 		    }
747 936
 		    $ignoreImport = false;
@@ -787,19 +976,25 @@  discard block
 block discarded – undo
787 976
 
788 977
 		    if (!$ignoreImport) {
789 978
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
790
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
979
+				if ($globalDebug) {
980
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
981
+				}
791 982
 				$timeelapsed = microtime(true);
792 983
 				$SpotterLive = new SpotterLive($this->db);
793 984
 				$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
794 985
 				$SpotterLive->db = null;
795
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
986
+				if ($globalDebugTimeElapsed) {
987
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
988
+				}
796 989
 
797 990
 				// Put statistics in $this->stats variable
798 991
 				//if ($line['format_source'] != 'aprs') {
799 992
 				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
800 993
 				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
801 994
 					$source = $this->all_flights[$id]['source_name'];
802
-					if ($source == '') $source = $this->all_flights[$id]['format_source'];
995
+					if ($source == '') {
996
+						$source = $this->all_flights[$id]['format_source'];
997
+					}
803 998
 					if (!isset($this->source_location[$source])) {
804 999
 						$Location = new Source();
805 1000
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -820,7 +1015,9 @@  discard block
 block discarded – undo
820 1015
 					$stats_heading = round($stats_heading/22.5);
821 1016
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
822 1017
 					$current_date = date('Y-m-d');
823
-					if ($stats_heading == 16) $stats_heading = 0;
1018
+					if ($stats_heading == 16) {
1019
+						$stats_heading = 0;
1020
+					}
824 1021
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
825 1022
 						for ($i=0;$i<=15;$i++) {
826 1023
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -838,7 +1035,9 @@  discard block
 block discarded – undo
838 1035
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
839 1036
 						    end($this->stats[$current_date][$source]['hist']);
840 1037
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
841
-						} else $mini = 0;
1038
+						} else {
1039
+							$mini = 0;
1040
+						}
842 1041
 						for ($i=$mini;$i<=$distance;$i+=10) {
843 1042
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
844 1043
 						}
@@ -849,20 +1048,30 @@  discard block
 block discarded – undo
849 1048
 				}
850 1049
 
851 1050
 				$this->all_flights[$id]['lastupdate'] = time();
852
-				if ($this->all_flights[$id]['putinarchive']) $send = true;
1051
+				if ($this->all_flights[$id]['putinarchive']) {
1052
+					$send = true;
1053
+				}
853 1054
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
854
-				if ($globalDebug) echo $result."\n";
855
-			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1055
+				if ($globalDebug) {
1056
+					echo $result."\n";
1057
+				}
1058
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
1059
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1060
+			}
856 1061
 			//$this->del();
857 1062
 			
858 1063
 			
859 1064
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
860
-			    if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1065
+			    if ($globalDebug) {
1066
+			    	echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1067
+			    }
861 1068
 			    $SpotterLive = new SpotterLive($this->db);
862 1069
 			    $SpotterLive->deleteLiveSpotterDataNotUpdated();
863 1070
 			    $SpotterLive->db = null;
864 1071
 			    //SpotterLive->deleteLiveSpotterData();
865
-			    if ($globalDebug) echo " Done\n";
1072
+			    if ($globalDebug) {
1073
+			    	echo " Done\n";
1074
+			    }
866 1075
 			    $this->last_delete_hourly = time();
867 1076
 			}
868 1077
 			
@@ -870,7 +1079,9 @@  discard block
 block discarded – undo
870 1079
 		    //$ignoreImport = false;
871 1080
 		}
872 1081
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
873
-		if ($send) return $this->all_flights[$id];
1082
+		if ($send) {
1083
+			return $this->all_flights[$id];
1084
+		}
874 1085
 	    }
875 1086
 	}
876 1087
     }
Please login to merge, or discard this patch.
require/class.Scheduler.php 3 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -8,29 +8,29 @@  discard block
 block discarded – undo
8 8
 
9 9
 class Schedule {
10 10
 	protected $cookies = array();
11
-        public $db;
11
+		public $db;
12 12
 	public function __construct($dbc = null) {
13 13
 		$Connection = new Connection($dbc);
14 14
 		$this->db = $Connection->db();
15
-        }
15
+		}
16 16
 	
17 17
 	/**
18
-	* Add schedule data to database
19
-	* @param String $ident aircraft ident
20
-	* @param String $departure_airport_icao departure airport icao
21
-	* @param String $departure_airport_time departure airport time
22
-	* @param String $arrival_airport_icao arrival airport icao
23
-	* @param String $arrival_airport_time arrival airport time
18
+	 * Add schedule data to database
19
+	 * @param String $ident aircraft ident
20
+	 * @param String $departure_airport_icao departure airport icao
21
+	 * @param String $departure_airport_time departure airport time
22
+	 * @param String $arrival_airport_icao arrival airport icao
23
+	 * @param String $arrival_airport_time arrival airport time
24 24
 	/ @param String $source source of data
25
-	*/
25
+	 */
26 26
 	
27 27
 	public function addSchedule($ident,$departure_airport_icao,$departure_airport_time,$arrival_airport_icao,$arrival_airport_time,$source = 'website') {
28 28
 		date_default_timezone_set('UTC');
29 29
 		$date = date("Y-m-d H:i:s",time());
30
-	        //if ($departure_airport_time == '' && $arrival_airport_time == '') exit;
31
-	        //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident";
32
-	        $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident";
33
-	        $query_values = array(':ident' => $ident);
30
+			//if ($departure_airport_time == '' && $arrival_airport_time == '') exit;
31
+			//$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident";
32
+			$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident";
33
+			$query_values = array(':ident' => $ident);
34 34
 		 try {
35 35
 			$sth = $this->db->prepare($query);
36 36
 			$sth->execute($query_values);
@@ -39,18 +39,18 @@  discard block
 block discarded – undo
39 39
 		}
40 40
 		if ($sth->fetchColumn() > 0) {
41 41
 			if ($departure_airport_time == '' && $arrival_airport_time == '') {
42
-			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao";
43
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao);
42
+				$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao";
43
+				$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao);
44 44
 			} elseif ($arrival_airport_time == '') {
45
-			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao";
46
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao);
45
+				$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao";
46
+				$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao);
47 47
 			} elseif ($departure_airport_time == '') {
48
-			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
49
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
48
+				$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
49
+				$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
50 50
 			} else {
51
-			    //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time";
52
-			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
53
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
51
+				//$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time";
52
+				$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
53
+				$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
54 54
 			}
55 55
 			try {
56 56
 				$sth = $this->db->prepare($query);
@@ -61,17 +61,17 @@  discard block
 block discarded – undo
61 61
 			if ($sth->fetchColumn() == 0) {
62 62
 				//$query = 'UPDATE schedule SET departure_airport_icao = :departure_airport_icao, departure_airport_time = :departure_airport_time, arrival_airport_icao = :arrival_airport_icao, arrival_airport_time = :arrival_airport_time, date_modified = :date, source = :source WHERE ident = :ident';
63 63
 				if ($departure_airport_time == '' && $arrival_airport_time == '') {
64
-                            	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
65
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
64
+									$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
65
+					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
66 66
 				} elseif ($arrival_airport_time == '') {
67
-                            	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
68
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
67
+									$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
68
+					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
69 69
 				} elseif ($departure_airport_time == '') {
70
-                            	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
71
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
70
+									$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
71
+					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
72 72
 				} else {
73
-                            	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
74
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
73
+									$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
74
+					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
75 75
 				}
76 76
 				 try {
77 77
 					$sth = $this->db->prepare($query);
@@ -104,15 +104,15 @@  discard block
 block discarded – undo
104 104
 	}
105 105
 
106 106
 	public function getSchedule($ident) {
107
-	        $Translation = new Translation($this->db);
108
-	        $operator = $Translation->checkTranslation($ident,false);
109
-	        if ($ident != $operator) {
110
-	    		$query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :operator OR CallSign = :ident LIMIT 1";
111
-	    		$query_values = array(':ident' => $ident,'operator' => $operator);
112
-	    	} else {
113
-		        $query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :ident LIMIT 1";
114
-	    		$query_values = array(':ident' => $ident);
115
-	    	}
107
+			$Translation = new Translation($this->db);
108
+			$operator = $Translation->checkTranslation($ident,false);
109
+			if ($ident != $operator) {
110
+				$query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :operator OR CallSign = :ident LIMIT 1";
111
+				$query_values = array(':ident' => $ident,'operator' => $operator);
112
+			} else {
113
+				$query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :ident LIMIT 1";
114
+				$query_values = array(':ident' => $ident);
115
+			}
116 116
 		 try {
117 117
 			$sth = $this->db->prepare($query);
118 118
 			$sth->execute($query_values);
@@ -128,15 +128,15 @@  discard block
 block discarded – undo
128 128
 
129 129
 	public function checkSchedule($ident) {
130 130
 		global $globalDBdriver;
131
-	        //$query = "SELECT COUNT(*) as nb FROM schedule WHERE ident = :ident AND date_added > DATE_SUB(CURDATE(), INTERVAL 8 DAY) - 8 LIMIT 1";
132
-	        if ($globalDBdriver == 'mysql') {
131
+			//$query = "SELECT COUNT(*) as nb FROM schedule WHERE ident = :ident AND date_added > DATE_SUB(CURDATE(), INTERVAL 8 DAY) - 8 LIMIT 1";
132
+			if ($globalDBdriver == 'mysql') {
133 133
 			$query = "SELECT COUNT(*) as nb FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :ident AND ((date_added BETWEEN DATE(DATE_SUB(CURDATE(), INTERVAL 1 MONTH)) AND DATE(NOW()) and date_modified IS NULL) OR (date_modified BETWEEN DATE(DATE_SUB(CURDATE(), INTERVAL 15 DAY)) AND DATE(NOW()))) LIMIT 1";
134 134
 		} else {
135 135
 			$query = "SELECT COUNT(*) as nb FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :ident 
136 136
 			AND ((date_added::timestamp BETWEEN CURRENT_TIMESTAMP - INTERVAL '1 MONTH' AND CURRENT_TIMESTAMP) and date_modified::timestamp IS NULL)
137 137
 			     OR (date_modified::timestamp BETWEEN CURRENT_TIMESTAMP - INTERVAL '1 MONTH' AND CURRENT_TIMESTAMP) LIMIT 1";
138 138
 		}
139
-	        $query_values = array(':ident' => $ident);
139
+			$query_values = array(':ident' => $ident);
140 140
 		 try {
141 141
 			$sth = $this->db->prepare($query);
142 142
 			$sth->execute($query_values);
@@ -149,12 +149,12 @@  discard block
 block discarded – undo
149 149
 	}
150 150
 
151 151
 	/**
152
-	* Get flight info from Air France
153
-	* @param String $callsign The callsign
154
-	* @param String $date date we want flight number info
155
-	* @param String $carrier IATA code
156
-	* @return Flight departure and arrival airports and time
157
-	*/
152
+	 * Get flight info from Air France
153
+	 * @param String $callsign The callsign
154
+	 * @param String $date date we want flight number info
155
+	 * @param String $carrier IATA code
156
+	 * @return Flight departure and arrival airports and time
157
+	 */
158 158
 	private function getAirFrance($callsign, $date = 'NOW',$carrier = 'AF') {
159 159
 		$Common = new Common();
160 160
 		$check_date = new Datetime($date);
@@ -190,11 +190,11 @@  discard block
 block discarded – undo
190 190
 	}
191 191
 
192 192
 	/**
193
-	* Get flight info from EasyJet
194
-	* @param String $callsign The callsign
195
-	* @param String $date date we want flight number info
196
-	* @return Flight departure and arrival airports and time
197
-	*/
193
+	 * Get flight info from EasyJet
194
+	 * @param String $callsign The callsign
195
+	 * @param String $date date we want flight number info
196
+	 * @return Flight departure and arrival airports and time
197
+	 */
198 198
 	private function getEasyJet($callsign, $date = 'NOW') {
199 199
 		global $globalTimezone;
200 200
 		$Common = new Common();
@@ -218,10 +218,10 @@  discard block
 block discarded – undo
218 218
 	}
219 219
 
220 220
 	/**
221
-	* Get flight info from Ryanair
222
-	* @param String $callsign The callsign
223
-	* @return Flight departure and arrival airports and time
224
-	*/
221
+	 * Get flight info from Ryanair
222
+	 * @param String $callsign The callsign
223
+	 * @return Flight departure and arrival airports and time
224
+	 */
225 225
 	private function getRyanair($callsign) {
226 226
 		$Common = new Common();
227 227
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -244,10 +244,10 @@  discard block
 block discarded – undo
244 244
 	}
245 245
 
246 246
 	/**
247
-	* Get flight info from Swiss
248
-	* @param String $callsign The callsign
249
-	* @return Flight departure and arrival airports and time
250
-	*/
247
+	 * Get flight info from Swiss
248
+	 * @param String $callsign The callsign
249
+	 * @return Flight departure and arrival airports and time
250
+	 */
251 251
 	private function getSwiss($callsign) {
252 252
 		$Common = new Common();
253 253
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -276,11 +276,11 @@  discard block
 block discarded – undo
276 276
 	}
277 277
 	
278 278
 	/**
279
-	* Get flight info from British Airways API
280
-	* @param String $callsign The callsign
281
-	* @param String $date date we want flight number info
282
-	* @return Flight departure and arrival airports and time
283
-	*/
279
+	 * Get flight info from British Airways API
280
+	 * @param String $callsign The callsign
281
+	 * @param String $date date we want flight number info
282
+	 * @return Flight departure and arrival airports and time
283
+	 */
284 284
 	public function getBritishAirways($callsign, $date = 'NOW') {
285 285
 		global $globalBritishAirwaysKey;
286 286
 		$Common = new Common();
@@ -304,11 +304,11 @@  discard block
 block discarded – undo
304 304
 	}
305 305
 
306 306
 	/**
307
-	* Get flight info from Lutfhansa API
308
-	* @param String $callsign The callsign
309
-	* @param String $date date we want flight number info
310
-	* @return Flight departure and arrival airports and time
311
-	*/
307
+	 * Get flight info from Lutfhansa API
308
+	 * @param String $callsign The callsign
309
+	 * @param String $date date we want flight number info
310
+	 * @return Flight departure and arrival airports and time
311
+	 */
312 312
 	public function getLufthansa($callsign, $date = 'NOW') {
313 313
 		global $globalLufthansaKey;
314 314
 		$Common = new Common();
@@ -338,11 +338,11 @@  discard block
 block discarded – undo
338 338
 	}
339 339
 
340 340
 	/**
341
-	* Get flight info from Transavia API
342
-	* @param String $callsign The callsign
343
-	* @param String $date date we want flight number info
344
-	* @return Flight departure and arrival airports and time
345
-	*/
341
+	 * Get flight info from Transavia API
342
+	 * @param String $callsign The callsign
343
+	 * @param String $date date we want flight number info
344
+	 * @return Flight departure and arrival airports and time
345
+	 */
346 346
 	public function getTransavia($callsign, $date = 'NOW') {
347 347
 		global $globalTransaviaKey;
348 348
 		$Common = new Common();
@@ -368,10 +368,10 @@  discard block
 block discarded – undo
368 368
 	}
369 369
 
370 370
 	/**
371
-	* Get flight info from Tunisair
372
-	* @param String $callsign The callsign
373
-	* @return Flight departure and arrival airports and time
374
-	*/
371
+	 * Get flight info from Tunisair
372
+	 * @param String $callsign The callsign
373
+	 * @return Flight departure and arrival airports and time
374
+	 */
375 375
 	public function getTunisair($callsign) {
376 376
 		$Common = new Common();
377 377
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -388,10 +388,10 @@  discard block
 block discarded – undo
388 388
 	}
389 389
 
390 390
 	/**
391
-	* Get flight info from Vueling
392
-	* @param String $callsign The callsign
393
-	* @return Flight departure and arrival airports and time
394
-	*/
391
+	 * Get flight info from Vueling
392
+	 * @param String $callsign The callsign
393
+	 * @return Flight departure and arrival airports and time
394
+	 */
395 395
 	public function getVueling($callsign,$date = 'NOW') {
396 396
 		$Common = new Common();
397 397
 		$check_date = new Datetime($date);
@@ -413,11 +413,11 @@  discard block
 block discarded – undo
413 413
 	}
414 414
 
415 415
 	/**
416
-	* Get flight info from Iberia
417
-	* @param String $callsign The callsign
418
-	* @param String $date date we want flight number info
419
-	* @return Flight departure and arrival airports and time
420
-	*/
416
+	 * Get flight info from Iberia
417
+	 * @param String $callsign The callsign
418
+	 * @param String $date date we want flight number info
419
+	 * @return Flight departure and arrival airports and time
420
+	 */
421 421
 	public function getIberia($callsign, $date = 'NOW') {
422 422
 		$Common = new Common();
423 423
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -447,11 +447,11 @@  discard block
 block discarded – undo
447 447
 	}
448 448
 
449 449
 	/**
450
-	* Get flight info from Star Alliance
451
-	* @param String $callsign The callsign
452
-	* @param String $date date we want flight number info
453
-	* @return Flight departure and arrival airports and time
454
-	*/
450
+	 * Get flight info from Star Alliance
451
+	 * @param String $callsign The callsign
452
+	 * @param String $date date we want flight number info
453
+	 * @return Flight departure and arrival airports and time
454
+	 */
455 455
 
456 456
 	private function getStarAlliance($callsign, $date = 'NOW',$carrier = '') {
457 457
 		$Common = new Common();
@@ -483,11 +483,11 @@  discard block
 block discarded – undo
483 483
 
484 484
 
485 485
 	/**
486
-	* Get flight info from Alitalia
487
-	* @param String $callsign The callsign
488
-	* @param String $date date we want flight number info
489
-	* @return Flight departure and arrival airports and time
490
-	*/
486
+	 * Get flight info from Alitalia
487
+	 * @param String $callsign The callsign
488
+	 * @param String $date date we want flight number info
489
+	 * @return Flight departure and arrival airports and time
490
+	 */
491 491
 	private function getAlitalia($callsign, $date = 'NOW') {
492 492
 		$Common = new Common();
493 493
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -506,11 +506,11 @@  discard block
 block discarded – undo
506 506
 	}
507 507
 
508 508
 	/**
509
-	* Get flight info from Brussels airlines
510
-	* @param String $callsign The callsign
511
-	* @param String $date date we want flight number info
512
-	* @return Flight departure and arrival airports and time
513
-	*/
509
+	 * Get flight info from Brussels airlines
510
+	 * @param String $callsign The callsign
511
+	 * @param String $date date we want flight number info
512
+	 * @return Flight departure and arrival airports and time
513
+	 */
514 514
 	private function getBrussels($callsign, $date = 'NOW') {
515 515
 		$Common = new Common();
516 516
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -520,24 +520,24 @@  discard block
 block discarded – undo
520 520
 		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
521 521
 		$data = $Common->getData($url);
522 522
 		if ($data != '') {
523
-		    //echo $data;
524
-		    $parsed_json = json_decode($data,true);
525
-		    if (isset($parsed_json[0]['FromAirportCode'])) {
523
+			//echo $data;
524
+			$parsed_json = json_decode($data,true);
525
+			if (isset($parsed_json[0]['FromAirportCode'])) {
526 526
 			$DepartureAirportIata = $parsed_json[0]['FromAirportCode'];
527 527
 			$ArrivalAirportIata = $parsed_json[0]['ToAirportCode'];
528 528
 			$departureTime = date('H:i',strtotime($parsed_json[0]['ScheduledDepatureDate']));
529 529
 			$arrivalTime = date('H:i',strtotime($parsed_json[0]['ScheduledArrivalDate']));
530 530
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_brussels');
531
-		    }
531
+			}
532 532
 		}
533 533
 	}
534 534
 
535 535
 	/**
536
-	* Get flight info from FlightRadar24
537
-	* @param String $callsign The callsign
538
-	* @param String $date date we want flight number info
539
-	* @return Flight departure and arrival airports and time
540
-	*/
536
+	 * Get flight info from FlightRadar24
537
+	 * @param String $callsign The callsign
538
+	 * @param String $date date we want flight number info
539
+	 * @return Flight departure and arrival airports and time
540
+	 */
541 541
 /*
542 542
 	public function getFlightRadar24($callsign, $date = 'NOW') {
543 543
 		$Common = new Common();
@@ -566,11 +566,11 @@  discard block
 block discarded – undo
566 566
 	}
567 567
   */
568 568
 	/**
569
-	* Get flight info from Lufthansa
570
-	* @param String $callsign The callsign
571
-	* @param String $date date we want flight number info
572
-	* @return Flight departure and arrival airports and time
573
-	*/
569
+	 * Get flight info from Lufthansa
570
+	 * @param String $callsign The callsign
571
+	 * @param String $date date we want flight number info
572
+	 * @return Flight departure and arrival airports and time
573
+	 */
574 574
 
575 575
 /*	private function getLufthansa($callsign, $date = 'NOW') {
576 576
 		$Common = new Common();
@@ -598,10 +598,10 @@  discard block
 block discarded – undo
598 598
 	}
599 599
   */
600 600
 	/**
601
-	* Get flight info from flytap
602
-	* @param String $callsign The callsign
603
-	* @return Flight departure and arrival airports and time
604
-	*/
601
+	 * Get flight info from flytap
602
+	 * @param String $callsign The callsign
603
+	 * @return Flight departure and arrival airports and time
604
+	 */
605 605
 	private function getFlyTap($callsign) {
606 606
 		$Common = new Common();
607 607
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -624,10 +624,10 @@  discard block
 block discarded – undo
624 624
 	}
625 625
 
626 626
 	/**
627
-	* Get flight info from flightmapper
628
-	* @param String $callsign The callsign
629
-	* @return Flight departure and arrival airports and time
630
-	*/
627
+	 * Get flight info from flightmapper
628
+	 * @param String $callsign The callsign
629
+	 * @return Flight departure and arrival airports and time
630
+	 */
631 631
 	public function getFlightMapper($callsign) {
632 632
 		$Common = new Common();
633 633
 		$airline_icao = '';
@@ -655,11 +655,11 @@  discard block
 block discarded – undo
655 655
 				$aarr = '';
656 656
 				$n = sscanf($sched,'%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])',$dhour,$darr,$ahour,$aarr);
657 657
 				if ($n == 7) {
658
-				    $departureTime = $dhour;
659
-				    $arrivalTime = $ahour;
660
-				    $DepartureAirportIata = str_replace(array('(',')'),'',$darr);
661
-				    $ArrivalAirportIata = str_replace(array('(',')'),'',$aarr);
662
-				    return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper');
658
+					$departureTime = $dhour;
659
+					$arrivalTime = $ahour;
660
+					$DepartureAirportIata = str_replace(array('(',')'),'',$darr);
661
+					$ArrivalAirportIata = str_replace(array('(',')'),'',$aarr);
662
+					return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper');
663 663
 				}
664 664
 			}
665 665
 		}
@@ -667,10 +667,10 @@  discard block
 block discarded – undo
667 667
 	}
668 668
 
669 669
 	/**
670
-	* Get flight info from flightaware
671
-	* @param String $callsign The callsign
672
-	* @return Flight departure and arrival airports and time
673
-	*/
670
+	 * Get flight info from flightaware
671
+	 * @param String $callsign The callsign
672
+	 * @return Flight departure and arrival airports and time
673
+	 */
674 674
 	public function getFlightAware($callsign) {
675 675
 		$Common = new Common();
676 676
 		/*
@@ -703,10 +703,10 @@  discard block
 block discarded – undo
703 703
 	}
704 704
 
705 705
 	/**
706
-	* Get flight info from CostToTravel
707
-	* @param String $callsign The callsign
708
-	* @return Flight departure and arrival airports and time
709
-	*/
706
+	 * Get flight info from CostToTravel
707
+	 * @param String $callsign The callsign
708
+	 * @return Flight departure and arrival airports and time
709
+	 */
710 710
 	public function getCostToTravel($callsign) {
711 711
 		$Common = new Common();
712 712
 		$url= "http://www.costtotravel.com/flight-number/".$callsign;
@@ -728,11 +728,11 @@  discard block
 block discarded – undo
728 728
 	}
729 729
 
730 730
 	/**
731
-	* Get flight info from Air Canada
732
-	* @param String $callsign The callsign
733
-	* @param String $date date we want flight number info
734
-	* @return Flight departure and arrival airports and time
735
-	*/
731
+	 * Get flight info from Air Canada
732
+	 * @param String $callsign The callsign
733
+	 * @param String $date date we want flight number info
734
+	 * @return Flight departure and arrival airports and time
735
+	 */
736 736
 	private function getAirCanada($callsign,$date = 'NOW') {
737 737
 		$Common = new Common();
738 738
 		date_default_timezone_set('UTC');
@@ -756,11 +756,11 @@  discard block
 block discarded – undo
756 756
 	}
757 757
 
758 758
 	/**
759
-	* Get flight info from Vietnam Airlines
760
-	* @param String $callsign The callsign
761
-	* @param String $date date we want flight number info
762
-	* @return Flight departure and arrival airports and time
763
-	*/
759
+	 * Get flight info from Vietnam Airlines
760
+	 * @param String $callsign The callsign
761
+	 * @param String $date date we want flight number info
762
+	 * @return Flight departure and arrival airports and time
763
+	 */
764 764
 	private function getVietnamAirlines($callsign, $date = 'NOW') {
765 765
 		$Common = new Common();
766 766
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -782,12 +782,12 @@  discard block
 block discarded – undo
782 782
 	}
783 783
 
784 784
 	/**
785
-	* Get flight info from Air Berlin
786
-	* @param String $callsign The callsign
787
-	* @param String $date date we want flight number info
788
-	* @param String $carrier airline code
789
-	* @return Flight departure and arrival airports and time
790
-	*/
785
+	 * Get flight info from Air Berlin
786
+	 * @param String $callsign The callsign
787
+	 * @param String $date date we want flight number info
788
+	 * @param String $carrier airline code
789
+	 * @return Flight departure and arrival airports and time
790
+	 */
791 791
 	private function getAirBerlin($callsign, $date = 'NOW',$carrier = 'AB') {
792 792
 		$Common = new Common();
793 793
 		date_default_timezone_set('UTC');
@@ -816,11 +816,11 @@  discard block
 block discarded – undo
816 816
 			$table = $Common->table2array($data);
817 817
 			$flight = $table;
818 818
 			if (isset($flight[5][4])) {
819
-			    $arrivalTime = $flight[5][4];
820
-			    $arrivalAirport = $flight[5][3];
819
+				$arrivalTime = $flight[5][4];
820
+				$arrivalAirport = $flight[5][3];
821 821
 			} else {
822
-			    $arrivalTime = '';
823
-			    $arrivalAirport = '';
822
+				$arrivalTime = '';
823
+				$arrivalAirport = '';
824 824
 			}
825 825
 		} else return array();
826 826
 		$url = 'http://www.airberlin.com/en-US/site/json/suggestAirport.php?searchfor=departures&searchflightid=0&departures%5B%5D=&suggestsource%5B0%5D=activeairports&withcountries=0&withoutroutings=0&promotion%5Bid%5D=&promotion%5Btype%5D=&routesource%5B0%5D=airberlin&routesource%5B1%5D=partner';
@@ -1088,7 +1088,7 @@  discard block
 block discarded – undo
1088 1088
 					}
1089 1089
 			}
1090 1090
 		}
1091
-	        return array();
1091
+			return array();
1092 1092
 	}
1093 1093
 }
1094 1094
 
Please login to merge, or discard this patch.
Spacing   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
 	/ @param String $source source of data
25 25
 	*/
26 26
 	
27
-	public function addSchedule($ident,$departure_airport_icao,$departure_airport_time,$arrival_airport_icao,$arrival_airport_time,$source = 'website') {
27
+	public function addSchedule($ident, $departure_airport_icao, $departure_airport_time, $arrival_airport_icao, $arrival_airport_time, $source = 'website') {
28 28
 		date_default_timezone_set('UTC');
29
-		$date = date("Y-m-d H:i:s",time());
29
+		$date = date("Y-m-d H:i:s", time());
30 30
 	        //if ($departure_airport_time == '' && $arrival_airport_time == '') exit;
31 31
 	        //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident";
32 32
 	        $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident";
@@ -34,69 +34,69 @@  discard block
 block discarded – undo
34 34
 		 try {
35 35
 			$sth = $this->db->prepare($query);
36 36
 			$sth->execute($query_values);
37
-		} catch(PDOException $e) {
37
+		} catch (PDOException $e) {
38 38
 			return "error : ".$e->getMessage();
39 39
 		}
40 40
 		if ($sth->fetchColumn() > 0) {
41 41
 			if ($departure_airport_time == '' && $arrival_airport_time == '') {
42 42
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao";
43
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao);
43
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao);
44 44
 			} elseif ($arrival_airport_time == '') {
45 45
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao";
46
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao);
46
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao);
47 47
 			} elseif ($departure_airport_time == '') {
48 48
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
49
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
49
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time);
50 50
 			} else {
51 51
 			    //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time";
52 52
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
53
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
53
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time);
54 54
 			}
55 55
 			try {
56 56
 				$sth = $this->db->prepare($query);
57 57
 				$sth->execute($query_values);
58
-			} catch(PDOException $e) {
58
+			} catch (PDOException $e) {
59 59
 				return "error : ".$e->getMessage();
60 60
 			}
61 61
 			if ($sth->fetchColumn() == 0) {
62 62
 				//$query = 'UPDATE schedule SET departure_airport_icao = :departure_airport_icao, departure_airport_time = :departure_airport_time, arrival_airport_icao = :arrival_airport_icao, arrival_airport_time = :arrival_airport_time, date_modified = :date, source = :source WHERE ident = :ident';
63 63
 				if ($departure_airport_time == '' && $arrival_airport_time == '') {
64 64
                             	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
65
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
65
+				    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
66 66
 				} elseif ($arrival_airport_time == '') {
67 67
                             	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
68
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
68
+				    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
69 69
 				} elseif ($departure_airport_time == '') {
70 70
                             	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
71
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
71
+				    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
72 72
 				} else {
73 73
                             	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
74
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
74
+				    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
75 75
 				}
76 76
 				 try {
77 77
 					$sth = $this->db->prepare($query);
78 78
 					$sth->execute($query_values);
79
-				} catch(PDOException $e) {
79
+				} catch (PDOException $e) {
80 80
 					return "error : ".$e->getMessage();
81 81
 				}
82 82
 			} else {
83 83
 				//$query = 'UPDATE schedule SET date_lastseen = :date WHERE ident = :ident';
84 84
 				$query = 'UPDATE routes SET date_lastseen = :date WHERE CallSign = :ident';
85
-				$query_values = array(':ident' => $ident,':date' => $date);
85
+				$query_values = array(':ident' => $ident, ':date' => $date);
86 86
 				 try {
87 87
 					$sth = $this->db->prepare($query);
88 88
 					$sth->execute($query_values);
89
-				} catch(PDOException $e) {
89
+				} catch (PDOException $e) {
90 90
 					return "error : ".$e->getMessage();
91 91
 				}
92 92
 			}
93 93
 		} else {
94 94
 			$query = 'INSERT INTO  routes (CallSign,FromAirport_ICAO, FromAirport_Time, ToAirport_ICAO, ToAirport_Time,date_added,source)  VALUES (:ident,:departure_airport_icao,:departure_airport_time,:arrival_airport_icao,:arrival_airport_time,:date,:source)';
95
-			$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
95
+			$query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
96 96
 			 try {
97 97
 				$sth = $this->db->prepare($query);
98 98
 				$sth->execute($query_values);
99
-			} catch(PDOException $e) {
99
+			} catch (PDOException $e) {
100 100
 				return "error : ".$e->getMessage();
101 101
 			}
102 102
 		}
@@ -105,10 +105,10 @@  discard block
 block discarded – undo
105 105
 
106 106
 	public function getSchedule($ident) {
107 107
 	        $Translation = new Translation($this->db);
108
-	        $operator = $Translation->checkTranslation($ident,false);
108
+	        $operator = $Translation->checkTranslation($ident, false);
109 109
 	        if ($ident != $operator) {
110 110
 	    		$query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :operator OR CallSign = :ident LIMIT 1";
111
-	    		$query_values = array(':ident' => $ident,'operator' => $operator);
111
+	    		$query_values = array(':ident' => $ident, 'operator' => $operator);
112 112
 	    	} else {
113 113
 		        $query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :ident LIMIT 1";
114 114
 	    		$query_values = array(':ident' => $ident);
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 		 try {
117 117
 			$sth = $this->db->prepare($query);
118 118
 			$sth->execute($query_values);
119
-		} catch(PDOException $e) {
119
+		} catch (PDOException $e) {
120 120
 			return "error : ".$e->getMessage();
121 121
 		}
122 122
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 		 try {
141 141
 			$sth = $this->db->prepare($query);
142 142
 			$sth->execute($query_values);
143
-		} catch(PDOException $e) {
143
+		} catch (PDOException $e) {
144 144
 			return "error : ".$e->getMessage();
145 145
 		}
146 146
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -155,16 +155,16 @@  discard block
 block discarded – undo
155 155
 	* @param String $carrier IATA code
156 156
 	* @return Flight departure and arrival airports and time
157 157
 	*/
158
-	private function getAirFrance($callsign, $date = 'NOW',$carrier = 'AF') {
158
+	private function getAirFrance($callsign, $date = 'NOW', $carrier = 'AF') {
159 159
 		$Common = new Common();
160 160
 		$check_date = new Datetime($date);
161
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
162
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
161
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
162
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
163 163
 		$url = "http://www.airfrance.fr/cgi-bin/AF/FR/fr/local/resainfovol/infovols/detailsVolJson.do?codeCompagnie[0]=".$carrier."&numeroVol[0]=".$numvol."&dayFlightDate=".$check_date->format('d')."&yearMonthFlightDate=".$check_date->format('Ym');
164 164
 		$json = $Common->getData($url);
165 165
 	
166 166
 		$parsed_json = json_decode($json);
167
-		if (property_exists($parsed_json,'errors') === false) {
167
+		if (property_exists($parsed_json, 'errors') === false) {
168 168
 			//$originLong = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originLong'};
169 169
 			$originShort = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originShort'};
170 170
 			//$departureDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'departureDateMedium'};
@@ -174,9 +174,9 @@  discard block
 block discarded – undo
174 174
 			//$arrivalDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalDateMedium'};
175 175
 			$arrivalTime = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalTime'};
176 176
 
177
-			preg_match('/\((.*?)\)/',$originShort,$originiata);
177
+			preg_match('/\((.*?)\)/', $originShort, $originiata);
178 178
 			$DepartureAirportIata = $originiata[1];
179
-			preg_match('/\((.*?)\)/',$destinationShort,$destinationiata);
179
+			preg_match('/\((.*?)\)/', $destinationShort, $destinationiata);
180 180
 			$ArrivalAirportIata = $destinationiata[1];
181 181
 
182 182
 			/*
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 			$arrivalTime = gmdate('H:i',strtotime($arrivalTime));
186 186
 			*/
187 187
 		
188
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airfrance');
188
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_airfrance');
189 189
 		} else return array();
190 190
 	}
191 191
 
@@ -200,8 +200,8 @@  discard block
 block discarded – undo
200 200
 		$Common = new Common();
201 201
 		date_default_timezone_set($globalTimezone);
202 202
 		$check_date = new Datetime($date);
203
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
204
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
203
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
204
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
205 205
 		$url = "http://www.easyjet.com/ft/api/flights?date=".$check_date->format('Y-m-d')."&fn=".$callsign;
206 206
 		$json = $Common->getData($url);
207 207
 		$parsed_json = json_decode($json);
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 			$departureTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fstd'};
214 214
 			$arrivalTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fsta'};
215 215
 
216
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_easyjet');
216
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_easyjet');
217 217
 		} else return array();
218 218
 	}
219 219
 
@@ -224,12 +224,12 @@  discard block
 block discarded – undo
224 224
 	*/
225 225
 	private function getRyanair($callsign) {
226 226
 		$Common = new Common();
227
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
228
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
227
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
228
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
229 229
 		$url = "http://www.ryanair.com/fr/api/2/flight-info/0/50/";
230 230
 		$post = '{"flight":"'.$numvol.'","minDepartureTime":"00:00","maxDepartureTime":"23:59"}';
231
-		$headers = array('Content-Type: application/json','Content-Length: ' . strlen($post));
232
-		$json = $Common->getData($url,'post',$post,$headers);
231
+		$headers = array('Content-Type: application/json', 'Content-Length: '.strlen($post));
232
+		$json = $Common->getData($url, 'post', $post, $headers);
233 233
 		$parsed_json = json_decode($json);
234 234
 		if (isset($parsed_json->{'flightInfo'})) {
235 235
 			$flights = $parsed_json->{'flightInfo'};
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 				$ArrivalAirportIata = $parsed_json->{'flightInfo'}[0]->{'arrivalAirport'}->{'iata'}; //name
239 239
 				$departureTime = $parsed_json->{'flightInfo'}[0]->{'departureTime'};
240 240
 				$arrivalTime = $parsed_json->{'flightInfo'}[0]->{'arrivalTime'};
241
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair');
241
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair');
242 242
 			} else return array();
243 243
 		} else return array();
244 244
 	}
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
 	*/
251 251
 	private function getSwiss($callsign) {
252 252
 		$Common = new Common();
253
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
254
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
253
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
254
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
255 255
 		$url = "http://www.world-of-swiss.com/fr/routenetwork.json";
256 256
 		$json = $Common->getData($url);
257 257
 		$parsed_json = json_decode($json);
@@ -265,12 +265,12 @@  discard block
 block discarded – undo
265 265
 				if ($flight->{'no'} == "Vol LX ".$numvol) {
266 266
 					$DepartureAirportIata = $flight->{'from'}->{'code'}; //city
267 267
 					$ArrivalAirportIata = $flight->{'to'}->{'code'}; //city
268
-					$departureTime = substr($flight->{'from'}->{'hour'},0,5);
269
-					$arrivalTime = substr($flight->{'to'}->{'hour'},0,5);
268
+					$departureTime = substr($flight->{'from'}->{'hour'},0, 5);
269
+					$arrivalTime = substr($flight->{'to'}->{'hour'},0, 5);
270 270
 				}
271 271
 			}
272 272
 			if (isset($DepartureAirportIata) && isset($ArrivalAirportIata)) {
273
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_swiss');
273
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_swiss');
274 274
 			} else return array();
275 275
 		} else return array();
276 276
 	}
@@ -285,21 +285,21 @@  discard block
 block discarded – undo
285 285
 		global $globalBritishAirwaysKey;
286 286
 		$Common = new Common();
287 287
 		$check_date = new Datetime($date);
288
-		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
289
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
288
+		$numvol = sprintf('%04d', preg_replace('/^[A-Z]*/', '', $callsign));
289
+		if (!filter_var(preg_replace('/^[A-Z]*/', '', $callsign), FILTER_VALIDATE_INT)) return array();
290 290
 		if ($globalBritishAirwaysKey == '') return array();
291 291
 		$url = "https://api.ba.com/rest-v1/v1/flights;flightNumber=".$numvol.";scheduledDepartureDate=".$check_date->format('Y-m-d').".json";
292 292
 		$headers = array('Client-Key: '.$globalBritishAirwaysKey);
293
-		$json = $Common->getData($url,'get','',$headers);
293
+		$json = $Common->getData($url, 'get', '', $headers);
294 294
 		if ($json == '') return array();
295 295
 		$parsed_json = json_decode($json);
296 296
 		$flights = $parsed_json->{'FlightsResponse'};
297 297
 		if (count($flights) > 0) {
298 298
 			$DepartureAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'DepartureAirport'};
299 299
 			$ArrivalAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ArrivalAirport'};
300
-			$departureTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'}));
301
-			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'}));
302
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_britishairways');
300
+			$departureTime = date('H:i', strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'}));
301
+			$arrivalTime = date('H:i', strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'}));
302
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_britishairways');
303 303
 		} else return array();
304 304
 	}
305 305
 
@@ -313,27 +313,27 @@  discard block
 block discarded – undo
313 313
 		global $globalLufthansaKey;
314 314
 		$Common = new Common();
315 315
 		$check_date = new Datetime($date);
316
-		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
317
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
316
+		$numvol = sprintf('%04d', preg_replace('/^[A-Z]*/', '', $callsign));
317
+		if (!filter_var(preg_replace('/^[A-Z]*/', '', $callsign), FILTER_VALIDATE_INT)) return array();
318 318
 		if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') return array();
319 319
 		$url = "https://api.lufthansa.com/v1/oauth/token";
320
-		$post = array('client_id' => $globalLufthansaKey['key'],'client_secret' => $globalLufthansaKey['secret'],'grant_type' => 'client_credentials');
321
-		$data = $Common->getData($url,'post',$post);
320
+		$post = array('client_id' => $globalLufthansaKey['key'], 'client_secret' => $globalLufthansaKey['secret'], 'grant_type' => 'client_credentials');
321
+		$data = $Common->getData($url, 'post', $post);
322 322
 		$parsed_data = json_decode($data);
323 323
 		if (!isset($parsed_data->{'access_token'})) return array();
324 324
 		$token = $parsed_data->{'access_token'};
325 325
 		
326 326
 		$url = "https://api.lufthansa.com/v1/operations/flightstatus/LH".$numvol."/".$check_date->format('Y-m-d');
327
-		$headers = array('Authorization: Bearer '.$token,'Accept: application/json');
328
-		$json = $Common->getData($url,'get','',$headers);
327
+		$headers = array('Authorization: Bearer '.$token, 'Accept: application/json');
328
+		$json = $Common->getData($url, 'get', '', $headers);
329 329
 		if ($json == '') return array();
330 330
 		$parsed_json = json_decode($json);
331 331
 		if (isset($parsed_json->{'FlightStatusResource'}) && count($parsed_json->{'FlightStatusResource'}) > 0) {
332 332
 			$DepartureAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'AirportCode'};
333
-			$departureTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'ScheduledTimeLocal'}->{'DateTime'}));
333
+			$departureTime = date('H:i', strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'ScheduledTimeLocal'}->{'DateTime'}));
334 334
 			$ArrivalAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'AirportCode'};
335
-			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'}));
336
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa');
335
+			$arrivalTime = date('H:i', strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'}));
336
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_lufthansa');
337 337
 		} else return array();
338 338
 	}
339 339
 
@@ -347,23 +347,23 @@  discard block
 block discarded – undo
347 347
 		global $globalTransaviaKey;
348 348
 		$Common = new Common();
349 349
 		$check_date = new Datetime($date);
350
-		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
351
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
350
+		$numvol = sprintf('%04d', preg_replace('/^[A-Z]*/', '', $callsign));
351
+		if (!filter_var(preg_replace('/^[A-Z]*/', '', $callsign), FILTER_VALIDATE_INT)) return array();
352 352
 		if ($globalTransaviaKey == '') return array();
353 353
 		$url = "https://tst.api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
354 354
 		//$url = "https://api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
355 355
 		$headers = array('apikey: '.$globalTransaviaKey);
356
-		$json = $Common->getData($url,'get','',$headers);
356
+		$json = $Common->getData($url, 'get', '', $headers);
357 357
 		//echo 'result : '.$json;
358 358
 		if ($json == '') return array();
359 359
 		$parsed_json = json_decode($json);
360 360
 		
361 361
 		if (isset($parsed_json->{'data'}[0])) {
362 362
 			$DepartureAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'departureAirport'}->{'locationCode'};
363
-			$departureTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'departureDateTime'}));
363
+			$departureTime = date('H:i', strtotime($parsed_json->{'data'}[0]->{'flight'}->{'departureDateTime'}));
364 364
 			$ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'};
365
-			$arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'}));
366
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia');
365
+			$arrivalTime = date('H:i', strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'}));
366
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_transavia');
367 367
 		} else return array();
368 368
 	}
369 369
 
@@ -374,14 +374,14 @@  discard block
 block discarded – undo
374 374
 	*/
375 375
 	public function getTunisair($callsign) {
376 376
 		$Common = new Common();
377
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
378
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
377
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
378
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
379 379
 		$url = "http://www.tunisair.com/site/publish/module/Volj/fr/Flight_List.asp";
380 380
 		$data = $Common->getData($url);
381 381
 		$table = $Common->table2array($data);
382 382
 		foreach ($table as $flight) {
383
-			if (isset($flight[1]) && $flight[1] == "TU ".sprintf('%04d',$numvol)) {
384
-				return array('DepartureAirportIATA' => $flight[2],'DepartureTime' => str_replace('.',':',$flight[5]),'ArrivalAirportIATA' => $flight[3],'ArrivalTime' => str_replace('.',':',$flight[6]),'Source' => 'website_tunisair');
383
+			if (isset($flight[1]) && $flight[1] == "TU ".sprintf('%04d', $numvol)) {
384
+				return array('DepartureAirportIATA' => $flight[2], 'DepartureTime' => str_replace('.', ':', $flight[5]), 'ArrivalAirportIATA' => $flight[3], 'ArrivalTime' => str_replace('.', ':', $flight[6]), 'Source' => 'website_tunisair');
385 385
 			}
386 386
 		}
387 387
 		return array();
@@ -392,21 +392,21 @@  discard block
 block discarded – undo
392 392
 	* @param String $callsign The callsign
393 393
 	* @return Flight departure and arrival airports and time
394 394
 	*/
395
-	public function getVueling($callsign,$date = 'NOW') {
395
+	public function getVueling($callsign, $date = 'NOW') {
396 396
 		$Common = new Common();
397 397
 		$check_date = new Datetime($date);
398
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
399
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
400
-		$final_date = str_replace('/','%2F',$check_date->format('d/m/Y'));
398
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
399
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
400
+		$final_date = str_replace('/', '%2F', $check_date->format('d/m/Y'));
401 401
 		$url = "http://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=FlightStatusResult&searchBy=bycode&date=".$final_date."&flightNumber=".$numvol."&idioma=en-GB";
402 402
 		$data = $Common->getData($url);
403
-		$data=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$data));
403
+		$data = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $data));
404 404
 		if ($data != '') {
405
-			preg_match('/flightOri=[A-Z]{3}/',$data,$result);
406
-			$DepartureAirportIata = str_replace('flightOri=','',$result[0]);
407
-			preg_match('/flightDest=[A-Z]{3}/',$data,$result);
408
-			$ArrivalAirportIata = str_replace('flightDest=','',$result[0]);
409
-			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling');
405
+			preg_match('/flightOri=[A-Z]{3}/', $data, $result);
406
+			$DepartureAirportIata = str_replace('flightOri=', '', $result[0]);
407
+			preg_match('/flightDest=[A-Z]{3}/', $data, $result);
408
+			$ArrivalAirportIata = str_replace('flightDest=', '', $result[0]);
409
+			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'Source' => 'website_vueling');
410 410
 			else return array();
411 411
 		}
412 412
 		return array();
@@ -420,27 +420,27 @@  discard block
 block discarded – undo
420 420
 	*/
421 421
 	public function getIberia($callsign, $date = 'NOW') {
422 422
 		$Common = new Common();
423
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
423
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
424 424
 		$check_date = new Datetime($date);
425
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
425
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
426 426
 		$url = "https://www.iberia.com/web/flightDetail.do";
427
-		$post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB');
428
-		$data = $Common->getData($url,'post',$post);
427
+		$post = array('numvuelo' => $numvol, 'fecha' => $check_date->format('Ymd'), 'airlineID' => 'IB');
428
+		$data = $Common->getData($url, 'post', $post);
429 429
 		if ($data != '') {
430 430
 			$table = $Common->table2array($data);
431 431
 			//print_r($table);
432 432
 			if (count($table) > 0) {
433 433
 				$flight = $table;
434
-				preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch);
435
-				preg_match('/([A-Z]{3})/',$flight[5][0],$ArrivalAirportIataMatch);
434
+				preg_match('/([A-Z]{3})/', $flight[3][0], $DepartureAirportIataMatch);
435
+				preg_match('/([A-Z]{3})/', $flight[5][0], $ArrivalAirportIataMatch);
436 436
 				$DepartureAirportIata = $DepartureAirportIataMatch[0];
437 437
 				$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
438
-				$departureTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[3][2]))),0,5);
439
-				$arrivalTime = trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][1])));
438
+				$departureTime = substr(trim(str_replace(' lunes', '', str_replace('&nbsp;', '', $flight[3][2]))), 0, 5);
439
+				$arrivalTime = trim(str_replace(' lunes', '', str_replace('&nbsp;', '', $flight[5][1])));
440 440
 				if ($arrivalTime == 'Hora estimada de llegada') {
441
-					$arrivalTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][2]))),0,5);
442
-				} else $arrivalTime = substr($arrivalTime,0,5);
443
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia');
441
+					$arrivalTime = substr(trim(str_replace(' lunes', '', str_replace('&nbsp;', '', $flight[5][2]))), 0, 5);
442
+				} else $arrivalTime = substr($arrivalTime, 0, 5);
443
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_iberia');
444 444
 			}
445 445
 		}
446 446
 		return array();
@@ -453,11 +453,11 @@  discard block
 block discarded – undo
453 453
 	* @return Flight departure and arrival airports and time
454 454
 	*/
455 455
 
456
-	private function getStarAlliance($callsign, $date = 'NOW',$carrier = '') {
456
+	private function getStarAlliance($callsign, $date = 'NOW', $carrier = '') {
457 457
 		$Common = new Common();
458
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
458
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
459 459
 		$check_date = new Datetime($date);
460
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
460
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
461 461
 		$url = "http://www.staralliance.com/flifoQueryAction.do?myAirline=&airlineCode=".$carrier."&flightNo=".$numvol."&day=".$check_date->format('d')."&month=".$check_date->format('m')."&year=".$check_date->format('Y')."&departuredate=".$check_date->format('d-M-Y');
462 462
 		$data = $Common->getData($url);
463 463
 		if ($data != '') {
@@ -466,13 +466,13 @@  discard block
 block discarded – undo
466 466
 				$flight = $table;
467 467
 				//print_r($table);
468 468
 				if (isset($flight[25]) && isset($flight[29])) {
469
-					preg_match('/([A-Z]{3})/',$flight[25][1],$DepartureAirportIataMatch);
470
-					preg_match('/([A-Z]{3})/',$flight[25][3],$ArrivalAirportIataMatch);
469
+					preg_match('/([A-Z]{3})/', $flight[25][1], $DepartureAirportIataMatch);
470
+					preg_match('/([A-Z]{3})/', $flight[25][3], $ArrivalAirportIataMatch);
471 471
 					$DepartureAirportIata = $DepartureAirportIataMatch[0];
472 472
 					$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
473
-					$departureTime = substr(trim(str_replace('Scheduled: ','',$flight[29][0])),0,5);
474
-					$arrivalTime = substr(trim(str_replace('Scheduled: ','',$flight[29][1])),0,5);
475
-					return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_staralliance');
473
+					$departureTime = substr(trim(str_replace('Scheduled: ', '', $flight[29][0])), 0, 5);
474
+					$arrivalTime = substr(trim(str_replace('Scheduled: ', '', $flight[29][1])), 0, 5);
475
+					return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_staralliance');
476 476
 				} else return array();
477 477
 			}
478 478
 			
@@ -490,10 +490,10 @@  discard block
 block discarded – undo
490 490
 	*/
491 491
 	private function getAlitalia($callsign, $date = 'NOW') {
492 492
 		$Common = new Common();
493
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
493
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
494 494
 		$check_date = new Datetime($date);
495
-		$url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y');
496
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
495
+		$url = "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y');
496
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
497 497
 		$data = $Common->getData($url);
498 498
 		if ($data != '') {
499 499
 			$table = $Common->text2array($data);
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
 			$ArrivalAirportIata = '';
502 502
 			$departureTime = $table[4];
503 503
 			$arrivalTime = $table[5];
504
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_alitalia');
504
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_alitalia');
505 505
 		}
506 506
 	}
507 507
 
@@ -513,21 +513,21 @@  discard block
 block discarded – undo
513 513
 	*/
514 514
 	private function getBrussels($callsign, $date = 'NOW') {
515 515
 		$Common = new Common();
516
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
516
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
517 517
 		$check_date = new Datetime($date);
518
-		$url= "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302";
518
+		$url = "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302";
519 519
 		//http://www.brusselsairlines.com/fr-fr/informations-pratiques/statut-de-votre-vol/resultat.aspx?flightnumber=".$numvol."&date=".$check_date->format('d/m/Y')."&lookup=flightnumber";
520
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
520
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
521 521
 		$data = $Common->getData($url);
522 522
 		if ($data != '') {
523 523
 		    //echo $data;
524
-		    $parsed_json = json_decode($data,true);
524
+		    $parsed_json = json_decode($data, true);
525 525
 		    if (isset($parsed_json[0]['FromAirportCode'])) {
526 526
 			$DepartureAirportIata = $parsed_json[0]['FromAirportCode'];
527 527
 			$ArrivalAirportIata = $parsed_json[0]['ToAirportCode'];
528
-			$departureTime = date('H:i',strtotime($parsed_json[0]['ScheduledDepatureDate']));
529
-			$arrivalTime = date('H:i',strtotime($parsed_json[0]['ScheduledArrivalDate']));
530
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_brussels');
528
+			$departureTime = date('H:i', strtotime($parsed_json[0]['ScheduledDepatureDate']));
529
+			$arrivalTime = date('H:i', strtotime($parsed_json[0]['ScheduledArrivalDate']));
530
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_brussels');
531 531
 		    }
532 532
 		}
533 533
 	}
@@ -604,21 +604,21 @@  discard block
 block discarded – undo
604 604
 	*/
605 605
 	private function getFlyTap($callsign) {
606 606
 		$Common = new Common();
607
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
608
-		$url= "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees";
607
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
608
+		$url = "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees";
609 609
 		//$check_date = new Datetime($date);
610
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
611
-		$post = array('arrivalsdepartures_content' => 'number','arrivalsdepartures_tp' => $numvol,'arrivalsdepartures_trk' => 'ARR','arrivalsdepartures_date_trk' => '1','aptCode' => '','arrivalsdepartures' => 'DEP','arrivalsdepartures_date' => '1','aptCodeFrom' => '','aptCodeTo' => '','arrivalsdepartures2' => 'DEP','arrivalsdepartures_date2' => '1');
612
-		$data = $Common->getData($url,'post',$post);
610
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
611
+		$post = array('arrivalsdepartures_content' => 'number', 'arrivalsdepartures_tp' => $numvol, 'arrivalsdepartures_trk' => 'ARR', 'arrivalsdepartures_date_trk' => '1', 'aptCode' => '', 'arrivalsdepartures' => 'DEP', 'arrivalsdepartures_date' => '1', 'aptCodeFrom' => '', 'aptCodeTo' => '', 'arrivalsdepartures2' => 'DEP', 'arrivalsdepartures_date2' => '1');
612
+		$data = $Common->getData($url, 'post', $post);
613 613
 		if ($data != '') {
614 614
 			$table = $Common->table2array($data);
615
-			$departureTime = trim(substr($table[15][0],0,5));
616
-			$arrivalTime = trim(substr($table[35][0],0,5));
617
-			preg_match('/([A-Z]{3})/',$table[11][0],$DepartureAirportIataMatch);
618
-			preg_match('/([A-Z]{3})/',$table[31][0],$ArrivalAirportIataMatch);
615
+			$departureTime = trim(substr($table[15][0], 0, 5));
616
+			$arrivalTime = trim(substr($table[35][0], 0, 5));
617
+			preg_match('/([A-Z]{3})/', $table[11][0], $DepartureAirportIataMatch);
618
+			preg_match('/([A-Z]{3})/', $table[31][0], $ArrivalAirportIataMatch);
619 619
 			$DepartureAirportIata = $DepartureAirportIataMatch[0];
620 620
 			$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
621
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flytap');
621
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_flytap');
622 622
 		}
623 623
 		return array();
624 624
 	}
@@ -640,10 +640,10 @@  discard block
 block discarded – undo
640 640
 			} 
641 641
 		}
642 642
 		if ($airline_icao == '') return array();
643
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
644
-		$url= "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol;
643
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
644
+		$url = "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol;
645 645
 		//$check_date = new Datetime($date);
646
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
646
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
647 647
 		$data = $Common->getData($url);
648 648
 		if ($data != '') {
649 649
 			$table = $Common->table2array($data);
@@ -653,13 +653,13 @@  discard block
 block discarded – undo
653 653
 				$darr = '';
654 654
 				$ahour = '';
655 655
 				$aarr = '';
656
-				$n = sscanf($sched,'%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])',$dhour,$darr,$ahour,$aarr);
656
+				$n = sscanf($sched, '%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])', $dhour, $darr, $ahour, $aarr);
657 657
 				if ($n == 7) {
658 658
 				    $departureTime = $dhour;
659 659
 				    $arrivalTime = $ahour;
660
-				    $DepartureAirportIata = str_replace(array('(',')'),'',$darr);
661
-				    $ArrivalAirportIata = str_replace(array('(',')'),'',$aarr);
662
-				    return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper');
660
+				    $DepartureAirportIata = str_replace(array('(', ')'), '', $darr);
661
+				    $ArrivalAirportIata = str_replace(array('(', ')'), '', $aarr);
662
+				    return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_flightmapper');
663 663
 				}
664 664
 			}
665 665
 		}
@@ -683,20 +683,20 @@  discard block
 block discarded – undo
683 683
 			} 
684 684
 		}
685 685
 		*/
686
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
687
-		$url= "http://fr.flightaware.com/live/flight/".$callsign;
686
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
687
+		$url = "http://fr.flightaware.com/live/flight/".$callsign;
688 688
 		//$check_date = new Datetime($date);
689
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
689
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
690 690
 		$data = $Common->getData($url);
691 691
 		if ($data != '') {
692 692
 			$table = $Common->table2array($data);
693 693
 			if (isset($table[11][0])) {
694
-				$departureTime = str_replace('h',':',substr($table[5][0],0,5));
695
-				$arrivalTime = str_replace('h',':',substr($table[5][1],0,5));
694
+				$departureTime = str_replace('h', ':', substr($table[5][0], 0, 5));
695
+				$arrivalTime = str_replace('h', ':', substr($table[5][1], 0, 5));
696 696
 				echo $table[3][0];
697
-				sscanf($table[3][0],'%*[^(] (%3[A-Z] / %*4[A-Z])',$DepartureAirportIata);
698
-				sscanf($table[3][1],'%*[^(] (%3[A-Z] / %*4[A-Z])',$ArrivalAirportIata);
699
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightaware');
697
+				sscanf($table[3][0], '%*[^(] (%3[A-Z] / %*4[A-Z])', $DepartureAirportIata);
698
+				sscanf($table[3][1], '%*[^(] (%3[A-Z] / %*4[A-Z])', $ArrivalAirportIata);
699
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_flightaware');
700 700
 			}
701 701
 		}
702 702
 		return array();
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
 	*/
710 710
 	public function getCostToTravel($callsign) {
711 711
 		$Common = new Common();
712
-		$url= "http://www.costtotravel.com/flight-number/".$callsign;
712
+		$url = "http://www.costtotravel.com/flight-number/".$callsign;
713 713
 		//$check_date = new Datetime($date);
714 714
 		//if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
715 715
 		$data = $Common->getData($url);
@@ -717,11 +717,11 @@  discard block
 block discarded – undo
717 717
 			$table = $Common->table2array($data);
718 718
 			//print_r($table);
719 719
 			if (isset($table[11][1])) {
720
-				$departureTime = substr($table[11][1],0,5);
721
-				$arrivalTime = substr($table[17][1],0,5);
722
-				$DepartureAirportIata = substr($table[13][1],0,3);
723
-				$ArrivalAirportIata = substr($table[15][1],0,3);
724
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_costtotravel');
720
+				$departureTime = substr($table[11][1], 0, 5);
721
+				$arrivalTime = substr($table[17][1], 0, 5);
722
+				$DepartureAirportIata = substr($table[13][1], 0, 3);
723
+				$ArrivalAirportIata = substr($table[15][1], 0, 3);
724
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_costtotravel');
725 725
 			}
726 726
 		}
727 727
 		return array();
@@ -733,13 +733,13 @@  discard block
 block discarded – undo
733 733
 	* @param String $date date we want flight number info
734 734
 	* @return Flight departure and arrival airports and time
735 735
 	*/
736
-	private function getAirCanada($callsign,$date = 'NOW') {
736
+	private function getAirCanada($callsign, $date = 'NOW') {
737 737
 		$Common = new Common();
738 738
 		date_default_timezone_set('UTC');
739 739
 		$check_date = new Datetime($date);
740
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
741
-		$url= "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249";
742
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
740
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
741
+		$url = "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249";
742
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
743 743
 		$data = $Common->getData($url);
744 744
 		$dom = new DomDocument();
745 745
 		$dom->loadXML($data);
@@ -747,11 +747,11 @@  discard block
 block discarded – undo
747 747
 		$departure = $dom->getElementsByTagName('DepartureStationInfo')->item(0);
748 748
 		if (isset($departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue)) {
749 749
 			$DepartureAirportIata = $departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
750
-			$departureTime = date('H:i',strtotime($departure->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
750
+			$departureTime = date('H:i', strtotime($departure->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
751 751
 			$arrival = $dom->getElementsByTagName('ArrivalStationInfo')->item(0);
752 752
 			$ArrivalAirportIata = $arrival->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
753
-			$arrivalTime = date('H:i',strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
754
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_aircanada');
753
+			$arrivalTime = date('H:i', strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
754
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_aircanada');
755 755
 		} else return array();
756 756
 	}
757 757
 
@@ -763,21 +763,21 @@  discard block
 block discarded – undo
763 763
 	*/
764 764
 	private function getVietnamAirlines($callsign, $date = 'NOW') {
765 765
 		$Common = new Common();
766
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
766
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
767 767
 		$check_date = new Datetime($date);
768
-		$url= "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&";
769
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
768
+		$url = "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&";
769
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
770 770
 		$data = $Common->getData($url);
771 771
 		if ($data != '') {
772 772
 			$table = $Common->table2array($data);
773 773
 			$flight = $table;
774
-			preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch);
775
-			preg_match('/([A-Z]{3})/',$flight[21][0],$ArrivalAirportIataMatch);
774
+			preg_match('/([A-Z]{3})/', $flight[3][0], $DepartureAirportIataMatch);
775
+			preg_match('/([A-Z]{3})/', $flight[21][0], $ArrivalAirportIataMatch);
776 776
 			$DepartureAirportIata = $DepartureAirportIataMatch[0];
777 777
 			$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
778 778
 			$departureTime = $flight[5][1];
779 779
 			$arrivalTime = $flight[23][1];
780
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_vietnamairlines');
780
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_vietnamairlines');
781 781
 		}
782 782
 	}
783 783
 
@@ -788,16 +788,16 @@  discard block
 block discarded – undo
788 788
 	* @param String $carrier airline code
789 789
 	* @return Flight departure and arrival airports and time
790 790
 	*/
791
-	private function getAirBerlin($callsign, $date = 'NOW',$carrier = 'AB') {
791
+	private function getAirBerlin($callsign, $date = 'NOW', $carrier = 'AB') {
792 792
 		$Common = new Common();
793 793
 		date_default_timezone_set('UTC');
794 794
 		//AB = airberlin, HG/NLY = NIKI, 4T/BHP = Belair 
795
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
795
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
796 796
 		$check_date = new Datetime($date);
797
-		$url= "http://www.airberlin.com/en-US/site/aims.php";
798
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
799
-		$post = array('type' => 'departure','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => $carrier);
800
-		$data = $Common->getData($url,'post',$post);
797
+		$url = "http://www.airberlin.com/en-US/site/aims.php";
798
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
799
+		$post = array('type' => 'departure', 'searchFlightNo' => '1', 'requestsent' => 'true', 'flightno' => $numvol, 'date' => $check_date->format('Y-m-d'), 'carrier' => $carrier);
800
+		$data = $Common->getData($url, 'post', $post);
801 801
 		//echo $data;
802 802
 		$DepartureAirportIata = '';
803 803
 		$ArrivalAirportIata = '';
@@ -810,8 +810,8 @@  discard block
 block discarded – undo
810 810
 			if (isset($flight[5][2])) $departureAirport = $flight[5][2];
811 811
 			else $departureAirport = '';
812 812
 		} else return array();
813
-		$post = array('type' => 'arrival','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB');
814
-		$data = $Common->getData($url,'post',$post);
813
+		$post = array('type' => 'arrival', 'searchFlightNo' => '1', 'requestsent' => 'true', 'flightno' => $numvol, 'date' => $check_date->format('Y-m-d'), 'carrier' => 'AB');
814
+		$data = $Common->getData($url, 'post', $post);
815 815
 		if ($data != '') {
816 816
 			$table = $Common->table2array($data);
817 817
 			$flight = $table;
@@ -839,13 +839,13 @@  discard block
 block discarded – undo
839 839
 			}
840 840
 		}
841 841
 		if (isset($DepartureAirportIata)) {
842
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airberlin');
842
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_airberlin');
843 843
 		} else return array();
844 844
 	}
845 845
 
846 846
 
847 847
 	
848
-	public function fetchSchedule($ident,$date = 'NOW') {
848
+	public function fetchSchedule($ident, $date = 'NOW') {
849 849
 		global $globalSchedulesSources, $globalSchedulesFetch;
850 850
 		//$Common = new Common();
851 851
 		if (!$globalSchedulesFetch) return array();
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
 				// Brussels Airlines
916 916
 				case "BEL":
917 917
 				case "SN":
918
-					return $this->getBrussels($ident,$date);
918
+					return $this->getBrussels($ident, $date);
919 919
 /*
920 920
 				// Copa Airlines
921 921
 				case "CMP":
@@ -1000,17 +1000,17 @@  discard block
 block discarded – undo
1000 1000
 				// Air France
1001 1001
 				case "AF":
1002 1002
 				case "AFR":
1003
-					return $this->getAirFrance($ident,$date,'AF');
1003
+					return $this->getAirFrance($ident, $date, 'AF');
1004 1004
 				// HOP
1005 1005
 				case "A5":
1006 1006
 				case "HOP":
1007
-					return $this->getAirFrance($ident,$date,'A5');
1007
+					return $this->getAirFrance($ident, $date, 'A5');
1008 1008
 				// EasyJet
1009 1009
 				case "U2":
1010 1010
 				case "DS":
1011 1011
 				case "EZY":
1012 1012
 				case "EZS":
1013
-					return $this->getEasyJet($ident,$date);
1013
+					return $this->getEasyJet($ident, $date);
1014 1014
 				// Ryanair
1015 1015
 				case "FR":
1016 1016
 				case "RYR":
@@ -1060,25 +1060,25 @@  discard block
 block discarded – undo
1060 1060
 					return $this->getIberia($ident);
1061 1061
 				// Vietnam Airlines
1062 1062
 				case "HVN":
1063
-					return $this->getVietnamAirlines($ident,$date);
1063
+					return $this->getVietnamAirlines($ident, $date);
1064 1064
 				// Air Berlin
1065 1065
 				case "AB":
1066 1066
 				case "BER":
1067
-					return $this->getAirBerlin($ident,$date,'AB');
1067
+					return $this->getAirBerlin($ident, $date, 'AB');
1068 1068
 				// NIKI
1069 1069
 				case "HG":
1070 1070
 				case "NLY":
1071
-					return $this->getAirBerlin($ident,$date,'HG');
1071
+					return $this->getAirBerlin($ident, $date, 'HG');
1072 1072
 				// BelAir
1073 1073
 				case "4T":
1074 1074
 				case "BHP":
1075
-					return $this->getAirBerlin($ident,$date,'4T');
1075
+					return $this->getAirBerlin($ident, $date, '4T');
1076 1076
 				default:
1077 1077
 					// Randomly use a generic function to get hours
1078 1078
 					if (strlen($airline_icao) == 2) {
1079
-						if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware');
1079
+						if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper', 'costtotravel', 'flightradar24', 'flightaware');
1080 1080
 						if (count($globalSchedulesSources) > 0) {
1081
-							$rand = mt_rand(0,count($globalSchedulesSources)-1);
1081
+							$rand = mt_rand(0, count($globalSchedulesSources) - 1);
1082 1082
 							$source = $globalSchedulesSources[$rand];
1083 1083
 							if ($source == 'flightmapper') return $this->getFlightMapper($ident);
1084 1084
 							elseif ($source == 'costtotravel') return $this->getCostToTravel($ident);
Please login to merge, or discard this patch.
Braces   +164 added lines, -56 removed lines patch added patch discarded remove patch
@@ -123,7 +123,9 @@  discard block
 block discarded – undo
123 123
 		$sth->closeCursor();
124 124
 		if (count($row) > 0) {
125 125
 			return $row;
126
-		} else return array();
126
+		} else {
127
+			return array();
128
+		}
127 129
 	}
128 130
 
129 131
 	public function checkSchedule($ident) {
@@ -159,7 +161,9 @@  discard block
 block discarded – undo
159 161
 		$Common = new Common();
160 162
 		$check_date = new Datetime($date);
161 163
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
162
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
164
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
165
+			return array();
166
+		}
163 167
 		$url = "http://www.airfrance.fr/cgi-bin/AF/FR/fr/local/resainfovol/infovols/detailsVolJson.do?codeCompagnie[0]=".$carrier."&numeroVol[0]=".$numvol."&dayFlightDate=".$check_date->format('d')."&yearMonthFlightDate=".$check_date->format('Ym');
164 168
 		$json = $Common->getData($url);
165 169
 	
@@ -186,7 +190,9 @@  discard block
 block discarded – undo
186 190
 			*/
187 191
 		
188 192
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airfrance');
189
-		} else return array();
193
+		} else {
194
+			return array();
195
+		}
190 196
 	}
191 197
 
192 198
 	/**
@@ -201,7 +207,9 @@  discard block
 block discarded – undo
201 207
 		date_default_timezone_set($globalTimezone);
202 208
 		$check_date = new Datetime($date);
203 209
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
204
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
210
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
211
+			return array();
212
+		}
205 213
 		$url = "http://www.easyjet.com/ft/api/flights?date=".$check_date->format('Y-m-d')."&fn=".$callsign;
206 214
 		$json = $Common->getData($url);
207 215
 		$parsed_json = json_decode($json);
@@ -214,7 +222,9 @@  discard block
 block discarded – undo
214 222
 			$arrivalTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fsta'};
215 223
 
216 224
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_easyjet');
217
-		} else return array();
225
+		} else {
226
+			return array();
227
+		}
218 228
 	}
219 229
 
220 230
 	/**
@@ -225,7 +235,9 @@  discard block
 block discarded – undo
225 235
 	private function getRyanair($callsign) {
226 236
 		$Common = new Common();
227 237
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
228
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
238
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
239
+			return array();
240
+		}
229 241
 		$url = "http://www.ryanair.com/fr/api/2/flight-info/0/50/";
230 242
 		$post = '{"flight":"'.$numvol.'","minDepartureTime":"00:00","maxDepartureTime":"23:59"}';
231 243
 		$headers = array('Content-Type: application/json','Content-Length: ' . strlen($post));
@@ -239,8 +251,12 @@  discard block
 block discarded – undo
239 251
 				$departureTime = $parsed_json->{'flightInfo'}[0]->{'departureTime'};
240 252
 				$arrivalTime = $parsed_json->{'flightInfo'}[0]->{'arrivalTime'};
241 253
 				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair');
242
-			} else return array();
243
-		} else return array();
254
+			} else {
255
+				return array();
256
+			}
257
+		} else {
258
+			return array();
259
+		}
244 260
 	}
245 261
 
246 262
 	/**
@@ -251,7 +267,9 @@  discard block
 block discarded – undo
251 267
 	private function getSwiss($callsign) {
252 268
 		$Common = new Common();
253 269
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
254
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
270
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
271
+			return array();
272
+		}
255 273
 		$url = "http://www.world-of-swiss.com/fr/routenetwork.json";
256 274
 		$json = $Common->getData($url);
257 275
 		$parsed_json = json_decode($json);
@@ -271,8 +289,12 @@  discard block
 block discarded – undo
271 289
 			}
272 290
 			if (isset($DepartureAirportIata) && isset($ArrivalAirportIata)) {
273 291
 				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_swiss');
274
-			} else return array();
275
-		} else return array();
292
+			} else {
293
+				return array();
294
+			}
295
+		} else {
296
+			return array();
297
+		}
276 298
 	}
277 299
 	
278 300
 	/**
@@ -286,12 +308,18 @@  discard block
 block discarded – undo
286 308
 		$Common = new Common();
287 309
 		$check_date = new Datetime($date);
288 310
 		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
289
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
290
-		if ($globalBritishAirwaysKey == '') return array();
311
+		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) {
312
+			return array();
313
+		}
314
+		if ($globalBritishAirwaysKey == '') {
315
+			return array();
316
+		}
291 317
 		$url = "https://api.ba.com/rest-v1/v1/flights;flightNumber=".$numvol.";scheduledDepartureDate=".$check_date->format('Y-m-d').".json";
292 318
 		$headers = array('Client-Key: '.$globalBritishAirwaysKey);
293 319
 		$json = $Common->getData($url,'get','',$headers);
294
-		if ($json == '') return array();
320
+		if ($json == '') {
321
+			return array();
322
+		}
295 323
 		$parsed_json = json_decode($json);
296 324
 		$flights = $parsed_json->{'FlightsResponse'};
297 325
 		if (count($flights) > 0) {
@@ -300,7 +328,9 @@  discard block
 block discarded – undo
300 328
 			$departureTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'}));
301 329
 			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'}));
302 330
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_britishairways');
303
-		} else return array();
331
+		} else {
332
+			return array();
333
+		}
304 334
 	}
305 335
 
306 336
 	/**
@@ -314,19 +344,27 @@  discard block
 block discarded – undo
314 344
 		$Common = new Common();
315 345
 		$check_date = new Datetime($date);
316 346
 		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
317
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
318
-		if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') return array();
347
+		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) {
348
+			return array();
349
+		}
350
+		if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') {
351
+			return array();
352
+		}
319 353
 		$url = "https://api.lufthansa.com/v1/oauth/token";
320 354
 		$post = array('client_id' => $globalLufthansaKey['key'],'client_secret' => $globalLufthansaKey['secret'],'grant_type' => 'client_credentials');
321 355
 		$data = $Common->getData($url,'post',$post);
322 356
 		$parsed_data = json_decode($data);
323
-		if (!isset($parsed_data->{'access_token'})) return array();
357
+		if (!isset($parsed_data->{'access_token'})) {
358
+			return array();
359
+		}
324 360
 		$token = $parsed_data->{'access_token'};
325 361
 		
326 362
 		$url = "https://api.lufthansa.com/v1/operations/flightstatus/LH".$numvol."/".$check_date->format('Y-m-d');
327 363
 		$headers = array('Authorization: Bearer '.$token,'Accept: application/json');
328 364
 		$json = $Common->getData($url,'get','',$headers);
329
-		if ($json == '') return array();
365
+		if ($json == '') {
366
+			return array();
367
+		}
330 368
 		$parsed_json = json_decode($json);
331 369
 		if (isset($parsed_json->{'FlightStatusResource'}) && count($parsed_json->{'FlightStatusResource'}) > 0) {
332 370
 			$DepartureAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'AirportCode'};
@@ -334,7 +372,9 @@  discard block
 block discarded – undo
334 372
 			$ArrivalAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'AirportCode'};
335 373
 			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'}));
336 374
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa');
337
-		} else return array();
375
+		} else {
376
+			return array();
377
+		}
338 378
 	}
339 379
 
340 380
 	/**
@@ -348,14 +388,20 @@  discard block
 block discarded – undo
348 388
 		$Common = new Common();
349 389
 		$check_date = new Datetime($date);
350 390
 		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
351
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
352
-		if ($globalTransaviaKey == '') return array();
391
+		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) {
392
+			return array();
393
+		}
394
+		if ($globalTransaviaKey == '') {
395
+			return array();
396
+		}
353 397
 		$url = "https://tst.api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
354 398
 		//$url = "https://api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
355 399
 		$headers = array('apikey: '.$globalTransaviaKey);
356 400
 		$json = $Common->getData($url,'get','',$headers);
357 401
 		//echo 'result : '.$json;
358
-		if ($json == '') return array();
402
+		if ($json == '') {
403
+			return array();
404
+		}
359 405
 		$parsed_json = json_decode($json);
360 406
 		
361 407
 		if (isset($parsed_json->{'data'}[0])) {
@@ -364,7 +410,9 @@  discard block
 block discarded – undo
364 410
 			$ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'};
365 411
 			$arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'}));
366 412
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia');
367
-		} else return array();
413
+		} else {
414
+			return array();
415
+		}
368 416
 	}
369 417
 
370 418
 	/**
@@ -375,7 +423,9 @@  discard block
 block discarded – undo
375 423
 	public function getTunisair($callsign) {
376 424
 		$Common = new Common();
377 425
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
378
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
426
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
427
+			return array();
428
+		}
379 429
 		$url = "http://www.tunisair.com/site/publish/module/Volj/fr/Flight_List.asp";
380 430
 		$data = $Common->getData($url);
381 431
 		$table = $Common->table2array($data);
@@ -396,7 +446,9 @@  discard block
 block discarded – undo
396 446
 		$Common = new Common();
397 447
 		$check_date = new Datetime($date);
398 448
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
399
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
449
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
450
+			return array();
451
+		}
400 452
 		$final_date = str_replace('/','%2F',$check_date->format('d/m/Y'));
401 453
 		$url = "http://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=FlightStatusResult&searchBy=bycode&date=".$final_date."&flightNumber=".$numvol."&idioma=en-GB";
402 454
 		$data = $Common->getData($url);
@@ -406,8 +458,11 @@  discard block
 block discarded – undo
406 458
 			$DepartureAirportIata = str_replace('flightOri=','',$result[0]);
407 459
 			preg_match('/flightDest=[A-Z]{3}/',$data,$result);
408 460
 			$ArrivalAirportIata = str_replace('flightDest=','',$result[0]);
409
-			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling');
410
-			else return array();
461
+			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') {
462
+				return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling');
463
+			} else {
464
+				return array();
465
+			}
411 466
 		}
412 467
 		return array();
413 468
 	}
@@ -422,7 +477,9 @@  discard block
 block discarded – undo
422 477
 		$Common = new Common();
423 478
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
424 479
 		$check_date = new Datetime($date);
425
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
480
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
481
+			return array();
482
+		}
426 483
 		$url = "https://www.iberia.com/web/flightDetail.do";
427 484
 		$post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB');
428 485
 		$data = $Common->getData($url,'post',$post);
@@ -439,7 +496,9 @@  discard block
 block discarded – undo
439 496
 				$arrivalTime = trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][1])));
440 497
 				if ($arrivalTime == 'Hora estimada de llegada') {
441 498
 					$arrivalTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][2]))),0,5);
442
-				} else $arrivalTime = substr($arrivalTime,0,5);
499
+				} else {
500
+					$arrivalTime = substr($arrivalTime,0,5);
501
+				}
443 502
 				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia');
444 503
 			}
445 504
 		}
@@ -457,7 +516,9 @@  discard block
 block discarded – undo
457 516
 		$Common = new Common();
458 517
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
459 518
 		$check_date = new Datetime($date);
460
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
519
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
520
+			return array();
521
+		}
461 522
 		$url = "http://www.staralliance.com/flifoQueryAction.do?myAirline=&airlineCode=".$carrier."&flightNo=".$numvol."&day=".$check_date->format('d')."&month=".$check_date->format('m')."&year=".$check_date->format('Y')."&departuredate=".$check_date->format('d-M-Y');
462 523
 		$data = $Common->getData($url);
463 524
 		if ($data != '') {
@@ -473,7 +534,9 @@  discard block
 block discarded – undo
473 534
 					$departureTime = substr(trim(str_replace('Scheduled: ','',$flight[29][0])),0,5);
474 535
 					$arrivalTime = substr(trim(str_replace('Scheduled: ','',$flight[29][1])),0,5);
475 536
 					return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_staralliance');
476
-				} else return array();
537
+				} else {
538
+					return array();
539
+				}
477 540
 			}
478 541
 			
479 542
 
@@ -493,7 +556,9 @@  discard block
 block discarded – undo
493 556
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
494 557
 		$check_date = new Datetime($date);
495 558
 		$url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y');
496
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
559
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
560
+			return array();
561
+		}
497 562
 		$data = $Common->getData($url);
498 563
 		if ($data != '') {
499 564
 			$table = $Common->text2array($data);
@@ -517,7 +582,9 @@  discard block
 block discarded – undo
517 582
 		$check_date = new Datetime($date);
518 583
 		$url= "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302";
519 584
 		//http://www.brusselsairlines.com/fr-fr/informations-pratiques/statut-de-votre-vol/resultat.aspx?flightnumber=".$numvol."&date=".$check_date->format('d/m/Y')."&lookup=flightnumber";
520
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
585
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
586
+			return array();
587
+		}
521 588
 		$data = $Common->getData($url);
522 589
 		if ($data != '') {
523 590
 		    //echo $data;
@@ -607,7 +674,9 @@  discard block
 block discarded – undo
607 674
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
608 675
 		$url= "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees";
609 676
 		//$check_date = new Datetime($date);
610
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
677
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
678
+			return array();
679
+		}
611 680
 		$post = array('arrivalsdepartures_content' => 'number','arrivalsdepartures_tp' => $numvol,'arrivalsdepartures_trk' => 'ARR','arrivalsdepartures_date_trk' => '1','aptCode' => '','arrivalsdepartures' => 'DEP','arrivalsdepartures_date' => '1','aptCodeFrom' => '','aptCodeTo' => '','arrivalsdepartures2' => 'DEP','arrivalsdepartures_date2' => '1');
612 681
 		$data = $Common->getData($url,'post',$post);
613 682
 		if ($data != '') {
@@ -639,11 +708,15 @@  discard block
 block discarded – undo
639 708
 				$airline_icao = substr($callsign, 0, 3);
640 709
 			} 
641 710
 		}
642
-		if ($airline_icao == '') return array();
711
+		if ($airline_icao == '') {
712
+			return array();
713
+		}
643 714
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
644 715
 		$url= "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol;
645 716
 		//$check_date = new Datetime($date);
646
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
717
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
718
+			return array();
719
+		}
647 720
 		$data = $Common->getData($url);
648 721
 		if ($data != '') {
649 722
 			$table = $Common->table2array($data);
@@ -686,7 +759,9 @@  discard block
 block discarded – undo
686 759
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
687 760
 		$url= "http://fr.flightaware.com/live/flight/".$callsign;
688 761
 		//$check_date = new Datetime($date);
689
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
762
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
763
+			return array();
764
+		}
690 765
 		$data = $Common->getData($url);
691 766
 		if ($data != '') {
692 767
 			$table = $Common->table2array($data);
@@ -739,11 +814,15 @@  discard block
 block discarded – undo
739 814
 		$check_date = new Datetime($date);
740 815
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
741 816
 		$url= "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249";
742
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
817
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
818
+			return array();
819
+		}
743 820
 		$data = $Common->getData($url);
744 821
 		$dom = new DomDocument();
745 822
 		$dom->loadXML($data);
746
-		if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) return array();
823
+		if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) {
824
+			return array();
825
+		}
747 826
 		$departure = $dom->getElementsByTagName('DepartureStationInfo')->item(0);
748 827
 		if (isset($departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue)) {
749 828
 			$DepartureAirportIata = $departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
@@ -752,7 +831,9 @@  discard block
 block discarded – undo
752 831
 			$ArrivalAirportIata = $arrival->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
753 832
 			$arrivalTime = date('H:i',strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
754 833
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_aircanada');
755
-		} else return array();
834
+		} else {
835
+			return array();
836
+		}
756 837
 	}
757 838
 
758 839
 	/**
@@ -766,7 +847,9 @@  discard block
 block discarded – undo
766 847
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
767 848
 		$check_date = new Datetime($date);
768 849
 		$url= "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&";
769
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
850
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
851
+			return array();
852
+		}
770 853
 		$data = $Common->getData($url);
771 854
 		if ($data != '') {
772 855
 			$table = $Common->table2array($data);
@@ -795,7 +878,9 @@  discard block
 block discarded – undo
795 878
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
796 879
 		$check_date = new Datetime($date);
797 880
 		$url= "http://www.airberlin.com/en-US/site/aims.php";
798
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
881
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
882
+			return array();
883
+		}
799 884
 		$post = array('type' => 'departure','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => $carrier);
800 885
 		$data = $Common->getData($url,'post',$post);
801 886
 		//echo $data;
@@ -805,11 +890,19 @@  discard block
 block discarded – undo
805 890
 		if ($data != '') {
806 891
 			$table = $Common->table2array($data);
807 892
 			$flight = $table;
808
-			if (isset($flight[5][4])) $departureTime = $flight[5][4];
809
-			else $departureTime = '';
810
-			if (isset($flight[5][2])) $departureAirport = $flight[5][2];
811
-			else $departureAirport = '';
812
-		} else return array();
893
+			if (isset($flight[5][4])) {
894
+				$departureTime = $flight[5][4];
895
+			} else {
896
+				$departureTime = '';
897
+			}
898
+			if (isset($flight[5][2])) {
899
+				$departureAirport = $flight[5][2];
900
+			} else {
901
+				$departureAirport = '';
902
+			}
903
+		} else {
904
+			return array();
905
+		}
813 906
 		$post = array('type' => 'arrival','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB');
814 907
 		$data = $Common->getData($url,'post',$post);
815 908
 		if ($data != '') {
@@ -822,10 +915,14 @@  discard block
 block discarded – undo
822 915
 			    $arrivalTime = '';
823 916
 			    $arrivalAirport = '';
824 917
 			}
825
-		} else return array();
918
+		} else {
919
+			return array();
920
+		}
826 921
 		$url = 'http://www.airberlin.com/en-US/site/json/suggestAirport.php?searchfor=departures&searchflightid=0&departures%5B%5D=&suggestsource%5B0%5D=activeairports&withcountries=0&withoutroutings=0&promotion%5Bid%5D=&promotion%5Btype%5D=&routesource%5B0%5D=airberlin&routesource%5B1%5D=partner';
827 922
 		$json = $Common->getData($url);
828
-		if ($json == '') return array();
923
+		if ($json == '') {
924
+			return array();
925
+		}
829 926
 		$parsed_json = json_decode($json);
830 927
 		$airports = $parsed_json->{'suggestList'};
831 928
 		if (count($airports) > 0) {
@@ -840,7 +937,9 @@  discard block
 block discarded – undo
840 937
 		}
841 938
 		if (isset($DepartureAirportIata)) {
842 939
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airberlin');
843
-		} else return array();
940
+		} else {
941
+			return array();
942
+		}
844 943
 	}
845 944
 
846 945
 
@@ -848,7 +947,9 @@  discard block
 block discarded – undo
848 947
 	public function fetchSchedule($ident,$date = 'NOW') {
849 948
 		global $globalSchedulesSources, $globalSchedulesFetch;
850 949
 		//$Common = new Common();
851
-		if (!$globalSchedulesFetch) return array();
950
+		if (!$globalSchedulesFetch) {
951
+			return array();
952
+		}
852 953
 		$airline_icao = '';
853 954
 		if (!is_numeric(substr($ident, 0, 3)))
854 955
 		{
@@ -1076,14 +1177,21 @@  discard block
 block discarded – undo
1076 1177
 				default:
1077 1178
 					// Randomly use a generic function to get hours
1078 1179
 					if (strlen($airline_icao) == 2) {
1079
-						if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware');
1180
+						if (!isset($globalSchedulesSources)) {
1181
+							$globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware');
1182
+						}
1080 1183
 						if (count($globalSchedulesSources) > 0) {
1081 1184
 							$rand = mt_rand(0,count($globalSchedulesSources)-1);
1082 1185
 							$source = $globalSchedulesSources[$rand];
1083
-							if ($source == 'flightmapper') return $this->getFlightMapper($ident);
1084
-							elseif ($source == 'costtotravel') return $this->getCostToTravel($ident);
1186
+							if ($source == 'flightmapper') {
1187
+								return $this->getFlightMapper($ident);
1188
+							} elseif ($source == 'costtotravel') {
1189
+								return $this->getCostToTravel($ident);
1190
+							}
1085 1191
 							//elseif ($source == 'flightradar24') return $this->getFlightRadar24($ident,$date);
1086
-							elseif ($source == 'flightaware') return $this->getFlightAware($ident);
1192
+							elseif ($source == 'flightaware') {
1193
+								return $this->getFlightAware($ident);
1194
+							}
1087 1195
 						}
1088 1196
 					}
1089 1197
 			}
Please login to merge, or discard this patch.
accident.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-$date = filter_input(INPUT_POST,'date',FILTER_SANITIZE_STRING);
2
+$date = filter_input(INPUT_POST, 'date', FILTER_SANITIZE_STRING);
3 3
 if ($date == '') $date = date('Y-m-d');
4 4
 header('Location: '.$globalURL.'/accident/'.$date);
5 5
 ?>
6 6
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 $date = filter_input(INPUT_POST,'date',FILTER_SANITIZE_STRING);
3
-if ($date == '') $date = date('Y-m-d');
3
+if ($date == '') {
4
+	$date = date('Y-m-d');
5
+}
4 6
 header('Location: '.$globalURL.'/accident/'.$date);
5 7
 ?>
6 8
\ No newline at end of file
Please login to merge, or discard this patch.