This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * This class is part of FlightAirMap. It's used to save stats |
||
4 | * |
||
5 | * Copyright (c) Ycarus (Yannick Chabanois) at Zugaina <[email protected]> |
||
6 | * Licensed under AGPL license. |
||
7 | * For more information see: https://www.flightairmap.com/ |
||
8 | */ |
||
9 | |||
10 | require_once(dirname(__FILE__).'/class.Spotter.php'); |
||
11 | require_once(dirname(__FILE__).'/class.Marine.php'); |
||
12 | require_once(dirname(__FILE__).'/class.Tracker.php'); |
||
13 | require_once(dirname(__FILE__).'/class.Accident.php'); |
||
14 | require_once(dirname(__FILE__).'/class.SpotterArchive.php'); |
||
15 | require_once(dirname(__FILE__).'/class.Common.php'); |
||
16 | class Stats { |
||
17 | public $db; |
||
18 | public $filter_name = ''; |
||
19 | |||
20 | /* |
||
21 | * Initialize DB connection |
||
22 | */ |
||
23 | public function __construct($dbc = null) { |
||
24 | global $globalFilterName; |
||
25 | if (isset($globalFilterName)) $this->filter_name = $globalFilterName; |
||
26 | $Connection = new Connection($dbc); |
||
27 | $this->db = $Connection->db(); |
||
28 | if ($this->db === null) die('Error: No DB connection. (Stats)'); |
||
29 | } |
||
30 | |||
31 | public function addLastStatsUpdate($type,$stats_date) { |
||
32 | $query = "DELETE FROM config WHERE name = :type; |
||
33 | INSERT INTO config (name,value) VALUES (:type,:stats_date);"; |
||
34 | $query_values = array('type' => $type,':stats_date' => $stats_date); |
||
35 | try { |
||
36 | $sth = $this->db->prepare($query); |
||
37 | $sth->execute($query_values); |
||
38 | } catch(PDOException $e) { |
||
39 | return "error : ".$e->getMessage(); |
||
40 | } |
||
41 | return ''; |
||
42 | } |
||
43 | |||
44 | public function getLastStatsUpdate($type = 'last_update_stats') { |
||
45 | $query = "SELECT value FROM config WHERE name = :type"; |
||
46 | try { |
||
47 | $sth = $this->db->prepare($query); |
||
48 | $sth->execute(array(':type' => $type)); |
||
49 | } catch(PDOException $e) { |
||
50 | echo "error : ".$e->getMessage(); |
||
51 | return array(); |
||
52 | } |
||
53 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
54 | return $all; |
||
55 | } |
||
56 | |||
57 | public function deleteStats($filter_name = '') { |
||
58 | /* |
||
59 | $query = "DELETE FROM config WHERE name = 'last_update_stats'"; |
||
60 | try { |
||
61 | $sth = $this->db->prepare($query); |
||
62 | $sth->execute(); |
||
63 | } catch(PDOException $e) { |
||
64 | return "error : ".$e->getMessage(); |
||
65 | } |
||
66 | */ |
||
67 | $query = "DELETE FROM stats WHERE filter_name = :filter_name;DELETE FROM stats_aircraft WHERE filter_name = :filter_name;DELETE FROM stats_airline WHERE filter_name = :filter_name;DELETE FROM stats_airport WHERE filter_name = :filter_name;DELETE FROM stats_callsign WHERE filter_name = :filter_name;DELETE FROM stats_country WHERE filter_name = :filter_name;DELETE FROM stats_flight WHERE filter_name = :filter_name;DELETE FROM stats_owner WHERE filter_name = :filter_name;DELETE FROM stats_pilot WHERE filter_name = :filter_name;DELETE FROM stats_registration WHERE filter_name = :filter_name;"; |
||
68 | try { |
||
69 | $sth = $this->db->prepare($query); |
||
70 | $sth->execute(array(':filter_name' => $filter_name)); |
||
71 | } catch(PDOException $e) { |
||
72 | return "error : ".$e->getMessage(); |
||
73 | } |
||
74 | } |
||
75 | public function deleteOldStats($filter_name = '') { |
||
76 | if ($filter_name == '') { |
||
77 | $query = "DELETE FROM config WHERE name = 'last_update_stats'"; |
||
78 | } else { |
||
79 | $query = "DELETE FROM config WHERE name = 'last_update_stats_".$filter_name."'"; |
||
80 | } |
||
81 | try { |
||
82 | $sth = $this->db->prepare($query); |
||
83 | $sth->execute(); |
||
84 | } catch(PDOException $e) { |
||
85 | return "error : ".$e->getMessage(); |
||
86 | } |
||
87 | $query = "DELETE FROM stats_aircraft WHERE filter_name = :filter_name;DELETE FROM stats_airline WHERE filter_name = :filter_name;DELETE FROM stats_callsign WHERE filter_name = :filter_name;DELETE FROM stats_country WHERE filter_name = :filter_name;DELETE FROM stats_owner WHERE filter_name = :filter_name;DELETE FROM stats_pilot WHERE filter_name = :filter_name;DELETE FROM stats_registration WHERE filter_name = :filter_name;"; |
||
88 | try { |
||
89 | $sth = $this->db->prepare($query); |
||
90 | $sth->execute(array(':filter_name' => $filter_name)); |
||
91 | } catch(PDOException $e) { |
||
92 | return "error : ".$e->getMessage(); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | public function getAllAirlineNames($filter_name = '') { |
||
97 | global $globalStatsFilters; |
||
98 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
99 | $query = "SELECT * FROM stats_airline WHERE filter_name = :filter_name ORDER BY airline_name ASC"; |
||
100 | try { |
||
101 | $sth = $this->db->prepare($query); |
||
102 | $sth->execute(array(':filter_name' => $filter_name)); |
||
103 | } catch(PDOException $e) { |
||
104 | echo "error : ".$e->getMessage(); |
||
105 | } |
||
106 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
107 | if (empty($all)) { |
||
108 | $filters = array(); |
||
109 | if ($filter_name != '') { |
||
110 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
111 | } |
||
112 | $Spotter = new Spotter($this->db); |
||
113 | $all = $Spotter->getAllAirlineNames('',NULL,$filters); |
||
114 | } |
||
115 | return $all; |
||
116 | } |
||
117 | public function getAllAircraftTypes($stats_airline = '',$filter_name = '') { |
||
118 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
119 | $query = "SELECT * FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_manufacturer ASC"; |
||
120 | try { |
||
121 | $sth = $this->db->prepare($query); |
||
122 | $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
||
123 | } catch(PDOException $e) { |
||
124 | echo "error : ".$e->getMessage(); |
||
125 | } |
||
126 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
127 | return $all; |
||
128 | } |
||
129 | public function getAllManufacturers($stats_airline = '',$filter_name = '') { |
||
130 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
131 | $query = "SELECT DISTINCT(aircraft_manufacturer) FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name AND aircraft_manufacturer <> '' ORDER BY aircraft_manufacturer ASC"; |
||
132 | try { |
||
133 | $sth = $this->db->prepare($query); |
||
134 | $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
||
135 | } catch(PDOException $e) { |
||
136 | echo "error : ".$e->getMessage(); |
||
137 | } |
||
138 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
139 | return $all; |
||
140 | } |
||
141 | public function getAllAirportNames($stats_airline = '',$filter_name = '') { |
||
142 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
143 | $query = "SELECT airport_icao, airport_name,airport_city,airport_country FROM stats_airport WHERE stats_airline = :stats_airline AND filter_name = :filter_name AND stats_type = 'daily' GROUP BY airport_icao,airport_name,airport_city,airport_country ORDER BY airport_city ASC"; |
||
144 | try { |
||
145 | $sth = $this->db->prepare($query); |
||
146 | $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
||
147 | } catch(PDOException $e) { |
||
148 | echo "error : ".$e->getMessage(); |
||
149 | } |
||
150 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
151 | return $all; |
||
152 | } |
||
153 | |||
154 | public function getAllOwnerNames($stats_airline = '',$filter_name = '') { |
||
155 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
156 | $query = "SELECT owner_name FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_name ASC"; |
||
157 | try { |
||
158 | $sth = $this->db->prepare($query); |
||
159 | $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
||
160 | } catch(PDOException $e) { |
||
161 | echo "error : ".$e->getMessage(); |
||
162 | } |
||
163 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
164 | return $all; |
||
165 | } |
||
166 | |||
167 | public function getAllPilotNames($stats_airline = '',$filter_name = '') { |
||
168 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
169 | $query = "SELECT pilot_id,pilot_name FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_name ASC"; |
||
170 | try { |
||
171 | $sth = $this->db->prepare($query); |
||
172 | $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
||
173 | } catch(PDOException $e) { |
||
174 | echo "error : ".$e->getMessage(); |
||
175 | } |
||
176 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
177 | return $all; |
||
178 | } |
||
179 | |||
180 | |||
181 | public function countAllAircraftTypes($limit = true, $stats_airline = '', $filter_name = '',$year = '', $month = '') { |
||
182 | global $globalStatsFilters; |
||
183 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
184 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
185 | $Spotter = new Spotter($this->db); |
||
186 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
187 | $alliance_airlines = array(); |
||
188 | foreach ($airlines as $airline) { |
||
189 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
190 | } |
||
191 | if ($year == '' && $month == '') { |
||
192 | if ($limit) $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name, aircraft_manufacturer FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' AND aircraft_icao <> 'NA' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name ORDER BY aircraft_icao_count DESC LIMIT 10 OFFSET 0"; |
||
193 | else $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name, aircraft_manufacturer FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' AND aircraft_icao <> 'NA' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name ORDER BY aircraft_icao_count DESC"; |
||
194 | try { |
||
195 | $sth = $this->db->prepare($query); |
||
196 | $sth->execute(array(':filter_name' => $filter_name)); |
||
197 | } catch(PDOException $e) { |
||
198 | echo "error : ".$e->getMessage(); |
||
199 | } |
||
200 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
201 | } else $all = array(); |
||
202 | } else { |
||
203 | if ($year == '' && $month == '') { |
||
204 | if ($limit) $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name, aircraft_manufacturer FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' AND aircraft_icao <> 'NA' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_icao_count DESC LIMIT 10 OFFSET 0"; |
||
205 | else $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name, aircraft_manufacturer FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' AND aircraft_icao <> 'NA' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_icao_count DESC"; |
||
206 | try { |
||
207 | $sth = $this->db->prepare($query); |
||
208 | $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
||
209 | } catch(PDOException $e) { |
||
210 | echo "error : ".$e->getMessage(); |
||
211 | } |
||
212 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
213 | } else $all = array(); |
||
214 | } |
||
215 | if (empty($all)) { |
||
216 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
217 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline)),'year' => $year,'month' => $month); |
||
218 | } else { |
||
219 | $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); |
||
220 | } |
||
221 | if ($filter_name != '') { |
||
222 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
223 | } |
||
224 | $Spotter = new Spotter($this->db); |
||
225 | //$all = $Spotter->countAllAircraftTypes($limit,0,'',$filters,$year,$month); |
||
226 | $all = $Spotter->countAllAircraftTypes($limit,0,'',$filters); |
||
227 | } |
||
228 | return $all; |
||
229 | } |
||
230 | public function countAllMarineTypes($limit = true, $filter_name = '',$year = '', $month = '') { |
||
231 | global $globalStatsFilters, $globalVM; |
||
232 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
233 | if ($year == '' && $month == '' && (!isset($globalVM) || $globalVM === FALSE)) { |
||
234 | if ($limit) $query = "SELECT type AS marine_type, cnt AS marine_type_count, type_id AS marine_type_id FROM stats_marine_type WHERE filter_name = :filter_name ORDER BY marine_type_count DESC LIMIT 10 OFFSET 0"; |
||
235 | else $query = "SELECT type AS marine_type, cnt AS marine_type_count, type_id AS marine_type_id FROM stats_marine_type WHERE filter_name = :filter_name ORDER BY aircraft_icao_count DESC"; |
||
236 | try { |
||
237 | $sth = $this->db->prepare($query); |
||
238 | $sth->execute(array(':filter_name' => $filter_name)); |
||
239 | } catch(PDOException $e) { |
||
240 | echo "error : ".$e->getMessage(); |
||
241 | } |
||
242 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
243 | } else $all = array(); |
||
244 | if (empty($all)) { |
||
245 | $filters = array('year' => $year,'month' => $month); |
||
246 | if ($filter_name != '') { |
||
247 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
248 | } |
||
249 | $Marine = new Marine($this->db); |
||
250 | //$all = $Spotter->countAllAircraftTypes($limit,0,'',$filters,$year,$month); |
||
251 | $all = $Marine->countAllMarineTypes($limit,0,'',$filters); |
||
252 | } |
||
253 | return $all; |
||
254 | } |
||
255 | public function countAllAirlineCountries($limit = true,$filter_name = '',$year = '',$month = '') { |
||
256 | global $globalStatsFilters; |
||
257 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
258 | if ($year == '' && $month == '') { |
||
259 | if ($limit) $query = "SELECT airlines.country AS airline_country, SUM(stats_airline.cnt) as airline_country_count, countries.iso3 AS airline_country_iso3 FROM stats_airline,airlines,countries WHERE countries.name = airlines.country AND stats_airline.airline_icao=airlines.icao AND filter_name = :filter_name GROUP BY airline_country, countries.iso3 ORDER BY airline_country_count DESC LIMIT 10 OFFSET 0"; |
||
260 | else $query = "SELECT airlines.country AS airline_country, SUM(stats_airline.cnt) as airline_country_count, countries.iso3 AS airline_country_iso3 FROM stats_airline,airlines,countries WHERE countries.name = airlines.country AND stats_airline.airline_icao=airlines.icao AND filter_name = :filter_name GROUP BY airline_country, countries.iso3 ORDER BY airline_country_count DESC"; |
||
261 | try { |
||
262 | $sth = $this->db->prepare($query); |
||
263 | $sth->execute(array(':filter_name' => $filter_name)); |
||
264 | } catch(PDOException $e) { |
||
265 | echo "error : ".$e->getMessage(); |
||
266 | } |
||
267 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
268 | } else $all = array(); |
||
269 | if (empty($all)) { |
||
270 | $Spotter = new Spotter($this->db); |
||
271 | $filters = array(); |
||
272 | $filters = array('year' => $year,'month' => $month); |
||
273 | if ($filter_name != '') { |
||
274 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
275 | } |
||
276 | //$all = $Spotter->countAllAirlineCountries($limit,$filters,$year,$month); |
||
277 | $all = $Spotter->countAllAirlineCountries($limit,$filters); |
||
278 | } |
||
279 | return $all; |
||
280 | } |
||
281 | public function countAllAircraftManufacturers($limit = true,$stats_airline = '', $filter_name = '',$year = '', $month = '') { |
||
282 | global $globalStatsFilters; |
||
283 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
284 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
285 | $Spotter = new Spotter($this->db); |
||
286 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
287 | $alliance_airlines = array(); |
||
288 | foreach ($airlines as $airline) { |
||
289 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
290 | } |
||
291 | if ($year == '' && $month == '') { |
||
292 | if ($limit) $query = "SELECT aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft WHERE stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY aircraft_manufacturer ORDER BY aircraft_manufacturer_count DESC LIMIT 10 OFFSET 0"; |
||
293 | else $query = "SELECT aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft WHERE stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY aircraft_manufacturer ORDER BY aircraft_manufacturer_count DESC"; |
||
294 | try { |
||
295 | $sth = $this->db->prepare($query); |
||
296 | $sth->execute(array(':filter_name' => $filter_name)); |
||
297 | } catch(PDOException $e) { |
||
298 | echo "error : ".$e->getMessage(); |
||
299 | } |
||
300 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
301 | } else $all = array(); |
||
302 | } else { |
||
303 | if ($year == '' && $month == '') { |
||
304 | if ($limit) $query = "SELECT aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY aircraft_manufacturer ORDER BY aircraft_manufacturer_count DESC LIMIT 10 OFFSET 0"; |
||
305 | else $query = "SELECT aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY aircraft_manufacturer ORDER BY aircraft_manufacturer_count DESC"; |
||
306 | try { |
||
307 | $sth = $this->db->prepare($query); |
||
308 | $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
||
309 | } catch(PDOException $e) { |
||
310 | echo "error : ".$e->getMessage(); |
||
311 | } |
||
312 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
313 | } else $all = array(); |
||
314 | } |
||
315 | if (empty($all)) { |
||
316 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
317 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline)),'year' => $year,'month' => $month); |
||
318 | } else { |
||
319 | $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); |
||
320 | } |
||
321 | if ($filter_name != '') { |
||
322 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
323 | } |
||
324 | $Spotter = new Spotter($this->db); |
||
325 | //$all = $Spotter->countAllAircraftManufacturers($filters,$year,$month); |
||
326 | $all = $Spotter->countAllAircraftManufacturers($filters); |
||
327 | } |
||
328 | return $all; |
||
329 | } |
||
330 | |||
331 | public function countAllArrivalCountries($limit = true, $stats_airline = '', $filter_name = '',$year = '', $month = '') { |
||
332 | global $globalStatsFilters; |
||
333 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
334 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
335 | $Spotter = new Spotter($this->db); |
||
336 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
337 | $alliance_airlines = array(); |
||
338 | foreach ($airlines as $airline) { |
||
339 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
340 | } |
||
341 | if ($year == '' && $month == '') { |
||
342 | if ($limit) $query = "SELECT airport_country AS airport_arrival_country, SUM(arrival) as airport_arrival_country_count, countries.iso3 AS airport_arrival_country_iso3 FROM stats_airport, countries WHERE countries.name = stats_airport.airport_country AND stats_type = 'yearly' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY airport_arrival_country, countries.iso3 ORDER BY airport_arrival_country_count DESC LIMIT 10 OFFSET 0"; |
||
343 | else $query = "SELECT airport_country AS airport_arrival_country, SUM(arrival) as airport_arrival_country_count, countries.iso3 AS airport_arrival_country_iso3 FROM stats_airport, countries WHERE countries.name = stats_aiport.airport_country AND stats_type = 'yearly' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY airport_arrival_country, countries.iso3 ORDER BY airport_arrival_country_count DESC"; |
||
344 | try { |
||
345 | $sth = $this->db->prepare($query); |
||
346 | $sth->execute(array(':filter_name' => $filter_name)); |
||
347 | } catch(PDOException $e) { |
||
348 | echo "error : ".$e->getMessage(); |
||
349 | } |
||
350 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
351 | } else $all = array(); |
||
352 | } else { |
||
353 | if ($year == '' && $month == '') { |
||
354 | if ($limit) $query = "SELECT airport_country AS airport_arrival_country, SUM(arrival) as airport_arrival_country_count, countries.iso3 AS airport_arrival_country_iso3 FROM stats_airport, countries WHERE countries.name = stats_airport.airport_country AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_arrival_country, countries.iso3 ORDER BY airport_arrival_country_count DESC LIMIT 10 OFFSET 0"; |
||
355 | else $query = "SELECT airport_country AS airport_arrival_country, SUM(arrival) as airport_arrival_country_count, countries.iso3 AS airport_arrival_country_iso3 FROM stats_airport, countries WHERE countries.name = stats_aiport.airport_country AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_arrival_country, countries.iso3 ORDER BY airport_arrival_country_count DESC"; |
||
356 | try { |
||
357 | $sth = $this->db->prepare($query); |
||
358 | $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
||
359 | } catch(PDOException $e) { |
||
360 | echo "error : ".$e->getMessage(); |
||
361 | } |
||
362 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
363 | } else $all = array(); |
||
364 | } |
||
365 | if (empty($all)) { |
||
366 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
367 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline)),'year' => $year,'month' => $month); |
||
368 | } else { |
||
369 | $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); |
||
370 | } |
||
371 | if ($filter_name != '') { |
||
372 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
373 | } |
||
374 | $Spotter = new Spotter($this->db); |
||
375 | //$all = $Spotter->countAllArrivalCountries($limit,$filters,$year,$month); |
||
376 | $all = $Spotter->countAllArrivalCountries($limit,$filters); |
||
377 | } |
||
378 | return $all; |
||
379 | } |
||
380 | public function countAllDepartureCountries($limit = true, $stats_airline = '', $filter_name = '', $year = '', $month = '') { |
||
381 | global $globalStatsFilters; |
||
382 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
383 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
384 | $Spotter = new Spotter($this->db); |
||
385 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
386 | $alliance_airlines = array(); |
||
387 | foreach ($airlines as $airline) { |
||
388 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
389 | } |
||
390 | if ($limit) $query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count, countries.iso3 as airport_departure_country_iso3 FROM stats_airport, countries WHERE countries.name = stats_airport.airport_country AND stats_type = 'yearly' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY airport_departure_country, countries.iso3 ORDER BY airport_departure_country_count DESC LIMIT 10 OFFSET 0"; |
||
391 | else $query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count, countries.iso3 as airport_departure_country_iso3 FROM stats_airport, countries WHERE countries.iso3 = stats_airport.airport_country AND stats_type = 'yearly' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY airport_departure_country, countries.iso3 ORDER BY airport_departure_country_count DESC"; |
||
392 | $query_values = array(':filter_name' => $filter_name); |
||
393 | } else { |
||
394 | if ($limit) $query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count, countries.iso3 as airport_departure_country_iso3 FROM stats_airport, countries WHERE countries.name = stats_airport.airport_country AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_departure_country, countries.iso3 ORDER BY airport_departure_country_count DESC LIMIT 10 OFFSET 0"; |
||
395 | else $query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count, countries.iso3 as airport_departure_country_iso3 FROM stats_airport, countries WHERE countries.iso3 = stats_airport.airport_country AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_departure_country, countries.iso3 ORDER BY airport_departure_country_count DESC"; |
||
396 | $query_values = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
||
397 | } |
||
398 | try { |
||
399 | $sth = $this->db->prepare($query); |
||
400 | $sth->execute($query_values); |
||
401 | } catch(PDOException $e) { |
||
402 | echo "error : ".$e->getMessage(); |
||
403 | } |
||
404 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
405 | if (empty($all)) { |
||
406 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
407 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline)),'year' => $year,'month' => $month); |
||
408 | } else { |
||
409 | $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); |
||
410 | } |
||
411 | if ($filter_name != '') { |
||
412 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
413 | } |
||
414 | $Spotter = new Spotter($this->db); |
||
415 | //$all = $Spotter->countAllDepartureCountries($filters,$year,$month); |
||
416 | $all = $Spotter->countAllDepartureCountries($filters); |
||
417 | } |
||
418 | return $all; |
||
419 | } |
||
420 | |||
421 | public function countAllAirlines($limit = true,$filter_name = '',$year = '',$month = '') { |
||
422 | global $globalStatsFilters, $globalVATSIM, $globalIVAO; |
||
423 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
424 | if ($year == '' && $month == '') { |
||
425 | if ($globalVATSIM) $forsource = 'vatsim'; |
||
426 | if ($globalIVAO) $forsource = 'ivao'; |
||
427 | if (isset($forsource)) { |
||
428 | if ($limit) $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource = :forsource ORDER BY airline_count DESC LIMIT 10 OFFSET 0"; |
||
429 | else $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource = :forsource ORDER BY airline_count DESC"; |
||
430 | $query_values = array(':filter_name' => $filter_name,':forsource' => $forsource); |
||
431 | } else { |
||
432 | if ($limit) $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource IS NULL ORDER BY airline_count DESC LIMIT 10 OFFSET 0"; |
||
433 | else $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource IS NULL ORDER BY airline_count DESC"; |
||
434 | $query_values = array(':filter_name' => $filter_name); |
||
435 | } |
||
436 | try { |
||
437 | $sth = $this->db->prepare($query); |
||
438 | $sth->execute($query_values); |
||
439 | } catch(PDOException $e) { |
||
440 | echo "error : ".$e->getMessage(); |
||
441 | } |
||
442 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
443 | } else $all = array(); |
||
444 | if (empty($all)) { |
||
445 | $Spotter = new Spotter($this->db); |
||
446 | $filters = array(); |
||
447 | $filters = array('year' => $year,'month' => $month); |
||
448 | if ($filter_name != '') { |
||
449 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
450 | } |
||
451 | //$all = $Spotter->countAllAirlines($limit,0,'',$filters,$year,$month); |
||
452 | $all = $Spotter->countAllAirlines($limit,0,'',$filters); |
||
453 | } |
||
454 | return $all; |
||
455 | } |
||
456 | public function countAllAircraftRegistrations($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') { |
||
457 | global $globalStatsFilters; |
||
458 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
459 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
460 | $Spotter = new Spotter($this->db); |
||
461 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
462 | $alliance_airlines = array(); |
||
463 | foreach ($airlines as $airline) { |
||
464 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
465 | } |
||
466 | if ($year == '' && $month == '') { |
||
467 | if ($limit) $query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name, s.registration FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao AND s.stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name ORDER BY aircraft_registration_count DESC LIMIT 10 OFFSET 0"; |
||
468 | else $query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao AND s.stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name ORDER BY aircraft_registration_count DESC"; |
||
469 | try { |
||
470 | $sth = $this->db->prepare($query); |
||
471 | $sth->execute(array(':filter_name' => $filter_name)); |
||
472 | } catch(PDOException $e) { |
||
473 | echo "error : ".$e->getMessage(); |
||
474 | } |
||
475 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
476 | } else $all = array(); |
||
477 | } else { |
||
478 | if ($year == '' && $month == '') { |
||
479 | if ($limit) $query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name, s.registration FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao AND s.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_registration_count DESC LIMIT 10 OFFSET 0"; |
||
480 | else $query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao AND s.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_registration_count DESC"; |
||
481 | try { |
||
482 | $sth = $this->db->prepare($query); |
||
483 | $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
||
484 | } catch(PDOException $e) { |
||
485 | echo "error : ".$e->getMessage(); |
||
486 | } |
||
487 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
488 | } else $all = array(); |
||
489 | } |
||
490 | if (empty($all)) { |
||
491 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
492 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline)),'year' => $year,'month' => $month); |
||
493 | } else { |
||
494 | $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); |
||
495 | } |
||
496 | if ($filter_name != '') { |
||
497 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
498 | } |
||
499 | $Spotter = new Spotter($this->db); |
||
500 | //$all = $Spotter->countAllAircraftRegistrations($limit,0,'',$filters,$year,$month); |
||
501 | $all = $Spotter->countAllAircraftRegistrations($limit,0,'',$filters); |
||
502 | } |
||
503 | return $all; |
||
504 | } |
||
505 | public function countAllCallsigns($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') { |
||
506 | global $globalStatsFilters; |
||
507 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
508 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
509 | $Spotter = new Spotter($this->db); |
||
510 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
511 | $alliance_airlines = array(); |
||
512 | foreach ($airlines as $airline) { |
||
513 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
514 | } |
||
515 | if ($year == '' && $month == '') { |
||
516 | if ($limit) $query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao AND s.airline_icao IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name ORDER BY callsign_icao_count DESC LIMIT 10 OFFSET 0"; |
||
517 | else $query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao AND s.airline_icao IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name ORDER BY callsign_icao_count DESC"; |
||
518 | try { |
||
519 | $sth = $this->db->prepare($query); |
||
520 | $sth->execute(array(':filter_name' => $filter_name)); |
||
521 | } catch(PDOException $e) { |
||
522 | echo "error : ".$e->getMessage(); |
||
523 | } |
||
524 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
525 | } else $all = array(); |
||
526 | } else { |
||
527 | if ($year == '' && $month == '') { |
||
528 | if ($limit) $query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao AND s.airline_icao = :stats_airline AND filter_name = :filter_name ORDER BY callsign_icao_count DESC LIMIT 10 OFFSET 0"; |
||
529 | else $query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao AND s.airline_icao = :stats_airline AND filter_name = :filter_name ORDER BY callsign_icao_count DESC"; |
||
530 | try { |
||
531 | $sth = $this->db->prepare($query); |
||
532 | $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
||
533 | } catch(PDOException $e) { |
||
534 | echo "error : ".$e->getMessage(); |
||
535 | } |
||
536 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
537 | } else $all = array(); |
||
538 | } |
||
539 | if (empty($all)) { |
||
540 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
541 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline)),'year' => $year,'month' => $month); |
||
542 | } else { |
||
543 | $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); |
||
544 | } |
||
545 | if ($filter_name != '') { |
||
546 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
547 | } |
||
548 | $Spotter = new Spotter($this->db); |
||
549 | //$all = $Spotter->countAllCallsigns($limit,0,'',$filters,$year,$month); |
||
550 | $all = $Spotter->countAllCallsigns($limit,0,'',$filters); |
||
551 | } |
||
552 | return $all; |
||
553 | } |
||
554 | public function countAllFlightOverCountries($limit = true, $stats_airline = '',$filter_name = '',$year = '',$month = '') { |
||
555 | $Connection = new Connection($this->db); |
||
556 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
557 | if ($Connection->tableExists('countries')) { |
||
558 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
559 | $Spotter = new Spotter($this->db); |
||
560 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
561 | if ($year == '' && $month == '') { |
||
562 | $alliance_airlines = array(); |
||
563 | foreach ($airlines as $airline) { |
||
564 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
565 | } |
||
566 | if ($limit) $query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 AND stats_country.stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name ORDER BY flight_count DESC LIMIT 20 OFFSET 0"; |
||
567 | else $query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 AND stats_country.stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name ORDER BY flight_count DESC"; |
||
568 | try { |
||
569 | $sth = $this->db->prepare($query); |
||
570 | $sth->execute(array(':filter_name' => $filter_name)); |
||
571 | } catch(PDOException $e) { |
||
572 | echo "error : ".$e->getMessage(); |
||
573 | } |
||
574 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
575 | return $all; |
||
576 | } else return array(); |
||
577 | } else { |
||
578 | if ($year == '' && $month == '') { |
||
579 | if ($limit) $query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 AND stats_country.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY flight_count DESC LIMIT 20 OFFSET 0"; |
||
580 | else $query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 AND stats_country.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY flight_count DESC"; |
||
581 | try { |
||
582 | $sth = $this->db->prepare($query); |
||
583 | $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
||
584 | } catch(PDOException $e) { |
||
585 | echo "error : ".$e->getMessage(); |
||
586 | } |
||
587 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
588 | return $all; |
||
589 | } else return array(); |
||
590 | } |
||
591 | $Spotter = new Spotter($this->db); |
||
592 | return $Spotter->countAllFlightOverCountries($limit); |
||
593 | } else return array(); |
||
594 | } |
||
595 | public function countAllMarineOverCountries($limit = true, $filter_name = '',$year = '',$month = '') { |
||
596 | $Connection = new Connection($this->db); |
||
597 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
598 | if ($Connection->tableExists('countries')) { |
||
599 | $all = array(); |
||
600 | if ($year == '' && $month == '') { |
||
601 | if ($limit) $query = "SELECT countries.iso3 as marine_country_iso3, countries.iso2 as marine_country_iso2, countries.name as marine_country, cnt as marine_count, lat as marine_country_latitude, lon as marine_country_longitude FROM stats_marine_country, countries WHERE stats_marine_country.iso2 = countries.iso2 AND filter_name = :filter_name ORDER BY marine_count DESC LIMIT 20 OFFSET 0"; |
||
602 | else $query = "SELECT countries.iso3 as marine_country_iso3, countries.iso2 as marine_country_iso2, countries.name as marine_country, cnt as marine_count, lat as marine_country_latitude, lon as marine_country_longitude FROM stats_marine_country, countries WHERE stats_marine_country.iso2 = countries.iso2 AND filter_name = :filter_name ORDER BY marine_count DESC"; |
||
603 | try { |
||
604 | $sth = $this->db->prepare($query); |
||
605 | $sth->execute(array(':filter_name' => $filter_name)); |
||
606 | } catch(PDOException $e) { |
||
607 | echo "error : ".$e->getMessage(); |
||
608 | } |
||
609 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
610 | } |
||
611 | if (empty($all)) { |
||
612 | $filters = array(); |
||
613 | if ($filter_name != '') { |
||
614 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
615 | } |
||
616 | $Marine = new Marine($this->db); |
||
617 | $all = $Marine->countAllMarineOverCountries($limit,0,'',$filters); |
||
618 | } |
||
619 | return $all; |
||
620 | } else return array(); |
||
621 | } |
||
622 | public function countAllTrackerOverCountries($limit = true, $filter_name = '',$year = '',$month = '') { |
||
623 | global $globalStatsFilters; |
||
624 | $Connection = new Connection($this->db); |
||
625 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
626 | if ($Connection->tableExists('countries')) { |
||
627 | $all = array(); |
||
628 | if ($year == '' && $month == '') { |
||
629 | if ($limit) $query = "SELECT countries.iso3 as tracker_country_iso3, countries.iso2 as tracker_country_iso2, countries.name as tracker_country, cnt as tracker_count, lat as tracker_country_latitude, lon as tracker_country_longitude FROM stats_tracker_country, countries WHERE stats_tracker_country.iso2 = countries.iso2 AND filter_name = :filter_name ORDER BY tracker_count DESC LIMIT 20 OFFSET 0"; |
||
630 | else $query = "SELECT countries.iso3 as tracker_country_iso3, countries.iso2 as tracker_country_iso2, countries.name as tracker_country, cnt as tracker_count, lat as tracker_country_latitude, lon as tracker_country_longitude FROM stats_tracker_country, countries WHERE stats_tracker_country.iso2 = countries.iso2 AND filter_name = :filter_name ORDER BY tracker_count DESC"; |
||
631 | try { |
||
632 | $sth = $this->db->prepare($query); |
||
633 | $sth->execute(array(':filter_name' => $filter_name)); |
||
634 | } catch(PDOException $e) { |
||
635 | echo "error : ".$e->getMessage(); |
||
636 | } |
||
637 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
638 | return $all; |
||
639 | } |
||
640 | if (empty($all)) { |
||
641 | $filters = array(); |
||
642 | if ($filter_name != '') { |
||
643 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
644 | } |
||
645 | $Tracker = new Tracker($this->db); |
||
646 | $all = $Tracker->countAllTrackerOverCountries($limit,0,'',$filters); |
||
647 | } |
||
648 | return $all; |
||
649 | } else return array(); |
||
650 | } |
||
651 | public function countAllPilots($limit = true,$stats_airline = '',$filter_name = '', $year = '',$month = '') { |
||
652 | global $globalStatsFilters; |
||
653 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
654 | if ($year == '' && $month == '') { |
||
655 | if ($limit) $query = "SELECT pilot_id, cnt AS pilot_count, pilot_name, format_source FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_count DESC LIMIT 10 OFFSET 0"; |
||
656 | else $query = "SELECT pilot_id, cnt AS pilot_count, pilot_name, format_source FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_count DESC"; |
||
657 | try { |
||
658 | $sth = $this->db->prepare($query); |
||
659 | $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
||
660 | } catch(PDOException $e) { |
||
661 | echo "error : ".$e->getMessage(); |
||
662 | } |
||
663 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
664 | } else $all = array(); |
||
665 | if (empty($all)) { |
||
666 | $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); |
||
667 | if ($filter_name != '') { |
||
668 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
669 | } |
||
670 | $Spotter = new Spotter($this->db); |
||
671 | //$all = $Spotter->countAllPilots($limit,0,'',$filters,$year,$month); |
||
672 | $all = $Spotter->countAllPilots($limit,0,'',$filters); |
||
673 | } |
||
674 | return $all; |
||
675 | } |
||
676 | |||
677 | public function countAllOwners($limit = true,$stats_airline = '', $filter_name = '',$year = '',$month = '') { |
||
678 | global $globalStatsFilters; |
||
679 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
680 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
681 | $Spotter = new Spotter($this->db); |
||
682 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
683 | if ($year == '' && $month == '') { |
||
684 | $alliance_airlines = array(); |
||
685 | foreach ($airlines as $airline) { |
||
686 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
687 | } |
||
688 | if ($limit) $query = "SELECT owner_name, cnt AS owner_count FROM stats_owner WHERE stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name ORDER BY owner_count DESC LIMIT 10 OFFSET 0"; |
||
689 | else $query = "SELECT owner_name, cnt AS owner_count FROM stats_owner WHERE stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name ORDER BY owner_count DESC"; |
||
690 | try { |
||
691 | $sth = $this->db->prepare($query); |
||
692 | $sth->execute(array(':filter_name' => $filter_name)); |
||
693 | } catch(PDOException $e) { |
||
694 | echo "error : ".$e->getMessage(); |
||
695 | } |
||
696 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
697 | } else $all = array(); |
||
698 | } else { |
||
699 | if ($year == '' && $month == '') { |
||
700 | if ($limit) $query = "SELECT owner_name, cnt AS owner_count FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_count DESC LIMIT 10 OFFSET 0"; |
||
701 | else $query = "SELECT owner_name, cnt AS owner_count FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_count DESC"; |
||
702 | try { |
||
703 | $sth = $this->db->prepare($query); |
||
704 | $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
||
705 | } catch(PDOException $e) { |
||
706 | echo "error : ".$e->getMessage(); |
||
707 | } |
||
708 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
709 | } else $all = array(); |
||
710 | } |
||
711 | if (empty($all)) { |
||
712 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
713 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline)),'year' => $year,'month' => $month); |
||
714 | } else { |
||
715 | $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); |
||
716 | } |
||
717 | if ($filter_name != '') { |
||
718 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
719 | } |
||
720 | $Spotter = new Spotter($this->db); |
||
721 | //$all = $Spotter->countAllOwners($limit,0,'',$filters,$year,$month); |
||
722 | $all = $Spotter->countAllOwners($limit,0,'',$filters); |
||
723 | } |
||
724 | return $all; |
||
725 | } |
||
726 | public function countAllDepartureAirports($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') { |
||
727 | global $globalStatsFilters; |
||
728 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
729 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
730 | $Spotter = new Spotter($this->db); |
||
731 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
732 | if ($year == '' && $month == '') { |
||
733 | $alliance_airlines = array(); |
||
734 | foreach ($airlines as $airline) { |
||
735 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
736 | } |
||
737 | if ($limit) $query = "SELECT DISTINCT airport_icao AS airport_departure_icao,airport.name AS airport_departure_name,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count, airport.latitude AS airport_departure_latitude, airport.longitude AS airport_departure_longitude FROM stats_airport,airport WHERE airport.icao = stats_airport.airport_icao AND departure > 0 AND stats_type = 'yearly' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name ORDER BY airport_departure_icao_count DESC LIMIT 10 OFFSET 0"; |
||
738 | else $query = "SELECT DISTINCT airport_icao AS airport_departure_icao,airport.name AS airport_departure_name,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count, airport.latitude AS airport_departure_latitude, airport.longitude AS airport_departure_longitude FROM stats_airport,airport WHERE airport.icao = stats_airport.airport_icao AND departure > 0 AND stats_type = 'yearly' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name ORDER BY airport_departure_icao_count DESC"; |
||
739 | try { |
||
740 | $sth = $this->db->prepare($query); |
||
741 | $sth->execute(array(':filter_name' => $filter_name)); |
||
742 | } catch(PDOException $e) { |
||
743 | echo "error : ".$e->getMessage(); |
||
744 | } |
||
745 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
746 | } else $all = array(); |
||
747 | } else { |
||
748 | if ($year == '' && $month == '') { |
||
749 | if ($limit) $query = "SELECT DISTINCT airport_icao AS airport_departure_icao,airport.name AS airport_departure_name,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count, airport.latitude AS airport_departure_latitude, airport.longitude AS airport_departure_longitude FROM stats_airport,airport WHERE airport.icao = stats_airport.airport_icao AND departure > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_departure_icao_count DESC LIMIT 10 OFFSET 0"; |
||
750 | else $query = "SELECT DISTINCT airport_icao AS airport_departure_icao,airport.name AS airport_departure_name,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count, airport.latitude AS airport_departure_latitude, airport.longitude AS airport_departure_longitude FROM stats_airport,airport WHERE airport.icao = stats_airport.airport_icao AND departure > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_departure_icao_count DESC"; |
||
751 | try { |
||
752 | $sth = $this->db->prepare($query); |
||
753 | $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
||
754 | } catch(PDOException $e) { |
||
755 | echo "error : ".$e->getMessage(); |
||
756 | } |
||
757 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
758 | } else $all = array(); |
||
759 | } |
||
760 | if (empty($all)) { |
||
761 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
762 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline)),'year' => $year,'month' => $month); |
||
763 | } else { |
||
764 | $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); |
||
765 | } |
||
766 | if ($filter_name != '') { |
||
767 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
768 | } |
||
769 | $Spotter = new Spotter($this->db); |
||
770 | // $pall = $Spotter->countAllDepartureAirports($limit,0,'',$filters,$year,$month); |
||
771 | // $dall = $Spotter->countAllDetectedDepartureAirports($limit,0,'',$filters,$year,$month); |
||
772 | $pall = $Spotter->countAllDepartureAirports($limit,0,'',$filters); |
||
773 | $dall = $Spotter->countAllDetectedDepartureAirports($limit,0,'',$filters); |
||
774 | $all = array(); |
||
775 | foreach ($pall as $value) { |
||
776 | $icao = $value['airport_departure_icao']; |
||
777 | $all[$icao] = $value; |
||
778 | } |
||
779 | foreach ($dall as $value) { |
||
780 | $icao = $value['airport_departure_icao']; |
||
781 | if (isset($all[$icao])) { |
||
782 | $all[$icao]['airport_departure_icao_count'] = $all[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count']; |
||
783 | } else $all[$icao] = $value; |
||
784 | } |
||
785 | $count = array(); |
||
786 | foreach ($all as $key => $row) { |
||
787 | $count[$key] = $row['airport_departure_icao_count']; |
||
788 | } |
||
789 | array_multisort($count,SORT_DESC,$all); |
||
790 | } |
||
791 | return $all; |
||
792 | } |
||
793 | public function countAllArrivalAirports($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') { |
||
794 | global $globalStatsFilters; |
||
795 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
796 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
797 | $Spotter = new Spotter($this->db); |
||
798 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
799 | if ($year == '' && $month == '') { |
||
800 | $alliance_airlines = array(); |
||
801 | foreach ($airlines as $airline) { |
||
802 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
803 | } |
||
804 | if ($limit) $query = "SELECT DISTINCT airport_icao AS airport_arrival_icao,airport.name AS airport_arrival_name, airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count, airport.latitude AS airport_arrival_latitude, airport.longitude AS airport_arrival_longitude FROM stats_airport, airport WHERE airport.icao = stats_airport.airport_icao AND arrival > 0 AND stats_type = 'yearly' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name ORDER BY airport_arrival_icao_count DESC LIMIT 10 OFFSET 0"; |
||
805 | else $query = "SELECT DISTINCT airport_icao AS airport_arrival_icao,airport.name AS airport_arrival_name, airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count, airport.latitude AS airport_arrival_latitude, airport.longitude AS airport_arrival_longitude FROM stats_airport, airport WHERE airport.icao = stats_airport.airport_icao AND arrival > 0 AND stats_type = 'yearly' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name ORDER BY airport_arrival_icao_count DESC"; |
||
806 | try { |
||
807 | $sth = $this->db->prepare($query); |
||
808 | $sth->execute(array(':filter_name' => $filter_name)); |
||
809 | } catch(PDOException $e) { |
||
810 | echo "error : ".$e->getMessage(); |
||
811 | } |
||
812 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
813 | } else $all = array(); |
||
814 | } else { |
||
815 | if ($year == '' && $month == '') { |
||
816 | if ($limit) $query = "SELECT DISTINCT airport_icao AS airport_arrival_icao,airport.name AS airport_arrival_name, airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count, airport.latitude AS airport_arrival_latitude, airport.longitude AS airport_arrival_longitude FROM stats_airport, airport WHERE airport.icao = stats_airport.airport_icao AND arrival > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_arrival_icao_count DESC LIMIT 10 OFFSET 0"; |
||
817 | else $query = "SELECT DISTINCT airport_icao AS airport_arrival_icao,airport.name AS airport_arrival_name, airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count, airport.latitude AS airport_arrival_latitude, airport.longitude AS airport_arrival_longitude FROM stats_airport, airport WHERE airport.icao = stats_airport.airport_icao AND arrival > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_arrival_icao_count DESC"; |
||
818 | try { |
||
819 | $sth = $this->db->prepare($query); |
||
820 | $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
||
821 | } catch(PDOException $e) { |
||
822 | echo "error : ".$e->getMessage(); |
||
823 | } |
||
824 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
825 | } else $all = array(); |
||
826 | } |
||
827 | if (empty($all)) { |
||
828 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
829 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline)),'year' => $year,'month' => $month); |
||
830 | } else { |
||
831 | $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); |
||
832 | } |
||
833 | if ($filter_name != '') { |
||
834 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
835 | } |
||
836 | $Spotter = new Spotter($this->db); |
||
837 | // $pall = $Spotter->countAllArrivalAirports($limit,0,'',false,$filters,$year,$month); |
||
838 | // $dall = $Spotter->countAllDetectedArrivalAirports($limit,0,'',false,$filters,$year,$month); |
||
839 | $pall = $Spotter->countAllArrivalAirports($limit,0,'',false,$filters); |
||
840 | $dall = $Spotter->countAllDetectedArrivalAirports($limit,0,'',false,$filters); |
||
841 | $all = array(); |
||
842 | foreach ($pall as $value) { |
||
843 | $icao = $value['airport_arrival_icao']; |
||
844 | $all[$icao] = $value; |
||
845 | } |
||
846 | foreach ($dall as $value) { |
||
847 | $icao = $value['airport_arrival_icao']; |
||
848 | if (isset($all[$icao])) { |
||
849 | $all[$icao]['airport_arrival_icao_count'] = $all[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count']; |
||
850 | } else $all[$icao] = $value; |
||
851 | } |
||
852 | $count = array(); |
||
853 | foreach ($all as $key => $row) { |
||
854 | $count[$key] = $row['airport_arrival_icao_count']; |
||
855 | } |
||
856 | array_multisort($count,SORT_DESC,$all); |
||
857 | } |
||
858 | return $all; |
||
859 | } |
||
860 | public function countAllMonthsLastYear($limit = true,$stats_airline = '',$filter_name = '') { |
||
861 | global $globalDBdriver, $globalStatsFilters; |
||
862 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
863 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
864 | $Spotter = new Spotter($this->db); |
||
865 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
866 | $alliance_airlines = array(); |
||
867 | foreach ($airlines as $airline) { |
||
868 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
869 | } |
||
870 | if ($globalDBdriver == 'mysql') { |
||
871 | if ($limit) $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, SUM(cnt) as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 12 MONTH) AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY stats_date"; |
||
872 | else $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, SUM(cnt) as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY stats_date"; |
||
873 | } else { |
||
874 | if ($limit) $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, SUM(cnt) as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '12 MONTHS' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY stats_date"; |
||
875 | else $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, SUM(cnt) as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY stats_date"; |
||
876 | } |
||
877 | $query_data = array(':filter_name' => $filter_name); |
||
878 | } else { |
||
879 | if ($globalDBdriver == 'mysql') { |
||
880 | if ($limit) $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 12 MONTH) AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
881 | else $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
882 | } else { |
||
883 | if ($limit) $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '12 MONTHS' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
884 | else $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
885 | } |
||
886 | $query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
||
887 | } |
||
888 | try { |
||
889 | $sth = $this->db->prepare($query); |
||
890 | $sth->execute($query_data); |
||
891 | } catch(PDOException $e) { |
||
892 | echo "error : ".$e->getMessage(); |
||
893 | } |
||
894 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
895 | if (empty($all)) { |
||
896 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
897 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
898 | } else { |
||
899 | $filters = array('airlines' => array($stats_airline)); |
||
900 | } |
||
901 | if ($filter_name != '') { |
||
902 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
903 | } |
||
904 | $Spotter = new Spotter($this->db); |
||
905 | $all = $Spotter->countAllMonthsLastYear($filters); |
||
906 | } |
||
907 | return $all; |
||
908 | } |
||
909 | |||
910 | public function countAllMarineMonthsLastYear($limit = true,$filter_name = '') { |
||
911 | global $globalDBdriver, $globalStatsFilters; |
||
912 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
913 | if ($globalDBdriver == 'mysql') { |
||
914 | if ($limit) $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'marine_bymonth' AND stats_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 12 MONTH) AND filter_name = :filter_name"; |
||
915 | else $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'marine_bymonth' AND filter_name = :filter_name"; |
||
916 | } else { |
||
917 | if ($limit) $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'marine_bymonth' AND stats_date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '12 MONTHS' AND filter_name = :filter_name"; |
||
918 | else $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'marine_bymonth' AND filter_name = :filter_name"; |
||
919 | } |
||
920 | $query_data = array(':filter_name' => $filter_name); |
||
921 | try { |
||
922 | $sth = $this->db->prepare($query); |
||
923 | $sth->execute($query_data); |
||
924 | } catch(PDOException $e) { |
||
925 | echo "error : ".$e->getMessage(); |
||
926 | } |
||
927 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
928 | if (empty($all)) { |
||
929 | $filters = array(); |
||
930 | if ($filter_name != '') { |
||
931 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
932 | } |
||
933 | $Marine = new Marine($this->db); |
||
934 | $all = $Marine->countAllMonthsLastYear($filters); |
||
935 | } |
||
936 | return $all; |
||
937 | } |
||
938 | |||
939 | public function countAllTrackerMonthsLastYear($limit = true,$filter_name = '') { |
||
940 | global $globalDBdriver, $globalStatsFilters; |
||
941 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
942 | if ($globalDBdriver == 'mysql') { |
||
943 | if ($limit) $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'tracker_bymonth' AND stats_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 12 MONTH) AND filter_name = :filter_name"; |
||
944 | else $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'tracker_bymonth' AND filter_name = :filter_name"; |
||
945 | } else { |
||
946 | if ($limit) $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'tracker_bymonth' AND stats_date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '12 MONTHS' AND filter_name = :filter_name"; |
||
947 | else $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'tracker_bymonth' AND filter_name = :filter_name"; |
||
948 | } |
||
949 | $query_data = array(':filter_name' => $filter_name); |
||
950 | try { |
||
951 | $sth = $this->db->prepare($query); |
||
952 | $sth->execute($query_data); |
||
953 | } catch(PDOException $e) { |
||
954 | echo "error : ".$e->getMessage(); |
||
955 | } |
||
956 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
957 | if (empty($all)) { |
||
958 | $filters = array(); |
||
959 | if ($filter_name != '') { |
||
960 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
961 | } |
||
962 | $Tracker = new Tracker($this->db); |
||
963 | $all = $Tracker->countAllMonthsLastYear($filters); |
||
964 | } |
||
965 | return $all; |
||
966 | } |
||
967 | |||
968 | public function countAllDatesLastMonth($stats_airline = '',$filter_name = '') { |
||
969 | global $globalStatsFilters; |
||
970 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
971 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
972 | $Spotter = new Spotter($this->db); |
||
973 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
974 | $alliance_airlines = array(); |
||
975 | foreach ($airlines as $airline) { |
||
976 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
977 | } |
||
978 | $query = "SELECT flight_date as date_name, SUM(cnt) as date_count FROM stats_flight WHERE stats_type = 'month' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY flight_date"; |
||
979 | $query_data = array(':filter_name' => $filter_name); |
||
980 | } else { |
||
981 | $query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'month' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
982 | $query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
||
983 | } |
||
984 | try { |
||
985 | $sth = $this->db->prepare($query); |
||
986 | $sth->execute($query_data); |
||
987 | } catch(PDOException $e) { |
||
988 | echo "error : ".$e->getMessage(); |
||
989 | } |
||
990 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
991 | if (empty($all)) { |
||
992 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
993 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
994 | } else { |
||
995 | $filters = array('airlines' => array($stats_airline)); |
||
996 | } |
||
997 | if ($filter_name != '') { |
||
998 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
999 | } |
||
1000 | $Spotter = new Spotter($this->db); |
||
1001 | $all = $Spotter->countAllDatesLastMonth($filters); |
||
1002 | } |
||
1003 | return $all; |
||
1004 | } |
||
1005 | public function countAllMarineDatesLastMonth($filter_name = '') { |
||
1006 | global $globalStatsFilters; |
||
1007 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1008 | $query = "SELECT marine_date as date_name, cnt as date_count FROM stats_marine WHERE stats_type = 'month' AND filter_name = :filter_name"; |
||
1009 | $query_data = array(':filter_name' => $filter_name); |
||
1010 | try { |
||
1011 | $sth = $this->db->prepare($query); |
||
1012 | $sth->execute($query_data); |
||
1013 | } catch(PDOException $e) { |
||
1014 | echo "error : ".$e->getMessage(); |
||
1015 | } |
||
1016 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1017 | if (empty($all)) { |
||
1018 | $filters = array(); |
||
1019 | if ($filter_name != '') { |
||
1020 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1021 | } |
||
1022 | $Marine = new Marine($this->db); |
||
1023 | $all = $Marine->countAllDatesLastMonth($filters); |
||
1024 | } |
||
1025 | return $all; |
||
1026 | } |
||
1027 | public function countAllTrackerDatesLastMonth($filter_name = '') { |
||
1028 | global $globalStatsFilters; |
||
1029 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1030 | $query = "SELECT tracker_date as date_name, cnt as date_count FROM stats_tracker WHERE stats_type = 'month' AND filter_name = :filter_name"; |
||
1031 | $query_data = array(':filter_name' => $filter_name); |
||
1032 | try { |
||
1033 | $sth = $this->db->prepare($query); |
||
1034 | $sth->execute($query_data); |
||
1035 | } catch(PDOException $e) { |
||
1036 | echo "error : ".$e->getMessage(); |
||
1037 | } |
||
1038 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1039 | if (empty($all)) { |
||
1040 | $filters = array(); |
||
1041 | if ($filter_name != '') { |
||
1042 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1043 | } |
||
1044 | $Tracker = new Tracker($this->db); |
||
1045 | $all = $Tracker->countAllDatesLastMonth($filters); |
||
1046 | } |
||
1047 | return $all; |
||
1048 | } |
||
1049 | public function countAllDatesLast7Days($stats_airline = '',$filter_name = '') { |
||
1050 | global $globalDBdriver, $globalStatsFilters; |
||
1051 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1052 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1053 | $Spotter = new Spotter($this->db); |
||
1054 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
1055 | $alliance_airlines = array(); |
||
1056 | foreach ($airlines as $airline) { |
||
1057 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
1058 | } |
||
1059 | if ($globalDBdriver == 'mysql') { |
||
1060 | $query = "SELECT flight_date as date_name, SUM(cnt) as date_count FROM stats_flight WHERE stats_type = 'month' AND flight_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY) AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY flight_date"; |
||
1061 | } else { |
||
1062 | $query = "SELECT flight_date as date_name, SUM(cnt) as date_count FROM stats_flight WHERE stats_type = 'month' AND flight_date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY flight_date"; |
||
1063 | } |
||
1064 | $query_data = array(':filter_name' => $filter_name); |
||
1065 | } else { |
||
1066 | if ($globalDBdriver == 'mysql') { |
||
1067 | $query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'month' AND flight_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY) AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1068 | } else { |
||
1069 | $query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'month' AND flight_date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1070 | } |
||
1071 | $query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
||
1072 | } |
||
1073 | try { |
||
1074 | $sth = $this->db->prepare($query); |
||
1075 | $sth->execute($query_data); |
||
1076 | } catch(PDOException $e) { |
||
1077 | echo "error : ".$e->getMessage(); |
||
1078 | } |
||
1079 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1080 | if (empty($all)) { |
||
1081 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1082 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
1083 | } else { |
||
1084 | $filters = array('airlines' => array($stats_airline)); |
||
1085 | } |
||
1086 | if ($filter_name != '') { |
||
1087 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1088 | } |
||
1089 | $Spotter = new Spotter($this->db); |
||
1090 | $all = $Spotter->countAllDatesLast7Days($filters); |
||
1091 | } |
||
1092 | return $all; |
||
1093 | } |
||
1094 | public function countAllMarineDatesLast7Days($filter_name = '') { |
||
1095 | global $globalDBdriver, $globalStatsFilters; |
||
1096 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1097 | if ($globalDBdriver == 'mysql') { |
||
1098 | $query = "SELECT marine_date as date_name, cnt as date_count FROM stats_marine WHERE stats_type = 'month' AND marine_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY) AND filter_name = :filter_name"; |
||
1099 | } else { |
||
1100 | $query = "SELECT marine_date as date_name, cnt as date_count FROM stats_marine WHERE stats_type = 'month' AND marine_date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND filter_name = :filter_name"; |
||
1101 | } |
||
1102 | $query_data = array(':filter_name' => $filter_name); |
||
1103 | try { |
||
1104 | $sth = $this->db->prepare($query); |
||
1105 | $sth->execute($query_data); |
||
1106 | } catch(PDOException $e) { |
||
1107 | echo "error : ".$e->getMessage(); |
||
1108 | } |
||
1109 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1110 | if (empty($all)) { |
||
1111 | $filters = array(); |
||
1112 | if ($filter_name != '') { |
||
1113 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1114 | } |
||
1115 | $Marine = new Marine($this->db); |
||
1116 | $all = $Marine->countAllDatesLast7Days($filters); |
||
1117 | } |
||
1118 | return $all; |
||
1119 | } |
||
1120 | public function countAllTrackerDatesLast7Days($filter_name = '') { |
||
1121 | global $globalDBdriver, $globalStatsFilters; |
||
1122 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1123 | if ($globalDBdriver == 'mysql') { |
||
1124 | $query = "SELECT tracker_date as date_name, cnt as date_count FROM stats_tracker WHERE stats_type = 'month' AND tracker_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY) AND filter_name = :filter_name"; |
||
1125 | } else { |
||
1126 | $query = "SELECT tracker_date as date_name, cnt as date_count FROM stats_tracker WHERE stats_type = 'month' AND tracker_date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND filter_name = :filter_name"; |
||
1127 | } |
||
1128 | $query_data = array(':filter_name' => $filter_name); |
||
1129 | try { |
||
1130 | $sth = $this->db->prepare($query); |
||
1131 | $sth->execute($query_data); |
||
1132 | } catch(PDOException $e) { |
||
1133 | echo "error : ".$e->getMessage(); |
||
1134 | } |
||
1135 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1136 | if (empty($all)) { |
||
1137 | $filters = array(); |
||
1138 | if ($filter_name != '') { |
||
1139 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1140 | } |
||
1141 | $Tracker = new Tracker($this->db); |
||
1142 | $all = $Tracker->countAllDatesLast7Days($filters); |
||
1143 | } |
||
1144 | return $all; |
||
1145 | } |
||
1146 | public function countAllDates($stats_airline = '',$filter_name = '') { |
||
1147 | global $globalStatsFilters; |
||
1148 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1149 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1150 | $Spotter = new Spotter($this->db); |
||
1151 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
1152 | $alliance_airlines = array(); |
||
1153 | foreach ($airlines as $airline) { |
||
1154 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
1155 | } |
||
1156 | $query = "SELECT flight_date as date_name, SUM(cnt) as date_count FROM stats_flight WHERE stats_type = 'date' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY flight_date ORDER BY date_count DESC"; |
||
1157 | $query_data = array(':filter_name' => $filter_name); |
||
1158 | } else { |
||
1159 | $query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'date' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY date_count DESC"; |
||
1160 | $query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
||
1161 | } |
||
1162 | try { |
||
1163 | $sth = $this->db->prepare($query); |
||
1164 | $sth->execute($query_data); |
||
1165 | } catch(PDOException $e) { |
||
1166 | echo "error : ".$e->getMessage(); |
||
1167 | } |
||
1168 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1169 | if (empty($all)) { |
||
1170 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1171 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
1172 | } else { |
||
1173 | $filters = array('airlines' => array($stats_airline)); |
||
1174 | } |
||
1175 | if ($filter_name != '') { |
||
1176 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1177 | } |
||
1178 | $Spotter = new Spotter($this->db); |
||
1179 | $all = $Spotter->countAllDates($filters); |
||
1180 | } |
||
1181 | return $all; |
||
1182 | } |
||
1183 | public function countAllDatesMarine($filter_name = '') { |
||
1184 | global $globalStatsFilters; |
||
1185 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1186 | $query = "SELECT marine_date as date_name, cnt as date_count FROM stats_marine WHERE stats_type = 'date' AND filter_name = :filter_name ORDER BY date_count DESC"; |
||
1187 | $query_data = array(':filter_name' => $filter_name); |
||
1188 | try { |
||
1189 | $sth = $this->db->prepare($query); |
||
1190 | $sth->execute($query_data); |
||
1191 | } catch(PDOException $e) { |
||
1192 | echo "error : ".$e->getMessage(); |
||
1193 | } |
||
1194 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1195 | if (empty($all)) { |
||
1196 | $filters = array(); |
||
1197 | if ($filter_name != '') { |
||
1198 | $filters = $globalStatsFilters[$filter_name]; |
||
1199 | } |
||
1200 | $Marine = new Marine($this->db); |
||
1201 | $all = $Marine->countAllDates($filters); |
||
1202 | } |
||
1203 | return $all; |
||
1204 | } |
||
1205 | public function countAllDatesTracker($filter_name = '') { |
||
1206 | global $globalStatsFilters; |
||
1207 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1208 | $query = "SELECT tracker_date as date_name, cnt as date_count FROM stats_tracker WHERE stats_type = 'date' AND filter_name = :filter_name ORDER BY date_count DESC"; |
||
1209 | $query_data = array(':filter_name' => $filter_name); |
||
1210 | try { |
||
1211 | $sth = $this->db->prepare($query); |
||
1212 | $sth->execute($query_data); |
||
1213 | } catch(PDOException $e) { |
||
1214 | echo "error : ".$e->getMessage(); |
||
1215 | } |
||
1216 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1217 | if (empty($all)) { |
||
1218 | $filters = array(); |
||
1219 | if ($filter_name != '') { |
||
1220 | $filters = $globalStatsFilters[$filter_name]; |
||
1221 | } |
||
1222 | $Tracker = new Tracker($this->db); |
||
1223 | $all = $Tracker->countAllDates($filters); |
||
1224 | } |
||
1225 | return $all; |
||
1226 | } |
||
1227 | public function countAllDatesByAirlines($filter_name = '') { |
||
1228 | global $globalStatsFilters; |
||
1229 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1230 | $query = "SELECT stats_airline as airline_icao, flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'date' AND filter_name = :filter_name"; |
||
1231 | $query_data = array('filter_name' => $filter_name); |
||
1232 | try { |
||
1233 | $sth = $this->db->prepare($query); |
||
1234 | $sth->execute($query_data); |
||
1235 | } catch(PDOException $e) { |
||
1236 | echo "error : ".$e->getMessage(); |
||
1237 | } |
||
1238 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1239 | if (empty($all)) { |
||
1240 | $filters = array(); |
||
1241 | if ($filter_name != '') { |
||
1242 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1243 | } |
||
1244 | $Spotter = new Spotter($this->db); |
||
1245 | $all = $Spotter->countAllDatesByAirlines($filters); |
||
1246 | } |
||
1247 | return $all; |
||
1248 | } |
||
1249 | public function countAllMonths($stats_airline = '',$filter_name = '') { |
||
1250 | global $globalStatsFilters, $globalDBdriver; |
||
1251 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1252 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1253 | $Spotter = new Spotter($this->db); |
||
1254 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
1255 | $alliance_airlines = array(); |
||
1256 | foreach ($airlines as $airline) { |
||
1257 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
1258 | } |
||
1259 | if ($globalDBdriver == 'mysql') { |
||
1260 | $query = "SELECT YEAR(stats_date) AS year_name,MONTH(stats_date) AS month_name, SUM(cnt) as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY stats_date ORDER BY date_count DESC"; |
||
1261 | } else { |
||
1262 | $query = "SELECT EXTRACT(YEAR FROM stats_date) AS year_name,EXTRACT(MONTH FROM stats_date) AS month_name, SUM(cnt) as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY stats_date ORDER BY date_count DESC"; |
||
1263 | } |
||
1264 | $query_data = array(':filter_name' => $filter_name); |
||
1265 | } else { |
||
1266 | if ($globalDBdriver == 'mysql') { |
||
1267 | $query = "SELECT YEAR(stats_date) AS year_name,MONTH(stats_date) AS month_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY date_count DESC"; |
||
1268 | } else { |
||
1269 | $query = "SELECT EXTRACT(YEAR FROM stats_date) AS year_name,EXTRACT(MONTH FROM stats_date) AS month_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY date_count DESC"; |
||
1270 | } |
||
1271 | $query_data = array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name); |
||
1272 | } |
||
1273 | try { |
||
1274 | $sth = $this->db->prepare($query); |
||
1275 | $sth->execute($query_data); |
||
1276 | } catch(PDOException $e) { |
||
1277 | echo "error : ".$e->getMessage(); |
||
1278 | } |
||
1279 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1280 | if (empty($all)) { |
||
1281 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1282 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
1283 | } else { |
||
1284 | $filters = array('airlines' => array($stats_airline)); |
||
1285 | } |
||
1286 | if ($filter_name != '') { |
||
1287 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1288 | } |
||
1289 | $Spotter = new Spotter($this->db); |
||
1290 | $all = $Spotter->countAllMonths($filters); |
||
1291 | } |
||
1292 | return $all; |
||
1293 | } |
||
1294 | public function countFatalitiesLast12Months() { |
||
1295 | global $globalStatsFilters, $globalDBdriver; |
||
1296 | if ($globalDBdriver == 'mysql') { |
||
1297 | $query = "SELECT YEAR(stats_date) AS year, MONTH(stats_date) as month,cnt as count FROM stats WHERE stats_type = 'fatalities_bymonth' ORDER BY stats_date"; |
||
1298 | } else { |
||
1299 | $query = "SELECT EXTRACT(YEAR FROM stats_date) AS year, EXTRACT(MONTH FROM stats_date) as month,cnt as count FROM stats WHERE stats_type = 'fatalities_bymonth' ORDER BY stats_date"; |
||
1300 | } |
||
1301 | try { |
||
1302 | $sth = $this->db->prepare($query); |
||
1303 | $sth->execute(); |
||
1304 | } catch(PDOException $e) { |
||
1305 | echo "error : ".$e->getMessage(); |
||
1306 | } |
||
1307 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1308 | if (empty($all)) { |
||
1309 | $Accident = new Accident($this->db); |
||
1310 | $all = $Accident->countFatalitiesLast12Months(); |
||
1311 | } |
||
1312 | return $all; |
||
1313 | } |
||
1314 | public function countFatalitiesByYear() { |
||
1315 | global $globalStatsFilters, $globalDBdriver; |
||
1316 | if ($globalDBdriver == 'mysql') { |
||
1317 | $query = "SELECT YEAR(stats_date) AS year, cnt as count FROM stats WHERE stats_type = 'fatalities_byyear' ORDER BY stats_date"; |
||
1318 | } else { |
||
1319 | $query = "SELECT EXTRACT(YEAR FROM stats_date) AS year, cnt as count FROM stats WHERE stats_type = 'fatalities_byyear' ORDER BY stats_date"; |
||
1320 | } |
||
1321 | try { |
||
1322 | $sth = $this->db->prepare($query); |
||
1323 | $sth->execute(); |
||
1324 | } catch(PDOException $e) { |
||
1325 | echo "error : ".$e->getMessage(); |
||
1326 | } |
||
1327 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1328 | if (empty($all)) { |
||
1329 | $Accident = new Accident($this->db); |
||
1330 | $all = $Accident->countFatalitiesByYear(); |
||
1331 | } |
||
1332 | return $all; |
||
1333 | } |
||
1334 | public function countAllMilitaryMonths($filter_name = '') { |
||
1335 | global $globalStatsFilters; |
||
1336 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1337 | $query = "SELECT YEAR(stats_date) AS year_name,MONTH(stats_date) AS month_name, cnt as date_count FROM stats WHERE stats_type = 'military_flights_bymonth' AND filter_name = :filter_name"; |
||
1338 | try { |
||
1339 | $sth = $this->db->prepare($query); |
||
1340 | $sth->execute(array(':filter_name' => $filter_name)); |
||
1341 | } catch(PDOException $e) { |
||
1342 | echo "error : ".$e->getMessage(); |
||
1343 | } |
||
1344 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1345 | if (empty($all)) { |
||
1346 | $filters = array(); |
||
1347 | if ($filter_name != '') { |
||
1348 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1349 | } |
||
1350 | $Spotter = new Spotter($this->db); |
||
1351 | $all = $Spotter->countAllMilitaryMonths($filters); |
||
1352 | } |
||
1353 | return $all; |
||
1354 | } |
||
1355 | public function countAllHours($orderby = 'hour',$limit = true,$stats_airline = '',$filter_name = '') { |
||
1356 | global $globalTimezone, $globalDBdriver, $globalStatsFilters; |
||
1357 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1358 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1359 | $Spotter = new Spotter($this->db); |
||
1360 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
1361 | $alliance_airlines = array(); |
||
1362 | foreach ($airlines as $airline) { |
||
1363 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
1364 | } |
||
1365 | if ($limit) $query = "SELECT flight_date as hour_name, SUM(cnt) as hour_count FROM stats_flight WHERE stats_type = 'hour' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY flight_date"; |
||
1366 | else $query = "SELECT flight_date as hour_name, SUM(cnt) as hour_count FROM stats_flight WHERE stats_type = 'hour' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name GROUP BY flight_date"; |
||
1367 | $query_data = array(':filter_name' => $filter_name); |
||
1368 | } else { |
||
1369 | if ($limit) $query = "SELECT flight_date as hour_name, cnt as hour_count FROM stats_flight WHERE stats_type = 'hour' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1370 | else $query = "SELECT flight_date as hour_name, cnt as hour_count FROM stats_flight WHERE stats_type = 'hour' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1371 | $query_data = array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name); |
||
1372 | } |
||
1373 | if ($orderby == 'hour') { |
||
1374 | if ($globalDBdriver == 'mysql') { |
||
1375 | $query .= " ORDER BY CAST(flight_date AS UNSIGNED) ASC"; |
||
1376 | } else { |
||
1377 | $query .= " ORDER BY CAST(flight_date AS integer) ASC"; |
||
1378 | } |
||
1379 | } |
||
1380 | if ($orderby == 'count') $query .= " ORDER BY hour_count DESC"; |
||
1381 | try { |
||
1382 | $sth = $this->db->prepare($query); |
||
1383 | $sth->execute($query_data); |
||
1384 | } catch(PDOException $e) { |
||
1385 | echo "error : ".$e->getMessage(); |
||
1386 | } |
||
1387 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1388 | if (empty($all)) { |
||
1389 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1390 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
1391 | } else { |
||
1392 | $filters = array('airlines' => array($stats_airline)); |
||
1393 | } |
||
1394 | if ($filter_name != '') { |
||
1395 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1396 | } |
||
1397 | $Spotter = new Spotter($this->db); |
||
1398 | $all = $Spotter->countAllHours($orderby,$filters); |
||
1399 | } |
||
1400 | return $all; |
||
1401 | } |
||
1402 | public function countAllMarineHours($orderby = 'hour',$limit = true,$filter_name = '') { |
||
1403 | global $globalTimezone, $globalDBdriver, $globalStatsFilters; |
||
1404 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1405 | if ($limit) $query = "SELECT marine_date as hour_name, cnt as hour_count FROM stats_marine WHERE stats_type = 'hour' AND filter_name = :filter_name"; |
||
1406 | else $query = "SELECT marine_date as hour_name, cnt as hour_count FROM stats_marine WHERE stats_type = 'hour' AND filter_name = :filter_name"; |
||
1407 | $query_data = array(':filter_name' => $filter_name); |
||
1408 | if ($orderby == 'hour') { |
||
1409 | if ($globalDBdriver == 'mysql') { |
||
1410 | $query .= " ORDER BY CAST(marine_date AS UNSIGNED) ASC"; |
||
1411 | } else { |
||
1412 | $query .= " ORDER BY CAST(marine_date AS integer) ASC"; |
||
1413 | } |
||
1414 | } |
||
1415 | if ($orderby == 'count') $query .= " ORDER BY hour_count DESC"; |
||
1416 | try { |
||
1417 | $sth = $this->db->prepare($query); |
||
1418 | $sth->execute($query_data); |
||
1419 | } catch(PDOException $e) { |
||
1420 | echo "error : ".$e->getMessage(); |
||
1421 | } |
||
1422 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1423 | if (empty($all)) { |
||
1424 | $filters = array(); |
||
1425 | if ($filter_name != '') { |
||
1426 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1427 | } |
||
1428 | $Marine = new Marine($this->db); |
||
1429 | $all = $Marine->countAllHours($orderby,$filters); |
||
1430 | } |
||
1431 | return $all; |
||
1432 | } |
||
1433 | public function countAllTrackerHours($orderby = 'hour',$limit = true,$filter_name = '') { |
||
1434 | global $globalTimezone, $globalDBdriver, $globalStatsFilters; |
||
1435 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1436 | if ($limit) $query = "SELECT tracker_date as hour_name, cnt as hour_count FROM stats_tracker WHERE stats_type = 'hour' AND filter_name = :filter_name"; |
||
1437 | else $query = "SELECT tracker_date as hour_name, cnt as hour_count FROM stats_tracker WHERE stats_type = 'hour' AND filter_name = :filter_name"; |
||
1438 | $query_data = array(':filter_name' => $filter_name); |
||
1439 | if ($orderby == 'hour') { |
||
1440 | if ($globalDBdriver == 'mysql') { |
||
1441 | $query .= " ORDER BY CAST(tracker_date AS UNSIGNED) ASC"; |
||
1442 | } else { |
||
1443 | $query .= " ORDER BY CAST(tracker_date AS integer) ASC"; |
||
1444 | } |
||
1445 | } |
||
1446 | if ($orderby == 'count') $query .= " ORDER BY hour_count DESC"; |
||
1447 | try { |
||
1448 | $sth = $this->db->prepare($query); |
||
1449 | $sth->execute($query_data); |
||
1450 | } catch(PDOException $e) { |
||
1451 | echo "error : ".$e->getMessage(); |
||
1452 | } |
||
1453 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1454 | if (empty($all)) { |
||
1455 | $filters = array(); |
||
1456 | if ($filter_name != '') { |
||
1457 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1458 | } |
||
1459 | $Tracker = new Tracker($this->db); |
||
1460 | $all = $Tracker->countAllHours($orderby,$filters); |
||
1461 | } |
||
1462 | return $all; |
||
1463 | } |
||
1464 | public function countOverallFlights($stats_airline = '', $filter_name = '',$year = '',$month = '') { |
||
1465 | global $globalStatsFilters; |
||
1466 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1467 | if ($year == '') $year = date('Y'); |
||
1468 | $all = $this->getSumStats('flights_bymonth',$year,$stats_airline,$filter_name,$month); |
||
1469 | if (empty($all)) { |
||
1470 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1471 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline)),'year' => $year,'month' => $month); |
||
1472 | } else { |
||
1473 | $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); |
||
1474 | } |
||
1475 | if ($filter_name != '') { |
||
1476 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1477 | } |
||
1478 | $Spotter = new Spotter($this->db); |
||
1479 | //$all = $Spotter->countOverallFlights($filters,$year,$month); |
||
1480 | $all = $Spotter->countOverallFlights($filters); |
||
1481 | } |
||
1482 | return $all; |
||
1483 | } |
||
1484 | public function countOverallMarine($filter_name = '',$year = '',$month = '') { |
||
1485 | global $globalStatsFilters; |
||
1486 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1487 | if ($year == '') $year = date('Y'); |
||
1488 | $all = $this->getSumStats('marine_bymonth',$year,'',$filter_name,$month); |
||
1489 | if (empty($all)) { |
||
1490 | $filters = array('year' => $year,'month' => $month); |
||
1491 | if ($filter_name != '') { |
||
1492 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1493 | } |
||
1494 | $Marine = new Marine($this->db); |
||
1495 | //$all = $Spotter->countOverallFlights($filters,$year,$month); |
||
1496 | $all = $Marine->countOverallMarine($filters); |
||
1497 | } |
||
1498 | return $all; |
||
1499 | } |
||
1500 | public function countOverallTracker($filter_name = '',$year = '',$month = '') { |
||
1501 | global $globalStatsFilters; |
||
1502 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1503 | if ($year == '') $year = date('Y'); |
||
1504 | $all = $this->getSumStats('tracker_bymonth',$year,'',$filter_name,$month); |
||
1505 | if (empty($all)) { |
||
1506 | $filters = array('year' => $year,'month' => $month); |
||
1507 | if ($filter_name != '') { |
||
1508 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1509 | } |
||
1510 | $Tracker = new Tracker($this->db); |
||
1511 | //$all = $Spotter->countOverallFlights($filters,$year,$month); |
||
1512 | $all = $Tracker->countOverallTracker($filters); |
||
1513 | } |
||
1514 | return $all; |
||
1515 | } |
||
1516 | public function countOverallMilitaryFlights($filter_name = '',$year = '', $month = '') { |
||
1517 | global $globalStatsFilters; |
||
1518 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1519 | if ($year == '') $year = date('Y'); |
||
1520 | $all = $this->getSumStats('military_flights_bymonth',$year,'',$filter_name,$month); |
||
1521 | if (empty($all)) { |
||
1522 | $filters = array(); |
||
1523 | $filters = array('year' => $year,'month' => $month); |
||
1524 | if ($filter_name != '') { |
||
1525 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1526 | } |
||
1527 | $Spotter = new Spotter($this->db); |
||
1528 | //$all = $Spotter->countOverallMilitaryFlights($filters,$year,$month); |
||
1529 | $all = $Spotter->countOverallMilitaryFlights($filters); |
||
1530 | } |
||
1531 | return $all; |
||
1532 | } |
||
1533 | public function countOverallArrival($stats_airline = '',$filter_name = '', $year = '', $month = '') { |
||
1534 | global $globalStatsFilters; |
||
1535 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1536 | if ($year == '') $year = date('Y'); |
||
1537 | $all = $this->getSumStats('realarrivals_bymonth',$year,$stats_airline,$filter_name,$month); |
||
1538 | if (empty($all)) { |
||
1539 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1540 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline)),'year' => $year,'month' => $month); |
||
1541 | } else { |
||
1542 | $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); |
||
1543 | } |
||
1544 | if ($filter_name != '') { |
||
1545 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1546 | } |
||
1547 | $Spotter = new Spotter($this->db); |
||
1548 | //$all = $Spotter->countOverallArrival($filters,$year,$month); |
||
1549 | $all = $Spotter->countOverallArrival($filters); |
||
1550 | } |
||
1551 | return $all; |
||
1552 | } |
||
1553 | public function countOverallAircrafts($stats_airline = '',$filter_name = '',$year = '', $month = '') { |
||
1554 | global $globalStatsFilters; |
||
1555 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1556 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1557 | $Spotter = new Spotter($this->db); |
||
1558 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
1559 | if ($year == '' && $month == '') { |
||
1560 | $alliance_airlines = array(); |
||
1561 | foreach ($airlines as $airline) { |
||
1562 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
1563 | } |
||
1564 | $query = "SELECT COUNT(*) AS nb FROM stats_aircraft WHERE stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name"; |
||
1565 | try { |
||
1566 | $sth = $this->db->prepare($query); |
||
1567 | $sth->execute(array(':filter_name' => $filter_name)); |
||
1568 | } catch(PDOException $e) { |
||
1569 | echo "error : ".$e->getMessage(); |
||
1570 | } |
||
1571 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1572 | $all = $result[0]['nb']; |
||
1573 | } else $all = $this->getSumStats('aircrafts_bymonth',$year,$stats_airline,$filter_name,$month); |
||
1574 | } else { |
||
1575 | if ($year == '' && $month == '') { |
||
1576 | $query = "SELECT COUNT(*) AS nb FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1577 | try { |
||
1578 | $sth = $this->db->prepare($query); |
||
1579 | $sth->execute(array(':filter_name' => $filter_name,':stats_airline' => $stats_airline)); |
||
1580 | } catch(PDOException $e) { |
||
1581 | echo "error : ".$e->getMessage(); |
||
1582 | } |
||
1583 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1584 | $all = $result[0]['nb']; |
||
1585 | } else $all = $this->getSumStats('aircrafts_bymonth',$year,$stats_airline,$filter_name,$month); |
||
1586 | } |
||
1587 | if (empty($all)) { |
||
1588 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1589 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline)),'year' => $year,'month' => $month); |
||
1590 | } else { |
||
1591 | $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); |
||
1592 | } |
||
1593 | if ($filter_name != '') { |
||
1594 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1595 | } |
||
1596 | $Spotter = new Spotter($this->db); |
||
1597 | //$all = $Spotter->countOverallAircrafts($filters,$year,$month); |
||
1598 | $all = $Spotter->countOverallAircrafts($filters); |
||
1599 | } |
||
1600 | return $all; |
||
1601 | } |
||
1602 | public function countOverallAirlines($filter_name = '',$year = '',$month = '') { |
||
1603 | global $globalStatsFilters; |
||
1604 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1605 | if ($year == '' && $month == '') { |
||
1606 | $query = "SELECT COUNT(*) AS nb_airline FROM stats_airline WHERE filter_name = :filter_name"; |
||
1607 | try { |
||
1608 | $sth = $this->db->prepare($query); |
||
1609 | $sth->execute(array(':filter_name' => $filter_name)); |
||
1610 | } catch(PDOException $e) { |
||
1611 | echo "error : ".$e->getMessage(); |
||
1612 | } |
||
1613 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1614 | $all = $result[0]['nb_airline']; |
||
1615 | } else $all = $this->getSumStats('airlines_bymonth',$year,'',$filter_name,$month); |
||
1616 | if (empty($all)) { |
||
1617 | $filters = array(); |
||
1618 | $filters = array('year' => $year,'month' => $month); |
||
1619 | if ($filter_name != '') { |
||
1620 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1621 | } |
||
1622 | $Spotter = new Spotter($this->db); |
||
1623 | //$all = $Spotter->countOverallAirlines($filters,$year,$month); |
||
1624 | $all = $Spotter->countOverallAirlines($filters); |
||
1625 | } |
||
1626 | return $all; |
||
1627 | } |
||
1628 | public function countOverallMarineTypes($filter_name = '',$year = '',$month = '') { |
||
1629 | global $globalStatsFilters; |
||
1630 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1631 | $all = array(); |
||
1632 | if ($year == '' && $month == '') { |
||
1633 | $query = "SELECT COUNT(*) AS nb_type FROM stats_marine_type WHERE filter_name = :filter_name"; |
||
1634 | try { |
||
1635 | $sth = $this->db->prepare($query); |
||
1636 | $sth->execute(array(':filter_name' => $filter_name)); |
||
1637 | } catch(PDOException $e) { |
||
1638 | echo "error : ".$e->getMessage(); |
||
1639 | } |
||
1640 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1641 | $all = $result[0]['nb_type']; |
||
1642 | } |
||
1643 | if (empty($all)) { |
||
1644 | $filters = array(); |
||
1645 | $filters = array('year' => $year,'month' => $month); |
||
1646 | if ($filter_name != '') { |
||
1647 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1648 | } |
||
1649 | $Marine = new Marine($this->db); |
||
1650 | //$all = $Spotter->countOverallAirlines($filters,$year,$month); |
||
1651 | $all = $Marine->countOverallMarineTypes($filters); |
||
1652 | } |
||
1653 | return $all; |
||
1654 | } |
||
1655 | public function countOverallOwners($stats_airline = '',$filter_name = '',$year = '', $month = '') { |
||
1656 | global $globalStatsFilters; |
||
1657 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1658 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1659 | $Spotter = new Spotter($this->db); |
||
1660 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
1661 | if ($year == '' && $month == '') { |
||
1662 | $alliance_airlines = array(); |
||
1663 | foreach ($airlines as $airline) { |
||
1664 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
1665 | } |
||
1666 | $query = "SELECT count(*) as nb FROM stats_owner WHERE stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name"; |
||
1667 | $query_values = array(':filter_name' => $filter_name); |
||
1668 | try { |
||
1669 | $sth = $this->db->prepare($query); |
||
1670 | $sth->execute($query_values); |
||
1671 | } catch(PDOException $e) { |
||
1672 | echo "error : ".$e->getMessage(); |
||
1673 | } |
||
1674 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1675 | $all = $result[0]['nb']; |
||
1676 | } else { |
||
1677 | $all = $this->getSumStats('owners_bymonth',$year,$stats_airline,$filter_name,$month); |
||
1678 | } |
||
1679 | } else { |
||
1680 | if ($year == '' && $month == '') { |
||
1681 | $query = "SELECT count(*) as nb FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1682 | $query_values = array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name); |
||
1683 | try { |
||
1684 | $sth = $this->db->prepare($query); |
||
1685 | $sth->execute($query_values); |
||
1686 | } catch(PDOException $e) { |
||
1687 | echo "error : ".$e->getMessage(); |
||
1688 | } |
||
1689 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1690 | $all = $result[0]['nb']; |
||
1691 | } else { |
||
1692 | $all = $this->getSumStats('owners_bymonth',$year,$stats_airline,$filter_name,$month); |
||
1693 | } |
||
1694 | } |
||
1695 | if (empty($all)) { |
||
1696 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1697 | $filters = array('alliance' => str_replace('_',' ',str_replace('alliance_','',$stats_airline)),'year' => $year,'month' => $month); |
||
1698 | } else { |
||
1699 | $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); |
||
1700 | } |
||
1701 | if ($filter_name != '') { |
||
1702 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1703 | } |
||
1704 | $Spotter = new Spotter($this->db); |
||
1705 | //$all = $Spotter->countOverallOwners($filters,$year,$month); |
||
1706 | $all = $Spotter->countOverallOwners($filters); |
||
1707 | } |
||
1708 | return $all; |
||
1709 | } |
||
1710 | public function countOverallPilots($stats_airline = '',$filter_name = '',$year = '',$month = '') { |
||
1711 | global $globalStatsFilters; |
||
1712 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1713 | //if ($year == '') $year = date('Y'); |
||
1714 | if ($year == '' && $month == '') { |
||
1715 | $query = "SELECT count(*) as nb FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1716 | $query_values = array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name); |
||
1717 | try { |
||
1718 | $sth = $this->db->prepare($query); |
||
1719 | $sth->execute($query_values); |
||
1720 | } catch(PDOException $e) { |
||
1721 | echo "error : ".$e->getMessage(); |
||
1722 | } |
||
1723 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1724 | $all = $result[0]['nb']; |
||
1725 | } else { |
||
1726 | $all = $this->getSumStats('pilots_bymonth',$year,$stats_airline,$filter_name,$month); |
||
1727 | } |
||
1728 | if (empty($all)) { |
||
1729 | $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); |
||
1730 | if ($filter_name != '') { |
||
1731 | $filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
||
1732 | } |
||
1733 | $Spotter = new Spotter($this->db); |
||
1734 | //$all = $Spotter->countOverallPilots($filters,$year,$month); |
||
1735 | $all = $Spotter->countOverallPilots($filters); |
||
1736 | } |
||
1737 | return $all; |
||
1738 | } |
||
1739 | |||
1740 | public function getLast7DaysAirports($airport_icao = '', $stats_airline = '',$filter_name = '') { |
||
1741 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1742 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1743 | $Spotter = new Spotter($this->db); |
||
1744 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
1745 | $alliance_airlines = array(); |
||
1746 | foreach ($airlines as $airline) { |
||
1747 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
1748 | } |
||
1749 | $query = "SELECT * FROM stats_airport WHERE stats_type = 'daily' AND airport_icao = :airport_icao AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name ORDER BY date"; |
||
1750 | $query_values = array(':airport_icao' => $airport_icao,':filter_name' => $filter_name); |
||
1751 | } else { |
||
1752 | $query = "SELECT * FROM stats_airport WHERE stats_type = 'daily' AND airport_icao = :airport_icao AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY date"; |
||
1753 | $query_values = array(':airport_icao' => $airport_icao,':stats_airline' => $stats_airline, ':filter_name' => $filter_name); |
||
1754 | } |
||
1755 | try { |
||
1756 | $sth = $this->db->prepare($query); |
||
1757 | $sth->execute($query_values); |
||
1758 | } catch(PDOException $e) { |
||
1759 | echo "error : ".$e->getMessage(); |
||
1760 | } |
||
1761 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1762 | return $all; |
||
1763 | } |
||
1764 | public function getStats($type,$stats_airline = '', $filter_name = '') { |
||
1765 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1766 | $query = "SELECT * FROM stats WHERE stats_type = :type AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY stats_date"; |
||
1767 | $query_values = array(':type' => $type,':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
||
1768 | try { |
||
1769 | $sth = $this->db->prepare($query); |
||
1770 | $sth->execute($query_values); |
||
1771 | } catch(PDOException $e) { |
||
1772 | echo "error : ".$e->getMessage(); |
||
1773 | } |
||
1774 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1775 | return $all; |
||
1776 | } |
||
1777 | public function deleteStatsByType($type,$stats_airline = '', $filter_name = '') { |
||
1778 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1779 | $query = "DELETE FROM stats WHERE stats_type = :type AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1780 | $query_values = array(':type' => $type,':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
||
1781 | try { |
||
1782 | $sth = $this->db->prepare($query); |
||
1783 | $sth->execute($query_values); |
||
1784 | } catch(PDOException $e) { |
||
1785 | echo "error : ".$e->getMessage(); |
||
1786 | } |
||
1787 | } |
||
1788 | public function getSumStats($type,$year,$stats_airline = '',$filter_name = '',$month = '') { |
||
1789 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1790 | global $globalArchiveMonths, $globalDBdriver; |
||
1791 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1792 | $Spotter = new Spotter($this->db); |
||
1793 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
1794 | $alliance_airlines = array(); |
||
1795 | foreach ($airlines as $airline) { |
||
1796 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
1797 | } |
||
1798 | if ($globalDBdriver == 'mysql') { |
||
1799 | if ($month == '') { |
||
1800 | $query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND YEAR(stats_date) = :year AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name"; |
||
1801 | $query_values = array(':type' => $type, ':year' => $year, ':filter_name' => $filter_name); |
||
1802 | } else { |
||
1803 | $query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND YEAR(stats_date) = :year AND MONTH(stats_date) = :month AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name"; |
||
1804 | $query_values = array(':type' => $type, ':year' => $year, ':filter_name' => $filter_name,':month' => $month); |
||
1805 | } |
||
1806 | } else { |
||
1807 | if ($month == '') { |
||
1808 | $query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND EXTRACT(YEAR FROM stats_date) = :year AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name"; |
||
1809 | $query_values = array(':type' => $type, ':year' => $year, ':filter_name' => $filter_name); |
||
1810 | } else { |
||
1811 | $query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND EXTRACT(YEAR FROM stats_date) = :year AND EXTRACT(MONTH FROM stats_date) = :month AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name"; |
||
1812 | $query_values = array(':type' => $type, ':year' => $year, ':filter_name' => $filter_name,':month' => $month); |
||
1813 | } |
||
1814 | } |
||
1815 | } else { |
||
1816 | if ($globalDBdriver == 'mysql') { |
||
1817 | if ($month == '') { |
||
1818 | $query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND YEAR(stats_date) = :year AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1819 | $query_values = array(':type' => $type, ':year' => $year, ':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
||
1820 | } else { |
||
1821 | $query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND YEAR(stats_date) = :year AND MONTH(stats_date) = :month AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1822 | $query_values = array(':type' => $type, ':year' => $year, ':stats_airline' => $stats_airline,':filter_name' => $filter_name,':month' => $month); |
||
1823 | } |
||
1824 | } else { |
||
1825 | if ($month == '') { |
||
1826 | $query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND EXTRACT(YEAR FROM stats_date) = :year AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1827 | $query_values = array(':type' => $type, ':year' => $year, ':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
||
1828 | } else { |
||
1829 | $query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND EXTRACT(YEAR FROM stats_date) = :year AND EXTRACT(MONTH FROM stats_date) = :month AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1830 | $query_values = array(':type' => $type, ':year' => $year, ':stats_airline' => $stats_airline,':filter_name' => $filter_name,':month' => $month); |
||
1831 | } |
||
1832 | } |
||
1833 | } |
||
1834 | try { |
||
1835 | $sth = $this->db->prepare($query); |
||
1836 | $sth->execute($query_values); |
||
1837 | } catch(PDOException $e) { |
||
1838 | echo "error : ".$e->getMessage(); |
||
1839 | } |
||
1840 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1841 | return $all[0]['total']; |
||
1842 | } |
||
1843 | public function getStatsTotal($type, $stats_airline = '', $filter_name = '') { |
||
1844 | global $globalArchiveMonths, $globalDBdriver; |
||
1845 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1846 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1847 | $Spotter = new Spotter($this->db); |
||
1848 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
1849 | $alliance_airlines = array(); |
||
1850 | foreach ($airlines as $airline) { |
||
1851 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
1852 | } |
||
1853 | if ($globalDBdriver == 'mysql') { |
||
1854 | $query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND stats_date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL ".$globalArchiveMonths." MONTH) AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name"; |
||
1855 | } else { |
||
1856 | $query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND stats_date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS' AND stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name"; |
||
1857 | } |
||
1858 | $query_values = array(':type' => $type, ':filter_name' => $filter_name); |
||
1859 | } else { |
||
1860 | if ($globalDBdriver == 'mysql') { |
||
1861 | $query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND stats_date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL ".$globalArchiveMonths." MONTH) AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1862 | } else { |
||
1863 | $query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND stats_date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1864 | } |
||
1865 | $query_values = array(':type' => $type, ':stats_airline' => $stats_airline, ':filter_name' => $filter_name); |
||
1866 | } |
||
1867 | try { |
||
1868 | $sth = $this->db->prepare($query); |
||
1869 | $sth->execute($query_values); |
||
1870 | } catch(PDOException $e) { |
||
1871 | echo "error : ".$e->getMessage(); |
||
1872 | } |
||
1873 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1874 | return $all[0]['total']; |
||
1875 | } |
||
1876 | public function getStatsAircraftTotal($stats_airline = '', $filter_name = '') { |
||
1877 | global $globalArchiveMonths, $globalDBdriver; |
||
1878 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1879 | if (strpos($stats_airline,'alliance_') !== FALSE) { |
||
1880 | $Spotter = new Spotter($this->db); |
||
1881 | $airlines = $Spotter->getAllAirlineNamesByAlliance(str_replace('_',' ',str_replace('alliance_','',$stats_airline))); |
||
1882 | $alliance_airlines = array(); |
||
1883 | foreach ($airlines as $airline) { |
||
1884 | $alliance_airlines = array_merge($alliance_airlines,array($airline['airline_icao'])); |
||
1885 | } |
||
1886 | if ($globalDBdriver == 'mysql') { |
||
1887 | $query = "SELECT SUM(cnt) as total FROM stats_aircraft WHERE stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name"; |
||
1888 | } else { |
||
1889 | $query = "SELECT SUM(cnt) as total FROM stats_aircraft WHERE stats_airline IN ('".implode("','",$alliance_airlines)."') AND filter_name = :filter_name"; |
||
1890 | } |
||
1891 | } else { |
||
1892 | if ($globalDBdriver == 'mysql') { |
||
1893 | $query = "SELECT SUM(cnt) as total FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1894 | } else { |
||
1895 | $query = "SELECT SUM(cnt) as total FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name"; |
||
1896 | } |
||
1897 | } |
||
1898 | try { |
||
1899 | $sth = $this->db->prepare($query); |
||
1900 | $sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name)); |
||
1901 | } catch(PDOException $e) { |
||
1902 | echo "error : ".$e->getMessage(); |
||
1903 | } |
||
1904 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1905 | return $all[0]['total']; |
||
1906 | } |
||
1907 | public function getStatsAirlineTotal($filter_name = '') { |
||
1908 | global $globalArchiveMonths, $globalDBdriver; |
||
1909 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1910 | if ($globalDBdriver == 'mysql') { |
||
1911 | $query = "SELECT SUM(cnt) as total FROM stats_airline WHERE filter_name = :filter_name"; |
||
1912 | } else { |
||
1913 | $query = "SELECT SUM(cnt) as total FROM stats_airline WHERE filter_name = :filter_name"; |
||
1914 | } |
||
1915 | try { |
||
1916 | $sth = $this->db->prepare($query); |
||
1917 | $sth->execute(array(':filter_name' => $filter_name)); |
||
1918 | } catch(PDOException $e) { |
||
1919 | echo "error : ".$e->getMessage(); |
||
1920 | } |
||
1921 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1922 | return $all[0]['total']; |
||
1923 | } |
||
1924 | public function getStatsOwnerTotal($filter_name = '') { |
||
1925 | global $globalArchiveMonths, $globalDBdriver; |
||
1926 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1927 | if ($globalDBdriver == 'mysql') { |
||
1928 | $query = "SELECT SUM(cnt) as total FROM stats_owner WHERE filter_name = :filter_name"; |
||
1929 | } else { |
||
1930 | $query = "SELECT SUM(cnt) as total FROM stats_owner WHERE filter_name = :filter_name"; |
||
1931 | } |
||
1932 | try { |
||
1933 | $sth = $this->db->prepare($query); |
||
1934 | $sth->execute(array(':filter_name' => $filter_name)); |
||
1935 | } catch(PDOException $e) { |
||
1936 | echo "error : ".$e->getMessage(); |
||
1937 | } |
||
1938 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1939 | return $all[0]['total']; |
||
1940 | } |
||
1941 | public function getStatsOwner($owner_name,$filter_name = '') { |
||
1942 | global $globalArchiveMonths, $globalDBdriver; |
||
1943 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1944 | $query = "SELECT cnt FROM stats_owner WHERE filter_name = :filter_name AND owner_name = :owner_name"; |
||
1945 | try { |
||
1946 | $sth = $this->db->prepare($query); |
||
1947 | $sth->execute(array(':filter_name' => $filter_name,':owner_name' => $owner_name)); |
||
1948 | } catch(PDOException $e) { |
||
1949 | echo "error : ".$e->getMessage(); |
||
1950 | } |
||
1951 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1952 | if (isset($all[0]['cnt'])) return $all[0]['cnt']; |
||
1953 | else return 0; |
||
1954 | } |
||
1955 | public function getStatsPilotTotal($filter_name = '') { |
||
1956 | global $globalArchiveMonths, $globalDBdriver; |
||
1957 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1958 | if ($globalDBdriver == 'mysql') { |
||
1959 | $query = "SELECT SUM(cnt) as total FROM stats_pilot WHERE filter_name = :filter_name"; |
||
1960 | } else { |
||
1961 | $query = "SELECT SUM(cnt) as total FROM stats_pilot WHERE filter_name = :filter_name"; |
||
1962 | } |
||
1963 | try { |
||
1964 | $sth = $this->db->prepare($query); |
||
1965 | $sth->execute(array(':filter_name' => $filter_name)); |
||
1966 | } catch(PDOException $e) { |
||
1967 | echo "error : ".$e->getMessage(); |
||
1968 | } |
||
1969 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1970 | return $all[0]['total']; |
||
1971 | } |
||
1972 | public function getStatsPilot($pilot,$filter_name = '') { |
||
1973 | global $globalArchiveMonths, $globalDBdriver; |
||
1974 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1975 | $query = "SELECT cnt FROM stats_pilot WHERE filter_name = :filter_name AND (pilot_name = :pilot OR pilot_id = :pilot)"; |
||
1976 | try { |
||
1977 | $sth = $this->db->prepare($query); |
||
1978 | $sth->execute(array(':filter_name' => $filter_name,':pilot' => $pilot)); |
||
1979 | } catch(PDOException $e) { |
||
1980 | echo "error : ".$e->getMessage(); |
||
1981 | } |
||
1982 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
1983 | if (isset($all[0]['cnt'])) return $all[0]['cnt']; |
||
1984 | else return 0; |
||
1985 | } |
||
1986 | |||
1987 | public function addStat($type,$cnt,$stats_date,$stats_airline = '',$filter_name = '') { |
||
1988 | global $globalDBdriver; |
||
1989 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
1990 | if ($globalDBdriver == 'mysql') { |
||
1991 | $query = "INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) VALUES (:type,:cnt,:stats_date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = :cnt"; |
||
1992 | } else { |
||
1993 | $query = "UPDATE stats SET cnt = :cnt WHERE stats_type = :type AND stats_date = :stats_date AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) SELECT :type,:cnt,:stats_date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats WHERE stats_type = :type AND stats_date = :stats_date AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
||
1994 | } |
||
1995 | $query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date, ':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
||
1996 | try { |
||
1997 | $sth = $this->db->prepare($query); |
||
1998 | $sth->execute($query_values); |
||
1999 | } catch(PDOException $e) { |
||
2000 | return "error : ".$e->getMessage(); |
||
2001 | } |
||
2002 | } |
||
2003 | public function updateStat($type,$cnt,$stats_date,$stats_airline = '',$filter_name = '') { |
||
2004 | global $globalDBdriver; |
||
2005 | if ($filter_name == '') $filter_name = $this->filter_name; |
||
2006 | if ($globalDBdriver == 'mysql') { |
||
2007 | $query = "INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) VALUES (:type,:cnt,:stats_date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, stats_date = :date"; |
||
2008 | } else { |
||
2009 | //$query = "INSERT INTO stats (stats_type,cnt,stats_date) VALUES (:type,:cnt,:stats_date) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, stats_date = :date"; |
||
2010 | $query = "UPDATE stats SET cnt = cnt+:cnt WHERE stats_type = :type AND stats_date = :stats_date AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) SELECT :type,:cnt,:stats_date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats WHERE stats_type = :type AND stats_date = :stats_date AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
||
2011 | } |
||
2012 | $query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date,':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
||
2013 | try { |
||
2014 | $sth = $this->db->prepare($query); |
||
2015 | $sth->execute($query_values); |
||
2016 | } catch(PDOException $e) { |
||
2017 | return "error : ".$e->getMessage(); |
||
2018 | } |
||
2019 | } |
||
2020 | /* |
||
2021 | public function getStatsSource($date,$stats_type = '') { |
||
2022 | if ($stats_type == '') { |
||
2023 | $query = "SELECT * FROM stats_source WHERE stats_date = :date ORDER BY source_name"; |
||
2024 | $query_values = array(':date' => $date); |
||
2025 | } else { |
||
2026 | $query = "SELECT * FROM stats_source WHERE stats_date = :date AND stats_type = :stats_type ORDER BY source_name"; |
||
2027 | $query_values = array(':date' => $date,':stats_type' => $stats_type); |
||
2028 | } |
||
2029 | try { |
||
2030 | $sth = $this->db->prepare($query); |
||
2031 | $sth->execute($query_values); |
||
2032 | } catch(PDOException $e) { |
||
2033 | echo "error : ".$e->getMessage(); |
||
2034 | } |
||
2035 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
2036 | return $all; |
||
2037 | } |
||
2038 | */ |
||
2039 | |||
2040 | public function getStatsSource($stats_type,$year = '',$month = '',$day = '') { |
||
2041 | global $globalDBdriver; |
||
2042 | $query = "SELECT * FROM stats_source WHERE stats_type = :stats_type"; |
||
2043 | $query_values = array(); |
||
2044 | if ($globalDBdriver == 'mysql') { |
||
2045 | if ($year != '') { |
||
2046 | $query .= ' AND YEAR(stats_date) = :year'; |
||
2047 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
2048 | } |
||
2049 | if ($month != '') { |
||
2050 | $query .= ' AND MONTH(stats_date) = :month'; |
||
2051 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
2052 | } |
||
2053 | if ($day != '') { |
||
2054 | $query .= ' AND DAY(stats_date) = :day'; |
||
2055 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
2056 | } |
||
2057 | } else { |
||
2058 | if ($year != '') { |
||
2059 | $query .= ' AND EXTRACT(YEAR FROM stats_date) = :year'; |
||
2060 | $query_values = array_merge($query_values,array(':year' => $year)); |
||
2061 | } |
||
2062 | if ($month != '') { |
||
2063 | $query .= ' AND EXTRACT(MONTH FROM stats_date) = :month'; |
||
2064 | $query_values = array_merge($query_values,array(':month' => $month)); |
||
2065 | } |
||
2066 | if ($day != '') { |
||
2067 | $query .= ' AND EXTRACT(DAY FROM stats_date) = :day'; |
||
2068 | $query_values = array_merge($query_values,array(':day' => $day)); |
||
2069 | } |
||
2070 | } |
||
2071 | $query .= " ORDER BY source_name"; |
||
2072 | $query_values = array_merge($query_values,array(':stats_type' => $stats_type)); |
||
2073 | try { |
||
2074 | $sth = $this->db->prepare($query); |
||
2075 | $sth->execute($query_values); |
||
2076 | } catch(PDOException $e) { |
||
2077 | echo "error : ".$e->getMessage(); |
||
2078 | } |
||
2079 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
2080 | return $all; |
||
2081 | } |
||
2082 | |||
2083 | public function addStatSource($data,$source_name,$stats_type,$date) { |
||
2084 | global $globalDBdriver; |
||
2085 | if ($globalDBdriver == 'mysql') { |
||
2086 | $query = "INSERT INTO stats_source (source_data,source_name,stats_type,stats_date) VALUES (:data,:source_name,:stats_type,:stats_date) ON DUPLICATE KEY UPDATE source_data = :data"; |
||
2087 | } else { |
||
2088 | $query = "UPDATE stats_source SET source_data = :data WHERE stats_date = :stats_date AND source_name = :source_name AND stats_type = :stats_type; INSERT INTO stats_source (source_data,source_name,stats_type,stats_date) SELECT :data,:source_name,:stats_type,:stats_date WHERE NOT EXISTS (SELECT 1 FROM stats_source WHERE stats_date = :stats_date AND source_name = :source_name AND stats_type = :stats_type);"; |
||
2089 | } |
||
2090 | $query_values = array(':data' => $data,':stats_date' => $date,':source_name' => $source_name,':stats_type' => $stats_type); |
||
2091 | try { |
||
2092 | $sth = $this->db->prepare($query); |
||
2093 | $sth->execute($query_values); |
||
2094 | } catch(PDOException $e) { |
||
2095 | return "error : ".$e->getMessage(); |
||
2096 | } |
||
2097 | } |
||
2098 | public function addStatFlight($type,$date_name,$cnt,$stats_airline = '',$filter_name = '') { |
||
2099 | $query = "INSERT INTO stats_flight (stats_type,flight_date,cnt,stats_airline,filter_name) VALUES (:type,:flight_date,:cnt,:stats_airline,:filter_name)"; |
||
2100 | $query_values = array(':type' => $type,':flight_date' => $date_name,':cnt' => $cnt, ':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
||
2101 | try { |
||
2102 | $sth = $this->db->prepare($query); |
||
2103 | $sth->execute($query_values); |
||
2104 | } catch(PDOException $e) { |
||
2105 | return "error : ".$e->getMessage(); |
||
2106 | } |
||
2107 | } |
||
2108 | public function addStatMarine($type,$date_name,$cnt,$filter_name = '') { |
||
2109 | $query = "INSERT INTO stats_marine (stats_type,marine_date,cnt,filter_name) VALUES (:type,:flight_date,:cnt,:filter_name)"; |
||
2110 | $query_values = array(':type' => $type,':flight_date' => $date_name,':cnt' => $cnt,':filter_name' => $filter_name); |
||
2111 | try { |
||
2112 | $sth = $this->db->prepare($query); |
||
2113 | $sth->execute($query_values); |
||
2114 | } catch(PDOException $e) { |
||
2115 | return "error : ".$e->getMessage(); |
||
2116 | } |
||
2117 | } |
||
2118 | public function addStatTracker($type,$date_name,$cnt,$filter_name = '') { |
||
2119 | $query = "INSERT INTO stats_tracker (stats_type,tracker_date,cnt,filter_name) VALUES (:type,:flight_date,:cnt,:filter_name)"; |
||
2120 | $query_values = array(':type' => $type,':flight_date' => $date_name,':cnt' => $cnt,':filter_name' => $filter_name); |
||
2121 | try { |
||
2122 | $sth = $this->db->prepare($query); |
||
2123 | $sth->execute($query_values); |
||
2124 | } catch(PDOException $e) { |
||
2125 | return "error : ".$e->getMessage(); |
||
2126 | } |
||
2127 | } |
||
2128 | public function addStatAircraftRegistration($registration,$cnt,$aircraft_icao = '',$airline_icao = '',$filter_name = '',$reset = false) { |
||
2129 | global $globalDBdriver; |
||
2130 | if ($globalDBdriver == 'mysql') { |
||
2131 | if ($reset) { |
||
2132 | $query = "INSERT INTO stats_registration (aircraft_icao,registration,cnt,stats_airline,filter_name) VALUES (:aircraft_icao,:registration,:cnt,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = :cnt"; |
||
2133 | } else { |
||
2134 | $query = "INSERT INTO stats_registration (aircraft_icao,registration,cnt,stats_airline,filter_name) VALUES (:aircraft_icao,:registration,:cnt,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt"; |
||
2135 | } |
||
2136 | } else { |
||
2137 | if ($reset) { |
||
2138 | $query = "UPDATE stats_registration SET cnt = :cnt WHERE registration = :registration AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_registration (aircraft_icao,registration,cnt,stats_airline,filter_name) SELECT :aircraft_icao,:registration,:cnt,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_registration WHERE registration = :registration AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
||
2139 | } else { |
||
2140 | $query = "UPDATE stats_registration SET cnt = cnt+:cnt WHERE registration = :registration AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_registration (aircraft_icao,registration,cnt,stats_airline,filter_name) SELECT :aircraft_icao,:registration,:cnt,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_registration WHERE registration = :registration AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
||
2141 | } |
||
2142 | } |
||
2143 | $query_values = array(':aircraft_icao' => $aircraft_icao,':registration' => $registration,':cnt' => $cnt,':stats_airline' => $airline_icao, ':filter_name' => $filter_name); |
||
2144 | try { |
||
2145 | $sth = $this->db->prepare($query); |
||
2146 | $sth->execute($query_values); |
||
2147 | } catch(PDOException $e) { |
||
2148 | return "error : ".$e->getMessage(); |
||
2149 | } |
||
2150 | } |
||
2151 | public function addStatCallsign($callsign_icao,$cnt,$airline_icao = '', $filter_name = '', $reset = false) { |
||
2152 | global $globalDBdriver; |
||
2153 | if ($globalDBdriver == 'mysql') { |
||
2154 | if ($reset) { |
||
2155 | $query = "INSERT INTO stats_callsign (callsign_icao,airline_icao,cnt,filter_name) VALUES (:callsign_icao,:airline_icao,:cnt,:filter_name) ON DUPLICATE KEY UPDATE cnt = :cnt"; |
||
2156 | } else { |
||
2157 | $query = "INSERT INTO stats_callsign (callsign_icao,airline_icao,cnt,filter_name) VALUES (:callsign_icao,:airline_icao,:cnt,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt"; |
||
2158 | } |
||
2159 | } else { |
||
2160 | if ($reset) { |
||
2161 | $query = "UPDATE stats_callsign SET cnt = :cnt WHERE callsign_icao = :callsign_icao AND filter_name = :filter_name; INSERT INTO stats_callsign (callsign_icao,airline_icao,cnt,filter_name) SELECT :callsign_icao,:airline_icao,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_callsign WHERE callsign_icao = :callsign_icao AND filter_name = :filter_name);"; |
||
2162 | } else { |
||
2163 | $query = "UPDATE stats_callsign SET cnt = cnt+:cnt WHERE callsign_icao = :callsign_icao AND filter_name = :filter_name; INSERT INTO stats_callsign (callsign_icao,airline_icao,cnt,filter_name) SELECT :callsign_icao,:airline_icao,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_callsign WHERE callsign_icao = :callsign_icao AND filter_name = :filter_name);"; |
||
2164 | } |
||
2165 | } |
||
2166 | $query_values = array(':callsign_icao' => $callsign_icao,':airline_icao' => $airline_icao,':cnt' => $cnt, ':filter_name' => $filter_name); |
||
2167 | try { |
||
2168 | $sth = $this->db->prepare($query); |
||
2169 | $sth->execute($query_values); |
||
2170 | } catch(PDOException $e) { |
||
2171 | return "error : ".$e->getMessage(); |
||
2172 | } |
||
2173 | } |
||
2174 | public function addStatCountry($iso2,$iso3,$name,$cnt,$airline_icao = '',$filter_name = '',$reset = false) { |
||
2175 | global $globalDBdriver; |
||
2176 | if ($globalDBdriver == 'mysql') { |
||
2177 | if ($reset) { |
||
2178 | $query = "INSERT INTO stats_country (iso2,iso3,name,cnt,stats_airline,filter_name) VALUES (:iso2,:iso3,:name,:cnt,:airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = :cnt"; |
||
2179 | } else { |
||
2180 | $query = "INSERT INTO stats_country (iso2,iso3,name,cnt,stats_airline,filter_name) VALUES (:iso2,:iso3,:name,:cnt,:airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt"; |
||
2181 | } |
||
2182 | } else { |
||
2183 | if ($reset) { |
||
2184 | $query = "UPDATE stats_country SET cnt = :cnt WHERE iso2 = :iso2 AND filter_name = :filter_name AND stats_airline = :airline; INSERT INTO stats_country (iso2,iso3,name,cnt,stats_airline,filter_name) SELECT :iso2,:iso3,:name,:cnt,:airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_country WHERE iso2 = :iso2 AND filter_name = :filter_name AND stats_airline = :airline);"; |
||
2185 | } else { |
||
2186 | $query = "UPDATE stats_country SET cnt = cnt+:cnt WHERE iso2 = :iso2 AND filter_name = :filter_name AND stats_airline = :airline; INSERT INTO stats_country (iso2,iso3,name,cnt,stats_airline,filter_name) SELECT :iso2,:iso3,:name,:cnt,:airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_country WHERE iso2 = :iso2 AND filter_name = :filter_name AND stats_airline = :airline);"; |
||
2187 | } |
||
2188 | } |
||
2189 | $query_values = array(':iso2' => $iso2,':iso3' => $iso3,':name' => $name,':cnt' => $cnt,':filter_name' => $filter_name,':airline' => $airline_icao); |
||
2190 | try { |
||
2191 | $sth = $this->db->prepare($query); |
||
2192 | $sth->execute($query_values); |
||
2193 | } catch(PDOException $e) { |
||
2194 | return "error : ".$e->getMessage(); |
||
2195 | } |
||
2196 | } |
||
2197 | public function addStatCountryMarine($iso2,$iso3,$name,$cnt,$filter_name = '',$reset = false) { |
||
2198 | global $globalDBdriver; |
||
2199 | if ($globalDBdriver == 'mysql') { |
||
2200 | if ($reset) { |
||
2201 | $query = "INSERT INTO stats_marine_country (iso2,iso3,name,cnt,filter_name) VALUES (:iso2,:iso3,:name,:cnt,:filter_name) ON DUPLICATE KEY UPDATE cnt = :cnt"; |
||
2202 | } else { |
||
2203 | $query = "INSERT INTO stats_marine_country (iso2,iso3,name,cnt,filter_name) VALUES (:iso2,:iso3,:name,:cnt,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt"; |
||
2204 | } |
||
2205 | } else { |
||
2206 | if ($reset) { |
||
2207 | $query = "UPDATE stats_marine_country SET cnt = :cnt WHERE iso2 = :iso2 AND filter_name = :filter_name; INSERT INTO stats_marine_country (iso2,iso3,name,cnt,filter_name) SELECT :iso2,:iso3,:name,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_marine_country WHERE iso2 = :iso2 AND filter_name = :filter_name);"; |
||
2208 | } else { |
||
2209 | $query = "UPDATE stats_marine_country SET cnt = cnt+:cnt WHERE iso2 = :iso2 AND filter_name = :filter_name; INSERT INTO stats_marine_country (iso2,iso3,name,cnt,filter_name) SELECT :iso2,:iso3,:name,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_marine_country WHERE iso2 = :iso2 AND filter_name = :filter_name);"; |
||
2210 | } |
||
2211 | } |
||
2212 | $query_values = array(':iso2' => $iso2,':iso3' => $iso3,':name' => $name,':cnt' => $cnt,':filter_name' => $filter_name); |
||
2213 | try { |
||
2214 | $sth = $this->db->prepare($query); |
||
2215 | $sth->execute($query_values); |
||
2216 | } catch(PDOException $e) { |
||
2217 | return "error : ".$e->getMessage(); |
||
2218 | } |
||
2219 | } |
||
2220 | public function addStatCountryTracker($iso2,$iso3,$name,$cnt,$filter_name = '',$reset = false) { |
||
2221 | global $globalDBdriver; |
||
2222 | if ($globalDBdriver == 'mysql') { |
||
2223 | if ($reset) { |
||
2224 | $query = "INSERT INTO stats_tracker_country (iso2,iso3,name,cnt,filter_name) VALUES (:iso2,:iso3,:name,:cnt,:filter_name) ON DUPLICATE KEY UPDATE cnt = :cnt"; |
||
2225 | } else { |
||
2226 | $query = "INSERT INTO stats_tracker_country (iso2,iso3,name,cnt,filter_name) VALUES (:iso2,:iso3,:name,:cnt,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt"; |
||
2227 | } |
||
2228 | } else { |
||
2229 | if ($reset) { |
||
2230 | $query = "UPDATE stats_tracker_country SET cnt = :cnt WHERE iso2 = :iso2 AND filter_name = :filter_name; INSERT INTO stats_tracker_country (iso2,iso3,name,cnt,filter_name) SELECT :iso2,:iso3,:name,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_tracker_country WHERE iso2 = :iso2 AND filter_name = :filter_name);"; |
||
2231 | } else { |
||
2232 | $query = "UPDATE stats_tracker_country SET cnt = cnt+:cnt WHERE iso2 = :iso2 AND filter_name = :filter_name; INSERT INTO stats_tracker_country (iso2,iso3,name,cnt,filter_name) SELECT :iso2,:iso3,:name,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_tracker_country WHERE iso2 = :iso2 AND filter_name = :filter_name);"; |
||
2233 | } |
||
2234 | } |
||
2235 | $query_values = array(':iso2' => $iso2,':iso3' => $iso3,':name' => $name,':cnt' => $cnt,':filter_name' => $filter_name); |
||
2236 | try { |
||
2237 | $sth = $this->db->prepare($query); |
||
2238 | $sth->execute($query_values); |
||
2239 | } catch(PDOException $e) { |
||
2240 | return "error : ".$e->getMessage(); |
||
2241 | } |
||
2242 | } |
||
2243 | public function addStatAircraft($aircraft_icao,$cnt,$aircraft_name = '',$aircraft_manufacturer = '', $airline_icao = '', $filter_name = '', $reset = false) { |
||
2244 | global $globalDBdriver; |
||
2245 | if ($globalDBdriver == 'mysql') { |
||
2246 | if ($reset) { |
||
2247 | $query = "INSERT INTO stats_aircraft (aircraft_icao,aircraft_name,aircraft_manufacturer,cnt,stats_airline, filter_name) VALUES (:aircraft_icao,:aircraft_name,:aircraft_manufacturer,:cnt,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = :cnt, aircraft_name = :aircraft_name, aircraft_manufacturer = :aircraft_manufacturer, stats_airline = :stats_airline"; |
||
2248 | } else { |
||
2249 | $query = "INSERT INTO stats_aircraft (aircraft_icao,aircraft_name,aircraft_manufacturer,cnt,stats_airline, filter_name) VALUES (:aircraft_icao,:aircraft_name,:aircraft_manufacturer,:cnt,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, aircraft_name = :aircraft_name, aircraft_manufacturer = :aircraft_manufacturer, stats_airline = :stats_airline"; |
||
2250 | } |
||
2251 | } else { |
||
2252 | if ($reset) { |
||
2253 | $query = "UPDATE stats_aircraft SET cnt = :cnt, aircraft_name = :aircraft_name, aircraft_manufacturer = :aircraft_manufacturer, filter_name = :filter_name WHERE aircraft_icao = :aircraft_icao AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_aircraft (aircraft_icao,aircraft_name,aircraft_manufacturer,cnt,stats_airline,filter_name) SELECT :aircraft_icao,:aircraft_name,:aircraft_manufacturer,:cnt,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_aircraft WHERE aircraft_icao = :aircraft_icao AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
||
2254 | } else { |
||
2255 | $query = "UPDATE stats_aircraft SET cnt = cnt+:cnt, aircraft_name = :aircraft_name, aircraft_manufacturer = :aircraft_manufacturer, filter_name = :filter_name WHERE aircraft_icao = :aircraft_icao AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_aircraft (aircraft_icao,aircraft_name,aircraft_manufacturer,cnt,stats_airline,filter_name) SELECT :aircraft_icao,:aircraft_name,:aircraft_manufacturer,:cnt,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_aircraft WHERE aircraft_icao = :aircraft_icao AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
||
2256 | } |
||
2257 | } |
||
2258 | $query_values = array(':aircraft_icao' => $aircraft_icao,':aircraft_name' => $aircraft_name,':cnt' => $cnt, ':aircraft_manufacturer' => $aircraft_manufacturer,':stats_airline' => $airline_icao, ':filter_name' => $filter_name); |
||
2259 | try { |
||
2260 | $sth = $this->db->prepare($query); |
||
2261 | $sth->execute($query_values); |
||
2262 | } catch(PDOException $e) { |
||
2263 | return "error : ".$e->getMessage(); |
||
2264 | } |
||
2265 | } |
||
2266 | public function addStatMarineType($type,$type_id,$cnt, $filter_name = '', $reset = false) { |
||
2267 | global $globalDBdriver; |
||
2268 | if ($globalDBdriver == 'mysql') { |
||
2269 | if ($reset) { |
||
2270 | $query = "INSERT INTO stats_marine_type (type,type_id,cnt, filter_name) VALUES (:type,:type_id,:cnt,:filter_name) ON DUPLICATE KEY UPDATE cnt = :cnt"; |
||
2271 | } else { |
||
2272 | $query = "INSERT INTO stats_marine_type (type,type_id,cnt, filter_name) VALUES (:type,:type_id,:cnt,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt"; |
||
2273 | } |
||
2274 | } else { |
||
2275 | if ($reset) { |
||
2276 | $query = "UPDATE stats_marine_type SET cnt = :cnt, type = :type, filter_name = :filter_name WHERE type_id = :type_id AND filter_name = :filter_name; INSERT INTO stats_marine_type (type, type_id,cnt,filter_name) SELECT :type,:type_id,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_marine_type WHERE type = :type AND filter_name = :filter_name);"; |
||
2277 | } else { |
||
2278 | $query = "UPDATE stats_marine_type SET cnt = cnt+:cnt, type = :type, filter_name = :filter_name WHERE type_id = :type_id AND filter_name = :filter_name; INSERT INTO stats_marine_type (type,type_id,cnt,filter_name) SELECT :type,:type_id,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_marine_type WHERE type = :type AND filter_name = :filter_name);"; |
||
2279 | } |
||
2280 | } |
||
2281 | $query_values = array(':type' => $type,':type_id' => $type_id,':cnt' => $cnt, ':filter_name' => $filter_name); |
||
2282 | try { |
||
2283 | $sth = $this->db->prepare($query); |
||
2284 | $sth->execute($query_values); |
||
2285 | } catch(PDOException $e) { |
||
2286 | return "error : ".$e->getMessage(); |
||
2287 | } |
||
2288 | } |
||
2289 | public function addStatTrackerType($type,$cnt, $filter_name = '', $reset = false) { |
||
2290 | global $globalDBdriver; |
||
2291 | if ($globalDBdriver == 'mysql') { |
||
2292 | if ($reset) { |
||
2293 | $query = "INSERT INTO stats_tracker_type (type,cnt, filter_name) VALUES (:type,:type_id,:cnt,:filter_name) ON DUPLICATE KEY UPDATE cnt = :cnt"; |
||
2294 | } else { |
||
2295 | $query = "INSERT INTO stats_tracker_type (type,cnt, filter_name) VALUES (:type,:type_id,:cnt,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt"; |
||
2296 | } |
||
2297 | } else { |
||
2298 | if ($reset) { |
||
2299 | $query = "UPDATE stats_tracker_type SET cnt = :cnt WHERE type = :type AND filter_name = :filter_name; INSERT INTO stats_tracker_type (type, cnt,filter_name) SELECT :type,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_tracker_type WHERE type = :type AND filter_name = :filter_name);"; |
||
2300 | } else { |
||
2301 | $query = "UPDATE stats_tracker_type SET cnt = cnt+:cnt WHERE type = :type AND filter_name = :filter_name; INSERT INTO stats_tracker_type (type,cnt,filter_name) SELECT :type,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_tracker_type WHERE type = :type AND filter_name = :filter_name);"; |
||
2302 | } |
||
2303 | } |
||
2304 | $query_values = array(':type' => $type,':cnt' => $cnt, ':filter_name' => $filter_name); |
||
2305 | try { |
||
2306 | $sth = $this->db->prepare($query); |
||
2307 | $sth->execute($query_values); |
||
2308 | } catch(PDOException $e) { |
||
2309 | return "error : ".$e->getMessage(); |
||
2310 | } |
||
2311 | } |
||
2312 | public function addStatAirline($airline_icao,$cnt,$airline_name = '',$filter_name = '', $reset = false) { |
||
2313 | global $globalDBdriver; |
||
2314 | if ($globalDBdriver == 'mysql') { |
||
2315 | if ($reset) { |
||
2316 | $query = "INSERT INTO stats_airline (airline_icao,airline_name,cnt,filter_name) VALUES (:airline_icao,:airline_name,:cnt,:filter_name) ON DUPLICATE KEY UPDATE cnt = :cnt,airline_name = :airline_name"; |
||
2317 | } else { |
||
2318 | $query = "INSERT INTO stats_airline (airline_icao,airline_name,cnt,filter_name) VALUES (:airline_icao,:airline_name,:cnt,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt,airline_name = :airline_name"; |
||
2319 | } |
||
2320 | } else { |
||
2321 | if ($reset) { |
||
2322 | $query = "UPDATE stats_airline SET cnt = :cnt WHERE airline_icao = :airline_icao AND filter_name = :filter_name; INSERT INTO stats_airline (airline_icao,airline_name,cnt,filter_name) SELECT :airline_icao,:airline_name,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airline WHERE airline_icao = :airline_icao AND filter_name = :filter_name);"; |
||
2323 | } else { |
||
2324 | $query = "UPDATE stats_airline SET cnt = cnt+:cnt WHERE airline_icao = :airline_icao AND filter_name = :filter_name; INSERT INTO stats_airline (airline_icao,airline_name,cnt,filter_name) SELECT :airline_icao,:airline_name,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airline WHERE airline_icao = :airline_icao AND filter_name = :filter_name);"; |
||
2325 | } |
||
2326 | } |
||
2327 | $query_values = array(':airline_icao' => $airline_icao,':airline_name' => $airline_name,':cnt' => $cnt,':filter_name' => $filter_name); |
||
2328 | try { |
||
2329 | $sth = $this->db->prepare($query); |
||
2330 | $sth->execute($query_values); |
||
2331 | } catch(PDOException $e) { |
||
2332 | return "error : ".$e->getMessage(); |
||
2333 | } |
||
2334 | } |
||
2335 | public function addStatOwner($owner_name,$cnt,$stats_airline = '', $filter_name = '', $reset = false) { |
||
2336 | global $globalDBdriver; |
||
2337 | if ($globalDBdriver == 'mysql') { |
||
2338 | if ($reset) { |
||
2339 | $query = "INSERT INTO stats_owner (owner_name,cnt,stats_airline,filter_name) VALUES (:owner_name,:cnt,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = :cnt"; |
||
2340 | } else { |
||
2341 | $query = "INSERT INTO stats_owner (owner_name,cnt,stats_airline,filter_name) VALUES (:owner_name,:cnt,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt"; |
||
2342 | } |
||
2343 | } else { |
||
2344 | if ($reset) { |
||
2345 | $query = "UPDATE stats_owner SET cnt = :cnt WHERE owner_name = :owner_name AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_owner (owner_name,cnt,stats_airline,filter_name) SELECT :owner_name,:cnt,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_owner WHERE owner_name = :owner_name AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
||
2346 | } else { |
||
2347 | $query = "UPDATE stats_owner SET cnt = cnt+:cnt WHERE owner_name = :owner_name AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_owner (owner_name,cnt,stats_airline,filter_name) SELECT :owner_name,:cnt,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_owner WHERE owner_name = :owner_name AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
||
2348 | } |
||
2349 | } |
||
2350 | $query_values = array(':owner_name' => $owner_name,':cnt' => $cnt,':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
||
2351 | try { |
||
2352 | $sth = $this->db->prepare($query); |
||
2353 | $sth->execute($query_values); |
||
2354 | } catch(PDOException $e) { |
||
2355 | return "error : ".$e->getMessage(); |
||
2356 | } |
||
2357 | } |
||
2358 | public function addStatPilot($pilot_id,$cnt,$pilot_name,$stats_airline = '',$filter_name = '',$format_source = '',$reset = false) { |
||
2359 | global $globalDBdriver; |
||
2360 | if ($globalDBdriver == 'mysql') { |
||
2361 | if ($reset) { |
||
2362 | $query = "INSERT INTO stats_pilot (pilot_id,cnt,pilot_name,stats_airline,filter_name,format_source) VALUES (:pilot_id,:cnt,:pilot_name,:stats_airline,:filter_name,:format_source) ON DUPLICATE KEY UPDATE cnt = :cnt, pilot_name = :pilot_name"; |
||
2363 | } else { |
||
2364 | $query = "INSERT INTO stats_pilot (pilot_id,cnt,pilot_name,stats_airline,filter_name,format_source) VALUES (:pilot_id,:cnt,:pilot_name,:stats_airline,:filter_name,:format_source) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, pilot_name = :pilot_name"; |
||
2365 | } |
||
2366 | } else { |
||
2367 | if ($reset) { |
||
2368 | $query = "UPDATE stats_pilot SET cnt = :cnt, pilot_name = :pilot_name WHERE pilot_id = :pilot_id AND stats_airline = :stats_airline AND filter_name = :filter_name AND format_source = :format_source; INSERT INTO stats_pilot (pilot_id,cnt,pilot_name,stats_airline,filter_name,format_source) SELECT :pilot_id,:cnt,:pilot_name,:stats_airline,:filter_name,:format_source WHERE NOT EXISTS (SELECT 1 FROM stats_pilot WHERE pilot_id = :pilot_id AND stats_airline = :stats_airline AND filter_name = :filter_name AND format_source = :format_source);"; |
||
2369 | } else { |
||
2370 | $query = "UPDATE stats_pilot SET cnt = cnt+:cnt, pilot_name = :pilot_name WHERE pilot_id = :pilot_id AND stats_airline = :stats_airline AND filter_name = :filter_name AND format_source = :format_source; INSERT INTO stats_pilot (pilot_id,cnt,pilot_name,stats_airline,filter_name,format_source) SELECT :pilot_id,:cnt,:pilot_name,:stats_airline,:filter_name,:format_source WHERE NOT EXISTS (SELECT 1 FROM stats_pilot WHERE pilot_id = :pilot_id AND stats_airline = :stats_airline AND filter_name = :filter_name AND format_source = :format_source);"; |
||
2371 | } |
||
2372 | } |
||
2373 | $query_values = array(':pilot_id' => $pilot_id,':cnt' => $cnt,':pilot_name' => $pilot_name,':stats_airline' => $stats_airline,':filter_name' => $filter_name,':format_source' => $format_source); |
||
2374 | try { |
||
2375 | $sth = $this->db->prepare($query); |
||
2376 | $sth->execute($query_values); |
||
2377 | } catch(PDOException $e) { |
||
2378 | return "error : ".$e->getMessage(); |
||
2379 | } |
||
2380 | } |
||
2381 | public function addStatDepartureAirports($airport_icao,$airport_name,$airport_city,$airport_country,$departure,$airline_icao = '',$filter_name = '',$reset = false) { |
||
2382 | global $globalDBdriver; |
||
2383 | if ($airport_icao != '') { |
||
2384 | if ($globalDBdriver == 'mysql') { |
||
2385 | if ($reset) { |
||
2386 | $query = "INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,departure,stats_type,date,stats_airline,filter_name) VALUES (:airport_icao,:airport_name,:airport_city,:airport_country,:departure,'yearly',:date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE departure = :departure"; |
||
2387 | } else { |
||
2388 | $query = "INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,departure,stats_type,date,stats_airline,filter_name) VALUES (:airport_icao,:airport_name,:airport_city,:airport_country,:departure,'yearly',:date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE departure = departure+:departure"; |
||
2389 | } |
||
2390 | } else { |
||
2391 | if ($reset) { |
||
2392 | $query = "UPDATE stats_airport SET departure = :departure WHERE airport_icao = :airport_icao AND stats_type = 'yearly' AND stats_airline = :stats_airline AND date = :date AND filter_name = :filter_name; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,departure,stats_type,date,stats_airline,filter_name) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:departure,'yearly',:date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airport WHERE airport_icao = :airport_icao AND stats_type = 'yearly' AND stats_airline = :stats_airline AND date = :date AND filter_name = :filter_name);"; |
||
2393 | } else { |
||
2394 | $query = "UPDATE stats_airport SET departure = departure+:departure WHERE airport_icao = :airport_icao AND stats_type = 'yearly' AND stats_airline = :stats_airline AND date = :date AND filter_name = :filter_name; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,departure,stats_type,date,stats_airline,filter_name) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:departure,'yearly',:date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airport WHERE airport_icao = :airport_icao AND stats_type = 'yearly' AND stats_airline = :stats_airline AND date = :date AND filter_name = :filter_name);"; |
||
2395 | } |
||
2396 | } |
||
2397 | $query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':departure' => $departure,':date' => date('Y').'-01-01 00:00:00', ':stats_airline' => $airline_icao,':filter_name' => $filter_name); |
||
2398 | try { |
||
2399 | $sth = $this->db->prepare($query); |
||
2400 | $sth->execute($query_values); |
||
2401 | } catch(PDOException $e) { |
||
2402 | return "error : ".$e->getMessage(); |
||
2403 | } |
||
2404 | } |
||
2405 | } |
||
2406 | public function addStatDepartureAirportsDaily($date,$airport_icao,$airport_name,$airport_city,$airport_country,$departure,$airline_icao = '',$filter_name = '') { |
||
2407 | global $globalDBdriver; |
||
2408 | if ($airport_icao != '') { |
||
2409 | if ($globalDBdriver == 'mysql') { |
||
2410 | $query = "INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,departure,stats_type,date,stats_airline,filter_name) VALUES (:airport_icao,:airport_name,:airport_city,:airport_country,:departure,'daily',:date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE departure = :departure"; |
||
2411 | } else { |
||
2412 | $query = "UPDATE stats_airport SET departure = :departure WHERE airport_icao = :airport_icao AND stats_type = 'daily' AND date = :date AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,departure,stats_type,date,stats_airline,filter_name) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:departure,'daily',:date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airport WHERE airport_icao = :airport_icao AND stats_type = 'daily' AND date = :date AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
||
2413 | } |
||
2414 | $query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':departure' => $departure,':date' => $date,':stats_airline' => $airline_icao,':filter_name' => $filter_name); |
||
2415 | try { |
||
2416 | $sth = $this->db->prepare($query); |
||
2417 | $sth->execute($query_values); |
||
2418 | } catch(PDOException $e) { |
||
2419 | return "error : ".$e->getMessage(); |
||
2420 | } |
||
2421 | } |
||
2422 | } |
||
2423 | public function addStatArrivalAirports($airport_icao,$airport_name,$airport_city,$airport_country,$arrival,$airline_icao = '',$filter_name = '',$reset = false) { |
||
2424 | global $globalDBdriver; |
||
2425 | if ($airport_icao != '') { |
||
2426 | if ($globalDBdriver == 'mysql') { |
||
2427 | if ($reset) { |
||
2428 | $query = "INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,arrival,stats_type,date,stats_airline,filter_name) VALUES (:airport_icao,:airport_name,:airport_city,:airport_country,:arrival,'yearly',:date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE arrival = :arrival"; |
||
2429 | } else { |
||
2430 | $query = "INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,arrival,stats_type,date,stats_airline,filter_name) VALUES (:airport_icao,:airport_name,:airport_city,:airport_country,:arrival,'yearly',:date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE arrival = arrival+:arrival"; |
||
2431 | } |
||
2432 | } else { |
||
2433 | if ($reset) { |
||
2434 | $query = "UPDATE stats_airport SET arrival = :arrival WHERE airport_icao = :airport_icao AND stats_type = 'yearly' AND stats_airline = :stats_airline AND date = :date AND filter_name = :filter_name; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,arrival,stats_type,date,stats_airline,filter_name) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:arrival,'yearly',:date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airport WHERE airport_icao = :airport_icao AND stats_type = 'yearly' AND stats_airline = :stats_airline AND date = :date AND filter_name = :filter_name);"; |
||
2435 | } else { |
||
2436 | $query = "UPDATE stats_airport SET arrival = arrival+:arrival WHERE airport_icao = :airport_icao AND stats_type = 'yearly' AND stats_airline = :stats_airline AND date = :date AND filter_name = :filter_name; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,arrival,stats_type,date,stats_airline,filter_name) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:arrival,'yearly',:date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airport WHERE airport_icao = :airport_icao AND stats_type = 'yearly' AND stats_airline = :stats_airline AND date = :date AND filter_name = :filter_name);"; |
||
2437 | } |
||
2438 | } |
||
2439 | $query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':arrival' => $arrival,':date' => date('Y').'-01-01 00:00:00',':stats_airline' => $airline_icao,':filter_name' => $filter_name); |
||
2440 | try { |
||
2441 | $sth = $this->db->prepare($query); |
||
2442 | $sth->execute($query_values); |
||
2443 | } catch(PDOException $e) { |
||
2444 | return "error : ".$e->getMessage(); |
||
2445 | } |
||
2446 | } |
||
2447 | } |
||
2448 | public function addStatArrivalAirportsDaily($date,$airport_icao,$airport_name,$airport_city,$airport_country,$arrival,$airline_icao = '',$filter_name = '') { |
||
2449 | global $globalDBdriver; |
||
2450 | if ($airport_icao != '') { |
||
2451 | if ($globalDBdriver == 'mysql') { |
||
2452 | $query = "INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,arrival,stats_type,date,stats_airline,filter_name) VALUES (:airport_icao,:airport_name,:airport_city,:airport_country,:arrival,'daily',:date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE arrival = :arrival"; |
||
2453 | } else { |
||
2454 | $query = "UPDATE stats_airport SET arrival = :arrival WHERE airport_icao = :airport_icao AND stats_type = 'daily' AND date = :date AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,arrival,stats_type,date,stats_airline,filter_name) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:arrival,'daily',:date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airport WHERE airport_icao = :airport_icao AND stats_type = 'daily' AND date = :date AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
||
2455 | } |
||
2456 | $query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':arrival' => $arrival, ':date' => $date,':stats_airline' => $airline_icao,':filter_name' => $filter_name); |
||
2457 | try { |
||
2458 | $sth = $this->db->prepare($query); |
||
2459 | $sth->execute($query_values); |
||
2460 | } catch(PDOException $e) { |
||
2461 | return "error : ".$e->getMessage(); |
||
2462 | } |
||
2463 | } |
||
2464 | } |
||
2465 | |||
2466 | public function deleteStat($id) { |
||
2467 | $query = "DELETE FROM stats WHERE stats_id = :id"; |
||
2468 | $query_values = array(':id' => $id); |
||
2469 | try { |
||
2470 | $sth = $this->db->prepare($query); |
||
2471 | $sth->execute($query_values); |
||
2472 | } catch(PDOException $e) { |
||
2473 | return "error : ".$e->getMessage(); |
||
2474 | } |
||
2475 | } |
||
2476 | public function deleteStatFlight($type) { |
||
2477 | $query = "DELETE FROM stats_flight WHERE stats_type = :type"; |
||
2478 | $query_values = array(':type' => $type); |
||
2479 | try { |
||
2480 | $sth = $this->db->prepare($query); |
||
2481 | $sth->execute($query_values); |
||
2482 | } catch(PDOException $e) { |
||
2483 | return "error : ".$e->getMessage(); |
||
2484 | } |
||
2485 | } |
||
2486 | public function deleteStatMarine($type) { |
||
2487 | $query = "DELETE FROM stats_marine WHERE stats_type = :type"; |
||
2488 | $query_values = array(':type' => $type); |
||
2489 | try { |
||
2490 | $sth = $this->db->prepare($query); |
||
2491 | $sth->execute($query_values); |
||
2492 | } catch(PDOException $e) { |
||
2493 | return "error : ".$e->getMessage(); |
||
2494 | } |
||
2495 | } |
||
2496 | public function deleteStatTracker($type) { |
||
2497 | $query = "DELETE FROM stats_tracker WHERE stats_type = :type"; |
||
2498 | $query_values = array(':type' => $type); |
||
2499 | try { |
||
2500 | $sth = $this->db->prepare($query); |
||
2501 | $sth->execute($query_values); |
||
2502 | } catch(PDOException $e) { |
||
2503 | return "error : ".$e->getMessage(); |
||
2504 | } |
||
2505 | } |
||
2506 | public function deleteStatAirport($type) { |
||
2507 | $query = "DELETE FROM stats_airport WHERE stats_type = :type"; |
||
2508 | $query_values = array(':type' => $type); |
||
2509 | try { |
||
2510 | $sth = $this->db->prepare($query); |
||
2511 | $sth->execute($query_values); |
||
2512 | } catch(PDOException $e) { |
||
2513 | return "error : ".$e->getMessage(); |
||
2514 | } |
||
2515 | } |
||
2516 | |||
2517 | public function addOldStats() { |
||
2518 | global $globalMasterServer, $globalAircraft, $globalMarine, $globalTracker, $globalDebug, $globalArchiveMonths, $globalArchive, $globalArchiveYear, $globalDBdriver, $globalStatsFilters,$globalDeleteLastYearStats,$globalStatsReset,$globalStatsResetYear, $globalAccidents; |
||
2519 | $Common = new Common(); |
||
2520 | $Connection = new Connection($this->db); |
||
2521 | date_default_timezone_set('UTC'); |
||
2522 | if ((isset($globalMarine) && $globalMarine) || (isset($globalMasterServer) && $globalMasterServer)) { |
||
2523 | $last_update = $this->getLastStatsUpdate('last_update_stats_marine'); |
||
2524 | if ($globalDebug) echo '!!! Update Marine stats !!!'."\n"; |
||
2525 | if (isset($last_update[0]['value'])) { |
||
2526 | $last_update_day = $last_update[0]['value']; |
||
2527 | } else $last_update_day = '2012-12-12 12:12:12'; |
||
2528 | $reset = false; |
||
2529 | $Marine = new Marine($this->db); |
||
2530 | $filtername = 'marine'; |
||
2531 | if ($Connection->tableExists('countries')) { |
||
2532 | if ($globalDebug) echo 'Count all vessels by countries...'."\n"; |
||
2533 | $alldata = $Marine->countAllMarineOverCountries(false,0,$last_update_day); |
||
2534 | foreach ($alldata as $number) { |
||
2535 | echo $this->addStatCountryMarine($number['marine_country_iso2'],$number['marine_country_iso3'],$number['marine_country'],$number['marine_count'],'','',$reset); |
||
0 ignored issues
–
show
|
|||
2536 | } |
||
2537 | } |
||
2538 | if ($globalDebug) echo 'Count all vessels by months...'."\n"; |
||
2539 | $last_month = date('Y-m-01 00:00:00', strtotime('-1 month', strtotime($last_update_day))); |
||
2540 | $filter_last_month = array('since_date' => $last_month); |
||
2541 | $alldata = $Marine->countAllMonths($filter_last_month); |
||
2542 | $lastyear = false; |
||
2543 | foreach ($alldata as $number) { |
||
2544 | if ($number['year_name'] != date('Y')) $lastyear = true; |
||
2545 | $this->addStat('marine_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
2546 | } |
||
2547 | echo 'Marine data...'."\n"; |
||
2548 | $this->deleteStatMarine('month'); |
||
2549 | echo '-> countAllDatesLastMonth...'."\n"; |
||
2550 | $alldata = $Marine->countAllDatesLastMonth($filter_last_month); |
||
2551 | foreach ($alldata as $number) { |
||
2552 | $this->addStatMarine('month',$number['date_name'],$number['date_count']); |
||
2553 | } |
||
2554 | echo '-> countAllDates...'."\n"; |
||
2555 | $previousdata = $this->countAllDatesMarine(); |
||
2556 | $this->deleteStatMarine('date'); |
||
2557 | $alldata = $Common->array_merge_noappend($previousdata,$Marine->countAllDates($filter_last_month)); |
||
2558 | $values = array(); |
||
2559 | foreach ($alldata as $cnt) { |
||
2560 | $values[] = $cnt['date_count']; |
||
2561 | } |
||
2562 | array_multisort($values,SORT_DESC,$alldata); |
||
2563 | array_splice($alldata,11); |
||
2564 | foreach ($alldata as $number) { |
||
2565 | $this->addStatMarine('date',$number['date_name'],$number['date_count']); |
||
2566 | } |
||
2567 | |||
2568 | $this->deleteStatMarine('hour'); |
||
2569 | echo '-> countAllHours...'."\n"; |
||
2570 | $alldata = $Marine->countAllHours('hour',$filter_last_month); |
||
2571 | foreach ($alldata as $number) { |
||
2572 | $this->addStatMarine('hour',$number['hour_name'],$number['hour_count']); |
||
2573 | } |
||
2574 | if ($globalDebug) echo 'Count all types...'."\n"; |
||
2575 | $alldata = $Marine->countAllMarineTypes(false,0,$last_update_day); |
||
2576 | foreach ($alldata as $number) { |
||
2577 | $this->addStatMarineType($number['marine_type'],$number['marine_type_id'],$number['marine_type_count'],'',$reset); |
||
2578 | } |
||
2579 | |||
2580 | echo 'Insert last stats update date...'."\n"; |
||
2581 | date_default_timezone_set('UTC'); |
||
2582 | $this->addLastStatsUpdate('last_update_stats_marine',date('Y-m-d G:i:s')); |
||
2583 | } |
||
2584 | if ((isset($globalTracker) && $globalTracker) || (isset($globalMasterServer) && $globalMasterServer)) { |
||
2585 | $last_update = $this->getLastStatsUpdate('last_update_stats_tracker'); |
||
2586 | if ($globalDebug) echo '!!! Update tracker stats !!!'."\n"; |
||
2587 | if (isset($last_update[0]['value'])) { |
||
2588 | $last_update_day = $last_update[0]['value']; |
||
2589 | } else $last_update_day = '2012-12-12 12:12:12'; |
||
2590 | $reset = false; |
||
2591 | $Tracker = new Tracker($this->db); |
||
2592 | if ($Connection->tableExists('countries')) { |
||
2593 | if ($globalDebug) echo 'Count all trackers by countries...'."\n"; |
||
2594 | $alldata = $Tracker->countAllTrackerOverCountries(false,0,$last_update_day); |
||
2595 | foreach ($alldata as $number) { |
||
2596 | $this->addStatCountryTracker($number['tracker_country_iso2'],$number['tracker_country_iso3'],$number['tracker_country'],$number['tracker_count'],'','',$reset); |
||
0 ignored issues
–
show
'' is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
2597 | } |
||
2598 | } |
||
2599 | if ($globalDebug) echo 'Count all vessels by months...'."\n"; |
||
2600 | $last_month = date('Y-m-01 00:00:00', strtotime('-1 month', strtotime($last_update_day))); |
||
2601 | $filter_last_month = array('since_date' => $last_month); |
||
2602 | $alldata = $Tracker->countAllMonths($filter_last_month); |
||
2603 | $lastyear = false; |
||
2604 | foreach ($alldata as $number) { |
||
2605 | if ($number['year_name'] != date('Y')) $lastyear = true; |
||
2606 | $this->addStat('tracker_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
2607 | } |
||
2608 | echo 'Tracker data...'."\n"; |
||
2609 | $this->deleteStatTracker('month'); |
||
2610 | echo '-> countAllDatesLastMonth...'."\n"; |
||
2611 | $alldata = $Tracker->countAllDatesLastMonth($filter_last_month); |
||
2612 | foreach ($alldata as $number) { |
||
2613 | $this->addStatTracker('month',$number['date_name'],$number['date_count']); |
||
2614 | } |
||
2615 | echo '-> countAllDates...'."\n"; |
||
2616 | $previousdata = $this->countAllDatesTracker(); |
||
2617 | $this->deleteStatTracker('date'); |
||
2618 | $alldata = $Common->array_merge_noappend($previousdata,$Tracker->countAllDates($filter_last_month)); |
||
2619 | $values = array(); |
||
2620 | foreach ($alldata as $cnt) { |
||
2621 | $values[] = $cnt['date_count']; |
||
2622 | } |
||
2623 | array_multisort($values,SORT_DESC,$alldata); |
||
2624 | array_splice($alldata,11); |
||
2625 | foreach ($alldata as $number) { |
||
2626 | $this->addStatTracker('date',$number['date_name'],$number['date_count']); |
||
2627 | } |
||
2628 | |||
2629 | $this->deleteStatTracker('hour'); |
||
2630 | echo '-> countAllHours...'."\n"; |
||
2631 | $alldata = $Tracker->countAllHours('hour',$filter_last_month); |
||
2632 | foreach ($alldata as $number) { |
||
2633 | $this->addStatTracker('hour',$number['hour_name'],$number['hour_count']); |
||
2634 | } |
||
2635 | if ($globalDebug) echo 'Count all types...'."\n"; |
||
2636 | $alldata = $Tracker->countAllTrackerTypes(false,0,$last_update_day); |
||
2637 | foreach ($alldata as $number) { |
||
2638 | $this->addStatTrackerType($number['tracker_type'],$number['tracker_type_count'],'',$reset); |
||
2639 | } |
||
2640 | echo 'Insert last stats update date...'."\n"; |
||
2641 | date_default_timezone_set('UTC'); |
||
2642 | $this->addLastStatsUpdate('last_update_stats_tracker',date('Y-m-d G:i:s')); |
||
2643 | } |
||
2644 | |||
2645 | if (!isset($globalAircraft) || (isset($globalAircraft) && $globalAircraft) || (isset($globalMasterServer) && $globalMasterServer)) { |
||
2646 | $last_update = $this->getLastStatsUpdate('last_update_stats'); |
||
2647 | if ($globalDebug) echo '!!! Update aicraft stats !!!'."\n"; |
||
2648 | if (isset($last_update[0]['value'])) { |
||
2649 | $last_update_day = $last_update[0]['value']; |
||
2650 | } else $last_update_day = '2012-12-12 12:12:12'; |
||
2651 | $reset = false; |
||
2652 | //if ($globalStatsResetYear && date('Y',strtotime($last_update_day)) != date('Y')) { |
||
2653 | if ($globalStatsResetYear) { |
||
2654 | $reset = true; |
||
2655 | $last_update_day = date('Y').'-01-01 00:00:00'; |
||
2656 | } |
||
2657 | $Spotter = new Spotter($this->db); |
||
2658 | |||
2659 | if ($globalDebug) echo 'Count all aircraft types...'."\n"; |
||
2660 | $alldata = $Spotter->countAllAircraftTypes(false,0,$last_update_day); |
||
2661 | foreach ($alldata as $number) { |
||
2662 | $this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name'],$number['aircraft_manufacturer'],'','',$reset); |
||
2663 | } |
||
2664 | if ($globalDebug) echo 'Count all airlines...'."\n"; |
||
2665 | $alldata = $Spotter->countAllAirlines(false,0,$last_update_day); |
||
2666 | foreach ($alldata as $number) { |
||
2667 | $this->addStatAirline($number['airline_icao'],$number['airline_count'],$number['airline_name'],'',$reset); |
||
2668 | } |
||
2669 | if ($globalDebug) echo 'Count all registrations...'."\n"; |
||
2670 | $alldata = $Spotter->countAllAircraftRegistrations(false,0,$last_update_day); |
||
2671 | foreach ($alldata as $number) { |
||
2672 | $this->addStatAircraftRegistration($number['registration'],$number['aircraft_registration_count'],$number['aircraft_icao'],'','',$reset); |
||
2673 | } |
||
2674 | if ($globalDebug) echo 'Count all callsigns...'."\n"; |
||
2675 | $alldata = $Spotter->countAllCallsigns(false,0,$last_update_day); |
||
2676 | foreach ($alldata as $number) { |
||
2677 | $this->addStatCallsign($number['callsign_icao'],$number['callsign_icao_count'],$number['airline_icao'],'',$reset); |
||
2678 | } |
||
2679 | if ($globalDebug) echo 'Count all owners...'."\n"; |
||
2680 | $alldata = $Spotter->countAllOwners(false,0,$last_update_day); |
||
2681 | foreach ($alldata as $number) { |
||
2682 | $this->addStatOwner($number['owner_name'],$number['owner_count'],'','',$reset); |
||
2683 | } |
||
2684 | if ($globalDebug) echo 'Count all pilots...'."\n"; |
||
2685 | $alldata = $Spotter->countAllPilots(false,0,$last_update_day); |
||
2686 | foreach ($alldata as $number) { |
||
2687 | if ($number['pilot_id'] == 0 || $number['pilot_id'] == '') $number['pilot_id'] = $number['pilot_name']; |
||
2688 | $this->addStatPilot($number['pilot_id'],$number['pilot_count'],$number['pilot_name'],'','',$number['format_source'],$reset); |
||
2689 | } |
||
2690 | |||
2691 | if ($globalDebug) echo 'Count all departure airports...'."\n"; |
||
2692 | $pall = $Spotter->countAllDepartureAirports(false,0,$last_update_day); |
||
2693 | if ($globalDebug) echo 'Count all detected departure airports...'."\n"; |
||
2694 | $dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day); |
||
2695 | if ($globalDebug) echo 'Order departure airports...'."\n"; |
||
2696 | $alldata = array(); |
||
2697 | foreach ($pall as $value) { |
||
2698 | $icao = $value['airport_departure_icao']; |
||
2699 | $alldata[$icao] = $value; |
||
2700 | } |
||
2701 | foreach ($dall as $value) { |
||
2702 | $icao = $value['airport_departure_icao']; |
||
2703 | if (isset($alldata[$icao])) { |
||
2704 | $alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count']; |
||
2705 | } else $alldata[$icao] = $value; |
||
2706 | } |
||
2707 | $count = array(); |
||
2708 | foreach ($alldata as $key => $row) { |
||
2709 | $count[$key] = $row['airport_departure_icao_count']; |
||
2710 | } |
||
2711 | array_multisort($count,SORT_DESC,$alldata); |
||
2712 | foreach ($alldata as $number) { |
||
2713 | echo $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count'],'','',$reset); |
||
2714 | } |
||
2715 | if ($globalDebug) echo 'Count all arrival airports...'."\n"; |
||
2716 | $pall = $Spotter->countAllArrivalAirports(false,0,$last_update_day); |
||
2717 | if ($globalDebug) echo 'Count all detected arrival airports...'."\n"; |
||
2718 | $dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day); |
||
2719 | if ($globalDebug) echo 'Order arrival airports...'."\n"; |
||
2720 | $alldata = array(); |
||
2721 | foreach ($pall as $value) { |
||
2722 | $icao = $value['airport_arrival_icao']; |
||
2723 | $alldata[$icao] = $value; |
||
2724 | } |
||
2725 | foreach ($dall as $value) { |
||
2726 | $icao = $value['airport_arrival_icao']; |
||
2727 | if (isset($alldata[$icao])) { |
||
2728 | $alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count']; |
||
2729 | } else $alldata[$icao] = $value; |
||
2730 | } |
||
2731 | $count = array(); |
||
2732 | foreach ($alldata as $key => $row) { |
||
2733 | $count[$key] = $row['airport_arrival_icao_count']; |
||
2734 | } |
||
2735 | array_multisort($count,SORT_DESC,$alldata); |
||
2736 | foreach ($alldata as $number) { |
||
2737 | echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count'],'','',$reset); |
||
2738 | } |
||
2739 | if ($Connection->tableExists('countries')) { |
||
2740 | if ($globalDebug) echo 'Count all flights by countries...'."\n"; |
||
2741 | //$SpotterArchive = new SpotterArchive(); |
||
2742 | //$alldata = $SpotterArchive->countAllFlightOverCountries(false,0,$last_update_day); |
||
2743 | $Spotter = new Spotter($this->db); |
||
2744 | $alldata = $Spotter->countAllFlightOverCountries(false,0,$last_update_day); |
||
2745 | foreach ($alldata as $number) { |
||
2746 | $this->addStatCountry($number['flight_country_iso2'],$number['flight_country_iso3'],$number['flight_country'],$number['flight_count'],'','',$reset); |
||
2747 | } |
||
2748 | } |
||
2749 | |||
2750 | if (isset($globalAccidents) && $globalAccidents) { |
||
2751 | if ($globalDebug) echo 'Count fatalities stats...'."\n"; |
||
2752 | $Accident = new Accident($this->db); |
||
2753 | $this->deleteStatsByType('fatalities_byyear'); |
||
2754 | $alldata = $Accident->countFatalitiesByYear(); |
||
2755 | foreach ($alldata as $number) { |
||
2756 | $this->addStat('fatalities_byyear',$number['count'],date('Y-m-d H:i:s',mktime(0,0,0,1,1,$number['year']))); |
||
2757 | } |
||
2758 | $this->deleteStatsByType('fatalities_bymonth'); |
||
2759 | $alldata = $Accident->countFatalitiesLast12Months(); |
||
2760 | foreach ($alldata as $number) { |
||
2761 | $this->addStat('fatalities_bymonth',$number['count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month'],1,$number['year']))); |
||
2762 | } |
||
2763 | } |
||
2764 | |||
2765 | // Add by month using getstat if month finish... |
||
2766 | //if (date('m',strtotime($last_update_day)) != date('m')) { |
||
2767 | if ($globalDebug) echo 'Count all flights by months...'."\n"; |
||
2768 | $last_month = date('Y-m-01 00:00:00', strtotime('-1 month', strtotime($last_update_day))); |
||
2769 | $filter_last_month = array('since_date' => $last_month); |
||
2770 | $Spotter = new Spotter($this->db); |
||
2771 | $alldata = $Spotter->countAllMonths($filter_last_month); |
||
2772 | $lastyear = false; |
||
2773 | foreach ($alldata as $number) { |
||
2774 | if ($number['year_name'] != date('Y')) $lastyear = true; |
||
2775 | $this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
2776 | } |
||
2777 | if ($globalDebug) echo 'Count all military flights by months...'."\n"; |
||
2778 | $alldata = $Spotter->countAllMilitaryMonths($filter_last_month); |
||
2779 | foreach ($alldata as $number) { |
||
2780 | $this->addStat('military_flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
2781 | } |
||
2782 | if ($globalDebug) echo 'Count all owners by months...'."\n"; |
||
2783 | $alldata = $Spotter->countAllMonthsOwners($filter_last_month); |
||
2784 | foreach ($alldata as $number) { |
||
2785 | $this->addStat('owners_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
2786 | } |
||
2787 | if ($globalDebug) echo 'Count all pilots by months...'."\n"; |
||
2788 | $alldata = $Spotter->countAllMonthsPilots($filter_last_month); |
||
2789 | foreach ($alldata as $number) { |
||
2790 | $this->addStat('pilots_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
2791 | } |
||
2792 | if ($globalDebug) echo 'Count all airlines by months...'."\n"; |
||
2793 | $alldata = $Spotter->countAllMonthsAirlines($filter_last_month); |
||
2794 | foreach ($alldata as $number) { |
||
2795 | $this->addStat('airlines_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
2796 | } |
||
2797 | if ($globalDebug) echo 'Count all aircrafts by months...'."\n"; |
||
2798 | $alldata = $Spotter->countAllMonthsAircrafts($filter_last_month); |
||
2799 | foreach ($alldata as $number) { |
||
2800 | $this->addStat('aircrafts_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
2801 | } |
||
2802 | if ($globalDebug) echo 'Count all real arrivals by months...'."\n"; |
||
2803 | $alldata = $Spotter->countAllMonthsRealArrivals($filter_last_month); |
||
2804 | foreach ($alldata as $number) { |
||
2805 | $this->addStat('realarrivals_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
2806 | } |
||
2807 | if ($globalDebug) echo 'Airports data...'."\n"; |
||
2808 | if ($globalDebug) echo '...Departure'."\n"; |
||
2809 | $this->deleteStatAirport('daily'); |
||
2810 | // $pall = $Spotter->getLast7DaysAirportsDeparture(); |
||
2811 | // $dall = $Spotter->getLast7DaysDetectedAirportsDeparture(); |
||
2812 | $pall = $Spotter->getLast7DaysAirportsDeparture(); |
||
2813 | $dall = $Spotter->getLast7DaysDetectedAirportsDeparture(); |
||
2814 | /* |
||
2815 | $alldata = array(); |
||
2816 | foreach ($pall as $value) { |
||
2817 | $icao = $value['departure_airport_icao']; |
||
2818 | $alldata[$icao] = $value; |
||
2819 | } |
||
2820 | foreach ($dall as $value) { |
||
2821 | $icao = $value['departure_airport_icao']; |
||
2822 | $ddate = $value['date']; |
||
2823 | if (isset($alldata[$icao])) { |
||
2824 | $alldata[$icao]['departure_airport_count'] = $alldata[$icao]['departure_airport_count'] + $value['departure_airport_count']; |
||
2825 | } else $alldata[$icao] = $value; |
||
2826 | } |
||
2827 | $count = array(); |
||
2828 | foreach ($alldata as $key => $row) { |
||
2829 | $count[$key] = $row['departure_airport_count']; |
||
2830 | } |
||
2831 | array_multisort($count,SORT_DESC,$alldata); |
||
2832 | */ |
||
2833 | foreach ($dall as $value) { |
||
2834 | $icao = $value['departure_airport_icao']; |
||
2835 | $ddate = $value['date']; |
||
2836 | $find = false; |
||
2837 | foreach ($pall as $pvalue) { |
||
2838 | if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate) { |
||
2839 | $pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count']; |
||
2840 | $find = true; |
||
2841 | break; |
||
2842 | } |
||
2843 | } |
||
2844 | if ($find === false) { |
||
2845 | $pall[] = $value; |
||
2846 | } |
||
2847 | } |
||
2848 | $alldata = $pall; |
||
2849 | foreach ($alldata as $number) { |
||
2850 | $this->addStatDepartureAirportsDaily($number['date'],$number['departure_airport_icao'],$number['departure_airport_name'],$number['departure_airport_city'],$number['departure_airport_country'],$number['departure_airport_count']); |
||
2851 | } |
||
2852 | echo '...Arrival'."\n"; |
||
2853 | $pall = $Spotter->getLast7DaysAirportsArrival(); |
||
2854 | $dall = $Spotter->getLast7DaysDetectedAirportsArrival(); |
||
2855 | /* |
||
2856 | $alldata = array(); |
||
2857 | foreach ($pall as $value) { |
||
2858 | $icao = $value['arrival_airport_icao']; |
||
2859 | $alldata[$icao] = $value; |
||
2860 | } |
||
2861 | foreach ($dall as $value) { |
||
2862 | $icao = $value['arrival_airport_icao']; |
||
2863 | if (isset($alldata[$icao])) { |
||
2864 | $alldata[$icao]['arrival_airport_icao_count'] = $alldata[$icao]['arrival_airport_count'] + $value['arrival_airport_count']; |
||
2865 | } else $alldata[$icao] = $value; |
||
2866 | } |
||
2867 | $count = array(); |
||
2868 | foreach ($alldata as $key => $row) { |
||
2869 | $count[$key] = $row['arrival_airport_count']; |
||
2870 | } |
||
2871 | array_multisort($count,SORT_DESC,$alldata); |
||
2872 | */ |
||
2873 | |||
2874 | foreach ($dall as $value) { |
||
2875 | $icao = $value['arrival_airport_icao']; |
||
2876 | $ddate = $value['date']; |
||
2877 | $find = false; |
||
2878 | foreach ($pall as $pvalue) { |
||
2879 | if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate) { |
||
2880 | $pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count']; |
||
2881 | $find = true; |
||
2882 | break; |
||
2883 | } |
||
2884 | } |
||
2885 | if ($find === false) { |
||
2886 | $pall[] = $value; |
||
2887 | } |
||
2888 | } |
||
2889 | $alldata = $pall; |
||
2890 | foreach ($alldata as $number) { |
||
2891 | $this->addStatArrivalAirportsDaily($number['date'],$number['arrival_airport_icao'],$number['arrival_airport_name'],$number['arrival_airport_city'],$number['arrival_airport_country'],$number['arrival_airport_count']); |
||
2892 | } |
||
2893 | |||
2894 | echo 'Flights data...'."\n"; |
||
2895 | $this->deleteStatFlight('month'); |
||
2896 | echo '-> countAllDatesLastMonth...'."\n"; |
||
2897 | $alldata = $Spotter->countAllDatesLastMonth($filter_last_month); |
||
2898 | foreach ($alldata as $number) { |
||
2899 | $this->addStatFlight('month',$number['date_name'],$number['date_count']); |
||
2900 | } |
||
2901 | echo '-> countAllDates...'."\n"; |
||
2902 | $previousdata = $this->countAllDates(); |
||
2903 | $previousdatabyairlines = $this->countAllDatesByAirlines(); |
||
2904 | $this->deleteStatFlight('date'); |
||
2905 | $alldata = $Common->array_merge_noappend($previousdata,$Spotter->countAllDates($filter_last_month)); |
||
2906 | $values = array(); |
||
2907 | foreach ($alldata as $cnt) { |
||
2908 | $values[] = $cnt['date_count']; |
||
2909 | } |
||
2910 | array_multisort($values,SORT_DESC,$alldata); |
||
2911 | array_splice($alldata,11); |
||
2912 | foreach ($alldata as $number) { |
||
2913 | $this->addStatFlight('date',$number['date_name'],$number['date_count']); |
||
2914 | } |
||
2915 | |||
2916 | $this->deleteStatFlight('hour'); |
||
2917 | echo '-> countAllHours...'."\n"; |
||
2918 | $alldata = $Spotter->countAllHours('hour',$filter_last_month); |
||
2919 | foreach ($alldata as $number) { |
||
2920 | $this->addStatFlight('hour',$number['hour_name'],$number['hour_count']); |
||
2921 | } |
||
2922 | |||
2923 | // Count by airlines |
||
2924 | echo '--- Stats by airlines ---'."\n"; |
||
2925 | if ($Connection->tableExists('countries')) { |
||
2926 | if ($globalDebug) echo 'Count all flights by countries by airlines...'."\n"; |
||
2927 | $SpotterArchive = new SpotterArchive($this->db); |
||
2928 | //$Spotter = new Spotter($this->db); |
||
2929 | $alldata = $SpotterArchive->countAllFlightOverCountriesByAirlines(false,0,$last_update_day); |
||
2930 | //$alldata = $Spotter->countAllFlightOverCountriesByAirlines(false,0,$last_update_day); |
||
2931 | foreach ($alldata as $number) { |
||
2932 | $this->addStatCountry($number['flight_country_iso2'],$number['flight_country_iso3'],$number['flight_country'],$number['flight_count'],$number['airline_icao'],'',$reset); |
||
2933 | } |
||
2934 | } |
||
2935 | if ($globalDebug) echo 'Count all aircraft types by airlines...'."\n"; |
||
2936 | $Spotter = new Spotter($this->db); |
||
2937 | $alldata = $Spotter->countAllAircraftTypesByAirlines(false,0,$last_update_day); |
||
2938 | foreach ($alldata as $number) { |
||
2939 | $this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name'],$number['aircraft_manufacturer'],$number['airline_icao'],'',$reset); |
||
2940 | } |
||
2941 | if ($globalDebug) echo 'Count all aircraft registrations by airlines...'."\n"; |
||
2942 | $alldata = $Spotter->countAllAircraftRegistrationsByAirlines(false,0,$last_update_day); |
||
2943 | foreach ($alldata as $number) { |
||
2944 | $this->addStatAircraftRegistration($number['registration'],$number['aircraft_registration_count'],$number['aircraft_icao'],$number['airline_icao'],'',$reset); |
||
2945 | } |
||
2946 | if ($globalDebug) echo 'Count all callsigns by airlines...'."\n"; |
||
2947 | $alldata = $Spotter->countAllCallsignsByAirlines(false,0,$last_update_day); |
||
2948 | foreach ($alldata as $number) { |
||
2949 | $this->addStatCallsign($number['callsign_icao'],$number['callsign_icao_count'],$number['airline_icao'],'',$reset); |
||
2950 | } |
||
2951 | if ($globalDebug) echo 'Count all owners by airlines...'."\n"; |
||
2952 | $alldata = $Spotter->countAllOwnersByAirlines(false,0,$last_update_day); |
||
2953 | foreach ($alldata as $number) { |
||
2954 | $this->addStatOwner($number['owner_name'],$number['owner_count'],$number['airline_icao'],'',$reset); |
||
2955 | } |
||
2956 | if ($globalDebug) echo 'Count all pilots by airlines...'."\n"; |
||
2957 | $alldata = $Spotter->countAllPilotsByAirlines(false,0,$last_update_day); |
||
2958 | foreach ($alldata as $number) { |
||
2959 | $this->addStatPilot($number['pilot_id'],$number['pilot_count'],$number['pilot_name'],$number['airline_icao'],'',$number['format_source'],$reset); |
||
2960 | } |
||
2961 | if ($globalDebug) echo 'Count all departure airports by airlines...'."\n"; |
||
2962 | $pall = $Spotter->countAllDepartureAirportsByAirlines(false,0,$last_update_day); |
||
2963 | if ($globalDebug) echo 'Count all detected departure airports by airlines...'."\n"; |
||
2964 | $dall = $Spotter->countAllDetectedDepartureAirportsByAirlines(false,0,$last_update_day); |
||
2965 | if ($globalDebug) echo 'Order detected departure airports by airlines...'."\n"; |
||
2966 | //$alldata = array(); |
||
2967 | foreach ($dall as $value) { |
||
2968 | $icao = $value['airport_departure_icao']; |
||
2969 | $dicao = $value['airline_icao']; |
||
2970 | $find = false; |
||
2971 | foreach ($pall as $pvalue) { |
||
2972 | if ($pvalue['airport_departure_icao'] == $icao && $pvalue['airline_icao'] = $dicao) { |
||
2973 | $pvalue['airport_departure_icao_count'] = $pvalue['airport_departure_icao_count'] + $value['airport_departure_icao_count']; |
||
2974 | $find = true; |
||
2975 | break; |
||
2976 | } |
||
2977 | } |
||
2978 | if ($find === false) { |
||
2979 | $pall[] = $value; |
||
2980 | } |
||
2981 | } |
||
2982 | $alldata = $pall; |
||
2983 | foreach ($alldata as $number) { |
||
2984 | echo $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count'],$number['airline_icao'],'',$reset); |
||
2985 | } |
||
2986 | if ($globalDebug) echo 'Count all arrival airports by airlines...'."\n"; |
||
2987 | $pall = $Spotter->countAllArrivalAirportsByAirlines(false,0,$last_update_day); |
||
2988 | if ($globalDebug) echo 'Count all detected arrival airports by airlines...'."\n"; |
||
2989 | $dall = $Spotter->countAllDetectedArrivalAirportsByAirlines(false,0,$last_update_day); |
||
2990 | if ($globalDebug) echo 'Order arrival airports by airlines...'."\n"; |
||
2991 | //$alldata = array(); |
||
2992 | foreach ($dall as $value) { |
||
2993 | $icao = $value['airport_arrival_icao']; |
||
2994 | $dicao = $value['airline_icao']; |
||
2995 | $find = false; |
||
2996 | foreach ($pall as $pvalue) { |
||
2997 | if ($pvalue['airport_arrival_icao'] == $icao && $pvalue['airline_icao'] = $dicao) { |
||
2998 | $pvalue['airport_arrival_icao_count'] = $pvalue['airport_arrival_icao_count'] + $value['airport_arrival_icao_count']; |
||
2999 | $find = true; |
||
3000 | break; |
||
3001 | } |
||
3002 | } |
||
3003 | if ($find === false) { |
||
3004 | $pall[] = $value; |
||
3005 | } |
||
3006 | } |
||
3007 | $alldata = $pall; |
||
3008 | foreach ($alldata as $number) { |
||
3009 | if ($number['airline_icao'] != '') echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count'],$number['airline_icao'],'',$reset); |
||
3010 | } |
||
3011 | if ($globalDebug) echo 'Count all flights by months by airlines...'."\n"; |
||
3012 | $Spotter = new Spotter($this->db); |
||
3013 | $alldata = $Spotter->countAllMonthsByAirlines($filter_last_month); |
||
3014 | $lastyear = false; |
||
3015 | foreach ($alldata as $number) { |
||
3016 | if ($number['year_name'] != date('Y')) $lastyear = true; |
||
3017 | $this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']); |
||
3018 | } |
||
3019 | if ($globalDebug) echo 'Count all owners by months by airlines...'."\n"; |
||
3020 | $alldata = $Spotter->countAllMonthsOwnersByAirlines($filter_last_month); |
||
3021 | foreach ($alldata as $number) { |
||
3022 | $this->addStat('owners_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']); |
||
3023 | } |
||
3024 | if ($globalDebug) echo 'Count all pilots by months by airlines...'."\n"; |
||
3025 | $alldata = $Spotter->countAllMonthsPilotsByAirlines($filter_last_month); |
||
3026 | foreach ($alldata as $number) { |
||
3027 | $this->addStat('pilots_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']); |
||
3028 | } |
||
3029 | if ($globalDebug) echo 'Count all aircrafts by months by airlines...'."\n"; |
||
3030 | $alldata = $Spotter->countAllMonthsAircraftsByAirlines($filter_last_month); |
||
3031 | foreach ($alldata as $number) { |
||
3032 | $this->addStat('aircrafts_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']); |
||
3033 | } |
||
3034 | if ($globalDebug) echo 'Count all real arrivals by months by airlines...'."\n"; |
||
3035 | $alldata = $Spotter->countAllMonthsRealArrivalsByAirlines($filter_last_month); |
||
3036 | foreach ($alldata as $number) { |
||
3037 | $this->addStat('realarrivals_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']); |
||
3038 | } |
||
3039 | if ($globalDebug) echo '...Departure'."\n"; |
||
3040 | $pall = $Spotter->getLast7DaysAirportsDepartureByAirlines(); |
||
3041 | $dall = $Spotter->getLast7DaysDetectedAirportsDepartureByAirlines(); |
||
3042 | foreach ($dall as $value) { |
||
3043 | $icao = $value['departure_airport_icao']; |
||
3044 | $airline = $value['airline_icao']; |
||
3045 | $ddate = $value['date']; |
||
3046 | $find = false; |
||
3047 | foreach ($pall as $pvalue) { |
||
3048 | if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate && $pvalue['airline_icao'] = $airline) { |
||
3049 | $pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count']; |
||
3050 | $find = true; |
||
3051 | break; |
||
3052 | } |
||
3053 | } |
||
3054 | if ($find === false) { |
||
3055 | $pall[] = $value; |
||
3056 | } |
||
3057 | } |
||
3058 | $alldata = $pall; |
||
3059 | foreach ($alldata as $number) { |
||
3060 | $this->addStatDepartureAirportsDaily($number['date'],$number['departure_airport_icao'],$number['departure_airport_name'],$number['departure_airport_city'],$number['departure_airport_country'],$number['departure_airport_count'],$number['airline_icao']); |
||
3061 | } |
||
3062 | if ($globalDebug) echo '...Arrival'."\n"; |
||
3063 | $pall = $Spotter->getLast7DaysAirportsArrivalByAirlines(); |
||
3064 | $dall = $Spotter->getLast7DaysDetectedAirportsArrivalByAirlines(); |
||
3065 | foreach ($dall as $value) { |
||
3066 | $icao = $value['arrival_airport_icao']; |
||
3067 | $airline = $value['airline_icao']; |
||
3068 | $ddate = $value['date']; |
||
3069 | $find = false; |
||
3070 | foreach ($pall as $pvalue) { |
||
3071 | if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate && $pvalue['airline_icao'] == $airline) { |
||
3072 | $pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count']; |
||
3073 | $find = true; |
||
3074 | break; |
||
3075 | } |
||
3076 | } |
||
3077 | if ($find === false) { |
||
3078 | $pall[] = $value; |
||
3079 | } |
||
3080 | } |
||
3081 | $alldata = $pall; |
||
3082 | foreach ($alldata as $number) { |
||
3083 | $this->addStatArrivalAirportsDaily($number['date'],$number['arrival_airport_icao'],$number['arrival_airport_name'],$number['arrival_airport_city'],$number['arrival_airport_country'],$number['arrival_airport_count'],$number['airline_icao']); |
||
3084 | } |
||
3085 | |||
3086 | if ($globalDebug) echo 'Flights data...'."\n"; |
||
3087 | if ($globalDebug) echo '-> countAllDatesLastMonth...'."\n"; |
||
3088 | $alldata = $Spotter->countAllDatesLastMonthByAirlines($filter_last_month); |
||
3089 | foreach ($alldata as $number) { |
||
3090 | $this->addStatFlight('month',$number['date_name'],$number['date_count'], $number['airline_icao']); |
||
3091 | } |
||
3092 | if ($globalDebug) echo '-> countAllDates...'."\n"; |
||
3093 | //$previousdata = $this->countAllDatesByAirlines(); |
||
3094 | $alldata = $Common->array_merge_noappend($previousdatabyairlines,$Spotter->countAllDatesByAirlines($filter_last_month)); |
||
3095 | $values = array(); |
||
3096 | foreach ($alldata as $cnt) { |
||
3097 | $values[] = $cnt['date_count']; |
||
3098 | } |
||
3099 | array_multisort($values,SORT_DESC,$alldata); |
||
3100 | array_splice($alldata,11); |
||
3101 | foreach ($alldata as $number) { |
||
3102 | $this->addStatFlight('date',$number['date_name'],$number['date_count'],$number['airline_icao']); |
||
3103 | } |
||
3104 | |||
3105 | if ($globalDebug) echo '-> countAllHours...'."\n"; |
||
3106 | $alldata = $Spotter->countAllHoursByAirlines('hour',$filter_last_month); |
||
3107 | foreach ($alldata as $number) { |
||
3108 | $this->addStatFlight('hour',$number['hour_name'],$number['hour_count'],$number['airline_icao']); |
||
3109 | } |
||
3110 | |||
3111 | // Stats by filters |
||
3112 | if (!isset($globalStatsFilters) || $globalStatsFilters == '') $globalStatsFilters = array(); |
||
3113 | foreach ($globalStatsFilters as $name => $filter) { |
||
3114 | if (!empty($filter)) { |
||
3115 | //$filter_name = $filter['name']; |
||
3116 | $filter_name = $name; |
||
3117 | $reset = false; |
||
3118 | $last_update = $this->getLastStatsUpdate('last_update_stats_'.$filter_name); |
||
3119 | if (isset($filter['resetall']) && isset($last_update[0]['value']) && strtotime($filter['resetall']) > strtotime($last_update[0]['value'])) { |
||
3120 | if ($globalDebug) echo '!!! Delete stats for filter '.$filter_name.' !!!'."\n"; |
||
3121 | $this->deleteOldStats($filter_name); |
||
3122 | unset($last_update); |
||
3123 | } |
||
3124 | if (isset($last_update[0]['value'])) { |
||
3125 | $last_update_day = $last_update[0]['value']; |
||
3126 | } else { |
||
3127 | $last_update_day = '2012-12-12 12:12:12'; |
||
3128 | if (isset($filter['DeleteLastYearStats'])) { |
||
3129 | $last_update_day = date('Y').'-01-01 00:00:00'; |
||
3130 | } |
||
3131 | } |
||
3132 | if (isset($filter['DeleteLastYearStats']) && date('Y',strtotime($last_update_day)) != date('Y')) { |
||
3133 | $last_update_day = date('Y').'-01-01 00:00:00'; |
||
3134 | $reset = true; |
||
3135 | } |
||
3136 | // Count by filter |
||
3137 | if ($globalDebug) echo '--- Stats for filter '.$filter_name.' ---'."\n"; |
||
3138 | $Spotter = new Spotter($this->db); |
||
3139 | if ($globalDebug) echo 'Count all aircraft types...'."\n"; |
||
3140 | $alldata = $Spotter->countAllAircraftTypes(false,0,$last_update_day,$filter); |
||
3141 | foreach ($alldata as $number) { |
||
3142 | $this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name'],$number['aircraft_manufacturer'],'',$filter_name,$reset); |
||
3143 | } |
||
3144 | if ($globalDebug) echo 'Count all airlines...'."\n"; |
||
3145 | $alldata = $Spotter->countAllAirlines(false,0,$last_update_day,$filter); |
||
3146 | foreach ($alldata as $number) { |
||
3147 | $this->addStatAirline($number['airline_icao'],$number['airline_count'],$number['airline_name'],$filter_name,$reset); |
||
3148 | } |
||
3149 | if ($globalDebug) echo 'Count all aircraft registrations...'."\n"; |
||
3150 | $alldata = $Spotter->countAllAircraftRegistrations(false,0,$last_update_day,$filter); |
||
3151 | foreach ($alldata as $number) { |
||
3152 | $this->addStatAircraftRegistration($number['registration'],$number['aircraft_registration_count'],$number['aircraft_icao'],'',$filter_name,$reset); |
||
3153 | } |
||
3154 | if ($globalDebug) echo 'Count all callsigns...'."\n"; |
||
3155 | $alldata = $Spotter->countAllCallsigns(false,0,$last_update_day,$filter); |
||
3156 | foreach ($alldata as $number) { |
||
3157 | $this->addStatCallsign($number['callsign_icao'],$number['callsign_icao_count'],'',$filter_name,$reset); |
||
3158 | } |
||
3159 | if ($globalDebug) echo 'Count all owners...'."\n"; |
||
3160 | $alldata = $Spotter->countAllOwners(false,0,$last_update_day,$filter); |
||
3161 | foreach ($alldata as $number) { |
||
3162 | $this->addStatOwner($number['owner_name'],$number['owner_count'],'',$filter_name,$reset); |
||
3163 | } |
||
3164 | if ($globalDebug) echo 'Count all pilots...'."\n"; |
||
3165 | $alldata = $Spotter->countAllPilots(false,0,$last_update_day,$filter); |
||
3166 | foreach ($alldata as $number) { |
||
3167 | $this->addStatPilot($number['pilot_id'],$number['pilot_count'],$number['pilot_name'],'',$filter_name,$number['format_source'],$reset); |
||
3168 | } |
||
3169 | if ($globalDebug) echo 'Count departure airports...'."\n"; |
||
3170 | $pall = $Spotter->countAllDepartureAirports(false,0,$last_update_day,$filter); |
||
3171 | $dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day,$filter); |
||
3172 | $alldata = array(); |
||
3173 | foreach ($pall as $value) { |
||
3174 | $icao = $value['airport_departure_icao']; |
||
3175 | $alldata[$icao] = $value; |
||
3176 | } |
||
3177 | foreach ($dall as $value) { |
||
3178 | $icao = $value['airport_departure_icao']; |
||
3179 | if (isset($alldata[$icao])) { |
||
3180 | $alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count']; |
||
3181 | } else $alldata[$icao] = $value; |
||
3182 | } |
||
3183 | $count = array(); |
||
3184 | foreach ($alldata as $key => $row) { |
||
3185 | $count[$key] = $row['airport_departure_icao_count']; |
||
3186 | } |
||
3187 | array_multisort($count,SORT_DESC,$alldata); |
||
3188 | foreach ($alldata as $number) { |
||
3189 | echo $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count'],'',$filter_name,$reset); |
||
3190 | } |
||
3191 | if ($globalDebug) echo 'Count all arrival airports...'."\n"; |
||
3192 | $pall = $Spotter->countAllArrivalAirports(false,0,$last_update_day,false,$filter); |
||
3193 | $dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day,false,$filter); |
||
3194 | $alldata = array(); |
||
3195 | foreach ($pall as $value) { |
||
3196 | $icao = $value['airport_arrival_icao']; |
||
3197 | $alldata[$icao] = $value; |
||
3198 | } |
||
3199 | foreach ($dall as $value) { |
||
3200 | $icao = $value['airport_arrival_icao']; |
||
3201 | if (isset($alldata[$icao])) { |
||
3202 | $alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count']; |
||
3203 | } else $alldata[$icao] = $value; |
||
3204 | } |
||
3205 | $count = array(); |
||
3206 | foreach ($alldata as $key => $row) { |
||
3207 | $count[$key] = $row['airport_arrival_icao_count']; |
||
3208 | } |
||
3209 | array_multisort($count,SORT_DESC,$alldata); |
||
3210 | foreach ($alldata as $number) { |
||
3211 | echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count'],'',$filter_name,$reset); |
||
3212 | } |
||
3213 | if ($globalDebug) echo 'Count all months...'."\n"; |
||
3214 | $Spotter = new Spotter($this->db); |
||
3215 | $alldata = $Spotter->countAllMonths($filter); |
||
3216 | $lastyear = false; |
||
3217 | foreach ($alldata as $number) { |
||
3218 | if ($number['year_name'] != date('Y')) $lastyear = true; |
||
3219 | $this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),'',$filter_name); |
||
3220 | } |
||
3221 | if ($globalDebug) echo 'Count all owners by months...'."\n"; |
||
3222 | $alldata = $Spotter->countAllMonthsOwners($filter); |
||
3223 | foreach ($alldata as $number) { |
||
3224 | $this->addStat('owners_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),'',$filter_name); |
||
3225 | } |
||
3226 | if ($globalDebug) echo 'Count all pilots by months...'."\n"; |
||
3227 | $alldata = $Spotter->countAllMonthsPilots($filter); |
||
3228 | foreach ($alldata as $number) { |
||
3229 | $this->addStat('pilots_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),'',$filter_name); |
||
3230 | } |
||
3231 | if ($globalDebug) echo 'Count all military by months...'."\n"; |
||
3232 | $alldata = $Spotter->countAllMilitaryMonths($filter); |
||
3233 | foreach ($alldata as $number) { |
||
3234 | $this->addStat('military_flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),'',$filter_name); |
||
3235 | } |
||
3236 | if ($globalDebug) echo 'Count all aircrafts by months...'."\n"; |
||
3237 | $alldata = $Spotter->countAllMonthsAircrafts($filter); |
||
3238 | foreach ($alldata as $number) { |
||
3239 | $this->addStat('aircrafts_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),'',$filter_name); |
||
3240 | } |
||
3241 | if ($globalDebug) echo 'Count all real arrivals by months...'."\n"; |
||
3242 | $alldata = $Spotter->countAllMonthsRealArrivals($filter); |
||
3243 | foreach ($alldata as $number) { |
||
3244 | $this->addStat('realarrivals_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),'',$filter_name); |
||
3245 | } |
||
3246 | echo '...Departure'."\n"; |
||
3247 | $pall = $Spotter->getLast7DaysAirportsDeparture('',$filter); |
||
3248 | $dall = $Spotter->getLast7DaysDetectedAirportsDeparture('',$filter); |
||
3249 | foreach ($dall as $value) { |
||
3250 | $icao = $value['departure_airport_icao']; |
||
3251 | $ddate = $value['date']; |
||
3252 | $find = false; |
||
3253 | foreach ($pall as $pvalue) { |
||
3254 | if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate) { |
||
3255 | $pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count']; |
||
3256 | $find = true; |
||
3257 | break; |
||
3258 | } |
||
3259 | } |
||
3260 | if ($find === false) { |
||
3261 | $pall[] = $value; |
||
3262 | } |
||
3263 | } |
||
3264 | $alldata = $pall; |
||
3265 | foreach ($alldata as $number) { |
||
3266 | $this->addStatDepartureAirportsDaily($number['date'],$number['departure_airport_icao'],$number['departure_airport_name'],$number['departure_airport_city'],$number['departure_airport_country'],$number['departure_airport_count'],'',$filter_name); |
||
3267 | } |
||
3268 | echo '...Arrival'."\n"; |
||
3269 | $pall = $Spotter->getLast7DaysAirportsArrival('',$filter); |
||
3270 | $dall = $Spotter->getLast7DaysDetectedAirportsArrival('',$filter); |
||
3271 | foreach ($dall as $value) { |
||
3272 | $icao = $value['arrival_airport_icao']; |
||
3273 | $ddate = $value['date']; |
||
3274 | $find = false; |
||
3275 | foreach ($pall as $pvalue) { |
||
3276 | if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate) { |
||
3277 | $pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count']; |
||
3278 | $find = true; |
||
3279 | break; |
||
3280 | } |
||
3281 | } |
||
3282 | if ($find === false) { |
||
3283 | $pall[] = $value; |
||
3284 | } |
||
3285 | } |
||
3286 | $alldata = $pall; |
||
3287 | foreach ($alldata as $number) { |
||
3288 | $this->addStatArrivalAirportsDaily($number['date'],$number['arrival_airport_icao'],$number['arrival_airport_name'],$number['arrival_airport_city'],$number['arrival_airport_country'],$number['arrival_airport_count'],'',$filter_name); |
||
3289 | } |
||
3290 | echo 'Flights data...'."\n"; |
||
3291 | echo '-> countAllDatesLastMonth...'."\n"; |
||
3292 | $alldata = $Spotter->countAllDatesLastMonth($filter); |
||
3293 | foreach ($alldata as $number) { |
||
3294 | $this->addStatFlight('month',$number['date_name'],$number['date_count'], '',$filter_name); |
||
3295 | } |
||
3296 | echo '-> countAllDates...'."\n"; |
||
3297 | $previousdata = $this->countAllDates('',$filter_name); |
||
3298 | $alldata = $Common->array_merge_noappend($previousdata,$Spotter->countAllDates($filter)); |
||
3299 | $values = array(); |
||
3300 | foreach ($alldata as $cnt) { |
||
3301 | $values[] = $cnt['date_count']; |
||
3302 | } |
||
3303 | array_multisort($values,SORT_DESC,$alldata); |
||
3304 | array_splice($alldata,11); |
||
3305 | foreach ($alldata as $number) { |
||
3306 | $this->addStatFlight('date',$number['date_name'],$number['date_count'],'',$filter_name); |
||
3307 | } |
||
3308 | |||
3309 | echo '-> countAllHours...'."\n"; |
||
3310 | $alldata = $Spotter->countAllHours('hour',$filter); |
||
3311 | foreach ($alldata as $number) { |
||
3312 | $this->addStatFlight('hour',$number['hour_name'],$number['hour_count'],'',$filter_name); |
||
3313 | } |
||
3314 | echo 'Insert last stats update date...'."\n"; |
||
3315 | date_default_timezone_set('UTC'); |
||
3316 | $this->addLastStatsUpdate('last_update_stats_'.$filter_name,date('Y-m-d G:i:s')); |
||
3317 | if (isset($filter['DeleteLastYearStats']) && $filter['DeleteLastYearStats'] == true) { |
||
3318 | if (date('Y',strtotime($last_update_day)) != date('Y')) { |
||
3319 | $this->deleteOldStats($filter_name); |
||
3320 | $this->addLastStatsUpdate('last_update_stats_'.$filter_name,date('Y').'-01-01 00:00:00'); |
||
3321 | } |
||
3322 | } |
||
3323 | } |
||
3324 | } |
||
3325 | } |
||
3326 | |||
3327 | // Last year stats |
||
3328 | if (isset($lastyear) && $lastyear) { |
||
3329 | echo 'Data from last year...'."\n"; |
||
3330 | // SUM all previous month to put as year |
||
3331 | $previous_year = date('Y'); |
||
3332 | $previous_year--; |
||
3333 | $this->addStat('aircrafts_byyear',$this->getSumStats('aircrafts_bymonth',$previous_year),$previous_year.'-01-01 00:00:00'); |
||
3334 | $this->addStat('airlines_byyear',$this->getSumStats('airlines_bymonth',$previous_year),$previous_year.'-01-01 00:00:00'); |
||
3335 | $this->addStat('owner_byyear',$this->getSumStats('owner_bymonth',$previous_year),$previous_year.'-01-01 00:00:00'); |
||
3336 | $this->addStat('pilot_byyear',$this->getSumStats('pilot_bymonth',$previous_year),$previous_year.'-01-01 00:00:00'); |
||
3337 | $allairlines = $this->getAllAirlineNames(); |
||
3338 | foreach ($allairlines as $data) { |
||
3339 | $this->addStat('aircrafts_byyear',$this->getSumStats('aircrafts_bymonth',$previous_year,$data['airline_icao']),$previous_year.'-01-01 00:00:00',$data['airline_icao']); |
||
3340 | $this->addStat('airlines_byyear',$this->getSumStats('airlines_bymonth',$previous_year,$data['airline_icao']),$previous_year.'-01-01 00:00:00',$data['airline_icao']); |
||
3341 | $this->addStat('owner_byyear',$this->getSumStats('owner_bymonth',$previous_year,$data['airline_icao']),$previous_year.'-01-01 00:00:00',$data['airline_icao']); |
||
3342 | $this->addStat('pilot_byyear',$this->getSumStats('pilot_bymonth',$previous_year,$data['airline_icao']),$previous_year.'-01-01 00:00:00',$data['airline_icao']); |
||
3343 | } |
||
3344 | |||
3345 | if (isset($globalArchiveYear) && $globalArchiveYear) { |
||
3346 | if ($globalArchive) { |
||
3347 | $query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < '".date('Y')."-01-01 00:00:00'"; |
||
3348 | try { |
||
3349 | $sth = $this->db->prepare($query); |
||
3350 | $sth->execute(); |
||
3351 | } catch(PDOException $e) { |
||
3352 | return "error : ".$e->getMessage().' - query : '.$query."\n"; |
||
3353 | } |
||
3354 | $query = "INSERT INTO tracker_archive_output SELECT * FROM tracker_output WHERE tracker_output.date < '".date('Y')."-01-01 00:00:00'"; |
||
3355 | try { |
||
3356 | $sth = $this->db->prepare($query); |
||
3357 | $sth->execute(); |
||
3358 | } catch(PDOException $e) { |
||
3359 | return "error : ".$e->getMessage().' - query : '.$query."\n"; |
||
3360 | } |
||
3361 | $query = "INSERT INTO marine_archive_output SELECT * FROM marine_output WHERE marine_output.date < '".date('Y')."-01-01 00:00:00'"; |
||
3362 | try { |
||
3363 | $sth = $this->db->prepare($query); |
||
3364 | $sth->execute(); |
||
3365 | } catch(PDOException $e) { |
||
3366 | return "error : ".$e->getMessage().' - query : '.$query."\n"; |
||
3367 | } |
||
3368 | } |
||
3369 | echo 'Delete old data'."\n"; |
||
3370 | if ($globalDBdriver == 'mysql') { |
||
3371 | $query = "DELETE FROM spotter_output WHERE spotter_output.date < '".date('Y')."-01-01 00:00:00' LIMIT 10000"; |
||
3372 | } else { |
||
3373 | $query = "DELETE FROM spotter_output WHERE spotter_id IN (SELECT spotter_id FROM spotter_output WHERE spotter_output.date < '".date('Y')."-01-01 00:00:00' LIMIT 10000)"; |
||
3374 | } |
||
3375 | try { |
||
3376 | $sth = $this->db->prepare($query); |
||
3377 | $sth->execute(); |
||
3378 | } catch(PDOException $e) { |
||
3379 | return "error : ".$e->getMessage().' - query : '.$query."\n"; |
||
3380 | } |
||
3381 | if ($globalDBdriver == 'mysql') { |
||
3382 | $query = "DELETE FROM tracker_output WHERE tracker_output.date < '".date('Y')."-01-01 00:00:00' LIMIT 10000"; |
||
3383 | } else { |
||
3384 | $query = "DELETE FROM tracker_output WHERE tracker_id IN (SELECT tracker_id FROM tracker_output WHERE tracker_output.date < '".date('Y')."-01-01 00:00:00' LIMIT 10000)"; |
||
3385 | } |
||
3386 | try { |
||
3387 | $sth = $this->db->prepare($query); |
||
3388 | $sth->execute(); |
||
3389 | } catch(PDOException $e) { |
||
3390 | return "error : ".$e->getMessage().' - query : '.$query."\n"; |
||
3391 | } |
||
3392 | if ($globalDBdriver == 'mysql') { |
||
3393 | $query = "DELETE FROM marine_output WHERE marine_output.date < '".date('Y')."-01-01 00:00:00' LIMIT 10000"; |
||
3394 | } else { |
||
3395 | $query = "DELETE FROM marine_output WHERE marine_id IN (SELECT marine_id FROM marine_output WHERE marine_output.date < '".date('Y')."-01-01 00:00:00' LIMIT 10000)"; |
||
3396 | } |
||
3397 | try { |
||
3398 | $sth = $this->db->prepare($query); |
||
3399 | $sth->execute(); |
||
3400 | } catch(PDOException $e) { |
||
3401 | return "error : ".$e->getMessage().' - query : '.$query."\n"; |
||
3402 | } |
||
3403 | } |
||
3404 | if (isset($globalDeleteLastYearStats) && $globalDeleteLastYearStats) { |
||
3405 | $last_update = $this->getLastStatsUpdate('last_update_stats'); |
||
3406 | if (date('Y',strtotime($last_update[0]['value'])) != date('Y')) { |
||
3407 | $this->deleteOldStats(); |
||
3408 | $this->addLastStatsUpdate('last_update_stats',date('Y').'-01-01 00:00:00'); |
||
3409 | $lastyearupdate = true; |
||
3410 | } |
||
3411 | } |
||
3412 | } |
||
3413 | if ($globalArchiveMonths > 0) { |
||
3414 | if ($globalArchive) { |
||
3415 | echo 'Archive old data...'."\n"; |
||
3416 | if ($globalDBdriver == 'mysql') { |
||
3417 | //$query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
||
3418 | $query = "INSERT INTO spotter_archive_output (spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,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,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time) |
||
3419 | SELECT spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,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,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time |
||
3420 | FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
||
3421 | } else { |
||
3422 | $query = "INSERT INTO spotter_archive_output (spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,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,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time) |
||
3423 | SELECT |
||
3424 | spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,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,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time |
||
3425 | FROM spotter_output WHERE spotter_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS', 'YYYY/mm/01') AS TIMESTAMP)"; |
||
3426 | } |
||
3427 | try { |
||
3428 | $sth = $this->db->prepare($query); |
||
3429 | $sth->execute(); |
||
3430 | } catch(PDOException $e) { |
||
3431 | return "error : ".$e->getMessage(); |
||
3432 | } |
||
3433 | echo 'Archive old tracker data...'."\n"; |
||
3434 | if ($globalDBdriver == 'mysql') { |
||
3435 | $query = "INSERT INTO tracker_archive_output (tracker_archive_output_id,famtrackid, ident, latitude, longitude, altitude, heading, ground_speed, date, format_source, source_name, comment, type) |
||
3436 | SELECT tracker_id,famtrackid, ident, latitude, longitude, altitude, heading, ground_speed, date, format_source, source_name, comment, type |
||
3437 | FROM tracker_output WHERE tracker_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
||
3438 | } else { |
||
3439 | $query = "INSERT INTO tracker_archive_output (tracker_archive_output_id,famtrackid, ident, latitude, longitude, altitude, heading, ground_speed, date, format_source, source_name, comment, type) |
||
3440 | SELECT tracker_id,famtrackid, ident, latitude, longitude, altitude, heading, ground_speed, date, format_source, source_name, comment, type |
||
3441 | FROM tracker_output WHERE tracker_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS', 'YYYY/mm/01') AS TIMESTAMP)"; |
||
3442 | } |
||
3443 | try { |
||
3444 | $sth = $this->db->prepare($query); |
||
3445 | $sth->execute(); |
||
3446 | } catch(PDOException $e) { |
||
3447 | return "error : ".$e->getMessage(); |
||
3448 | } |
||
3449 | echo 'Archive old marine data...'."\n"; |
||
3450 | if ($globalDBdriver == 'mysql') { |
||
3451 | $query = "INSERT INTO marine_archive_output (marine_archive_output_id,fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) |
||
3452 | SELECT marine_id,fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date |
||
3453 | FROM marine_output WHERE marine_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
||
3454 | } else { |
||
3455 | $query = "INSERT INTO marine_archive_output (marine_archive_output_id,fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) |
||
3456 | SELECT marine_id,fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date |
||
3457 | FROM marine_output WHERE marine_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS', 'YYYY/mm/01') AS TIMESTAMP)"; |
||
3458 | } |
||
3459 | try { |
||
3460 | $sth = $this->db->prepare($query); |
||
3461 | $sth->execute(); |
||
3462 | } catch(PDOException $e) { |
||
3463 | return "error : ".$e->getMessage(); |
||
3464 | } |
||
3465 | } |
||
3466 | echo 'Deleting old data...'."\n"; |
||
3467 | if ($globalDBdriver == 'mysql') { |
||
3468 | $query = "DELETE FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
||
3469 | } else { |
||
3470 | $query = "DELETE FROM spotter_output WHERE spotter_id IN ( SELECT spotter_id FROM spotter_output WHERE spotter_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS', 'YYYY/mm/01') AS TIMESTAMP))"; |
||
3471 | } |
||
3472 | try { |
||
3473 | $sth = $this->db->prepare($query); |
||
3474 | $sth->execute(); |
||
3475 | } catch(PDOException $e) { |
||
3476 | return "error : ".$e->getMessage(); |
||
3477 | } |
||
3478 | echo 'Deleting old tracker data...'."\n"; |
||
3479 | if ($globalDBdriver == 'mysql') { |
||
3480 | $query = "DELETE FROM tracker_output WHERE tracker_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
||
3481 | } else { |
||
3482 | $query = "DELETE FROM tracker_output WHERE tracker_id IN ( SELECT tracker_id FROM tracker_output WHERE tracker_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS', 'YYYY/mm/01') AS TIMESTAMP))"; |
||
3483 | } |
||
3484 | try { |
||
3485 | $sth = $this->db->prepare($query); |
||
3486 | $sth->execute(); |
||
3487 | } catch(PDOException $e) { |
||
3488 | return "error : ".$e->getMessage(); |
||
3489 | } |
||
3490 | echo 'Deleting old marine data...'."\n"; |
||
3491 | if ($globalDBdriver == 'mysql') { |
||
3492 | $query = "DELETE FROM marine_output WHERE marine_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
||
3493 | } else { |
||
3494 | $query = "DELETE FROM marine_output WHERE marine_id IN ( SELECT marine_id FROM marine_output WHERE marine_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS', 'YYYY/mm/01') AS TIMESTAMP))"; |
||
3495 | } |
||
3496 | try { |
||
3497 | $sth = $this->db->prepare($query); |
||
3498 | $sth->execute(); |
||
3499 | } catch(PDOException $e) { |
||
3500 | return "error : ".$e->getMessage(); |
||
3501 | } |
||
3502 | } |
||
3503 | if (!isset($lastyearupdate)) { |
||
3504 | echo 'Insert last stats update date...'."\n"; |
||
3505 | date_default_timezone_set('UTC'); |
||
3506 | $this->addLastStatsUpdate('last_update_stats',date('Y-m-d G:i:s')); |
||
3507 | } |
||
3508 | if ($globalStatsResetYear) { |
||
3509 | require_once(dirname(__FILE__).'/../install/class.settings.php'); |
||
3510 | settings::modify_settings(array('globalStatsResetYear' => 'FALSE')); |
||
3511 | } |
||
3512 | } |
||
3513 | } |
||
3514 | |||
3515 | ?> |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: