Completed
Push — master ( c7884b...e258db )
by Yannick
36:25
created
require/class.SpotterArchive.php 1 patch
Spacing   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -14,75 +14,75 @@  discard block
 block discarded – undo
14 14
 	* @param Array $filter the filter
15 15
 	* @return Array the SQL part
16 16
 	*/
17
-	public function getFilter($filter = array(),$where = false,$and = false) {
17
+	public function getFilter($filter = array(), $where = false, $and = false) {
18 18
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
19 19
 		$filters = array();
20 20
 		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) {
21 21
 			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) {
22 22
 				$filters = $globalStatsFilters[$globalFilterName];
23 23
 			} else {
24
-				$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]);
24
+				$filter = array_merge($filter, $globalStatsFilters[$globalFilterName]);
25 25
 			}
26 26
 		}
27 27
 		if (isset($filter[0]['source'])) {
28
-			$filters = array_merge($filters,$filter);
28
+			$filters = array_merge($filters, $filter);
29 29
 		}
30
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
30
+		if (is_array($globalFilter)) $filter = array_merge($filter, $globalFilter);
31 31
 		$filter_query_join = '';
32 32
 		$filter_query_where = '';
33
-		foreach($filters as $flt) {
33
+		foreach ($filters as $flt) {
34 34
 			if (isset($flt['airlines']) && !empty($flt['airlines'])) {
35 35
 				if ($flt['airlines'][0] != '' && $flt['airlines'][0] != 'all') {
36 36
 					if (isset($flt['source'])) {
37
-						$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$flt['airlines'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) saff ON saff.flightaware_id = spotter_archive_output.flightaware_id";
37
+						$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','", $flt['airlines'])."') AND spotter_archive_output.format_source IN ('".implode("','", $flt['source'])."')) saff ON saff.flightaware_id = spotter_archive_output.flightaware_id";
38 38
 					} else {
39
-						$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$flt['airlines'])."')) saff ON saff.flightaware_id = spotter_archive_output.flightaware_id";
39
+						$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','", $flt['airlines'])."')) saff ON saff.flightaware_id = spotter_archive_output.flightaware_id";
40 40
 					}
41 41
 				}
42 42
 			}
43 43
 			if (isset($flt['pilots_id']) && !empty($flt['pilots_id'])) {
44 44
 				if (isset($flt['source'])) {
45
-					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) sp ON sp.flightaware_id = spotter_archive_output.flightaware_id";
45
+					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.pilot_id IN ('".implode("','", $flt['pilots_id'])."') AND spotter_archive_output.format_source IN ('".implode("','", $flt['source'])."')) sp ON sp.flightaware_id = spotter_archive_output.flightaware_id";
46 46
 				} else {
47
-					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."')) sp ON sp.flightaware_id = spotter_archive_output.flightaware_id";
47
+					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.pilot_id IN ('".implode("','", $flt['pilots_id'])."')) sp ON sp.flightaware_id = spotter_archive_output.flightaware_id";
48 48
 				}
49 49
 			}
50 50
 			if (isset($flt['idents']) && !empty($flt['idents'])) {
51 51
 				if (isset($flt['source'])) {
52
-					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.ident IN ('".implode("','",$flt['idents'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) spi ON spi.flightaware_id = spotter_archive_output.flightaware_id";
52
+					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.ident IN ('".implode("','", $flt['idents'])."') AND spotter_archive_output.format_source IN ('".implode("','", $flt['source'])."')) spi ON spi.flightaware_id = spotter_archive_output.flightaware_id";
53 53
 				} else {
54
-					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.ident IN ('".implode("','",$flt['idents'])."')) spi ON spi.flightaware_id = spotter_archive_output.flightaware_id";
54
+					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.ident IN ('".implode("','", $flt['idents'])."')) spi ON spi.flightaware_id = spotter_archive_output.flightaware_id";
55 55
 				}
56 56
 			}
57 57
 			if (isset($flt['registrations']) && !empty($flt['registrations'])) {
58 58
 				if (isset($flt['source'])) {
59
-					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.registration IN ('".implode("','",$flt['registrations'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) sre ON sre.flightaware_id = spotter_archive_output.flightaware_id";
59
+					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.registration IN ('".implode("','", $flt['registrations'])."') AND spotter_archive_output.format_source IN ('".implode("','", $flt['source'])."')) sre ON sre.flightaware_id = spotter_archive_output.flightaware_id";
60 60
 				} else {
61
-					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.registration IN ('".implode("','",$flt['registrations'])."')) sre ON sre.flightaware_id = spotter_archive_output.flightaware_id";
61
+					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.registration IN ('".implode("','", $flt['registrations'])."')) sre ON sre.flightaware_id = spotter_archive_output.flightaware_id";
62 62
 				}
63 63
 			}
64 64
 			if ((isset($flt['airlines']) && empty($flt['airlines']) && isset($flt['pilots_id']) && empty($flt['pilots_id']) && isset($flt['idents']) && empty($flt['idents']) && isset($flt['registrations']) && empty($flt['registrations'])) || (!isset($flt['airlines']) && !isset($flt['pilots_id']) && !isset($flt['idents']) && !isset($flt['registrations']))) {
65 65
 				if (isset($flt['source'])) {
66
-					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_output.format_source IN ('".implode("','",$flt['source'])."')) saa ON saa.flightaware_id = spotter_archive_output.flightaware_id";
66
+					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_output.format_source IN ('".implode("','", $flt['source'])."')) saa ON saa.flightaware_id = spotter_archive_output.flightaware_id";
67 67
 				}
68 68
 			}
69 69
 		}
70 70
 		if (isset($filter['airlines']) && !empty($filter['airlines'])) {
71 71
 			if ($filter['airlines'][0] != '' && $filter['airlines'][0] != 'all') {
72
-				$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) saf ON saf.flightaware_id = spotter_archive_output.flightaware_id";
72
+				$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','", $filter['airlines'])."')) saf ON saf.flightaware_id = spotter_archive_output.flightaware_id";
73 73
 			}
74 74
 		}
75 75
 		if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
76 76
 			$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_archive_output.flightaware_id ";
77 77
 		}
78 78
 		if (isset($filter['pilots_id']) && !empty($filter['pilots_id'])) {
79
-			$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.pilot_id IN ('".implode("','",$filter['pilots_id'])."')) spi ON spi.flightaware_id = spotter_archive_output.flightaware_id";
79
+			$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.pilot_id IN ('".implode("','", $filter['pilots_id'])."')) spi ON spi.flightaware_id = spotter_archive_output.flightaware_id";
80 80
 		}
81 81
 		if (isset($filter['source']) && !empty($filter['source'])) {
82 82
 			if (count($filter['source']) == 1) {
83 83
 				$filter_query_where .= " AND format_source = '".$filter['source'][0]."'";
84 84
 			} else {
85
-				$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')";
85
+				$filter_query_where .= " AND format_source IN ('".implode("','", $filter['source'])."')";
86 86
 			}
87 87
 		}
88 88
 		if (isset($filter['ident']) && !empty($filter['ident'])) {
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 			$filter_query_where .= " AND flightaware_id = '".$filter['id']."'";
93 93
 		}
94 94
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
95
-			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
95
+			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')";
96 96
 		}
97 97
 		if ((isset($filter['year']) && $filter['year'] != '') || (isset($filter['month']) && $filter['month'] != '') || (isset($filter['day']) && $filter['day'] != '')) {
98 98
 			$filter_query_date = '';
@@ -117,41 +117,41 @@  discard block
 block discarded – undo
117 117
 					$filter_query_date .= " AND EXTRACT(DAY FROM spotter_archive_output.date) = '".$filter['day']."'";
118 118
 				}
119 119
 			}
120
-			$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output".preg_replace('/^ AND/',' WHERE',$filter_query_date).") sd ON sd.flightaware_id = spotter_archive_output.flightaware_id";
120
+			$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output".preg_replace('/^ AND/', ' WHERE', $filter_query_date).") sd ON sd.flightaware_id = spotter_archive_output.flightaware_id";
121 121
 		}
122 122
 		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
123 123
 		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
124 124
 		if ($filter_query_where != '') {
125
-			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
125
+			$filter_query_where = preg_replace('/^ AND/', ' WHERE', $filter_query_where);
126 126
 		}
127 127
 		$filter_query = $filter_query_join.$filter_query_where;
128 128
 		return $filter_query;
129 129
 	}
130 130
 
131 131
 	// Spotter_archive
132
-	public function addSpotterArchiveData($flightaware_id = '', $ident = '', $registration = '', $airline_name = '', $airline_icao = '', $airline_country = '', $airline_type = '', $aircraft_icao = '', $aircraft_shadow = '', $aircraft_name = '', $aircraft_manufacturer = '', $departure_airport_icao = '', $departure_airport_name = '', $departure_airport_city = '', $departure_airport_country = '', $departure_airport_time = '',$arrival_airport_icao = '', $arrival_airport_name = '', $arrival_airport_city ='', $arrival_airport_country = '', $arrival_airport_time = '', $route_stop = '', $date = '',$latitude = '', $longitude = '', $waypoints = '', $altitude = '', $real_altitude = '',$heading = '', $ground_speed = '', $squawk = '', $ModeS = '', $pilot_id = '', $pilot_name = '',$verticalrate = '',$format_source = '', $source_name = '', $over_country = '') {
132
+	public function addSpotterArchiveData($flightaware_id = '', $ident = '', $registration = '', $airline_name = '', $airline_icao = '', $airline_country = '', $airline_type = '', $aircraft_icao = '', $aircraft_shadow = '', $aircraft_name = '', $aircraft_manufacturer = '', $departure_airport_icao = '', $departure_airport_name = '', $departure_airport_city = '', $departure_airport_country = '', $departure_airport_time = '', $arrival_airport_icao = '', $arrival_airport_name = '', $arrival_airport_city = '', $arrival_airport_country = '', $arrival_airport_time = '', $route_stop = '', $date = '', $latitude = '', $longitude = '', $waypoints = '', $altitude = '', $real_altitude = '', $heading = '', $ground_speed = '', $squawk = '', $ModeS = '', $pilot_id = '', $pilot_name = '', $verticalrate = '', $format_source = '', $source_name = '', $over_country = '') {
133 133
 		require_once(dirname(__FILE__).'/class.Spotter.php');
134 134
 		if ($over_country == '') {
135 135
 			$Spotter = new Spotter($this->db);
136
-			$data_country = $Spotter->getCountryFromLatitudeLongitude($latitude,$longitude);
136
+			$data_country = $Spotter->getCountryFromLatitudeLongitude($latitude, $longitude);
137 137
 			if (!empty($data_country)) $country = $data_country['iso2'];
138 138
 			else $country = '';
139 139
 		} else $country = $over_country;
140
-		if ($airline_type === NULL) $airline_type ='';
140
+		if ($airline_type === NULL) $airline_type = '';
141 141
 
142 142
 		//if ($country == '') echo "\n".'************ UNKNOW COUNTRY ****************'."\n";
143 143
 		//else echo "\n".'*/*/*/*/*/*/*/ Country : '.$country.' */*/*/*/*/*/*/*/*/'."\n";
144 144
 
145 145
 		// Route is not added in spotter_archive
146
-		$query  = "INSERT INTO spotter_archive (flightaware_id, ident, registration, airline_name, airline_icao, airline_country, airline_type, aircraft_icao, aircraft_shadow, aircraft_name, aircraft_manufacturer, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, departure_airport_time,arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, arrival_airport_time, route_stop, date,latitude, longitude, waypoints, altitude, heading, ground_speed, squawk, ModeS, pilot_id, pilot_name, verticalrate,format_source,over_country,source_name,real_altitude)
146
+		$query = "INSERT INTO spotter_archive (flightaware_id, ident, registration, airline_name, airline_icao, airline_country, airline_type, aircraft_icao, aircraft_shadow, aircraft_name, aircraft_manufacturer, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, departure_airport_time,arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, arrival_airport_time, route_stop, date,latitude, longitude, waypoints, altitude, heading, ground_speed, squawk, ModeS, pilot_id, pilot_name, verticalrate,format_source,over_country,source_name,real_altitude)
147 147
 		          VALUES (:flightaware_id, :ident, :registration, :airline_name, :airline_icao, :airline_country, :airline_type, :aircraft_icao, :aircraft_shadow, :aircraft_name, :aircraft_manufacturer, :departure_airport_icao, :departure_airport_name, :departure_airport_city, :departure_airport_country, :departure_airport_time,:arrival_airport_icao, :arrival_airport_name, :arrival_airport_city, :arrival_airport_country, :arrival_airport_time, :route_stop, :date,:latitude, :longitude, :waypoints, :altitude, :heading, :ground_speed, :squawk, :ModeS, :pilot_id, :pilot_name, :verticalrate, :format_source, :over_country, :source_name,:real_altitude)";
148 148
 
149
-		$query_values = array(':flightaware_id' => $flightaware_id, ':ident' => $ident, ':registration' => $registration, ':airline_name' => $airline_name, ':airline_icao' => $airline_icao, ':airline_country' => $airline_country, ':airline_type' => $airline_type, ':aircraft_icao' => $aircraft_icao, ':aircraft_shadow' => $aircraft_shadow, ':aircraft_name' => $aircraft_name, ':aircraft_manufacturer' => $aircraft_manufacturer, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_name' => $departure_airport_name, ':departure_airport_city' => $departure_airport_city, ':departure_airport_country' => $departure_airport_country, ':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_name' => $arrival_airport_name, ':arrival_airport_city' => $arrival_airport_city, ':arrival_airport_country' => $arrival_airport_country, ':arrival_airport_time' => $arrival_airport_time, ':route_stop' => $route_stop, ':date' => $date,':latitude' => $latitude, ':longitude' => $longitude, ':waypoints' => $waypoints, ':altitude' => $altitude, ':heading' => $heading, ':ground_speed' => $ground_speed, ':squawk' => $squawk, ':ModeS' => $ModeS, ':pilot_id' => $pilot_id, ':pilot_name' => $pilot_name, ':verticalrate' => $verticalrate, ':format_source' => $format_source, ':over_country' => $country, ':source_name' => $source_name,':real_altitude' => $real_altitude);
149
+		$query_values = array(':flightaware_id' => $flightaware_id, ':ident' => $ident, ':registration' => $registration, ':airline_name' => $airline_name, ':airline_icao' => $airline_icao, ':airline_country' => $airline_country, ':airline_type' => $airline_type, ':aircraft_icao' => $aircraft_icao, ':aircraft_shadow' => $aircraft_shadow, ':aircraft_name' => $aircraft_name, ':aircraft_manufacturer' => $aircraft_manufacturer, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_name' => $departure_airport_name, ':departure_airport_city' => $departure_airport_city, ':departure_airport_country' => $departure_airport_country, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_name' => $arrival_airport_name, ':arrival_airport_city' => $arrival_airport_city, ':arrival_airport_country' => $arrival_airport_country, ':arrival_airport_time' => $arrival_airport_time, ':route_stop' => $route_stop, ':date' => $date, ':latitude' => $latitude, ':longitude' => $longitude, ':waypoints' => $waypoints, ':altitude' => $altitude, ':heading' => $heading, ':ground_speed' => $ground_speed, ':squawk' => $squawk, ':ModeS' => $ModeS, ':pilot_id' => $pilot_id, ':pilot_name' => $pilot_name, ':verticalrate' => $verticalrate, ':format_source' => $format_source, ':over_country' => $country, ':source_name' => $source_name, ':real_altitude' => $real_altitude);
150 150
 		try {
151 151
 			$sth = $this->db->prepare($query);
152 152
 			$sth->execute($query_values);
153 153
 			$sth->closeCursor();
154
-		} catch(PDOException $e) {
154
+		} catch (PDOException $e) {
155 155
 			return "error : ".$e->getMessage();
156 156
 		}
157 157
 		return "success";
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
 
171 171
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
172 172
 		//$query  = "SELECT spotter_archive.* FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate LIMIT 1";
173
-		$query  = "SELECT spotter_archive.* FROM spotter_archive WHERE ident = :ident ORDER BY date DESC LIMIT 1";
173
+		$query = "SELECT spotter_archive.* FROM spotter_archive WHERE ident = :ident ORDER BY date DESC LIMIT 1";
174 174
 
175
-		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident));
175
+		$spotter_array = $Spotter->getDataFromDB($query, array(':ident' => $ident));
176 176
 
177 177
 		return $spotter_array;
178 178
 	}
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
191 191
 		//$query  = SpotterArchive->$global_query." WHERE spotter_archive.flightaware_id = :id";
192 192
 		//$query  = "SELECT spotter_archive.* FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate LIMIT 1";
193
-		$query  = "SELECT * FROM spotter_archive WHERE flightaware_id = :id ORDER BY date DESC LIMIT 1";
193
+		$query = "SELECT * FROM spotter_archive WHERE flightaware_id = :id ORDER BY date DESC LIMIT 1";
194 194
 
195 195
 //              $spotter_array = Spotter->getDataFromDB($query,array(':id' => $id));
196 196
 		/*
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 		}
204 204
 		$spotter_array = $sth->fetchAll(PDO->FETCH_ASSOC);
205 205
 		*/
206
-		$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id));
206
+		$spotter_array = $Spotter->getDataFromDB($query, array(':id' => $id));
207 207
 
208 208
 		return $spotter_array;
209 209
 	}
@@ -217,14 +217,14 @@  discard block
 block discarded – undo
217 217
 	public function getAllArchiveSpotterDataById($id) {
218 218
 		date_default_timezone_set('UTC');
219 219
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
220
-		$query  = $this->global_query." WHERE spotter_archive.flightaware_id = :id ORDER BY date";
220
+		$query = $this->global_query." WHERE spotter_archive.flightaware_id = :id ORDER BY date";
221 221
 
222 222
 //              $spotter_array = Spotter->getDataFromDB($query,array(':id' => $id));
223 223
 
224 224
 		try {
225 225
 			$sth = $this->db->prepare($query);
226 226
 			$sth->execute(array(':id' => $id));
227
-		} catch(PDOException $e) {
227
+		} catch (PDOException $e) {
228 228
 			echo $e->getMessage();
229 229
 			die;
230 230
 		}
@@ -242,11 +242,11 @@  discard block
 block discarded – undo
242 242
 	public function getCoordArchiveSpotterDataById($id) {
243 243
 		date_default_timezone_set('UTC');
244 244
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
245
-		$query  = "SELECT spotter_archive.latitude, spotter_archive.longitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id ORDER by spotter_archive.date ASC";
245
+		$query = "SELECT spotter_archive.latitude, spotter_archive.longitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id ORDER by spotter_archive.date ASC";
246 246
 		try {
247 247
 			$sth = $this->db->prepare($query);
248 248
 			$sth->execute(array(':id' => $id));
249
-		} catch(PDOException $e) {
249
+		} catch (PDOException $e) {
250 250
 			echo $e->getMessage();
251 251
 			die;
252 252
 		}
@@ -260,14 +260,14 @@  discard block
 block discarded – undo
260 260
 	* @return Array the spotter information
261 261
 	*
262 262
 	*/
263
-	public function getCoordArchiveSpotterDataByIdDate($id,$begindate,$enddate) {
263
+	public function getCoordArchiveSpotterDataByIdDate($id, $begindate, $enddate) {
264 264
 		date_default_timezone_set('UTC');
265 265
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
266
-		$query  = "SELECT spotter_archive.latitude, spotter_archive.longitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id AND spotter_archive.date BETWEEN :begindate AND :enddate ORDER by spotter_archive.date ASC";
266
+		$query = "SELECT spotter_archive.latitude, spotter_archive.longitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id AND spotter_archive.date BETWEEN :begindate AND :enddate ORDER by spotter_archive.date ASC";
267 267
 		try {
268 268
 			$sth = $this->db->prepare($query);
269
-			$sth->execute(array(':id' => $id,':begindate' => $begindate,':enddate' => $enddate));
270
-		} catch(PDOException $e) {
269
+			$sth->execute(array(':id' => $id, ':begindate' => $begindate, ':enddate' => $enddate));
270
+		} catch (PDOException $e) {
271 271
 			echo $e->getMessage();
272 272
 			die;
273 273
 		}
@@ -287,12 +287,12 @@  discard block
 block discarded – undo
287 287
 		date_default_timezone_set('UTC');
288 288
 
289 289
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
290
-		$query  = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.ident = :ident AND spotter_archive.latitude <> 0 AND spotter_archive.longitude <> 0 ORDER BY date";
290
+		$query = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.ident = :ident AND spotter_archive.latitude <> 0 AND spotter_archive.longitude <> 0 ORDER BY date";
291 291
 
292 292
 		try {
293 293
 			$sth = $this->db->prepare($query);
294 294
 			$sth->execute(array(':ident' => $ident));
295
-		} catch(PDOException $e) {
295
+		} catch (PDOException $e) {
296 296
 			echo $e->getMessage();
297 297
 			die;
298 298
 		}
@@ -312,12 +312,12 @@  discard block
 block discarded – undo
312 312
 		date_default_timezone_set('UTC');
313 313
 
314 314
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
315
-		$query  = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id AND spotter_archive.latitude <> 0 AND spotter_archive.longitude <> 0 ORDER BY date";
315
+		$query = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id AND spotter_archive.latitude <> 0 AND spotter_archive.longitude <> 0 ORDER BY date";
316 316
 
317 317
 		try {
318 318
 			$sth = $this->db->prepare($query);
319 319
 			$sth->execute(array(':id' => $id));
320
-		} catch(PDOException $e) {
320
+		} catch (PDOException $e) {
321 321
 			echo $e->getMessage();
322 322
 			die;
323 323
 		}
@@ -335,11 +335,11 @@  discard block
 block discarded – undo
335 335
 	public function getAltitudeSpeedArchiveSpotterDataById($id) {
336 336
 		date_default_timezone_set('UTC');
337 337
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
338
-		$query  = "SELECT spotter_archive.altitude, spotter_archive.real_altitude,spotter_archive.ground_speed, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id ORDER BY date";
338
+		$query = "SELECT spotter_archive.altitude, spotter_archive.real_altitude,spotter_archive.ground_speed, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id ORDER BY date";
339 339
 		try {
340 340
 			$sth = $this->db->prepare($query);
341 341
 			$sth->execute(array(':id' => $id));
342
-		} catch(PDOException $e) {
342
+		} catch (PDOException $e) {
343 343
 			echo $e->getMessage();
344 344
 			die;
345 345
 		}
@@ -356,12 +356,12 @@  discard block
 block discarded – undo
356 356
 	public function getLastAltitudeArchiveSpotterDataByIdent($ident) {
357 357
 		date_default_timezone_set('UTC');
358 358
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
359
-		$query  = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate LIMIT 1";
359
+		$query = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate LIMIT 1";
360 360
 //                $query  = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.ident = :ident";
361 361
 		try {
362 362
 			$sth = $this->db->prepare($query);
363 363
 			$sth->execute(array(':ident' => $ident));
364
-		} catch(PDOException $e) {
364
+		} catch (PDOException $e) {
365 365
 			echo $e->getMessage();
366 366
 			die;
367 367
 		}
@@ -377,11 +377,11 @@  discard block
 block discarded – undo
377 377
 	 * @return Array the spotter information
378 378
 	 *
379 379
 	 */
380
-	public function getSpotterArchiveData($ident,$flightaware_id,$date) {
380
+	public function getSpotterArchiveData($ident, $flightaware_id, $date) {
381 381
 		$Spotter = new Spotter($this->db);
382 382
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
383
-		$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident AND l.flightaware_id = :flightaware_id AND l.date LIKE :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate";
384
-		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':flightaware_id' => $flightaware_id,':date' => $date.'%'));
383
+		$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident AND l.flightaware_id = :flightaware_id AND l.date LIKE :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate";
384
+		$spotter_array = $Spotter->getDataFromDB($query, array(':ident' => $ident, ':flightaware_id' => $flightaware_id, ':date' => $date.'%'));
385 385
 		return $spotter_array;
386 386
 	}
387 387
 
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
 		try {
396 396
 			$sth = $this->db->prepare($query);
397 397
 			$sth->execute();
398
-		} catch(PDOException $e) {
398
+		} catch (PDOException $e) {
399 399
 			echo $e->getMessage();
400 400
 			die;
401 401
 		}
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
 		try {
407 407
 			$sth = $this->db->prepare($query);
408 408
 			$sth->execute(array(':id' => $id));
409
-		} catch(PDOException $e) {
409
+		} catch (PDOException $e) {
410 410
 			echo $e->getMessage();
411 411
 			die;
412 412
 		}
@@ -418,39 +418,39 @@  discard block
 block discarded – undo
418 418
 	    * @return Array the spotter information
419 419
 	    *
420 420
 	    */
421
-	public function getMinLiveSpotterData($begindate,$enddate,$filter = array(),$part = 0) {
421
+	public function getMinLiveSpotterData($begindate, $enddate, $filter = array(), $part = 0) {
422 422
 		global $globalDBdriver, $globalLiveInterval;
423 423
 		date_default_timezone_set('UTC');
424 424
 		//$filter_query = $this->getFilter($filter,true,true);
425 425
 
426 426
 		$filter_query = '';
427 427
 		if (isset($filter['source']) && !empty($filter['source'])) {
428
-			$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') ";
428
+			$filter_query .= " AND format_source IN ('".implode("','", $filter['source'])."') ";
429 429
 		}
430 430
 		// Use spotter_output also ?
431 431
 		if (isset($filter['airlines']) && !empty($filter['airlines'])) {
432
-			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_archive.flightaware_id ";
432
+			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','", $filter['airlines'])."')) so ON so.flightaware_id = spotter_archive.flightaware_id ";
433 433
 		}
434 434
 		if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
435 435
 			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_archive.flightaware_id ";
436 436
 		}
437 437
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
438
-			$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
438
+			$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')";
439 439
 		}
440 440
 
441 441
 		$limit = '';
442 442
 		if ($part != 0) {
443
-			$limit = ' LIMIT 100 OFFSET '.($part-1)*100;
443
+			$limit = ' LIMIT 100 OFFSET '.($part - 1)*100;
444 444
 		}
445 445
 		if ($globalDBdriver == 'mysql') {
446
-			$query  = 'SELECT spotter_archive.date,spotter_archive.flightaware_id, spotter_archive.ident, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, a.aircraft_shadow,a.engine_type, a.engine_count, a.wake_category
446
+			$query = 'SELECT spotter_archive.date,spotter_archive.flightaware_id, spotter_archive.ident, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, a.aircraft_shadow,a.engine_type, a.engine_count, a.wake_category
447 447
 			          FROM spotter_archive
448 448
 			          INNER JOIN aircraft a on spotter_archive.aircraft_icao = a.icao
449 449
 			          WHERE spotter_archive.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".'
450 450
 			          '.$filter_query.' ORDER BY flightaware_id'.$limit;
451 451
 		} else {
452 452
 			
453
-			$query  = 'SELECT spotter_archive.flightaware_id, spotter_archive.date, spotter_archive.ident, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, a.aircraft_shadow,a.engine_type, a.engine_count, a.wake_category
453
+			$query = 'SELECT spotter_archive.flightaware_id, spotter_archive.date, spotter_archive.ident, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, a.aircraft_shadow,a.engine_type, a.engine_count, a.wake_category
454 454
 			          FROM spotter_archive
455 455
 			          INNER JOIN aircraft a on spotter_archive.aircraft_icao = a.icao
456 456
 			          WHERE spotter_archive.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".'
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
 		try {
469 469
 			$sth = $this->db->prepare($query);
470 470
 			$sth->execute();
471
-		} catch(PDOException $e) {
471
+		} catch (PDOException $e) {
472 472
 			echo $e->getMessage();
473 473
 			die;
474 474
 		}
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
 	    * @return Array the spotter information
483 483
 	    *
484 484
 	    */
485
-	public function getMinLiveSpotterDataPlayback($begindate,$enddate,$filter = array()) {
485
+	public function getMinLiveSpotterDataPlayback($begindate, $enddate, $filter = array()) {
486 486
 		global $globalDBdriver, $globalLiveInterval;
487 487
 		date_default_timezone_set('UTC');
488 488
 
@@ -490,17 +490,17 @@  discard block
 block discarded – undo
490 490
 
491 491
 		$filter_query = '';
492 492
 		if (isset($filter['source']) && !empty($filter['source'])) {
493
-			$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') ";
493
+			$filter_query .= " AND format_source IN ('".implode("','", $filter['source'])."') ";
494 494
 		}
495 495
 		// Use spotter_output also ?
496 496
 		if (isset($filter['airlines']) && !empty($filter['airlines'])) {
497
-			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_archive.flightaware_id ";
497
+			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','", $filter['airlines'])."')) so ON so.flightaware_id = spotter_archive.flightaware_id ";
498 498
 		}
499 499
 		if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
500 500
 			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_archive.flightaware_id ";
501 501
 		}
502 502
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
503
-			$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
503
+			$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')";
504 504
 		}
505 505
 
506 506
 
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 				    FROM spotter_archive
512 512
 				    INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE (l.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".') GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate '.$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_archive.aircraft_icao = a.icao';
513 513
 			*/
514
-			$query  = 'SELECT a.aircraft_shadow, spotter_archive_output.ident, spotter_archive_output.flightaware_id, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao as departure_airport, spotter_archive_output.arrival_airport_icao as arrival_airport, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk
514
+			$query = 'SELECT a.aircraft_shadow, spotter_archive_output.ident, spotter_archive_output.flightaware_id, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao as departure_airport, spotter_archive_output.arrival_airport_icao as arrival_airport, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk
515 515
 			          FROM spotter_archive_output
516 516
 			          LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_archive_output.aircraft_icao = a.icao
517 517
 			          WHERE (spotter_archive_output.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".')
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
 			 	    WHERE spotter_archive_output.date >= '."'".$begindate."'".' AND spotter_archive_output.date <= '."'".$enddate."'".'
527 527
 			 	    '.$filter_query.' GROUP BY spotter_archive_output.flightaware_id, spotter_archive_output.ident, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao, spotter_archive_output.arrival_airport_icao, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk, a.aircraft_shadow';
528 528
 			 */
529
-			$query  = 'SELECT DISTINCT spotter_archive_output.flightaware_id, spotter_archive_output.ident, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao as departure_airport, spotter_archive_output.arrival_airport_icao as arrival_airport, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk, a.aircraft_shadow
529
+			$query = 'SELECT DISTINCT spotter_archive_output.flightaware_id, spotter_archive_output.ident, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao as departure_airport, spotter_archive_output.arrival_airport_icao as arrival_airport, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk, a.aircraft_shadow
530 530
 			          FROM spotter_archive_output
531 531
 			          INNER JOIN (SELECT * FROM aircraft) a on spotter_archive_output.aircraft_icao = a.icao
532 532
 			          WHERE spotter_archive_output.date >= '."'".$begindate."'".' AND spotter_archive_output.date <= '."'".$enddate."'".'
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
 		try {
539 539
 			$sth = $this->db->prepare($query);
540 540
 			$sth->execute();
541
-		} catch(PDOException $e) {
541
+		} catch (PDOException $e) {
542 542
 			echo $e->getMessage();
543 543
 			die;
544 544
 		}
@@ -553,22 +553,22 @@  discard block
 block discarded – undo
553 553
 	   * @return Array the spotter information
554 554
 	   *
555 555
 	   */
556
-	public function getLiveSpotterCount($begindate,$enddate,$filter = array()) {
556
+	public function getLiveSpotterCount($begindate, $enddate, $filter = array()) {
557 557
 		global $globalDBdriver, $globalLiveInterval;
558 558
 		date_default_timezone_set('UTC');
559 559
 
560 560
 		$filter_query = '';
561 561
 		if (isset($filter['source']) && !empty($filter['source'])) {
562
-			$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') ";
562
+			$filter_query .= " AND format_source IN ('".implode("','", $filter['source'])."') ";
563 563
 		}
564 564
 		if (isset($filter['airlines']) && !empty($filter['airlines'])) {
565
-			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_archive.flightaware_id ";
565
+			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','", $filter['airlines'])."')) so ON so.flightaware_id = spotter_archive.flightaware_id ";
566 566
 		}
567 567
 		if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
568 568
 			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_archive.flightaware_id ";
569 569
 		}
570 570
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
571
-			$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
571
+			$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')";
572 572
 		}
573 573
 
574 574
 		//if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
 		try {
584 584
 			$sth = $this->db->prepare($query);
585 585
 			$sth->execute();
586
-		} catch(PDOException $e) {
586
+		} catch (PDOException $e) {
587 587
 			echo $e->getMessage();
588 588
 			die;
589 589
 		}
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
 	* @return Array the spotter information
604 604
 	*
605 605
 	*/
606
-	public function searchSpotterData($q = '', $registration = '', $aircraft_icao = '', $aircraft_manufacturer = '', $highlights = '', $airline_icao = '', $airline_country = '', $airline_type = '', $airport = '', $airport_country = '', $callsign = '', $departure_airport_route = '', $arrival_airport_route = '', $owner = '',$pilot_id = '',$pilot_name = '',$altitude = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '',$origLat = '',$origLon = '',$dist = '', $filters=array()) {
606
+	public function searchSpotterData($q = '', $registration = '', $aircraft_icao = '', $aircraft_manufacturer = '', $highlights = '', $airline_icao = '', $airline_country = '', $airline_type = '', $airport = '', $airport_country = '', $callsign = '', $departure_airport_route = '', $arrival_airport_route = '', $owner = '', $pilot_id = '', $pilot_name = '', $altitude = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '', $origLat = '', $origLon = '', $dist = '', $filters = array()) {
607 607
 		global $globalTimezone, $globalDBdriver;
608 608
 		require_once(dirname(__FILE__).'/class.Translation.php');
609 609
 		$Translation = new Translation($this->db);
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
 		}
654 654
 
655 655
 		if ($registration != "") {
656
-			$registration = filter_var($registration,FILTER_SANITIZE_STRING);
656
+			$registration = filter_var($registration, FILTER_SANITIZE_STRING);
657 657
 			if (!is_string($registration)) {
658 658
 				return array();
659 659
 			} else {
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
 		}
663 663
 
664 664
 		if ($aircraft_icao != "") {
665
-			$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
665
+			$aircraft_icao = filter_var($aircraft_icao, FILTER_SANITIZE_STRING);
666 666
 			if (!is_string($aircraft_icao)) {
667 667
 				return array();
668 668
 			} else {
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
 		}
672 672
 
673 673
 		if ($aircraft_manufacturer != "") {
674
-			$aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING);
674
+			$aircraft_manufacturer = filter_var($aircraft_manufacturer, FILTER_SANITIZE_STRING);
675 675
 			if (!is_string($aircraft_manufacturer)) {
676 676
 				return array();
677 677
 			} else {
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
 		}
689 689
 
690 690
 		if ($airline_icao != "") {
691
-			$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING);
691
+			$airline_icao = filter_var($airline_icao, FILTER_SANITIZE_STRING);
692 692
 			if (!is_string($airline_icao)) {
693 693
 				return array();
694 694
 			} else {
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
 		}
698 698
 
699 699
 		if ($airline_country != "") {
700
-			$airline_country = filter_var($airline_country,FILTER_SANITIZE_STRING);
700
+			$airline_country = filter_var($airline_country, FILTER_SANITIZE_STRING);
701 701
 			if (!is_string($airline_country)) {
702 702
 				return array();
703 703
 			} else {
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
 		}
707 707
 
708 708
 		if ($airline_type != "") {
709
-			$airline_type = filter_var($airline_type,FILTER_SANITIZE_STRING);
709
+			$airline_type = filter_var($airline_type, FILTER_SANITIZE_STRING);
710 710
 			if (!is_string($airline_type)) {
711 711
 				return array();
712 712
 			} else {
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
 		}
724 724
 
725 725
 		if ($airport != "") {
726
-			$airport = filter_var($airport,FILTER_SANITIZE_STRING);
726
+			$airport = filter_var($airport, FILTER_SANITIZE_STRING);
727 727
 			if (!is_string($airport)) {
728 728
 				return array();
729 729
 			} else {
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
 		}
733 733
 
734 734
 		if ($airport_country != "") {
735
-			$airport_country = filter_var($airport_country,FILTER_SANITIZE_STRING);
735
+			$airport_country = filter_var($airport_country, FILTER_SANITIZE_STRING);
736 736
 			if (!is_string($airport_country)) {
737 737
 				return array();
738 738
 			} else {
@@ -741,14 +741,14 @@  discard block
 block discarded – undo
741 741
 		}
742 742
 
743 743
 		if ($callsign != "") {
744
-			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
744
+			$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
745 745
 			if (!is_string($callsign)) {
746 746
 				return array();
747 747
 			} else {
748 748
 				$translate = $Translation->ident2icao($callsign);
749 749
 				if ($translate != $callsign) {
750 750
 					$additional_query .= " AND (spotter_archive_output.ident = :callsign OR spotter_archive_output.ident = :translate)";
751
-					$query_values = array_merge($query_values,array(':callsign' => $callsign,':translate' => $translate));
751
+					$query_values = array_merge($query_values, array(':callsign' => $callsign, ':translate' => $translate));
752 752
 				} else {
753 753
 					$additional_query .= " AND (spotter_archive_output.ident = '".$callsign."')";
754 754
 				}
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
 		}
757 757
 
758 758
 		if ($owner != "") {
759
-			$owner = filter_var($owner,FILTER_SANITIZE_STRING);
759
+			$owner = filter_var($owner, FILTER_SANITIZE_STRING);
760 760
 			if (!is_string($owner)) {
761 761
 				return array();
762 762
 			} else {
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
 		}
766 766
 
767 767
 		if ($pilot_name != "") {
768
-			$pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING);
768
+			$pilot_name = filter_var($pilot_name, FILTER_SANITIZE_STRING);
769 769
 			if (!is_string($pilot_name)) {
770 770
 				return array();
771 771
 			} else {
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
 		}
775 775
 
776 776
 		if ($pilot_id != "") {
777
-			$pilot_id = filter_var($pilot_id,FILTER_SANITIZE_NUMBER_INT);
777
+			$pilot_id = filter_var($pilot_id, FILTER_SANITIZE_NUMBER_INT);
778 778
 			if (!is_string($pilot_id)) {
779 779
 				return array();
780 780
 			} else {
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
 		}
784 784
 
785 785
 		if ($departure_airport_route != "") {
786
-			$departure_airport_route = filter_var($departure_airport_route,FILTER_SANITIZE_STRING);
786
+			$departure_airport_route = filter_var($departure_airport_route, FILTER_SANITIZE_STRING);
787 787
 			if (!is_string($departure_airport_route)) {
788 788
 				return array();
789 789
 			} else {
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
 		}
793 793
 
794 794
 		if ($arrival_airport_route != "") {
795
-			$arrival_airport_route = filter_var($arrival_airport_route,FILTER_SANITIZE_STRING);
795
+			$arrival_airport_route = filter_var($arrival_airport_route, FILTER_SANITIZE_STRING);
796 796
 			if (!is_string($arrival_airport_route)) {
797 797
 				return array();
798 798
 			} else {
@@ -803,8 +803,8 @@  discard block
 block discarded – undo
803 803
 		if ($altitude != "") {
804 804
 			$altitude_array = explode(",", $altitude);
805 805
 
806
-			$altitude_array[0] = filter_var($altitude_array[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
807
-			$altitude_array[1] = filter_var($altitude_array[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
806
+			$altitude_array[0] = filter_var($altitude_array[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
807
+			$altitude_array[1] = filter_var($altitude_array[1], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
808 808
 
809 809
 
810 810
 			if ($altitude_array[1] != "") {
@@ -819,8 +819,8 @@  discard block
 block discarded – undo
819 819
 
820 820
 		if ($date_posted != "") {
821 821
 			$date_array = explode(",", $date_posted);
822
-			$date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING);
823
-			$date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING);
822
+			$date_array[0] = filter_var($date_array[0], FILTER_SANITIZE_STRING);
823
+			$date_array[1] = filter_var($date_array[1], FILTER_SANITIZE_STRING);
824 824
 			if ($globalTimezone != '') {
825 825
 				date_default_timezone_set($globalTimezone);
826 826
 				$datetime = new DateTime();
@@ -845,16 +845,16 @@  discard block
 block discarded – undo
845 845
 		}
846 846
 		if ($limit != "") {
847 847
 			$limit_array = explode(",", $limit);
848
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
849
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
848
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
849
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
850 850
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) {
851 851
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
852 852
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
853 853
 			}
854 854
 		}
855 855
 		if ($origLat != "" && $origLon != "" && $dist != "") {
856
-			$dist = number_format($dist*0.621371,2,'.','');
857
-			$query="SELECT spotter_archive_output.*, 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - ABS(CAST(spotter_archive.latitude as double precision)))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(ABS(CAST(spotter_archive.latitude as double precision))*pi()/180)*POWER(SIN(($origLon-CAST(spotter_archive.longitude as double precision))*pi()/180/2),2))) as distance
856
+			$dist = number_format($dist*0.621371, 2, '.', '');
857
+			$query = "SELECT spotter_archive_output.*, 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - ABS(CAST(spotter_archive.latitude as double precision)))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(ABS(CAST(spotter_archive.latitude as double precision))*pi()/180)*POWER(SIN(($origLon-CAST(spotter_archive.longitude as double precision))*pi()/180/2),2))) as distance
858 858
 			       FROM spotter_archive_output, spotter_archive WHERE spotter_output_archive.flightaware_id = spotter_archive.flightaware_id AND spotter_output.ident <> '' ".$additional_query."AND CAST(spotter_archive.longitude as double precision) between ($origLon-$dist/ABS(cos(radians($origLat))*69)) and ($origLon+$dist/ABS(cos(radians($origLat))*69)) and CAST(spotter_archive.latitude as double precision) between ($origLat-($dist/69)) and ($origLat+($dist/69))
859 859
 			       AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - ABS(CAST(spotter_archive.latitude as double precision)))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(ABS(CAST(spotter_archive.latitude as double precision))*pi()/180)*POWER(SIN(($origLon-CAST(spotter_archive.longitude as double precision))*pi()/180/2),2)))) < $dist".$filter_query." ORDER BY distance";
860 860
 		} else {
@@ -868,12 +868,12 @@  discard block
 block discarded – undo
868 868
 				$additional_query .= " AND (spotter_archive_output.waypoints <> '')";
869 869
 			}
870 870
 
871
-			$query  = "SELECT spotter_archive_output.* FROM spotter_archive_output
871
+			$query = "SELECT spotter_archive_output.* FROM spotter_archive_output
872 872
 			          WHERE spotter_archive_output.ident <> ''
873 873
 			          ".$additional_query."
874 874
 			          ".$filter_query.$orderby_query;
875 875
 		}
876
-		$spotter_array = $Spotter->getDataFromDB($query, $query_values,$limit_query);
876
+		$spotter_array = $Spotter->getDataFromDB($query, $query_values, $limit_query);
877 877
 		return $spotter_array;
878 878
 	}
879 879
 
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
 		try {
889 889
 			$sth = $this->db->prepare($query);
890 890
 			$sth->execute();
891
-		} catch(PDOException $e) {
891
+		} catch (PDOException $e) {
892 892
 			return "error";
893 893
 		}
894 894
 	}
@@ -921,8 +921,8 @@  discard block
 block discarded – undo
921 921
 		if ($limit != "") {
922 922
 			$limit_array = explode(",", $limit);
923 923
 
924
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
925
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
924
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
925
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
926 926
 
927 927
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) {
928 928
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
@@ -960,7 +960,7 @@  discard block
 block discarded – undo
960 960
 		$query_values = array();
961 961
 		$limit_query = '';
962 962
 		$additional_query = '';
963
-		$filter_query = $this->getFilter($filter,true,true);
963
+		$filter_query = $this->getFilter($filter, true, true);
964 964
 
965 965
 		if ($owner != "") {
966 966
 			if (!is_string($owner)) {
@@ -974,8 +974,8 @@  discard block
 block discarded – undo
974 974
 		if ($limit != "") {
975 975
 			$limit_array = explode(",", $limit);
976 976
 
977
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
978
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
977
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
978
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
979 979
 
980 980
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) {
981 981
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
 		$query_values = array();
1013 1013
 		$limit_query = '';
1014 1014
 		$additional_query = '';
1015
-		$filter_query = $this->getFilter($filter,true,true);
1015
+		$filter_query = $this->getFilter($filter, true, true);
1016 1016
 
1017 1017
 		if ($pilot != "") {
1018 1018
 			$additional_query = " AND (spotter_archive_output.pilot_id = :pilot OR spotter_archive_output.pilot_name = :pilot)";
@@ -1022,8 +1022,8 @@  discard block
 block discarded – undo
1022 1022
 		if ($limit != "") {
1023 1023
 			$limit_array = explode(",", $limit);
1024 1024
 
1025
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1026
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1025
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
1026
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
1027 1027
 
1028 1028
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) {
1029 1029
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
 	* @return Array the airline country list
1052 1052
 	*
1053 1053
 	*/
1054
-	public function countAllFlightOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '') {
1054
+	public function countAllFlightOverCountries($limit = true, $olderthanmonths = 0, $sincedate = '') {
1055 1055
 		global $globalDBdriver;
1056 1056
 		/*
1057 1057
 		$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb
@@ -1079,7 +1079,7 @@  discard block
 block discarded – undo
1079 1079
 		$flight_array = array();
1080 1080
 		$temp_array = array();
1081 1081
 
1082
-		while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
1082
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
1083 1083
 			$temp_array['flight_count'] = $row['nb'];
1084 1084
 			$temp_array['flight_country'] = $row['name'];
1085 1085
 			$temp_array['flight_country_iso3'] = $row['iso3'];
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
 	* @return Array the airline country list
1096 1096
 	*
1097 1097
 	*/
1098
-	public function countAllFlightOverCountriesByAirlines($limit = true,$olderthanmonths = 0,$sincedate = '') {
1098
+	public function countAllFlightOverCountriesByAirlines($limit = true, $olderthanmonths = 0, $sincedate = '') {
1099 1099
 		global $globalDBdriver;
1100 1100
 		/*
1101 1101
 		$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb
@@ -1123,7 +1123,7 @@  discard block
 block discarded – undo
1123 1123
 		$flight_array = array();
1124 1124
 		$temp_array = array();
1125 1125
 
1126
-		while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
1126
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
1127 1127
 			$temp_array['airline_icao'] = $row['airline_icao'];
1128 1128
 			$temp_array['flight_count'] = $row['nb'];
1129 1129
 			$temp_array['flight_country'] = $row['name'];
@@ -1140,13 +1140,13 @@  discard block
 block discarded – undo
1140 1140
 	* @return Array the spotter information
1141 1141
 	*
1142 1142
 	*/
1143
-	public function getDateArchiveSpotterDataById($id,$date) {
1143
+	public function getDateArchiveSpotterDataById($id, $date) {
1144 1144
 		$Spotter = new Spotter($this->db);
1145 1145
 		date_default_timezone_set('UTC');
1146 1146
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
1147
-		$query  = 'SELECT spotter_archive.* FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.flightaware_id = :id AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate ORDER BY spotter_archive.date DESC';
1148
-		$date = date('c',$date);
1149
-		$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id,':date' => $date));
1147
+		$query = 'SELECT spotter_archive.* FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.flightaware_id = :id AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate ORDER BY spotter_archive.date DESC';
1148
+		$date = date('c', $date);
1149
+		$spotter_array = $Spotter->getDataFromDB($query, array(':id' => $id, ':date' => $date));
1150 1150
 		return $spotter_array;
1151 1151
 	}
1152 1152
 
@@ -1156,13 +1156,13 @@  discard block
 block discarded – undo
1156 1156
 	* @return Array the spotter information
1157 1157
 	*
1158 1158
 	*/
1159
-	public function getDateArchiveSpotterDataByIdent($ident,$date) {
1159
+	public function getDateArchiveSpotterDataByIdent($ident, $date) {
1160 1160
 		$Spotter = new Spotter($this->db);
1161 1161
 		date_default_timezone_set('UTC');
1162 1162
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
1163
-		$query  = 'SELECT spotter_archive.* FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate ORDER BY spotter_archive.date DESC';
1164
-		$date = date('c',$date);
1165
-		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
1163
+		$query = 'SELECT spotter_archive.* FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate ORDER BY spotter_archive.date DESC';
1164
+		$date = date('c', $date);
1165
+		$spotter_array = $Spotter->getDataFromDB($query, array(':ident' => $ident, ':date' => $date));
1166 1166
 		return $spotter_array;
1167 1167
 	}
1168 1168
 
@@ -1172,14 +1172,14 @@  discard block
 block discarded – undo
1172 1172
 	* @return Array the spotter information
1173 1173
 	*
1174 1174
 	*/
1175
-	public function getSpotterDataByAirport($airport = '', $limit = '', $sort = '',$filters = array()) {
1175
+	public function getSpotterDataByAirport($airport = '', $limit = '', $sort = '', $filters = array()) {
1176 1176
 		global $global_query;
1177 1177
 		$Spotter = new Spotter($this->db);
1178 1178
 		date_default_timezone_set('UTC');
1179 1179
 		$query_values = array();
1180 1180
 		$limit_query = '';
1181 1181
 		$additional_query = '';
1182
-		$filter_query = $this->getFilter($filters,true,true);
1182
+		$filter_query = $this->getFilter($filters, true, true);
1183 1183
 
1184 1184
 		if ($airport != "") {
1185 1185
 			if (!is_string($airport)) {
@@ -1193,8 +1193,8 @@  discard block
 block discarded – undo
1193 1193
 		if ($limit != "") {
1194 1194
 			$limit_array = explode(",", $limit);
1195 1195
 
1196
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1197
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1196
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
1197
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
1198 1198
 
1199 1199
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) {
1200 1200
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
Please login to merge, or discard this patch.
require/class.SpotterImport.php 3 patches
Indentation   +433 added lines, -433 removed lines patch added patch discarded remove patch
@@ -16,20 +16,20 @@  discard block
 block discarded – undo
16 16
 require_once(dirname(__FILE__).'/class.Source.php');
17 17
 require_once(dirname(__FILE__).'/class.GeoidHeight.php');
18 18
 if (isset($globalServerAPRS) && $globalServerAPRS) {
19
-    require_once(dirname(__FILE__).'/class.APRS.php');
19
+	require_once(dirname(__FILE__).'/class.APRS.php');
20 20
 }
21 21
 
22 22
 class SpotterImport {
23
-    private $all_flights = array();
24
-    private $last_delete_hourly = 0;
25
-    private $last_delete = 0;
26
-    private $stats = array();
27
-    private $tmd = 0;
28
-    private $source_location = array();
29
-    public $db = null;
30
-    public $nb = 0;
23
+	private $all_flights = array();
24
+	private $last_delete_hourly = 0;
25
+	private $last_delete = 0;
26
+	private $stats = array();
27
+	private $tmd = 0;
28
+	private $source_location = array();
29
+	public $db = null;
30
+	public $nb = 0;
31 31
 
32
-    public function __construct($dbc = null) {
32
+	public function __construct($dbc = null) {
33 33
 	global $globalBeta, $globalServerAPRS, $APRSSpotter, $globalNoDB, $GeoidClass, $globalDebug, $globalGeoid;
34 34
 	if (!(isset($globalNoDB) && $globalNoDB)) {
35 35
 		$Connection = new Connection($dbc);
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
 		$currentdate = date('Y-m-d');
42 42
 		$sourcestat = $Stats->getStatsSource($currentdate);
43 43
 		if (!empty($sourcestat)) {
44
-		    foreach($sourcestat as $srcst) {
45
-		    	$type = $srcst['stats_type'];
44
+			foreach($sourcestat as $srcst) {
45
+				$type = $srcst['stats_type'];
46 46
 			if ($type == 'polar' || $type == 'hist') {
47
-			    $source = $srcst['source_name'];
48
-			    $data = $srcst['source_data'];
49
-			    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
50
-	    		}
51
-		    }
47
+				$source = $srcst['source_name'];
48
+				$data = $srcst['source_data'];
49
+				$this->stats[$currentdate][$source][$type] = json_decode($data,true);
50
+				}
51
+			}
52 52
 		}
53 53
 	}
54 54
 	if (isset($globalServerAPRS) && $globalServerAPRS) {
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 			$GeoidClass = FALSE;
64 64
 		}
65 65
 	}
66
-    }
66
+	}
67 67
 
68
-    public function get_Schedule($id,$ident) {
68
+	public function get_Schedule($id,$ident) {
69 69
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
70 70
 	// Get schedule here, so it's done only one time
71 71
 	
@@ -85,43 +85,43 @@  discard block
 block discarded – undo
85 85
 	$operator = $Spotter->getOperator($ident);
86 86
 	$scheduleexist = false;
87 87
 	if ($Schedule->checkSchedule($operator) == 0) {
88
-	    $operator = $Translation->checkTranslation($ident);
89
-	    if ($Schedule->checkSchedule($operator) == 0) {
88
+		$operator = $Translation->checkTranslation($ident);
89
+		if ($Schedule->checkSchedule($operator) == 0) {
90 90
 		$schedule = $Schedule->fetchSchedule($operator);
91 91
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
92
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
93
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
94
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
95
-		    // Should also check if route schedule = route from DB
96
-		    if ($schedule['DepartureAirportIATA'] != '') {
92
+			if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
93
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
94
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
95
+			// Should also check if route schedule = route from DB
96
+			if ($schedule['DepartureAirportIATA'] != '') {
97 97
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
98
-			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
99
-			    if (trim($airport_icao) != '') {
98
+				$airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
99
+				if (trim($airport_icao) != '') {
100 100
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
101 101
 				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
102
-			    }
102
+				}
103
+			}
103 104
 			}
104
-		    }
105
-		    if ($schedule['ArrivalAirportIATA'] != '') {
105
+			if ($schedule['ArrivalAirportIATA'] != '') {
106 106
 			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) {
107
-			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
108
-			    if (trim($airport_icao) != '') {
107
+				$airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
108
+				if (trim($airport_icao) != '') {
109 109
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
110 110
 				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
111
-			    }
111
+				}
112 112
 			}
113
-		    }
114
-		    $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']);
113
+			}
114
+			$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']);
115 115
 		}
116
-	    } else $scheduleexist = true;
116
+		} else $scheduleexist = true;
117 117
 	} else $scheduleexist = true;
118 118
 	// close connection, at least one way will work ?
119
-       if ($scheduleexist) {
119
+	   if ($scheduleexist) {
120 120
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
121
-    		$sch = $Schedule->getSchedule($operator);
121
+			$sch = $Schedule->getSchedule($operator);
122 122
 		$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']));
123 123
 		if ($this->all_flights[$id]['addedSpotter'] == 1) $Spotter->updateLatestScheduleSpotterData($this->all_flights[$id]['id'],$sch['departure_airport_icao'],$sch['departure_airport_time'],$sch['arrival_airport_icao'],$sch['arrival_airport_time']);
124
-       }
124
+	   }
125 125
 	$Spotter->db = null;
126 126
 	$Schedule->db = null;
127 127
 	$Translation->db = null;
@@ -136,65 +136,65 @@  discard block
 block discarded – undo
136 136
 	}
137 137
 	  */
138 138
 	}
139
-    }
139
+	}
140 140
 
141
-    public function checkAll() {
141
+	public function checkAll() {
142 142
 	global $globalDebug, $globalNoImport;
143 143
 	if ($globalDebug) echo "Update last seen flights data...\n";
144 144
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
145
-	    foreach ($this->all_flights as $key => $flight) {
145
+		foreach ($this->all_flights as $key => $flight) {
146 146
 		if (isset($this->all_flights[$key]['id'])) {
147
-		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
148
-    		    $Spotter = new Spotter($this->db);
149
-        	    $real_arrival = $this->arrival($key);
150
-        	    if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) $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']);
151
-        	}
152
-	    }
147
+			//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
148
+				$Spotter = new Spotter($this->db);
149
+				$real_arrival = $this->arrival($key);
150
+				if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) $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']);
151
+			}
152
+		}
153
+	}
153 154
 	}
154
-    }
155 155
 
156
-    public function arrival($key) {
156
+	public function arrival($key) {
157 157
 	global $globalClosestMinDist, $globalDebug;
158 158
 	if ($globalDebug) echo 'Update arrival...'."\n";
159 159
 	$Spotter = new Spotter($this->db);
160
-        $airport_icao = '';
161
-        $airport_time = '';
162
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
160
+		$airport_icao = '';
161
+		$airport_time = '';
162
+		if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
163 163
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
164
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
165
-    	    if (isset($closestAirports[0])) {
166
-        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
167
-        	    $airport_icao = $closestAirports[0]['icao'];
168
-        	    $airport_time = $this->all_flights[$key]['datetime'];
169
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
170
-        	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
171
-        	    foreach ($closestAirports as $airport) {
172
-        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
173
-        		    $airport_icao = $airport['icao'];
174
-        		    $airport_time = $this->all_flights[$key]['datetime'];
175
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
176
-        		    break;
177
-        		}
178
-        	    }
179
-        	} 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))) {
180
-        		$airport_icao = $closestAirports[0]['icao'];
181
-        		$airport_time = $this->all_flights[$key]['datetime'];
182
-        	} else {
183
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
184
-        	}
185
-    	    } else {
186
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
187
-    	    }
164
+		$closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
165
+			if (isset($closestAirports[0])) {
166
+			if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
167
+				$airport_icao = $closestAirports[0]['icao'];
168
+				$airport_time = $this->all_flights[$key]['datetime'];
169
+				if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
170
+			} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
171
+				foreach ($closestAirports as $airport) {
172
+				if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
173
+					$airport_icao = $airport['icao'];
174
+					$airport_time = $this->all_flights[$key]['datetime'];
175
+					if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
176
+					break;
177
+				}
178
+				}
179
+			} 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))) {
180
+				$airport_icao = $closestAirports[0]['icao'];
181
+				$airport_time = $this->all_flights[$key]['datetime'];
182
+			} else {
183
+				if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
184
+			}
185
+			} else {
186
+				if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
187
+			}
188 188
 
189
-        } else {
190
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
191
-        }
192
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
193
-    }
189
+		} else {
190
+			if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
191
+		}
192
+		return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
193
+	}
194 194
 
195 195
 
196 196
 
197
-    public function del() {
197
+	public function del() {
198 198
 	global $globalDebug, $globalNoImport, $globalNoDB;
199 199
 	// Delete old infos
200 200
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
 			}
207 207
 		}
208 208
 	}
209
-    }
209
+	}
210 210
 
211
-    public function delKey($key) {
211
+	public function delKey($key) {
212 212
 	global $globalDebug, $globalNoImport, $globalNoDB;
213 213
 	// Delete old infos
214 214
 	if (isset($this->all_flights[$key]['id'])) {
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
 		if ($globalDebug) echo "\n";
231 231
 	}
232 232
 	unset($this->all_flights[$key]);
233
-    }
233
+	}
234 234
 
235
-    public function add($line) {
235
+	public function add($line) {
236 236
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport, $globalNoDB, $globalVA, $globalAircraftMaxUpdate, $globalAircraftMinUpdate, $globalLiveInterval, $GeoidClass, $globalArchive;
237 237
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
238 238
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.01';
@@ -258,20 +258,20 @@  discard block
 block discarded – undo
258 258
 	
259 259
 	// SBS format is CSV format
260 260
 	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
261
-	    //print_r($line);
262
-	    if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
263
-  	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && substr($line['hex'],0,1) != '~' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
261
+		//print_r($line);
262
+		if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
263
+  		if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && substr($line['hex'],0,1) != '~' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
264 264
 
265 265
 		// Increment message number
266 266
 		if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) {
267
-		    $current_date = date('Y-m-d');
268
-		    if (isset($line['source_name'])) $source = $line['source_name'];
269
-		    else $source = '';
270
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
271
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
272
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
273
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
274
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
267
+			$current_date = date('Y-m-d');
268
+			if (isset($line['source_name'])) $source = $line['source_name'];
269
+			else $source = '';
270
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
271
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
272
+				$this->stats[$current_date][$source]['msg']['date'] = time();
273
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
274
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
275 275
 		}
276 276
 		
277 277
 		/*
@@ -287,54 +287,54 @@  discard block
 block discarded – undo
287 287
 		//$this->db = $dbc;
288 288
 
289 289
 		//$hex = trim($line['hex']);
290
-	        if (!isset($line['id'])) $id = trim($line['hex']);
291
-	        else $id = trim($line['id']);
290
+			if (!isset($line['id'])) $id = trim($line['hex']);
291
+			else $id = trim($line['id']);
292 292
 		
293 293
 		if (!isset($this->all_flights[$id])) {
294
-		    if ($globalDebug) echo 'New flight...'."\n";
295
-		    $this->all_flights[$id] = array();
296
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
297
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => '','coordinates' => 0));
298
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
299
-		    if (!isset($line['id'])) {
294
+			if ($globalDebug) echo 'New flight...'."\n";
295
+			$this->all_flights[$id] = array();
296
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
297
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => '','coordinates' => 0));
298
+			if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
299
+			if (!isset($line['id'])) {
300 300
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
301 301
 //			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')));
302 302
 //			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')));
303 303
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
304
-		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
305
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
306
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
304
+				//else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
305
+			 } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
306
+			if ($globalAllFlights !== FALSE) $dataFound = true;
307 307
 		}
308 308
 		if (isset($line['source_type']) && $line['source_type'] != '') {
309
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
309
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
310 310
 		}
311 311
 		
312 312
 		//print_r($this->all_flights);
313 313
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
314
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
315
-		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
314
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
315
+			//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
316 316
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
317
-		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
318
-		    if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
317
+			//} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
318
+			if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
319 319
 			$timeelapsed = microtime(true);
320 320
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
321
-			    $Spotter = new Spotter($this->db);
322
-			    if (isset($this->all_flights[$id]['source_type'])) {
321
+				$Spotter = new Spotter($this->db);
322
+				if (isset($this->all_flights[$id]['source_type'])) {
323 323
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
324
-			    } else {
324
+				} else {
325 325
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
326
-			    }
327
-			    $Spotter->db = null;
328
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
329
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
326
+				}
327
+				$Spotter->db = null;
328
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
329
+				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
330 330
 			}
331
-		    }
332
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
333
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
331
+			}
332
+			if ($globalAllFlights !== FALSE) $dataFound = true;
333
+			if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
334 334
 		}
335
-	        if (isset($line['id']) && !isset($line['hex'])) {
336
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
337
-	        }
335
+			if (isset($line['id']) && !isset($line['hex'])) {
336
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
337
+			}
338 338
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
339 339
 			$icao = $line['aircraft_icao'];
340 340
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -364,9 +364,9 @@  discard block
 block discarded – undo
364 364
 		}
365 365
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
366 366
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) {
367
-		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
367
+			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
368 368
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
369
-		    } else {
369
+			} else {
370 370
 				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";
371 371
 				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";
372 372
 				/*
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 				print_r($line);
376 376
 				*/
377 377
 				return '';
378
-		    }
378
+			}
379 379
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
380 380
 			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
381 381
 			return '';
@@ -391,21 +391,21 @@  discard block
 block discarded – undo
391 391
 		}
392 392
 
393 393
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG' && $line['registration'] != 'NA') {
394
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
394
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
395 395
 		}
396 396
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
397
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
397
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
398 398
 		}
399 399
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
400
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
400
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
401 401
 		}
402 402
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
403
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
403
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
404 404
 		}
405 405
  
406 406
 		if (isset($line['ident']) && trim($line['ident']) != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
407 407
 
408
-		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
408
+			if ($this->all_flights[$id]['addedSpotter'] == 1) {
409 409
 			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
410 410
 				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
411 411
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
@@ -414,23 +414,23 @@  discard block
 block discarded – undo
414 414
 				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
415 415
 				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']));
416 416
 			} else {
417
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
418
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
417
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
418
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
419 419
 				$timeelapsed = microtime(true);
420
-            			$Spotter = new Spotter($this->db);
421
-            			$fromsource = NULL;
422
-            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
423
-            			elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
420
+						$Spotter = new Spotter($this->db);
421
+						$fromsource = NULL;
422
+						if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
423
+						elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
424 424
 				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
425 425
 				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
426 426
 				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
427
-            			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource,$this->all_flights[$id]['source_type']);
427
+						$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource,$this->all_flights[$id]['source_type']);
428 428
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
429 429
 				$Spotter->db = null;
430 430
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
431
-			    }
431
+				}
432 432
 			}
433
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
433
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
434 434
 		    
435 435
 /*
436 436
 		    if (!isset($line['id'])) {
@@ -440,63 +440,63 @@  discard block
 block discarded – undo
440 440
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
441 441
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
442 442
   */
443
-		    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']));
443
+			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']));
444 444
 
445
-		    //$putinarchive = true;
446
-		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
445
+			//$putinarchive = true;
446
+			if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
447 447
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
448
-		    }
449
-		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
448
+			}
449
+			if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
450 450
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
451
-		    }
452
-		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
453
-		    		$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' => ''));
454
-		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
451
+			}
452
+			if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
453
+					$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' => ''));
454
+			} elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
455 455
 			$timeelapsed = microtime(true);
456 456
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
457 457
 				$Spotter = new Spotter($this->db);
458 458
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
459 459
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
460
-		    		$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' => ''));
460
+					$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' => ''));
461 461
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
462
-                        }
463
-		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
462
+						}
463
+			} elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
464 464
 			$timeelapsed = microtime(true);
465 465
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
466
-			    $Spotter = new Spotter($this->db);
467
-			    $route = $Spotter->getRouteInfo(trim($line['ident']));
468
-			    if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) {
466
+				$Spotter = new Spotter($this->db);
467
+				$route = $Spotter->getRouteInfo(trim($line['ident']));
468
+				if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) {
469 469
 				$Translation = new Translation($this->db);
470 470
 				$ident = $Translation->checkTranslation(trim($line['ident']));
471 471
 				$route = $Spotter->getRouteInfo($ident);
472 472
 				$Translation->db = null;
473
-			    }
474
-			    $Spotter->db = null;
475
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
476
-                    	}
473
+				}
474
+				$Spotter->db = null;
475
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
476
+						}
477 477
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
478
-			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
479
-			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
478
+				//if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
479
+				if ($route['fromairport_icao'] != $route['toairport_icao']) {
480 480
 				//    $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']));
481
-		    		$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']));
482
-		    	    }
481
+					$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']));
482
+					}
483 483
 			}
484 484
 			if (!isset($globalFork)) $globalFork = TRUE;
485 485
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
486 486
 				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
487 487
 			}
488
-		    }
488
+			}
489 489
 		}
490 490
 
491 491
 		if (isset($line['speed']) && $line['speed'] != '' && $line['speed'] != 0) {
492 492
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
493
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
494
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
495
-		    //$dataFound = true;
493
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
494
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
495
+			//$dataFound = true;
496 496
 		} 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'])) {
497
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
498
-		    if ($distance > 1000 && $distance < 10000) {
499
-		    // use datetime
497
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
498
+			if ($distance > 1000 && $distance < 10000) {
499
+			// use datetime
500 500
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
501 501
 			$speed = $speed*3.6;
502 502
 			if ($speed < 1000) {
@@ -505,49 +505,49 @@  discard block
 block discarded – undo
505 505
 	  		} else {
506 506
 	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
507 507
 	  		}
508
-		    }
508
+			}
509 509
 		}
510 510
 
511 511
 
512 512
 
513
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
514
-	    	    if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
515
-	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
516
-	    	    	return false;
517
-	    	    }
518
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
519
-	    	    else unset($timediff);
520
-	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
521
-	    	    else unset($timediff_archive);
522
-	    	    if ($this->tmd > 5
523
-	    	        || (isset($line['format_source']) 
524
-	    	    	    && $line['format_source'] == 'airwhere' 
525
-	    	    	    && ((!isset($this->all_flights[$id]['latitude']) 
526
-	    	    		|| !isset($this->all_flights[$id]['longitude'])) 
527
-	    	    		|| (isset($this->all_flights[$id]['latitude']) 
528
-	    	    		    && isset($this->all_flights[$id]['longitude']) 
529
-	    	    		    && $this->all_flights[$id]['latitude'] != $line['latitude'] 
530
-	    	    		    && $this->all_flights[$id]['longitude'] != $line['longitude']
531
-	    	    		)
532
-	    	    	    )
533
-	    	    	)
534
-	    		|| (isset($globalVA) && $globalVA) 
535
-	    	    	|| (isset($globalIVAO) && $globalIVAO)
536
-	    	    	|| (isset($globalVATSIM) && $globalVATSIM)
537
-	    	    	|| (isset($globalphpVMS) && $globalphpVMS)
538
-	    	    	|| (isset($globalVAM) && $globalVAM)
539
-	    	    	|| !isset($timediff)
540
-	    	    	|| $timediff > $globalLiveInterval
541
-	    	    	|| $globalArchive
542
-	    	    	|| ($timediff > 30 
543
-	    	    	    && isset($this->all_flights[$id]['latitude']) 
544
-	    	    	    && isset($this->all_flights[$id]['longitude']) 
545
-	    	    	    && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
546
-	    	    	    )
547
-	    	    	) {
513
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
514
+				if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
515
+					if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
516
+					return false;
517
+				}
518
+				if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
519
+				else unset($timediff);
520
+				if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
521
+				else unset($timediff_archive);
522
+				if ($this->tmd > 5
523
+					|| (isset($line['format_source']) 
524
+						&& $line['format_source'] == 'airwhere' 
525
+						&& ((!isset($this->all_flights[$id]['latitude']) 
526
+						|| !isset($this->all_flights[$id]['longitude'])) 
527
+						|| (isset($this->all_flights[$id]['latitude']) 
528
+							&& isset($this->all_flights[$id]['longitude']) 
529
+							&& $this->all_flights[$id]['latitude'] != $line['latitude'] 
530
+							&& $this->all_flights[$id]['longitude'] != $line['longitude']
531
+						)
532
+						)
533
+					)
534
+				|| (isset($globalVA) && $globalVA) 
535
+					|| (isset($globalIVAO) && $globalIVAO)
536
+					|| (isset($globalVATSIM) && $globalVATSIM)
537
+					|| (isset($globalphpVMS) && $globalphpVMS)
538
+					|| (isset($globalVAM) && $globalVAM)
539
+					|| !isset($timediff)
540
+					|| $timediff > $globalLiveInterval
541
+					|| $globalArchive
542
+					|| ($timediff > 30 
543
+						&& isset($this->all_flights[$id]['latitude']) 
544
+						&& isset($this->all_flights[$id]['longitude']) 
545
+						&& $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
546
+						)
547
+					) {
548 548
 
549 549
 			if ((isset($timediff) && !isset($timediff_archive)) || (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']))) {
550
-			    if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
550
+				if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
551 551
 				|| (isset($line['format_source']) && $line['format_source'] == 'airwhere') 
552 552
 				|| !$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'])) {
553 553
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -556,9 +556,9 @@  discard block
 block discarded – undo
556 556
 				if ($this->tmd > 5 && $this->all_flights[$id]['putinarchive'] == 1) $updateinitial = true;
557 557
 				$this->tmd = 0;
558 558
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
559
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
560
-				    $timeelapsed = microtime(true);
561
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
559
+					if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
560
+					$timeelapsed = microtime(true);
561
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
562 562
 					$Spotter = new Spotter($this->db);
563 563
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
564 564
 					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
@@ -566,11 +566,11 @@  discard block
 block discarded – undo
566 566
 					$Spotter->db = null;
567 567
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
568 568
 					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
569
-				    }
569
+					}
570 570
 				}
571 571
 				$this->all_flights[$id]['time_last_archive_coord'] = time();
572
-			    } 
573
-			    /*
572
+				} 
573
+				/*
574 574
 			    else {
575 575
 				if (!isset($timediff)) echo 'NO TIMEDIFF';
576 576
 				else {
@@ -584,16 +584,16 @@  discard block
 block discarded – undo
584 584
 			}
585 585
 
586 586
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
587
-			    //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) {
587
+				//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) {
588 588
 				if (!isset($this->all_flights[$id]['archive_latitude'])) {
589 589
 					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
590 590
 					$this->all_flights[$id]['time_last_coord'] = time();
591 591
 				}
592 592
 				//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' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
593 593
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
594
-				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
595
-				    $dataFound = true;
596
-				    $this->all_flights[$id]['time_last_coord'] = time();
594
+					$this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
595
+					$dataFound = true;
596
+					$this->all_flights[$id]['time_last_coord'] = time();
597 597
 				}
598 598
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
599 599
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
@@ -604,25 +604,25 @@  discard block
 block discarded – undo
604 604
 				    //$putinarchive = true;
605 605
 				}
606 606
 				*/
607
-			    /*
607
+				/*
608 608
 			    } elseif (isset($this->all_flights[$id]['latitude'])) {
609 609
 				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";
610 610
 			    }
611 611
 			    */
612 612
 			}
613 613
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
614
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
615
-			    //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) {
614
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
615
+				//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) {
616 616
 				if (!isset($this->all_flights[$id]['archive_longitude'])) {
617 617
 					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
618 618
 					$this->all_flights[$id]['time_last_coord'] = time();
619 619
 				}
620 620
 				//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' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
621 621
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
622
-				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
623
-				    $dataFound = true;
624
-				    $this->all_flights[$id]['coordinates'] += 1;
625
-				    $this->all_flights[$id]['time_last_coord'] = time();
622
+					$this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
623
+					$dataFound = true;
624
+					$this->all_flights[$id]['coordinates'] += 1;
625
+					$this->all_flights[$id]['time_last_coord'] = time();
626 626
 				}
627 627
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
628 628
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
@@ -640,76 +640,76 @@  discard block
 block discarded – undo
640 640
 			    */
641 641
 			}
642 642
 			if ($globalDaemon === TRUE && isset($updateinitial) && $updateinitial && $this->all_flights[$id]['addedSpotter'] == 1) {
643
-			    if ($globalDebug) echo '>>> Update initial data !'."\n";
644
-			    unset($updateinitial);
645
-			    $SpotterArchive = new SpotterArchive();
646
-			    $SpotterArchive->deleteSpotterArchiveTrackDataByID($this->all_flights[$id]['id']);
647
-			    $SpotterArchive->db = null;
648
-			    $Spotter = new Spotter();
649
-			    $Spotter->updateInitialSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime']);
650
-			    $Spotter->db = null;
643
+				if ($globalDebug) echo '>>> Update initial data !'."\n";
644
+				unset($updateinitial);
645
+				$SpotterArchive = new SpotterArchive();
646
+				$SpotterArchive->deleteSpotterArchiveTrackDataByID($this->all_flights[$id]['id']);
647
+				$SpotterArchive->db = null;
648
+				$Spotter = new Spotter();
649
+				$Spotter->updateInitialSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime']);
650
+				$Spotter->db = null;
651 651
 			}
652
-		    } else if ($globalDebug && $timediff > 30) {
652
+			} else if ($globalDebug && $timediff > 30) {
653 653
 			$this->tmd = $this->tmd + 1;
654 654
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
655 655
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
656 656
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
657 657
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
658
-		    }
658
+			}
659 659
 		}
660 660
 		if (isset($line['last_update']) && $line['last_update'] != '') {
661
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
662
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
661
+			if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
662
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
663 663
 		}
664 664
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
665
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
666
-		    //$dataFound = true;
665
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
666
+			//$dataFound = true;
667 667
 		}
668 668
 		if (isset($line['format_source']) && $line['format_source'] != '') {
669
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
669
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
670 670
 		}
671 671
 		if (isset($line['source_name']) && $line['source_name'] != '') {
672
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
672
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
673 673
 		}
674 674
 		if (isset($line['emergency']) && $line['emergency'] != '') {
675
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
676
-		    //$dataFound = true;
675
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
676
+			//$dataFound = true;
677 677
 		}
678 678
 		if (isset($line['ground']) && $line['ground'] != '') {
679
-		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
679
+			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
680 680
 			// Here we force archive of flight because after ground it's a new one (or should be)
681 681
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
682 682
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
683 683
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
684
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
684
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
685 685
 			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']));
686
-		    }
687
-		    if ($line['ground'] != 1) $line['ground'] = 0;
688
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
689
-		    //$dataFound = true;
686
+			}
687
+			if ($line['ground'] != 1) $line['ground'] = 0;
688
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
689
+			//$dataFound = true;
690 690
 		}
691 691
 		if (isset($line['squawk']) && $line['squawk'] != '') {
692
-		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
693
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
694
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
695
-			    $highlight = '';
696
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
697
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
698
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
699
-			    if ($highlight != '') {
692
+			if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
693
+				if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
694
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
695
+				$highlight = '';
696
+				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
697
+				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
698
+				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
699
+				if ($highlight != '') {
700 700
 				$timeelapsed = microtime(true);
701 701
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
702
-				    $Spotter = new Spotter($this->db);
703
-				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
704
-				    $Spotter->db = null;
705
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
702
+					$Spotter = new Spotter($this->db);
703
+					$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
704
+					$Spotter->db = null;
705
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
706 706
 				}
707 707
 				//$putinarchive = true;
708 708
 				//$highlight = '';
709
-			    }
709
+				}
710 710
 			    
711
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
712
-		    //$dataFound = true;
711
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
712
+			//$dataFound = true;
713 713
 		}
714 714
 
715 715
 		if (isset($line['altitude']) && $line['altitude'] != '') {
@@ -720,13 +720,13 @@  discard block
 block discarded – undo
720 720
 					$line['altitude'] = $line['altitude'] - $geoid;
721 721
 				}
722 722
 			}
723
-		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
723
+			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
724 724
 			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
725 725
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
726 726
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
727 727
 			//$dataFound = true;
728
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
729
-		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
728
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
729
+			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
730 730
 			if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
731 731
 				if ($globalDebug) echo '--- Reset because of altitude'."\n";
732 732
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
@@ -735,27 +735,27 @@  discard block
 block discarded – undo
735 735
 				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
736 736
 				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']));
737 737
 			}
738
-		    }
739
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
738
+			}
739
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
740 740
 		}
741 741
 
742 742
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
743
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
743
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
744 744
 		}
745 745
 		
746 746
 		if (isset($line['heading']) && $line['heading'] != '') {
747
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
748
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
749
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
750
-		    //$dataFound = true;
747
+			if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
748
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
749
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
750
+			//$dataFound = true;
751 751
   		} 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']) {
752
-  		    $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']);
753
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
754
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
755
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
752
+  			$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']);
753
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
754
+			if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
755
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
756 756
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
757
-  		    // If not enough messages and ACARS set heading to 0
758
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
757
+  			// If not enough messages and ACARS set heading to 0
758
+  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
759 759
   		}
760 760
 		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
761 761
 		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
@@ -768,133 +768,133 @@  discard block
 block discarded – undo
768 768
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
769 769
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
770 770
 		if ($dataFound === true && isset($this->all_flights[$id]['id'])) {
771
-		    $this->all_flights[$id]['lastupdate'] = time();
772
-		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
773
-		        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'])) {
774
-			    //print_r($this->all_flights);
775
-			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
776
-			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
777
-			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
771
+			$this->all_flights[$id]['lastupdate'] = time();
772
+			if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
773
+				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'])) {
774
+				//print_r($this->all_flights);
775
+				//echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
776
+				//$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
777
+				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
778 778
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
779
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
780
-				    $timeelapsed = microtime(true);
781
-				    $SpotterLive = new SpotterLive($this->db);
782
-				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) {
779
+					if ($globalDebug) echo "Check if aircraft is already in DB...";
780
+					$timeelapsed = microtime(true);
781
+					$SpotterLive = new SpotterLive($this->db);
782
+					if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) {
783 783
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
784 784
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
785
-				    } elseif (isset($line['id'])) {
785
+					} elseif (isset($line['id'])) {
786 786
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
787 787
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
788
-				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
788
+					} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
789 789
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
790 790
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
791
-				    } else $recent_ident = '';
792
-				    $SpotterLive->db=null;
793
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
794
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
791
+					} else $recent_ident = '';
792
+					$SpotterLive->db=null;
793
+					if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
794
+					elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
795 795
 				} else $recent_ident = '';
796
-			    } else {
796
+				} else {
797 797
 				$recent_ident = '';
798 798
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
799
-			    }
800
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
801
-			    if($recent_ident == "")
802
-			    {
799
+				}
800
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
801
+				if($recent_ident == "")
802
+				{
803 803
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
804 804
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
805 805
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
806 806
 				//adds the spotter data for the archive
807 807
 				$ignoreImport = false;
808 808
 				foreach($globalAirportIgnore as $airportIgnore) {
809
-				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
809
+					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
810 810
 					$ignoreImport = true;
811
-				    }
811
+					}
812 812
 				}
813 813
 				if (count($globalAirportAccept) > 0) {
814
-				    $ignoreImport = true;
815
-				    foreach($globalAirportIgnore as $airportIgnore) {
814
+					$ignoreImport = true;
815
+					foreach($globalAirportIgnore as $airportIgnore) {
816 816
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
817
-					    $ignoreImport = false;
817
+						$ignoreImport = false;
818
+					}
818 819
 					}
819
-				    }
820 820
 				}
821 821
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
822
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
822
+					foreach($globalAirlineIgnore as $airlineIgnore) {
823 823
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
824
-					    $ignoreImport = true;
824
+						$ignoreImport = true;
825
+					}
825 826
 					}
826
-				    }
827 827
 				}
828 828
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
829
-				    $ignoreImport = true;
830
-				    foreach($globalAirlineAccept as $airlineAccept) {
829
+					$ignoreImport = true;
830
+					foreach($globalAirlineAccept as $airlineAccept) {
831 831
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
832
-					    $ignoreImport = false;
832
+						$ignoreImport = false;
833
+					}
833 834
 					}
834
-				    }
835 835
 				}
836 836
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
837
-				    $ignoreImport = true;
838
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
837
+					$ignoreImport = true;
838
+					foreach($globalPilotIdAccept as $pilotIdAccept) {
839 839
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
840
-					    $ignoreImport = false;
840
+						$ignoreImport = false;
841
+					}
841 842
 					}
842
-				    }
843 843
 				}
844 844
 				
845 845
 				if (!$ignoreImport) {
846
-				    $highlight = '';
847
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
848
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
849
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
850
-				    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')));
851
-				    $timeelapsed = microtime(true);
852
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
846
+					$highlight = '';
847
+					if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
848
+					if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
849
+					if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
850
+					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')));
851
+					$timeelapsed = microtime(true);
852
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
853 853
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
854
-					    $Spotter = new Spotter($this->db);
855
-					    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
856
-					    $Spotter->db = null;
857
-					    if ($globalDebug) {
854
+						$Spotter = new Spotter($this->db);
855
+						$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
856
+						$Spotter->db = null;
857
+						if ($globalDebug) {
858 858
 						if (isset($result['error'])) echo 'Error: '.$result['error']."\n";
859 859
 						else echo 'Success';
860
-					    }
861
-					    if (count($result) > 1) {
862
-					    // ':airline_name' => $airline_name,':airline_icao' => $airline_icao,':airline_country' => $airline_country,':airline_type' => $airline_type,
860
+						}
861
+						if (count($result) > 1) {
862
+						// ':airline_name' => $airline_name,':airline_icao' => $airline_icao,':airline_country' => $airline_country,':airline_type' => $airline_type,
863 863
 						if ($this->all_flights[$id]['aircraft_icao'] == '') $this->all_flights[$id]['aircraft_icao'] = $result[':aircraft_icao'];
864 864
 						if ($this->all_flights[$id]['registration'] == '') $this->all_flights[$id]['registration'] = $result[':registration'];
865
-					    }
865
+						}
866 866
 					}
867
-				    }
868
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
869
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
867
+					}
868
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
869
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
870 870
 
871
-				    // Add source stat in DB
872
-				    $Stats = new Stats($this->db);
873
-				    if (!empty($this->stats)) {
871
+					// Add source stat in DB
872
+					$Stats = new Stats($this->db);
873
+					if (!empty($this->stats)) {
874 874
 					if ($globalDebug) echo 'Add source stats : ';
875
-				        foreach($this->stats as $date => $data) {
876
-					    foreach($data as $source => $sourced) {
877
-					        //print_r($sourced);
878
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
879
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
880
-				    		if (isset($sourced['msg'])) {
881
-				    		    if (time() - $sourced['msg']['date'] > 10) {
882
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
883
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
884
-			    			        unset($this->stats[$date][$source]['msg']);
885
-			    			    }
886
-			    			}
887
-			    		    }
888
-			    		    if ($date != date('Y-m-d')) {
889
-			    			unset($this->stats[$date]);
890
-			    		    }
891
-				    	}
892
-				    	if ($globalDebug) echo 'Done'."\n";
875
+						foreach($this->stats as $date => $data) {
876
+						foreach($data as $source => $sourced) {
877
+							//print_r($sourced);
878
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
879
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
880
+							if (isset($sourced['msg'])) {
881
+								if (time() - $sourced['msg']['date'] > 10) {
882
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
883
+									echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
884
+									unset($this->stats[$date][$source]['msg']);
885
+								}
886
+							}
887
+							}
888
+							if ($date != date('Y-m-d')) {
889
+							unset($this->stats[$date]);
890
+							}
891
+						}
892
+						if ($globalDebug) echo 'Done'."\n";
893 893
 
894
-				    }
895
-				    $Stats->db = null;
896
-				    }
897
-				    $this->del();
894
+					}
895
+					$Stats->db = null;
896
+					}
897
+					$this->del();
898 898
 				} elseif ($globalDebug) echo 'Ignore data'."\n";
899 899
 				//$ignoreImport = false;
900 900
 				$this->all_flights[$id]['addedSpotter'] = 1;
@@ -912,41 +912,41 @@  discard block
 block discarded – undo
912 912
 			*/
913 913
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
914 914
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
915
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
916
-				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
917
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
915
+					if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
916
+					//SpotterLive->deleteLiveSpotterDataNotUpdated();
917
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
918 918
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
919
-					    $SpotterLive = new SpotterLive($this->db);
920
-					    $SpotterLive->deleteLiveSpotterData();
921
-					    $SpotterLive->db=null;
919
+						$SpotterLive = new SpotterLive($this->db);
920
+						$SpotterLive->deleteLiveSpotterData();
921
+						$SpotterLive->db=null;
922 922
 					}
923
-				    }
924
-				    if ($globalDebug) echo " Done\n";
925
-				    $this->last_delete = time();
923
+					}
924
+					if ($globalDebug) echo " Done\n";
925
+					$this->last_delete = time();
926 926
 				}
927
-			    } else {
927
+				} else {
928 928
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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'] === 'famaprs' || $line['format_source'] === 'airwhere')) {
929
-				    $this->all_flights[$id]['id'] = $recent_ident;
930
-				    $this->all_flights[$id]['addedSpotter'] = 1;
929
+					$this->all_flights[$id]['id'] = $recent_ident;
930
+					$this->all_flights[$id]['addedSpotter'] = 1;
931 931
 				}
932 932
 				if (isset($globalDaemon) && !$globalDaemon) {
933
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
933
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
934 934
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
935
-					    $Spotter = new Spotter($this->db);
936
-					    $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
937
-					    $Spotter->db = null;
935
+						$Spotter = new Spotter($this->db);
936
+						$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
937
+						$Spotter->db = null;
938
+					}
938 939
 					}
939
-				    }
940 940
 				}
941 941
 				
942
-			    }
942
+				}
943 943
 			}
944
-		    }
945
-		    //adds the spotter LIVE data
946
-		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
947
-		    //echo "\nAdd in Live !! \n";
948
-		    //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";
949
-		    if ($globalDebug) {
944
+			}
945
+			//adds the spotter LIVE data
946
+			//SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
947
+			//echo "\nAdd in Live !! \n";
948
+			//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";
949
+			if ($globalDebug) {
950 950
 			if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
951 951
 				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";
952 952
 				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";
@@ -954,60 +954,60 @@  discard block
 block discarded – undo
954 954
 				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";
955 955
 				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";
956 956
 			}
957
-		    }
958
-		    $ignoreImport = false;
959
-		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
960
-		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
957
+			}
958
+			$ignoreImport = false;
959
+			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
960
+			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
961 961
 
962
-		    foreach($globalAirportIgnore as $airportIgnore) {
963
-		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
964
-			    $ignoreImport = true;
962
+			foreach($globalAirportIgnore as $airportIgnore) {
963
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
964
+				$ignoreImport = true;
965
+			}
965 966
 			}
966
-		    }
967
-		    if (count($globalAirportAccept) > 0) {
968
-		        $ignoreImport = true;
969
-		        foreach($globalAirportIgnore as $airportIgnore) {
970
-			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
967
+			if (count($globalAirportAccept) > 0) {
968
+				$ignoreImport = true;
969
+				foreach($globalAirportIgnore as $airportIgnore) {
970
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
971 971
 				$ignoreImport = false;
972
-			    }
972
+				}
973 973
 			}
974
-		    }
975
-		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
974
+			}
975
+			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
976 976
 			foreach($globalAirlineIgnore as $airlineIgnore) {
977
-			    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)) {
977
+				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)) {
978 978
 				$ignoreImport = true;
979
-			    }
979
+				}
980 980
 			}
981
-		    }
982
-		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
981
+			}
982
+			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
983 983
 			$ignoreImport = true;
984 984
 			foreach($globalAirlineAccept as $airlineAccept) {
985
-			    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)) {
985
+				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)) {
986 986
 				$ignoreImport = false;
987
-			    }
987
+				}
988
+			}
988 989
 			}
989
-		    }
990
-		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
990
+			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
991 991
 			$ignoreImport = true;
992 992
 			foreach($globalPilotIdAccept as $pilotIdAccept) {
993
-			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
994
-			        $ignoreImport = false;
995
-			    }
993
+				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
994
+					$ignoreImport = false;
995
+				}
996
+			}
996 997
 			}
997
-		    }
998 998
 
999
-		    if (!$ignoreImport) {
999
+			if (!$ignoreImport) {
1000 1000
 			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'])) {
1001 1001
 				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')));
1002 1002
 				$timeelapsed = microtime(true);
1003 1003
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
1004
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
1004
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
1005 1005
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1006 1006
 					$SpotterLive = new SpotterLive($this->db);
1007 1007
 					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
1008 1008
 					$SpotterLive->db = null;
1009 1009
 					if ($globalDebug) echo $result."\n";
1010
-				    }
1010
+					}
1011 1011
 				}
1012 1012
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
1013 1013
 					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
@@ -1019,7 +1019,7 @@  discard block
 block discarded – undo
1019 1019
 				//if ($line['format_source'] != 'aprs') {
1020 1020
 				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
1021 1021
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
1022
-				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
1022
+					if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
1023 1023
 					$source = $this->all_flights[$id]['source_name'];
1024 1024
 					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1025 1025
 					if (!isset($this->source_location[$source])) {
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
 					if ($stats_heading == 16) $stats_heading = 0;
1046 1046
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
1047 1047
 						for ($i=0;$i<=15;$i++) {
1048
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
1048
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
1049 1049
 						}
1050 1050
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
1051 1051
 					} else {
@@ -1058,17 +1058,17 @@  discard block
 block discarded – undo
1058 1058
 					//var_dump($this->stats);
1059 1059
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
1060 1060
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1061
-						    end($this->stats[$current_date][$source]['hist']);
1062
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1061
+							end($this->stats[$current_date][$source]['hist']);
1062
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
1063 1063
 						} else $mini = 0;
1064 1064
 						for ($i=$mini;$i<=$distance;$i+=10) {
1065
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1065
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
1066 1066
 						}
1067 1067
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
1068 1068
 					} else {
1069 1069
 						$this->stats[$current_date][$source]['hist'][$distance] += 1;
1070 1070
 					}
1071
-				    }
1071
+					}
1072 1072
 				}
1073 1073
 
1074 1074
 				$this->all_flights[$id]['lastupdate'] = time();
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
 			//$this->del();
1079 1079
 			
1080 1080
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
1081
-			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1081
+				if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1082 1082
 				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1083 1083
 				$SpotterLive = new SpotterLive($this->db);
1084 1084
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
@@ -1086,19 +1086,19 @@  discard block
 block discarded – undo
1086 1086
 				//SpotterLive->deleteLiveSpotterData();
1087 1087
 				if ($globalDebug) echo " Done\n";
1088 1088
 				$this->last_delete_hourly = time();
1089
-			    } else {
1089
+				} else {
1090 1090
 				$this->del();
1091 1091
 				$this->last_delete_hourly = time();
1092
-			    }
1092
+				}
1093 1093
 			}
1094 1094
 			
1095
-		    }
1096
-		    //$ignoreImport = false;
1095
+			}
1096
+			//$ignoreImport = false;
1097 1097
 		}
1098 1098
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
1099 1099
 		if ($send) return $this->all_flights[$id];
1100
-	    }
1100
+		}
1101
+	}
1101 1102
 	}
1102
-    }
1103 1103
 }
1104 1104
 ?>
Please login to merge, or discard this patch.
Spacing   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -41,12 +41,12 @@  discard block
 block discarded – undo
41 41
 		$currentdate = date('Y-m-d');
42 42
 		$sourcestat = $Stats->getStatsSource($currentdate);
43 43
 		if (!empty($sourcestat)) {
44
-		    foreach($sourcestat as $srcst) {
44
+		    foreach ($sourcestat as $srcst) {
45 45
 		    	$type = $srcst['stats_type'];
46 46
 			if ($type == 'polar' || $type == 'hist') {
47 47
 			    $source = $srcst['source_name'];
48 48
 			    $data = $srcst['source_data'];
49
-			    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
49
+			    $this->stats[$currentdate][$source][$type] = json_decode($data, true);
50 50
 	    		}
51 51
 		    }
52 52
 		}
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
 	if (isset($globalGeoid) && $globalGeoid) {
59 59
 		try {
60 60
 			$GeoidClass = new GeoidHeight();
61
-		} catch(Exception $e) {
61
+		} catch (Exception $e) {
62 62
 			if ($globalDebug) echo "Can't calculate geoid, check that you downloaded it via update_db.php (".$e.")\n";
63 63
 			$GeoidClass = FALSE;
64 64
 		}
65 65
 	}
66 66
     }
67 67
 
68
-    public function get_Schedule($id,$ident) {
68
+    public function get_Schedule($id, $ident) {
69 69
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
70 70
 	// Get schedule here, so it's done only one time
71 71
 	
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
 		$schedule = $Schedule->fetchSchedule($operator);
91 91
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
92 92
 		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
93
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
94
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
93
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $schedule['DepartureTime']));
94
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $schedule['ArrivalTime']));
95 95
 		    // Should also check if route schedule = route from DB
96 96
 		    if ($schedule['DepartureAirportIATA'] != '') {
97 97
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 			    }
112 112
 			}
113 113
 		    }
114
-		    $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']);
114
+		    $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']);
115 115
 		}
116 116
 	    } else $scheduleexist = true;
117 117
 	} else $scheduleexist = true;
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
        if ($scheduleexist) {
120 120
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
121 121
     		$sch = $Schedule->getSchedule($operator);
122
-		$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']));
123
-		if ($this->all_flights[$id]['addedSpotter'] == 1) $Spotter->updateLatestScheduleSpotterData($this->all_flights[$id]['id'],$sch['departure_airport_icao'],$sch['departure_airport_time'],$sch['arrival_airport_icao'],$sch['arrival_airport_time']);
122
+		$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']));
123
+		if ($this->all_flights[$id]['addedSpotter'] == 1) $Spotter->updateLatestScheduleSpotterData($this->all_flights[$id]['id'], $sch['departure_airport_icao'], $sch['departure_airport_time'], $sch['arrival_airport_icao'], $sch['arrival_airport_time']);
124 124
        }
125 125
 	$Spotter->db = null;
126 126
 	$Schedule->db = null;
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
148 148
     		    $Spotter = new Spotter($this->db);
149 149
         	    $real_arrival = $this->arrival($key);
150
-        	    if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) $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']);
150
+        	    if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) $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']);
151 151
         	}
152 152
 	    }
153 153
 	}
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
         $airport_time = '';
162 162
         if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
163 163
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
164
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
164
+	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $globalClosestMinDist);
165 165
     	    if (isset($closestAirports[0])) {
166 166
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
167 167
         	    $airport_icao = $closestAirports[0]['icao'];
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
         		    break;
177 177
         		}
178 178
         	    }
179
-        	} 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))) {
179
+        	} 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))) {
180 180
         		$airport_icao = $closestAirports[0]['icao'];
181 181
         		$airport_time = $this->all_flights[$key]['datetime'];
182 182
         	} else {
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
         } else {
190 190
         	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
191 191
         }
192
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
192
+        return array('airport_icao' => $airport_icao, 'airport_time' => $airport_time);
193 193
     }
194 194
 
195 195
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 	
202 202
 	foreach ($this->all_flights as $key => $flight) {
203 203
 		if (isset($flight['lastupdate'])) {
204
-			if ($flight['lastupdate'] < (time()-1800)) {
204
+			if ($flight['lastupdate'] < (time() - 1800)) {
205 205
 				$this->delKey($key);
206 206
 			}
207 207
 		}
@@ -218,10 +218,10 @@  discard block
 block discarded – undo
218 218
 			$Spotter = new Spotter($this->db);
219 219
 			$SpotterLive = new SpotterLive($this->db);
220 220
 			if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
221
-				$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']);
221
+				$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']);
222 222
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
223 223
 				$this->all_flights[$key]['putinarchive'] = true;
224
-				$result = $SpotterLive->addLiveSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['aircraft_icao'], $this->all_flights[$key]['departure_airport'], $this->all_flights[$key]['arrival_airport'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['waypoints'], $this->all_flights[$key]['altitude'],$this->all_flights[$key]['altitude_real'], $this->all_flights[$key]['heading'], $this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'], $this->all_flights[$key]['departure_airport_time'], $this->all_flights[$key]['arrival_airport_time'], $this->all_flights[$key]['squawk'],$this->all_flights[$key]['route_stop'],$this->all_flights[$key]['hex'],$this->all_flights[$key]['putinarchive'],$this->all_flights[$key]['registration'],$this->all_flights[$key]['pilot_id'],$this->all_flights[$key]['pilot_name'], $this->all_flights[$key]['verticalrate'], $this->all_flights[$key]['noarchive'], $this->all_flights[$key]['ground'],$this->all_flights[$key]['format_source'],$this->all_flights[$key]['source_name'],$this->all_flights[$key]['over_country']);
224
+				$result = $SpotterLive->addLiveSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['aircraft_icao'], $this->all_flights[$key]['departure_airport'], $this->all_flights[$key]['arrival_airport'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['waypoints'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['altitude_real'], $this->all_flights[$key]['heading'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $this->all_flights[$key]['departure_airport_time'], $this->all_flights[$key]['arrival_airport_time'], $this->all_flights[$key]['squawk'], $this->all_flights[$key]['route_stop'], $this->all_flights[$key]['hex'], $this->all_flights[$key]['putinarchive'], $this->all_flights[$key]['registration'], $this->all_flights[$key]['pilot_id'], $this->all_flights[$key]['pilot_name'], $this->all_flights[$key]['verticalrate'], $this->all_flights[$key]['noarchive'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['format_source'], $this->all_flights[$key]['source_name'], $this->all_flights[$key]['over_country']);
225 225
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
226 226
 			}
227 227
 			$Spotter->db = null;
@@ -257,10 +257,10 @@  discard block
 block discarded – undo
257 257
 	$send = false;
258 258
 	
259 259
 	// SBS format is CSV format
260
-	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
260
+	if (is_array($line) && (isset($line['hex']) || isset($line['id']))) {
261 261
 	    //print_r($line);
262 262
 	    if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
263
-  	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && substr($line['hex'],0,1) != '~' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
263
+  	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && substr($line['hex'], 0, 1) != '~' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
264 264
 
265 265
 		// Increment message number
266 266
 		if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) {
@@ -293,25 +293,25 @@  discard block
 block discarded – undo
293 293
 		if (!isset($this->all_flights[$id])) {
294 294
 		    if ($globalDebug) echo 'New flight...'."\n";
295 295
 		    $this->all_flights[$id] = array();
296
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
297
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => '','coordinates' => 0));
298
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
296
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
297
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => '', 'departure_airport' => '', 'arrival_airport' => '', 'latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'altitude_real' => '', 'altitude_previous' => '', 'heading' => '', 'departure_airport_time' => '', 'arrival_airport_time' => '', 'squawk' => '', 'route_stop' => '', 'registration' => '', 'pilot_id' => '', 'pilot_name' => '', 'waypoints' => '', 'ground' => '0', 'format_source' => '', 'source_name' => '', 'over_country' => '', 'verticalrate' => '', 'noarchive' => false, 'putinarchive' => true, 'source_type' => '', 'coordinates' => 0));
298
+		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('lastupdate' => time()));
299 299
 		    if (!isset($line['id'])) {
300 300
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
301 301
 //			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')));
302 302
 //			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')));
303
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
303
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi')));
304 304
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
305
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
305
+		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
306 306
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
307 307
 		}
308 308
 		if (isset($line['source_type']) && $line['source_type'] != '') {
309
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
309
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_type' => $line['source_type']));
310 310
 		}
311 311
 		
312 312
 		//print_r($this->all_flights);
313 313
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
314
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
314
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('hex' => trim($line['hex'])));
315 315
 		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
316 316
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
317 317
 		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -320,20 +320,20 @@  discard block
 block discarded – undo
320 320
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
321 321
 			    $Spotter = new Spotter($this->db);
322 322
 			    if (isset($this->all_flights[$id]['source_type'])) {
323
-				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
323
+				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']), $this->all_flights[$id]['source_type']);
324 324
 			    } else {
325 325
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
326 326
 			    }
327 327
 			    $Spotter->db = null;
328
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
329
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
328
+			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
329
+			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
330 330
 			}
331 331
 		    }
332 332
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
333 333
 		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
334 334
 		}
335 335
 	        if (isset($line['id']) && !isset($line['hex'])) {
336
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
336
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('hex' => ''));
337 337
 	        }
338 338
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
339 339
 			$icao = $line['aircraft_icao'];
@@ -342,14 +342,14 @@  discard block
 block discarded – undo
342 342
 				if (isset($Spotter->aircraft_correct_icaotype[$icao])) $icao = $Spotter->aircraft_correct_icaotype[$icao];
343 343
 				$Spotter->db = null;
344 344
 			}
345
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $icao));
345
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $icao));
346 346
 		} elseif (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_name'])) {
347 347
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
348 348
 				// Get aircraft ICAO from aircraft name
349 349
 				$Spotter = new Spotter($this->db);
350 350
 				$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
351 351
 				$Spotter->db = null;
352
-				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
352
+				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
353 353
 			}
354 354
 		}
355 355
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
@@ -357,15 +357,15 @@  discard block
 block discarded – undo
357 357
 			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
358 358
 			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
359 359
 			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
360
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
360
+			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
361 361
 		}
362 362
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
363
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
363
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => 'NA'));
364 364
 		}
365 365
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
366
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) {
366
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 20*60 && strtotime($line['datetime']) < time() + 20*60) {
367 367
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
368
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
368
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => $line['datetime']));
369 369
 		    } else {
370 370
 				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";
371 371
 				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";
@@ -376,31 +376,31 @@  discard block
 block discarded – undo
376 376
 				*/
377 377
 				return '';
378 378
 		    }
379
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
379
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time() - 20*60) {
380 380
 			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
381 381
 			return '';
382
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) {
382
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time() + 20*60) {
383 383
 			if ($globalDebug) echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
384 384
 			return '';
385 385
 		} elseif (!isset($line['datetime'])) {
386 386
 			date_default_timezone_set('UTC');
387
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
387
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => date('Y-m-d H:i:s')));
388 388
 		} else {
389 389
 			if ($globalDebug) echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
390 390
 			return '';
391 391
 		}
392 392
 
393 393
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG' && $line['registration'] != 'NA') {
394
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
394
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('registration' => $line['registration']));
395 395
 		}
396 396
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
397
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
397
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('waypoints' => $line['waypoints']));
398 398
 		}
399 399
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
400
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
400
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_id' => trim($line['pilot_id'])));
401 401
 		}
402 402
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
403
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
403
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_name' => trim($line['pilot_name'])));
404 404
 		}
405 405
  
406 406
 		if (isset($line['ident']) && trim($line['ident']) != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
@@ -408,13 +408,13 @@  discard block
 block discarded – undo
408 408
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
409 409
 			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
410 410
 				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
411
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
412
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
413
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
414
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
415
-				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']));
411
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
412
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
413
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi')));
414
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
415
+				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']));
416 416
 			} else {
417
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
417
+			    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident'])));
418 418
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
419 419
 				$timeelapsed = microtime(true);
420 420
             			$Spotter = new Spotter($this->db);
@@ -424,13 +424,13 @@  discard block
 block discarded – undo
424 424
 				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
425 425
 				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
426 426
 				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
427
-            			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource,$this->all_flights[$id]['source_type']);
427
+            			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $fromsource, $this->all_flights[$id]['source_type']);
428 428
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
429 429
 				$Spotter->db = null;
430
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
430
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
431 431
 			    }
432 432
 			}
433
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
433
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident'])));
434 434
 		    
435 435
 /*
436 436
 		    if (!isset($line['id'])) {
@@ -440,25 +440,25 @@  discard block
 block discarded – undo
440 440
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
441 441
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
442 442
   */
443
-		    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']));
443
+		    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']));
444 444
 
445 445
 		    //$putinarchive = true;
446 446
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
447
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
447
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $line['departure_airport_time']));
448 448
 		    }
449 449
 		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
450
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
450
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $line['arrival_airport_time']));
451 451
 		    }
452 452
 		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
453
-		    		$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' => ''));
453
+		    		$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' => ''));
454 454
 		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
455 455
 			$timeelapsed = microtime(true);
456 456
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
457 457
 				$Spotter = new Spotter($this->db);
458 458
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
459 459
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
460
-		    		$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' => ''));
461
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
460
+		    		$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' => ''));
461
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
462 462
                         }
463 463
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
464 464
 			$timeelapsed = microtime(true);
@@ -472,35 +472,35 @@  discard block
 block discarded – undo
472 472
 				$Translation->db = null;
473 473
 			    }
474 474
 			    $Spotter->db = null;
475
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
475
+			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
476 476
                     	}
477 477
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
478 478
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
479 479
 			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
480 480
 				//    $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']));
481
-		    		$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']));
481
+		    		$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']));
482 482
 		    	    }
483 483
 			}
484 484
 			if (!isset($globalFork)) $globalFork = TRUE;
485 485
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
486
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
486
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id, trim($line['ident']));
487 487
 			}
488 488
 		    }
489 489
 		}
490 490
 
491 491
 		if (isset($line['speed']) && $line['speed'] != '' && $line['speed'] != 0) {
492 492
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
493
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
494
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
493
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($line['speed'])));
494
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed_fromsrc' => true));
495 495
 		    //$dataFound = true;
496 496
 		} 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'])) {
497
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
497
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm');
498 498
 		    if ($distance > 1000 && $distance < 10000) {
499 499
 		    // use datetime
500 500
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
501 501
 			$speed = $speed*3.6;
502 502
 			if ($speed < 1000) {
503
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
503
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($speed)));
504 504
 	  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
505 505
 	  		} else {
506 506
 	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
@@ -515,9 +515,9 @@  discard block
 block discarded – undo
515 515
 	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
516 516
 	    	    	return false;
517 517
 	    	    }
518
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
518
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time() - $this->all_flights[$id]['time_last_coord']);
519 519
 	    	    else unset($timediff);
520
-	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
520
+	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time() - $this->all_flights[$id]['time_last_archive_coord']);
521 521
 	    	    else unset($timediff_archive);
522 522
 	    	    if ($this->tmd > 5
523 523
 	    	        || (isset($line['format_source']) 
@@ -542,14 +542,14 @@  discard block
 block discarded – undo
542 542
 	    	    	|| ($timediff > 30 
543 543
 	    	    	    && isset($this->all_flights[$id]['latitude']) 
544 544
 	    	    	    && isset($this->all_flights[$id]['longitude']) 
545
-	    	    	    && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
545
+	    	    	    && $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm'))
546 546
 	    	    	    )
547 547
 	    	    	) {
548 548
 
549 549
 			if ((isset($timediff) && !isset($timediff_archive)) || (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']))) {
550 550
 			    if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
551 551
 				|| (isset($line['format_source']) && $line['format_source'] == 'airwhere') 
552
-				|| !$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'])) {
552
+				|| !$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'])) {
553 553
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
554 554
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
555 555
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -560,11 +560,11 @@  discard block
 block discarded – undo
560 560
 				    $timeelapsed = microtime(true);
561 561
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
562 562
 					$Spotter = new Spotter($this->db);
563
-					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
563
+					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
564 564
 					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
565 565
 					else $this->all_flights[$id]['over_country'] = '';
566 566
 					$Spotter->db = null;
567
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
567
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
568 568
 					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
569 569
 				    }
570 570
 				}
@@ -590,13 +590,13 @@  discard block
 block discarded – undo
590 590
 					$this->all_flights[$id]['time_last_coord'] = time();
591 591
 				}
592 592
 				//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' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
593
-				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
593
+				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude'] - $line['latitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude'] - $line['latitude']) > 0.0001)) {
594 594
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
595 595
 				    $dataFound = true;
596 596
 				    $this->all_flights[$id]['time_last_coord'] = time();
597 597
 				}
598 598
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
599
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
599
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('latitude' => $line['latitude']));
600 600
 				/*
601 601
 				if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) {
602 602
 				    $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -618,14 +618,14 @@  discard block
 block discarded – undo
618 618
 					$this->all_flights[$id]['time_last_coord'] = time();
619 619
 				}
620 620
 				//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' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
621
-				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
621
+				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude'] - $line['longitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude'] - $line['longitude']) > 0.0001)) {
622 622
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
623 623
 				    $dataFound = true;
624 624
 				    $this->all_flights[$id]['coordinates'] += 1;
625 625
 				    $this->all_flights[$id]['time_last_coord'] = time();
626 626
 				}
627 627
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
628
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
628
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('longitude' => $line['longitude']));
629 629
 				/*
630 630
 				if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) {
631 631
 				    $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
@@ -646,52 +646,52 @@  discard block
 block discarded – undo
646 646
 			    $SpotterArchive->deleteSpotterArchiveTrackDataByID($this->all_flights[$id]['id']);
647 647
 			    $SpotterArchive->db = null;
648 648
 			    $Spotter = new Spotter();
649
-			    $Spotter->updateInitialSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime']);
649
+			    $Spotter->updateInitialSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime']);
650 650
 			    $Spotter->db = null;
651 651
 			}
652 652
 		    } else if ($globalDebug && $timediff > 30) {
653 653
 			$this->tmd = $this->tmd + 1;
654 654
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
655
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
656
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
655
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')."m -";
656
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
657 657
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
658 658
 		    }
659 659
 		}
660 660
 		if (isset($line['last_update']) && $line['last_update'] != '') {
661 661
 		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
662
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
662
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('last_update' => $line['last_update']));
663 663
 		}
664 664
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
665
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
665
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('verticalrate' => $line['verticalrate']));
666 666
 		    //$dataFound = true;
667 667
 		}
668 668
 		if (isset($line['format_source']) && $line['format_source'] != '') {
669
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
669
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('format_source' => $line['format_source']));
670 670
 		}
671 671
 		if (isset($line['source_name']) && $line['source_name'] != '') {
672
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
672
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_name' => $line['source_name']));
673 673
 		}
674 674
 		if (isset($line['emergency']) && $line['emergency'] != '') {
675
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
675
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('emergency' => $line['emergency']));
676 676
 		    //$dataFound = true;
677 677
 		}
678 678
 		if (isset($line['ground']) && $line['ground'] != '') {
679 679
 		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
680 680
 			// Here we force archive of flight because after ground it's a new one (or should be)
681
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
682
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
683
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
684
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
685
-			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']));
681
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
682
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
683
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi')));
684
+		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
685
+			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']));
686 686
 		    }
687 687
 		    if ($line['ground'] != 1) $line['ground'] = 0;
688
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
688
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ground' => $line['ground']));
689 689
 		    //$dataFound = true;
690 690
 		}
691 691
 		if (isset($line['squawk']) && $line['squawk'] != '') {
692 692
 		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
693 693
 			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
694
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
694
+			    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
695 695
 			    $highlight = '';
696 696
 			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
697 697
 			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
@@ -700,66 +700,66 @@  discard block
 block discarded – undo
700 700
 				$timeelapsed = microtime(true);
701 701
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
702 702
 				    $Spotter = new Spotter($this->db);
703
-				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
703
+				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'], $highlight);
704 704
 				    $Spotter->db = null;
705
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
705
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
706 706
 				}
707 707
 				//$putinarchive = true;
708 708
 				//$highlight = '';
709 709
 			    }
710 710
 			    
711
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
711
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
712 712
 		    //$dataFound = true;
713 713
 		}
714 714
 
715 715
 		if (isset($line['altitude']) && $line['altitude'] != '') {
716 716
 			if (isset($line['altitude_relative']) && isset($GeoidClass) && is_object($GeoidClass)) {
717 717
 				if ($line['altitude_relative'] == 'AMSL' || $line['altitude_relative'] == 'MSL') {
718
-					$geoid = round($GeoidClass->get($this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'])*3.28084,2);
718
+					$geoid = round($GeoidClass->get($this->all_flights[$id]['livedb_latitude'], $this->all_flights[$id]['livedb_longitude'])*3.28084, 2);
719 719
 					//if ($globalDebug) echo '=> Set altitude to WGS84 Ellipsoid, add '.$geoid.' to '.$line['altitude']."\n";
720 720
 					$line['altitude'] = $line['altitude'] - $geoid;
721 721
 				}
722 722
 			}
723 723
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
724
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
725
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
726
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
724
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100) - $this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
725
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude' => round($line['altitude']/100)));
726
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_real' => $line['altitude']));
727 727
 			//$dataFound = true;
728 728
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
729 729
 		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
730 730
 			if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
731 731
 				if ($globalDebug) echo '--- Reset because of altitude'."\n";
732
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
733
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
734
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
735
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
736
-				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']));
732
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
733
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
734
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi')));
735
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
736
+				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']));
737 737
 			}
738 738
 		    }
739
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
739
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_previous' => $line['altitude']));
740 740
 		}
741 741
 
742 742
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
743
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
743
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('noarchive' => true));
744 744
 		}
745 745
 		
746 746
 		if (isset($line['heading']) && $line['heading'] != '') {
747
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
748
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
749
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
747
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading'] - round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
748
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($line['heading'])));
749
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading_fromsrc' => true));
750 750
 		    //$dataFound = true;
751 751
   		} 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']) {
752
-  		    $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']);
753
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
754
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
752
+  		    $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']);
753
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($heading)));
754
+		    if (abs($this->all_flights[$id]['heading'] - round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
755 755
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
756 756
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
757 757
   		    // If not enough messages and ACARS set heading to 0
758
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
758
+  		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => 0));
759 759
   		}
760
-		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
761
-		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
762
-		elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalAircraftMinupdate) $dataFound = false;
760
+		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
761
+		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
762
+		elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalAircraftMinupdate) $dataFound = false;
763 763
 
764 764
 //		print_r($this->all_flights[$id]);
765 765
 		//gets the callsign from the last hour
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
 		if ($dataFound === true && isset($this->all_flights[$id]['id'])) {
771 771
 		    $this->all_flights[$id]['lastupdate'] = time();
772 772
 		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
773
-		        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'])) {
773
+		        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'])) {
774 774
 			    //print_r($this->all_flights);
775 775
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
776 776
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
@@ -781,61 +781,61 @@  discard block
 block discarded – undo
781 781
 				    $SpotterLive = new SpotterLive($this->db);
782 782
 				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) {
783 783
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
784
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
784
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
785 785
 				    } elseif (isset($line['id'])) {
786 786
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
787
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
787
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
788 788
 				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
789 789
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
790
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
790
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
791 791
 				    } else $recent_ident = '';
792
-				    $SpotterLive->db=null;
792
+				    $SpotterLive->db = null;
793 793
 				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
794 794
 				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
795 795
 				} else $recent_ident = '';
796 796
 			    } else {
797 797
 				$recent_ident = '';
798
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
798
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 0));
799 799
 			    }
800 800
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
801
-			    if($recent_ident == "")
801
+			    if ($recent_ident == "")
802 802
 			    {
803 803
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
804 804
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
805 805
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
806 806
 				//adds the spotter data for the archive
807 807
 				$ignoreImport = false;
808
-				foreach($globalAirportIgnore as $airportIgnore) {
808
+				foreach ($globalAirportIgnore as $airportIgnore) {
809 809
 				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
810 810
 					$ignoreImport = true;
811 811
 				    }
812 812
 				}
813 813
 				if (count($globalAirportAccept) > 0) {
814 814
 				    $ignoreImport = true;
815
-				    foreach($globalAirportIgnore as $airportIgnore) {
815
+				    foreach ($globalAirportIgnore as $airportIgnore) {
816 816
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
817 817
 					    $ignoreImport = false;
818 818
 					}
819 819
 				    }
820 820
 				}
821 821
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
822
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
823
-					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)) {
822
+				    foreach ($globalAirlineIgnore as $airlineIgnore) {
823
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) {
824 824
 					    $ignoreImport = true;
825 825
 					}
826 826
 				    }
827 827
 				}
828 828
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
829 829
 				    $ignoreImport = true;
830
-				    foreach($globalAirlineAccept as $airlineAccept) {
831
-					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)) {
830
+				    foreach ($globalAirlineAccept as $airlineAccept) {
831
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) {
832 832
 					    $ignoreImport = false;
833 833
 					}
834 834
 				    }
835 835
 				}
836 836
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
837 837
 				    $ignoreImport = true;
838
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
838
+				    foreach ($globalPilotIdAccept as $pilotIdAccept) {
839 839
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
840 840
 					    $ignoreImport = false;
841 841
 					}
@@ -847,12 +847,12 @@  discard block
 block discarded – undo
847 847
 				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
848 848
 				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
849 849
 				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
850
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
850
+				    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')));
851 851
 				    $timeelapsed = microtime(true);
852 852
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
853 853
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
854 854
 					    $Spotter = new Spotter($this->db);
855
-					    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
855
+					    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $highlight, $this->all_flights[$id]['hex'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['source_type']);
856 856
 					    $Spotter->db = null;
857 857
 					    if ($globalDebug) {
858 858
 						if (isset($result['error'])) echo 'Error: '.$result['error']."\n";
@@ -865,22 +865,22 @@  discard block
 block discarded – undo
865 865
 					    }
866 866
 					}
867 867
 				    }
868
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
868
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
869 869
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
870 870
 
871 871
 				    // Add source stat in DB
872 872
 				    $Stats = new Stats($this->db);
873 873
 				    if (!empty($this->stats)) {
874 874
 					if ($globalDebug) echo 'Add source stats : ';
875
-				        foreach($this->stats as $date => $data) {
876
-					    foreach($data as $source => $sourced) {
875
+				        foreach ($this->stats as $date => $data) {
876
+					    foreach ($data as $source => $sourced) {
877 877
 					        //print_r($sourced);
878
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
879
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
878
+				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar', $date);
879
+				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist', $date);
880 880
 				    		if (isset($sourced['msg'])) {
881 881
 				    		    if (time() - $sourced['msg']['date'] > 10) {
882 882
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
883
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
883
+				    		        echo $Stats->addStatSource($nbmsg, $source, 'msg', $date);
884 884
 			    			        unset($this->stats[$date][$source]['msg']);
885 885
 			    			    }
886 886
 			    			}
@@ -918,14 +918,14 @@  discard block
 block discarded – undo
918 918
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
919 919
 					    $SpotterLive = new SpotterLive($this->db);
920 920
 					    $SpotterLive->deleteLiveSpotterData();
921
-					    $SpotterLive->db=null;
921
+					    $SpotterLive->db = null;
922 922
 					}
923 923
 				    }
924 924
 				    if ($globalDebug) echo " Done\n";
925 925
 				    $this->last_delete = time();
926 926
 				}
927 927
 			    } else {
928
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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'] === 'famaprs' || $line['format_source'] === 'airwhere')) {
928
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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'] === 'famaprs' || $line['format_source'] === 'airwhere')) {
929 929
 				    $this->all_flights[$id]['id'] = $recent_ident;
930 930
 				    $this->all_flights[$id]['addedSpotter'] = 1;
931 931
 				}
@@ -933,7 +933,7 @@  discard block
 block discarded – undo
933 933
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
934 934
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
935 935
 					    $Spotter = new Spotter($this->db);
936
-					    $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
936
+					    $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time']);
937 937
 					    $Spotter->db = null;
938 938
 					}
939 939
 				    }
@@ -959,37 +959,37 @@  discard block
 block discarded – undo
959 959
 		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
960 960
 		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
961 961
 
962
-		    foreach($globalAirportIgnore as $airportIgnore) {
962
+		    foreach ($globalAirportIgnore as $airportIgnore) {
963 963
 		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
964 964
 			    $ignoreImport = true;
965 965
 			}
966 966
 		    }
967 967
 		    if (count($globalAirportAccept) > 0) {
968 968
 		        $ignoreImport = true;
969
-		        foreach($globalAirportIgnore as $airportIgnore) {
969
+		        foreach ($globalAirportIgnore as $airportIgnore) {
970 970
 			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
971 971
 				$ignoreImport = false;
972 972
 			    }
973 973
 			}
974 974
 		    }
975 975
 		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
976
-			foreach($globalAirlineIgnore as $airlineIgnore) {
977
-			    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)) {
976
+			foreach ($globalAirlineIgnore as $airlineIgnore) {
977
+			    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)) {
978 978
 				$ignoreImport = true;
979 979
 			    }
980 980
 			}
981 981
 		    }
982 982
 		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
983 983
 			$ignoreImport = true;
984
-			foreach($globalAirlineAccept as $airlineAccept) {
985
-			    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)) {
984
+			foreach ($globalAirlineAccept as $airlineAccept) {
985
+			    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)) {
986 986
 				$ignoreImport = false;
987 987
 			    }
988 988
 			}
989 989
 		    }
990 990
 		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
991 991
 			$ignoreImport = true;
992
-			foreach($globalPilotIdAccept as $pilotIdAccept) {
992
+			foreach ($globalPilotIdAccept as $pilotIdAccept) {
993 993
 			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
994 994
 			        $ignoreImport = false;
995 995
 			    }
@@ -997,23 +997,23 @@  discard block
 block discarded – undo
997 997
 		    }
998 998
 
999 999
 		    if (!$ignoreImport) {
1000
-			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'])) {
1001
-				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')));
1000
+			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'])) {
1001
+				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')));
1002 1002
 				$timeelapsed = microtime(true);
1003 1003
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
1004 1004
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
1005 1005
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1006 1006
 					$SpotterLive = new SpotterLive($this->db);
1007
-					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
1007
+					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $this->all_flights[$id]['hex'], $this->all_flights[$id]['putinarchive'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['over_country']);
1008 1008
 					$SpotterLive->db = null;
1009 1009
 					if ($globalDebug) echo $result."\n";
1010 1010
 				    }
1011 1011
 				}
1012 1012
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
1013
-					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
1013
+					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $this->all_flights[$id]['hex'], $this->all_flights[$id]['putinarchive'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['over_country']);
1014 1014
 				}
1015 1015
 				$this->all_flights[$id]['putinarchive'] = false;
1016
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1016
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
1017 1017
 
1018 1018
 				// Put statistics in $this->stats variable
1019 1019
 				//if ($line['format_source'] != 'aprs') {
@@ -1032,19 +1032,19 @@  discard block
 block discarded – undo
1032 1032
 							$latitude = $globalCenterLatitude;
1033 1033
 							$longitude = $globalCenterLongitude;
1034 1034
 						}
1035
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
1035
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
1036 1036
 					} else {
1037 1037
 						$latitude = $this->source_location[$source]['latitude'];
1038 1038
 						$longitude = $this->source_location[$source]['longitude'];
1039 1039
 					}
1040
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
1040
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
1041 1041
 					//$stats_heading = $stats_heading%22.5;
1042 1042
 					$stats_heading = round($stats_heading/22.5);
1043
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
1043
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
1044 1044
 					$current_date = date('Y-m-d');
1045 1045
 					if ($stats_heading == 16) $stats_heading = 0;
1046 1046
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
1047
-						for ($i=0;$i<=15;$i++) {
1047
+						for ($i = 0; $i <= 15; $i++) {
1048 1048
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
1049 1049
 						}
1050 1050
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -1059,9 +1059,9 @@  discard block
 block discarded – undo
1059 1059
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
1060 1060
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1061 1061
 						    end($this->stats[$current_date][$source]['hist']);
1062
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1062
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
1063 1063
 						} else $mini = 0;
1064
-						for ($i=$mini;$i<=$distance;$i+=10) {
1064
+						for ($i = $mini; $i <= $distance; $i += 10) {
1065 1065
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1066 1066
 						}
1067 1067
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -1074,7 +1074,7 @@  discard block
 block discarded – undo
1074 1074
 				$this->all_flights[$id]['lastupdate'] = time();
1075 1075
 				if ($this->all_flights[$id]['putinarchive']) $send = true;
1076 1076
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1077
-			} 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";
1077
+			} 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";
1078 1078
 			//$this->del();
1079 1079
 			
1080 1080
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
Please login to merge, or discard this patch.
Braces   +424 added lines, -151 removed lines patch added patch discarded remove patch
@@ -59,7 +59,9 @@  discard block
 block discarded – undo
59 59
 		try {
60 60
 			$GeoidClass = new GeoidHeight();
61 61
 		} catch(Exception $e) {
62
-			if ($globalDebug) echo "Can't calculate geoid, check that you downloaded it via update_db.php (".$e.")\n";
62
+			if ($globalDebug) {
63
+				echo "Can't calculate geoid, check that you downloaded it via update_db.php (".$e.")\n";
64
+			}
63 65
 			$GeoidClass = FALSE;
64 66
 		}
65 67
 	}
@@ -78,7 +80,9 @@  discard block
 block discarded – undo
78 80
 	$dbc = $this->db;
79 81
 	$this->all_flights[$id]['schedule_check'] = true;
80 82
 	if ($globalSchedulesFetch) {
81
-	if ($globalDebug) echo 'Getting schedule info...'."\n";
83
+	if ($globalDebug) {
84
+		echo 'Getting schedule info...'."\n";
85
+	}
82 86
 	$Spotter = new Spotter($dbc);
83 87
 	$Schedule = new Schedule($dbc);
84 88
 	$Translation = new Translation($dbc);
@@ -89,7 +93,9 @@  discard block
 block discarded – undo
89 93
 	    if ($Schedule->checkSchedule($operator) == 0) {
90 94
 		$schedule = $Schedule->fetchSchedule($operator);
91 95
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
92
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
96
+		    if ($globalDebug) {
97
+		    	echo "-> Schedule info for ".$operator." (".$ident.")\n";
98
+		    }
93 99
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
94 100
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
95 101
 		    // Should also check if route schedule = route from DB
@@ -98,7 +104,9 @@  discard block
 block discarded – undo
98 104
 			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
99 105
 			    if (trim($airport_icao) != '') {
100 106
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
101
-				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
107
+				if ($globalDebug) {
108
+					echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
109
+				}
102 110
 			    }
103 111
 			}
104 112
 		    }
@@ -107,20 +115,30 @@  discard block
 block discarded – undo
107 115
 			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
108 116
 			    if (trim($airport_icao) != '') {
109 117
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
110
-				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
118
+				if ($globalDebug) {
119
+					echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
120
+				}
111 121
 			    }
112 122
 			}
113 123
 		    }
114 124
 		    $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']);
115 125
 		}
116
-	    } else $scheduleexist = true;
117
-	} else $scheduleexist = true;
126
+	    } else {
127
+	    	$scheduleexist = true;
128
+	    }
129
+	} else {
130
+		$scheduleexist = true;
131
+	}
118 132
 	// close connection, at least one way will work ?
119 133
        if ($scheduleexist) {
120
-		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
134
+		if ($globalDebug) {
135
+			echo "-> get arrival/departure airport info for ".$ident."\n";
136
+		}
121 137
     		$sch = $Schedule->getSchedule($operator);
122 138
 		$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']));
123
-		if ($this->all_flights[$id]['addedSpotter'] == 1) $Spotter->updateLatestScheduleSpotterData($this->all_flights[$id]['id'],$sch['departure_airport_icao'],$sch['departure_airport_time'],$sch['arrival_airport_icao'],$sch['arrival_airport_time']);
139
+		if ($this->all_flights[$id]['addedSpotter'] == 1) {
140
+			$Spotter->updateLatestScheduleSpotterData($this->all_flights[$id]['id'],$sch['departure_airport_icao'],$sch['departure_airport_time'],$sch['arrival_airport_icao'],$sch['arrival_airport_time']);
141
+		}
124 142
        }
125 143
 	$Spotter->db = null;
126 144
 	$Schedule->db = null;
@@ -140,14 +158,18 @@  discard block
 block discarded – undo
140 158
 
141 159
     public function checkAll() {
142 160
 	global $globalDebug, $globalNoImport;
143
-	if ($globalDebug) echo "Update last seen flights data...\n";
161
+	if ($globalDebug) {
162
+		echo "Update last seen flights data...\n";
163
+	}
144 164
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
145 165
 	    foreach ($this->all_flights as $key => $flight) {
146 166
 		if (isset($this->all_flights[$key]['id'])) {
147 167
 		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
148 168
     		    $Spotter = new Spotter($this->db);
149 169
         	    $real_arrival = $this->arrival($key);
150
-        	    if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) $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']);
170
+        	    if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) {
171
+        	    	$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']);
172
+        	    }
151 173
         	}
152 174
 	    }
153 175
 	}
@@ -155,24 +177,32 @@  discard block
 block discarded – undo
155 177
 
156 178
     public function arrival($key) {
157 179
 	global $globalClosestMinDist, $globalDebug;
158
-	if ($globalDebug) echo 'Update arrival...'."\n";
180
+	if ($globalDebug) {
181
+		echo 'Update arrival...'."\n";
182
+	}
159 183
 	$Spotter = new Spotter($this->db);
160 184
         $airport_icao = '';
161 185
         $airport_time = '';
162
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
186
+        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') {
187
+        	$globalClosestMinDist = 50;
188
+        }
163 189
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
164 190
 	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
165 191
     	    if (isset($closestAirports[0])) {
166 192
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
167 193
         	    $airport_icao = $closestAirports[0]['icao'];
168 194
         	    $airport_time = $this->all_flights[$key]['datetime'];
169
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
195
+        	    if ($globalDebug) {
196
+        	    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
197
+        	    }
170 198
         	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
171 199
         	    foreach ($closestAirports as $airport) {
172 200
         		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
173 201
         		    $airport_icao = $airport['icao'];
174 202
         		    $airport_time = $this->all_flights[$key]['datetime'];
175
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
203
+        		    if ($globalDebug) {
204
+        		    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
205
+        		    }
176 206
         		    break;
177 207
         		}
178 208
         	    }
@@ -180,14 +210,20 @@  discard block
 block discarded – undo
180 210
         		$airport_icao = $closestAirports[0]['icao'];
181 211
         		$airport_time = $this->all_flights[$key]['datetime'];
182 212
         	} else {
183
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
213
+        		if ($globalDebug) {
214
+        			echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
215
+        		}
184 216
         	}
185 217
     	    } else {
186
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
218
+    		    if ($globalDebug) {
219
+    		    	echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
220
+    		    }
187 221
     	    }
188 222
 
189 223
         } else {
190
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
224
+        	if ($globalDebug) {
225
+        		echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
226
+        	}
191 227
         }
192 228
         return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
193 229
     }
@@ -197,7 +233,9 @@  discard block
 block discarded – undo
197 233
     public function del() {
198 234
 	global $globalDebug, $globalNoImport, $globalNoDB;
199 235
 	// Delete old infos
200
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
236
+	if ($globalDebug) {
237
+		echo 'Delete old values and update latest data...'."\n";
238
+	}
201 239
 	
202 240
 	foreach ($this->all_flights as $key => $flight) {
203 241
 		if (isset($flight['lastupdate'])) {
@@ -212,22 +250,30 @@  discard block
 block discarded – undo
212 250
 	global $globalDebug, $globalNoImport, $globalNoDB;
213 251
 	// Delete old infos
214 252
 	if (isset($this->all_flights[$key]['id'])) {
215
-		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
253
+		if ($globalDebug) {
254
+			echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
255
+		}
216 256
 		if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
217 257
 			$real_arrival = $this->arrival($key);
218 258
 			$Spotter = new Spotter($this->db);
219 259
 			$SpotterLive = new SpotterLive($this->db);
220 260
 			if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
221 261
 				$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']);
222
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
262
+				if ($globalDebug && $result != 'success') {
263
+					echo '!!! ERROR : '.$result."\n";
264
+				}
223 265
 				$this->all_flights[$key]['putinarchive'] = true;
224 266
 				$result = $SpotterLive->addLiveSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['aircraft_icao'], $this->all_flights[$key]['departure_airport'], $this->all_flights[$key]['arrival_airport'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['waypoints'], $this->all_flights[$key]['altitude'],$this->all_flights[$key]['altitude_real'], $this->all_flights[$key]['heading'], $this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'], $this->all_flights[$key]['departure_airport_time'], $this->all_flights[$key]['arrival_airport_time'], $this->all_flights[$key]['squawk'],$this->all_flights[$key]['route_stop'],$this->all_flights[$key]['hex'],$this->all_flights[$key]['putinarchive'],$this->all_flights[$key]['registration'],$this->all_flights[$key]['pilot_id'],$this->all_flights[$key]['pilot_name'], $this->all_flights[$key]['verticalrate'], $this->all_flights[$key]['noarchive'], $this->all_flights[$key]['ground'],$this->all_flights[$key]['format_source'],$this->all_flights[$key]['source_name'],$this->all_flights[$key]['over_country']);
225
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
267
+				if ($globalDebug && $result != 'success') {
268
+					echo '!!! ERROR : '.$result."\n";
269
+				}
226 270
 			}
227 271
 			$Spotter->db = null;
228 272
 			$SpotterLive->db = null;
229 273
 		}
230
-		if ($globalDebug) echo "\n";
274
+		if ($globalDebug) {
275
+			echo "\n";
276
+		}
231 277
 	}
232 278
 	unset($this->all_flights[$key]);
233 279
     }
@@ -235,9 +281,13 @@  discard block
 block discarded – undo
235 281
     public function add($line) {
236 282
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport, $globalNoDB, $globalVA, $globalAircraftMaxUpdate, $globalAircraftMinUpdate, $globalLiveInterval, $GeoidClass, $globalArchive;
237 283
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
238
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.01';
239
-	if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') $globalAircraftMaxUpdate = 3000;
240
-/*
284
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
285
+		$globalCoordMinChange = '0.01';
286
+	}
287
+	if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') {
288
+		$globalAircraftMaxUpdate = 3000;
289
+	}
290
+	/*
241 291
 	$Spotter = new Spotter();
242 292
 	$dbc = $Spotter->db;
243 293
 	$SpotterLive = new SpotterLive($dbc);
@@ -259,19 +309,28 @@  discard block
 block discarded – undo
259 309
 	// SBS format is CSV format
260 310
 	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
261 311
 	    //print_r($line);
262
-	    if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
312
+	    if (isset($line['hex'])) {
313
+	    	$line['hex'] = strtoupper($line['hex']);
314
+	    }
263 315
   	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && substr($line['hex'],0,1) != '~' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
264 316
 
265 317
 		// Increment message number
266 318
 		if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) {
267 319
 		    $current_date = date('Y-m-d');
268
-		    if (isset($line['source_name'])) $source = $line['source_name'];
269
-		    else $source = '';
270
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
320
+		    if (isset($line['source_name'])) {
321
+		    	$source = $line['source_name'];
322
+		    } else {
323
+		    	$source = '';
324
+		    }
325
+		    if ($source == '' || $line['format_source'] == 'aprs') {
326
+		    	$source = $line['format_source'];
327
+		    }
271 328
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
272 329
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
273 330
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
274
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
331
+		    } else {
332
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
333
+		    }
275 334
 		}
276 335
 		
277 336
 		/*
@@ -287,23 +346,38 @@  discard block
 block discarded – undo
287 346
 		//$this->db = $dbc;
288 347
 
289 348
 		//$hex = trim($line['hex']);
290
-	        if (!isset($line['id'])) $id = trim($line['hex']);
291
-	        else $id = trim($line['id']);
349
+	        if (!isset($line['id'])) {
350
+	        	$id = trim($line['hex']);
351
+	        } else {
352
+	        	$id = trim($line['id']);
353
+	        }
292 354
 		
293 355
 		if (!isset($this->all_flights[$id])) {
294
-		    if ($globalDebug) echo 'New flight...'."\n";
356
+		    if ($globalDebug) {
357
+		    	echo 'New flight...'."\n";
358
+		    }
295 359
 		    $this->all_flights[$id] = array();
296 360
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
297 361
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => '','coordinates' => 0));
298
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
362
+		    if (isset($globalDaemon) && $globalDaemon === FALSE) {
363
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
364
+		    }
299 365
 		    if (!isset($line['id'])) {
300
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
301
-//			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')));
366
+			if (!isset($globalDaemon)) {
367
+				$globalDaemon = TRUE;
368
+			}
369
+			//			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')));
302 370
 //			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')));
303
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
371
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) {
372
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
373
+			}
304 374
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
305
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
306
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
375
+		     } else {
376
+		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
377
+		     }
378
+		    if ($globalAllFlights !== FALSE) {
379
+		    	$dataFound = true;
380
+		    }
307 381
 		}
308 382
 		if (isset($line['source_type']) && $line['source_type'] != '') {
309 383
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
@@ -325,12 +399,20 @@  discard block
 block discarded – undo
325 399
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
326 400
 			    }
327 401
 			    $Spotter->db = null;
328
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
329
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
402
+			    if ($globalDebugTimeElapsed) {
403
+			    	echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
404
+			    }
405
+			    if ($aircraft_icao != '') {
406
+			    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
407
+			    }
330 408
 			}
331 409
 		    }
332
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
333
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
410
+		    if ($globalAllFlights !== FALSE) {
411
+		    	$dataFound = true;
412
+		    }
413
+		    if ($globalDebug) {
414
+		    	echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
415
+		    }
334 416
 		}
335 417
 	        if (isset($line['id']) && !isset($line['hex'])) {
336 418
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
@@ -339,7 +421,9 @@  discard block
 block discarded – undo
339 421
 			$icao = $line['aircraft_icao'];
340 422
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
341 423
 				$Spotter = new Spotter($this->db);
342
-				if (isset($Spotter->aircraft_correct_icaotype[$icao])) $icao = $Spotter->aircraft_correct_icaotype[$icao];
424
+				if (isset($Spotter->aircraft_correct_icaotype[$icao])) {
425
+					$icao = $Spotter->aircraft_correct_icaotype[$icao];
426
+				}
343 427
 				$Spotter->db = null;
344 428
 			}
345 429
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $icao));
@@ -349,15 +433,24 @@  discard block
 block discarded – undo
349 433
 				$Spotter = new Spotter($this->db);
350 434
 				$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
351 435
 				$Spotter->db = null;
352
-				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
436
+				if ($aircraft_icao != '') {
437
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
438
+				}
353 439
 			}
354 440
 		}
355 441
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
356
-			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
357
-			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
358
-			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
359
-			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
360
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
442
+			if ($line['aircraft_type'] == 'PARA_GLIDER') {
443
+				$aircraft_icao = 'GLID';
444
+			} elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') {
445
+				$aircraft_icao = 'UHEL';
446
+			} elseif ($line['aircraft_type'] == 'TOW_PLANE') {
447
+				$aircraft_icao = 'TOWPLANE';
448
+			} elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') {
449
+				$aircraft_icao = 'POWAIRC';
450
+			}
451
+			if (isset($aircraft_icao)) {
452
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
453
+			}
361 454
 		}
362 455
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
363 456
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
@@ -367,8 +460,11 @@  discard block
 block discarded – undo
367 460
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
368 461
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
369 462
 		    } else {
370
-				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";
371
-				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";
463
+				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
464
+					echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
465
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
466
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
467
+				}
372 468
 				/*
373 469
 				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
374 470
 				print_r($this->all_flights[$id]);
@@ -377,16 +473,22 @@  discard block
 block discarded – undo
377 473
 				return '';
378 474
 		    }
379 475
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
380
-			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
476
+			if ($globalDebug) {
477
+				echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
478
+			}
381 479
 			return '';
382 480
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) {
383
-			if ($globalDebug) echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
481
+			if ($globalDebug) {
482
+				echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n";
483
+			}
384 484
 			return '';
385 485
 		} elseif (!isset($line['datetime'])) {
386 486
 			date_default_timezone_set('UTC');
387 487
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
388 488
 		} else {
389
-			if ($globalDebug) echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
489
+			if ($globalDebug) {
490
+				echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
491
+			}
390 492
 			return '';
391 493
 		}
392 494
 
@@ -407,30 +509,48 @@  discard block
 block discarded – undo
407 509
 
408 510
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
409 511
 			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
410
-				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
512
+				if ($globalDebug) {
513
+					echo '---!!!! New ident, reset aircraft data...'."\n";
514
+				}
411 515
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
412 516
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
413
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
414
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
415
-				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']));
517
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) {
518
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
519
+				} elseif (isset($line['id'])) {
520
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
521
+				} elseif (isset($this->all_flights[$id]['ident'])) {
522
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
523
+				}
416 524
 			} else {
417 525
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
418 526
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
419 527
 				$timeelapsed = microtime(true);
420 528
             			$Spotter = new Spotter($this->db);
421 529
             			$fromsource = NULL;
422
-            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
423
-            			elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
424
-				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
425
-				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
426
-				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
530
+            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') {
531
+            				$fromsource = $globalAirlinesSource;
532
+            			} elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') {
533
+            				$fromsource = 'vatsim';
534
+            			} elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') {
535
+					$fromsource = 'ivao';
536
+				} elseif (isset($globalVATSIM) && $globalVATSIM) {
537
+					$fromsource = 'vatsim';
538
+				} elseif (isset($globalIVAO) && $globalIVAO) {
539
+					$fromsource = 'ivao';
540
+				}
427 541
             			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource,$this->all_flights[$id]['source_type']);
428
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
542
+				if ($globalDebug && $result != 'success') {
543
+					echo '!!! ERROR : '.$result."\n";
544
+				}
429 545
 				$Spotter->db = null;
430
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
546
+				if ($globalDebugTimeElapsed) {
547
+					echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
548
+				}
431 549
 			    }
432 550
 			}
433
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
551
+		    } else {
552
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
553
+		    }
434 554
 		    
435 555
 /*
436 556
 		    if (!isset($line['id'])) {
@@ -440,7 +560,9 @@  discard block
 block discarded – undo
440 560
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
441 561
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
442 562
   */
443
-		    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']));
563
+		    if (!isset($this->all_flights[$id]['id'])) {
564
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
565
+		    }
444 566
 
445 567
 		    //$putinarchive = true;
446 568
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
@@ -458,7 +580,9 @@  discard block
 block discarded – undo
458 580
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
459 581
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
460 582
 		    		$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' => ''));
461
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
583
+				if ($globalDebugTimeElapsed) {
584
+					echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
585
+				}
462 586
                         }
463 587
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
464 588
 			$timeelapsed = microtime(true);
@@ -472,7 +596,9 @@  discard block
 block discarded – undo
472 596
 				$Translation->db = null;
473 597
 			    }
474 598
 			    $Spotter->db = null;
475
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
599
+			    if ($globalDebugTimeElapsed) {
600
+			    	echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
601
+			    }
476 602
                     	}
477 603
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
478 604
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
@@ -481,9 +607,13 @@  discard block
 block discarded – undo
481 607
 		    		$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']));
482 608
 		    	    }
483 609
 			}
484
-			if (!isset($globalFork)) $globalFork = TRUE;
610
+			if (!isset($globalFork)) {
611
+				$globalFork = TRUE;
612
+			}
485 613
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
486
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
614
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) {
615
+					$this->get_Schedule($id,trim($line['ident']));
616
+				}
487 617
 			}
488 618
 		    }
489 619
 		}
@@ -501,9 +631,13 @@  discard block
 block discarded – undo
501 631
 			$speed = $speed*3.6;
502 632
 			if ($speed < 1000) {
503 633
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
504
-	  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
634
+	  			if ($globalDebug) {
635
+	  				echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
636
+	  			}
505 637
 	  		} else {
506
-	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
638
+	  			if ($globalDebug) {
639
+	  				echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
640
+	  			}
507 641
 	  		}
508 642
 		    }
509 643
 		}
@@ -512,13 +646,21 @@  discard block
 block discarded – undo
512 646
 
513 647
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
514 648
 	    	    if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
515
-	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
649
+	    	    	if ($globalDebug) {
650
+	    	    		echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
651
+	    	    	}
516 652
 	    	    	return false;
517 653
 	    	    }
518
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
519
-	    	    else unset($timediff);
520
-	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
521
-	    	    else unset($timediff_archive);
654
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) {
655
+	    	    	$timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
656
+	    	    } else {
657
+	    	    	unset($timediff);
658
+	    	    }
659
+	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) {
660
+	    	    	$timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
661
+	    	    } else {
662
+	    	    	unset($timediff_archive);
663
+	    	    }
522 664
 	    	    if ($this->tmd > 5
523 665
 	    	        || (isset($line['format_source']) 
524 666
 	    	    	    && $line['format_source'] == 'airwhere' 
@@ -553,19 +695,30 @@  discard block
 block discarded – undo
553 695
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
554 696
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
555 697
 				$this->all_flights[$id]['putinarchive'] = true;
556
-				if ($this->tmd > 5 && $this->all_flights[$id]['putinarchive'] == 1) $updateinitial = true;
698
+				if ($this->tmd > 5 && $this->all_flights[$id]['putinarchive'] == 1) {
699
+					$updateinitial = true;
700
+				}
557 701
 				$this->tmd = 0;
558 702
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
559
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
703
+				    if ($globalDebug) {
704
+				    	echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
705
+				    }
560 706
 				    $timeelapsed = microtime(true);
561 707
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
562 708
 					$Spotter = new Spotter($this->db);
563 709
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
564
-					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
565
-					else $this->all_flights[$id]['over_country'] = '';
710
+					if (!empty($all_country)) {
711
+						$this->all_flights[$id]['over_country'] = $all_country['iso2'];
712
+					} else {
713
+						$this->all_flights[$id]['over_country'] = '';
714
+					}
566 715
 					$Spotter->db = null;
567
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
568
-					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
716
+					if ($globalDebugTimeElapsed) {
717
+						echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
718
+					}
719
+					if ($globalDebug) {
720
+						echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
721
+					}
569 722
 				    }
570 723
 				}
571 724
 				$this->all_flights[$id]['time_last_archive_coord'] = time();
@@ -611,7 +764,9 @@  discard block
 block discarded – undo
611 764
 			    */
612 765
 			}
613 766
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
614
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
767
+			    if ($line['longitude'] > 180) {
768
+			    	$line['longitude'] = $line['longitude'] - 360;
769
+			    }
615 770
 			    //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) {
616 771
 				if (!isset($this->all_flights[$id]['archive_longitude'])) {
617 772
 					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
@@ -640,7 +795,9 @@  discard block
 block discarded – undo
640 795
 			    */
641 796
 			}
642 797
 			if ($globalDaemon === TRUE && isset($updateinitial) && $updateinitial && $this->all_flights[$id]['addedSpotter'] == 1) {
643
-			    if ($globalDebug) echo '>>> Update initial data !'."\n";
798
+			    if ($globalDebug) {
799
+			    	echo '>>> Update initial data !'."\n";
800
+			    }
644 801
 			    unset($updateinitial);
645 802
 			    $SpotterArchive = new SpotterArchive();
646 803
 			    $SpotterArchive->deleteSpotterArchiveTrackDataByID($this->all_flights[$id]['id']);
@@ -658,7 +815,9 @@  discard block
 block discarded – undo
658 815
 		    }
659 816
 		}
660 817
 		if (isset($line['last_update']) && $line['last_update'] != '') {
661
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
818
+		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) {
819
+		    	$dataFound = true;
820
+		    }
662 821
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
663 822
 		}
664 823
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
@@ -680,35 +839,53 @@  discard block
 block discarded – undo
680 839
 			// Here we force archive of flight because after ground it's a new one (or should be)
681 840
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
682 841
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
683
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
684
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
685
-			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']));
842
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) {
843
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
844
+			} elseif (isset($line['id'])) {
845
+		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
846
+		        } elseif (isset($this->all_flights[$id]['ident'])) {
847
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
848
+			}
849
+		    }
850
+		    if ($line['ground'] != 1) {
851
+		    	$line['ground'] = 0;
686 852
 		    }
687
-		    if ($line['ground'] != 1) $line['ground'] = 0;
688 853
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
689 854
 		    //$dataFound = true;
690 855
 		}
691 856
 		if (isset($line['squawk']) && $line['squawk'] != '') {
692 857
 		    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'])) {
693
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
858
+			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) {
859
+			    	$this->all_flights[$id]['putinarchive'] = true;
860
+			    }
694 861
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
695 862
 			    $highlight = '';
696
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
697
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
698
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
863
+			    if ($this->all_flights[$id]['squawk'] == '7500') {
864
+			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
865
+			    }
866
+			    if ($this->all_flights[$id]['squawk'] == '7600') {
867
+			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
868
+			    }
869
+			    if ($this->all_flights[$id]['squawk'] == '7700') {
870
+			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
871
+			    }
699 872
 			    if ($highlight != '') {
700 873
 				$timeelapsed = microtime(true);
701 874
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
702 875
 				    $Spotter = new Spotter($this->db);
703 876
 				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
704 877
 				    $Spotter->db = null;
705
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
878
+				    if ($globalDebugTimeElapsed) {
879
+				    	echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
880
+				    }
706 881
 				}
707 882
 				//$putinarchive = true;
708 883
 				//$highlight = '';
709 884
 			    }
710 885
 			    
711
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
886
+		    } else {
887
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
888
+		    }
712 889
 		    //$dataFound = true;
713 890
 		}
714 891
 
@@ -721,19 +898,27 @@  discard block
 block discarded – undo
721 898
 				}
722 899
 			}
723 900
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
724
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
901
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) {
902
+				$this->all_flights[$id]['putinarchive'] = true;
903
+			}
725 904
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
726 905
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
727 906
 			//$dataFound = true;
728 907
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
729 908
 		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
730 909
 			if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
731
-				if ($globalDebug) echo '--- Reset because of altitude'."\n";
910
+				if ($globalDebug) {
911
+					echo '--- Reset because of altitude'."\n";
912
+				}
732 913
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
733 914
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
734
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
735
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
736
-				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']));
915
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) {
916
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
917
+				} elseif (isset($line['id'])) {
918
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
919
+				} elseif (isset($this->all_flights[$id]['ident'])) {
920
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
921
+				}
737 922
 			}
738 923
 		    }
739 924
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
@@ -744,22 +929,32 @@  discard block
 block discarded – undo
744 929
 		}
745 930
 		
746 931
 		if (isset($line['heading']) && $line['heading'] != '') {
747
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
932
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) {
933
+		    	$this->all_flights[$id]['putinarchive'] = true;
934
+		    }
748 935
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
749 936
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
750 937
 		    //$dataFound = true;
751 938
   		} 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']) {
752 939
   		    $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']);
753 940
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
754
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
755
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
941
+		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) {
942
+		    	$this->all_flights[$id]['putinarchive'] = true;
943
+		    }
944
+  		    if ($globalDebug) {
945
+  		    	echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
946
+  		    }
756 947
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
757 948
   		    // If not enough messages and ACARS set heading to 0
758 949
   		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
759 950
   		}
760
-		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
761
-		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
762
-		elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalAircraftMinupdate) $dataFound = false;
951
+		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) {
952
+			$dataFound = false;
953
+		} elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) {
954
+			$dataFound = false;
955
+		} elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalAircraftMinupdate) {
956
+			$dataFound = false;
957
+		}
763 958
 
764 959
 //		print_r($this->all_flights[$id]);
765 960
 		//gets the callsign from the last hour
@@ -776,23 +971,38 @@  discard block
 block discarded – undo
776 971
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
777 972
 			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
778 973
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
779
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
974
+				    if ($globalDebug) {
975
+				    	echo "Check if aircraft is already in DB...";
976
+				    }
780 977
 				    $timeelapsed = microtime(true);
781 978
 				    $SpotterLive = new SpotterLive($this->db);
782 979
 				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $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' || $line['format_source'] === 'famaprs')) {
783 980
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
784
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
981
+					if ($globalDebugTimeElapsed) {
982
+						echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
983
+					}
785 984
 				    } elseif (isset($line['id'])) {
786 985
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
787
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
986
+					if ($globalDebugTimeElapsed) {
987
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
988
+					}
788 989
 				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
789 990
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
790
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
791
-				    } else $recent_ident = '';
991
+					if ($globalDebugTimeElapsed) {
992
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
993
+					}
994
+				    } else {
995
+				    	$recent_ident = '';
996
+				    }
792 997
 				    $SpotterLive->db=null;
793
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
794
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
795
-				} else $recent_ident = '';
998
+				    if ($globalDebug && $recent_ident == '') {
999
+				    	echo " Not in DB.\n";
1000
+				    } elseif ($globalDebug && $recent_ident != '') {
1001
+				    	echo " Already in DB.\n";
1002
+				    }
1003
+				} else {
1004
+					$recent_ident = '';
1005
+				}
796 1006
 			    } else {
797 1007
 				$recent_ident = '';
798 1008
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
@@ -800,7 +1010,9 @@  discard block
 block discarded – undo
800 1010
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
801 1011
 			    if($recent_ident == "")
802 1012
 			    {
803
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
1013
+				if ($globalDebug) {
1014
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
1015
+				}
804 1016
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
805 1017
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
806 1018
 				//adds the spotter data for the archive
@@ -844,10 +1056,18 @@  discard block
 block discarded – undo
844 1056
 				
845 1057
 				if (!$ignoreImport) {
846 1058
 				    $highlight = '';
847
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
848
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
849
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
850
-				    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')));
1059
+				    if ($this->all_flights[$id]['squawk'] == '7500') {
1060
+				    	$highlight = 'Squawk 7500 : Hijack';
1061
+				    }
1062
+				    if ($this->all_flights[$id]['squawk'] == '7600') {
1063
+				    	$highlight = 'Squawk 7600 : Lost Comm (radio failure)';
1064
+				    }
1065
+				    if ($this->all_flights[$id]['squawk'] == '7700') {
1066
+				    	$highlight = 'Squawk 7700 : Emergency';
1067
+				    }
1068
+				    if (!isset($this->all_flights[$id]['id'])) {
1069
+				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1070
+				    }
851 1071
 				    $timeelapsed = microtime(true);
852 1072
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
853 1073
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -855,28 +1075,43 @@  discard block
 block discarded – undo
855 1075
 					    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
856 1076
 					    $Spotter->db = null;
857 1077
 					    if ($globalDebug) {
858
-						if (isset($result['error'])) echo 'Error: '.$result['error']."\n";
859
-						else echo 'Success';
1078
+						if (isset($result['error'])) {
1079
+							echo 'Error: '.$result['error']."\n";
1080
+						} else {
1081
+							echo 'Success';
1082
+						}
860 1083
 					    }
861 1084
 					    if (count($result) > 1) {
862 1085
 					    // ':airline_name' => $airline_name,':airline_icao' => $airline_icao,':airline_country' => $airline_country,':airline_type' => $airline_type,
863
-						if ($this->all_flights[$id]['aircraft_icao'] == '') $this->all_flights[$id]['aircraft_icao'] = $result[':aircraft_icao'];
864
-						if ($this->all_flights[$id]['registration'] == '') $this->all_flights[$id]['registration'] = $result[':registration'];
1086
+						if ($this->all_flights[$id]['aircraft_icao'] == '') {
1087
+							$this->all_flights[$id]['aircraft_icao'] = $result[':aircraft_icao'];
1088
+						}
1089
+						if ($this->all_flights[$id]['registration'] == '') {
1090
+							$this->all_flights[$id]['registration'] = $result[':registration'];
1091
+						}
865 1092
 					    }
866 1093
 					}
867 1094
 				    }
868
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1095
+				    if ($globalDebugTimeElapsed) {
1096
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1097
+				    }
869 1098
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
870 1099
 
871 1100
 				    // Add source stat in DB
872 1101
 				    $Stats = new Stats($this->db);
873 1102
 				    if (!empty($this->stats)) {
874
-					if ($globalDebug) echo 'Add source stats : ';
1103
+					if ($globalDebug) {
1104
+						echo 'Add source stats : ';
1105
+					}
875 1106
 				        foreach($this->stats as $date => $data) {
876 1107
 					    foreach($data as $source => $sourced) {
877 1108
 					        //print_r($sourced);
878
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
879
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
1109
+				    	        if (isset($sourced['polar'])) {
1110
+				    	        	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
1111
+				    	        }
1112
+				    	        if (isset($sourced['hist'])) {
1113
+				    	        	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
1114
+				    	        }
880 1115
 				    		if (isset($sourced['msg'])) {
881 1116
 				    		    if (time() - $sourced['msg']['date'] > 10) {
882 1117
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -889,13 +1124,17 @@  discard block
 block discarded – undo
889 1124
 			    			unset($this->stats[$date]);
890 1125
 			    		    }
891 1126
 				    	}
892
-				    	if ($globalDebug) echo 'Done'."\n";
1127
+				    	if ($globalDebug) {
1128
+				    		echo 'Done'."\n";
1129
+				    	}
893 1130
 
894 1131
 				    }
895 1132
 				    $Stats->db = null;
896 1133
 				    }
897 1134
 				    $this->del();
898
-				} elseif ($globalDebug) echo 'Ignore data'."\n";
1135
+				} elseif ($globalDebug) {
1136
+					echo 'Ignore data'."\n";
1137
+				}
899 1138
 				//$ignoreImport = false;
900 1139
 				$this->all_flights[$id]['addedSpotter'] = 1;
901 1140
 				//print_r($this->all_flights[$id]);
@@ -912,7 +1151,9 @@  discard block
 block discarded – undo
912 1151
 			*/
913 1152
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
914 1153
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
915
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
1154
+				    if ($globalDebug) {
1155
+				    	echo "---- Deleting Live Spotter data older than 9 hours...";
1156
+				    }
916 1157
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
917 1158
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
918 1159
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -921,7 +1162,9 @@  discard block
 block discarded – undo
921 1162
 					    $SpotterLive->db=null;
922 1163
 					}
923 1164
 				    }
924
-				    if ($globalDebug) echo " Done\n";
1165
+				    if ($globalDebug) {
1166
+				    	echo " Done\n";
1167
+				    }
925 1168
 				    $this->last_delete = time();
926 1169
 				}
927 1170
 			    } else {
@@ -948,11 +1191,17 @@  discard block
 block discarded – undo
948 1191
 		    //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";
949 1192
 		    if ($globalDebug) {
950 1193
 			if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
951
-				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";
952
-				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";
1194
+				if (isset($this->all_flights[$id]['source_name'])) {
1195
+					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";
1196
+				} else {
1197
+					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";
1198
+				}
953 1199
 			} else {
954
-				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";
955
-				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";
1200
+				if (isset($this->all_flights[$id]['source_name'])) {
1201
+					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";
1202
+				} else {
1203
+					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";
1204
+				}
956 1205
 			}
957 1206
 		    }
958 1207
 		    $ignoreImport = false;
@@ -998,22 +1247,30 @@  discard block
 block discarded – undo
998 1247
 
999 1248
 		    if (!$ignoreImport) {
1000 1249
 			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'])) {
1001
-				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')));
1250
+				if (!isset($this->all_flights[$id]['id'])) {
1251
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1252
+				}
1002 1253
 				$timeelapsed = microtime(true);
1003 1254
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
1004 1255
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
1005
-					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1256
+					if ($globalDebug) {
1257
+						echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1258
+					}
1006 1259
 					$SpotterLive = new SpotterLive($this->db);
1007 1260
 					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
1008 1261
 					$SpotterLive->db = null;
1009
-					if ($globalDebug) echo $result."\n";
1262
+					if ($globalDebug) {
1263
+						echo $result."\n";
1264
+					}
1010 1265
 				    }
1011 1266
 				}
1012 1267
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
1013 1268
 					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
1014 1269
 				}
1015 1270
 				$this->all_flights[$id]['putinarchive'] = false;
1016
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1271
+				if ($globalDebugTimeElapsed) {
1272
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1273
+				}
1017 1274
 
1018 1275
 				// Put statistics in $this->stats variable
1019 1276
 				//if ($line['format_source'] != 'aprs') {
@@ -1021,7 +1278,9 @@  discard block
 block discarded – undo
1021 1278
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
1022 1279
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
1023 1280
 					$source = $this->all_flights[$id]['source_name'];
1024
-					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1281
+					if ($source == '') {
1282
+						$source = $this->all_flights[$id]['format_source'];
1283
+					}
1025 1284
 					if (!isset($this->source_location[$source])) {
1026 1285
 						$Location = new Source($this->db);
1027 1286
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -1042,7 +1301,9 @@  discard block
 block discarded – undo
1042 1301
 					$stats_heading = round($stats_heading/22.5);
1043 1302
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
1044 1303
 					$current_date = date('Y-m-d');
1045
-					if ($stats_heading == 16) $stats_heading = 0;
1304
+					if ($stats_heading == 16) {
1305
+						$stats_heading = 0;
1306
+					}
1046 1307
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
1047 1308
 						for ($i=0;$i<=15;$i++) {
1048 1309
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -1060,7 +1321,9 @@  discard block
 block discarded – undo
1060 1321
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1061 1322
 						    end($this->stats[$current_date][$source]['hist']);
1062 1323
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1063
-						} else $mini = 0;
1324
+						} else {
1325
+							$mini = 0;
1326
+						}
1064 1327
 						for ($i=$mini;$i<=$distance;$i+=10) {
1065 1328
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1066 1329
 						}
@@ -1072,19 +1335,27 @@  discard block
 block discarded – undo
1072 1335
 				}
1073 1336
 
1074 1337
 				$this->all_flights[$id]['lastupdate'] = time();
1075
-				if ($this->all_flights[$id]['putinarchive']) $send = true;
1338
+				if ($this->all_flights[$id]['putinarchive']) {
1339
+					$send = true;
1340
+				}
1076 1341
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1077
-			} 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";
1342
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
1343
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1344
+			}
1078 1345
 			//$this->del();
1079 1346
 			
1080 1347
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
1081 1348
 			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1082
-				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1349
+				if ($globalDebug) {
1350
+					echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1351
+				}
1083 1352
 				$SpotterLive = new SpotterLive($this->db);
1084 1353
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
1085 1354
 				$SpotterLive->db = null;
1086 1355
 				//SpotterLive->deleteLiveSpotterData();
1087
-				if ($globalDebug) echo " Done\n";
1356
+				if ($globalDebug) {
1357
+					echo " Done\n";
1358
+				}
1088 1359
 				$this->last_delete_hourly = time();
1089 1360
 			    } else {
1090 1361
 				$this->del();
@@ -1096,7 +1367,9 @@  discard block
 block discarded – undo
1096 1367
 		    //$ignoreImport = false;
1097 1368
 		}
1098 1369
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
1099
-		if ($send) return $this->all_flights[$id];
1370
+		if ($send) {
1371
+			return $this->all_flights[$id];
1372
+		}
1100 1373
 	    }
1101 1374
 	}
1102 1375
     }
Please login to merge, or discard this patch.