Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / airline-statistics-departure-airport-country.php
blobe300dd05d2a61a653550f19eaeed6e864685ea2b
1 <?php
2 require_once('require/class.Connection.php');
3 require_once('require/class.Spotter.php');
4 require_once('require/class.Stats.php');
5 require_once('require/class.Language.php');
6 if (!isset($_GET['airline'])) {
7 header('Location: '.$globalURL.'/airline');
8 die();
10 $airline = urldecode(filter_input(INPUT_GET,'airline',FILTER_SANITIZE_STRING));
11 $Spotter = new Spotter();
12 $alliance = false;
13 if (strpos($airline,'alliance_') !== FALSE) {
14 $alliance = true;
15 } else {
16 $spotter_array = $Spotter->getSpotterDataByAirline($airline,"0,1","");
19 if (!empty($spotter_array) || $alliance === true)
21 if ($alliance) {
22 $title = sprintf(_("Most Common Departure Airports by Country from %s"),str_replace('_',' ',str_replace('alliance_','',$airline)));
23 } else {
24 $title = sprintf(_("Most Common Departure Airports by Country from %s (%s)"),$spotter_array[0]['airline_name'],$spotter_array[0]['airline_icao']);
26 require_once('header.php');
27 print '<div class="select-item">';
28 print '<form action="'.$globalURL.'/airline" method="post">';
29 print '<select name="airline" class="selectpicker" data-live-search="true">';
30 print '<option></option>';
31 $alliances = $Spotter->getAllAllianceNames();
32 if (!empty($alliances)) {
33 foreach ($alliances as $al) {
34 if ($alliance && str_replace('_',' ',str_replace('alliance_','',$airline)) == $al['alliance']) {
35 print '<option value="alliance_'.str_replace(' ','_',$al['alliance']).'" selected>'.$al['alliance'].'</option>';
36 } else {
37 print '<option value="alliance_'.str_replace(' ','_',$al['alliance']).'">'.$al['alliance'].'</option>';
40 print '<option disabled>──────────────────</option>';
42 $Stats = new Stats();
43 $airline_names = $Stats->getAllAirlineNames();
44 if (empty($airline_names)) $airline_names = $Spotter->getAllAirlineNames();
45 foreach($airline_names as $airline_name)
47 if($airline == $airline_name['airline_icao'])
49 print '<option value="'.$airline_name['airline_icao'].'" selected="selected">'.$airline_name['airline_name'].' ('.$airline_name['airline_icao'].')</option>';
50 } else {
51 print '<option value="'.$airline_name['airline_icao'].'">'.$airline_name['airline_name'].' ('.$airline_name['airline_icao'].')</option>';
54 print '</select>';
55 print '<button type="submit"><i class="fa fa-angle-double-right"></i></button>';
56 print '</form>';
57 print '</div>';
58 print '<br />';
60 if ($airline != "NA")
62 if ($alliance === false) {
63 print '<div class="info column">';
64 print '<h1>'.$spotter_array[0]['airline_name'].' ('.$spotter_array[0]['airline_icao'].')</h1>';
65 if ($globalIVAO && @getimagesize($globalURL.'/images/airlines/'.$spotter_array[0]['airline_icao'].'.gif'))
67 print '<img src="'.$globalURL.'/images/airlines/'.$spotter_array[0]['airline_icao'].'.gif" alt="'.$spotter_array[0]['airline_name'].' ('.$spotter_array[0]['airline_icao'].')" title="'.$spotter_array[0]['airline_name'].' ('.$spotter_array[0]['airline_icao'].')" class="logo" />';
69 elseif (@getimagesize($globalURL.'/images/airlines/'.$spotter_array[0]['airline_icao'].'.png'))
71 print '<img src="'.$globalURL.'/images/airlines/'.$spotter_array[0]['airline_icao'].'.png" alt="'.$spotter_array[0]['airline_name'].' ('.$spotter_array[0]['airline_icao'].')" title="'.$spotter_array[0]['airline_name'].' ('.$spotter_array[0]['airline_icao'].')" class="logo" />';
73 print '<div><span class="label">'._("Name").'</span>'.$spotter_array[0]['airline_name'].'</div>';
74 print '<div><span class="label">'._("Country").'</span>'.$spotter_array[0]['airline_country'].'</div>';
75 print '<div><span class="label">'._("ICAO").'</span>'.$spotter_array[0]['airline_icao'].'</div>';
76 print '<div><span class="label">'._("IATA").'</span>'.$spotter_array[0]['airline_iata'].'</div>';
77 print '<div><span class="label">'._("Callsign").'</span>'.$spotter_array[0]['airline_callsign'].'</div>';
78 print '<div><span class="label">'._("Type").'</span>'.ucwords($spotter_array[0]['airline_type']).'</div>';
79 print '</div>';
80 } else {
81 print '<div class="info column">';
82 print '<h1>'.str_replace('_',' ',str_replace('alliance_','',$airline)).'</h1>';
83 if (@getimagesize($globalURL.'/images/airlines/'.str_replace('alliance_','',$airline).'.png') || @getimagesize('images/airlines/'.str_replace('alliance_','',$airline).'.png'))
85 print '<img src="'.$globalURL.'/images/airlines/'.str_replace('alliance_','',$airline).'.png" alt="'.str_replace('_',' ',str_replace('alliance_','',$airline)).'" title="'.str_replace('_',' ',str_replace('alliance_','',$airline)).'" class="logo" />';
87 print '<div><span class="label">'._("Name").'</span>'.str_replace('_',' ',str_replace('alliance_','',$airline)).'</div>';
88 print '</div>';
90 } else {
91 print '<div class="alert alert-warning">'._("This special airline profile shows all flights that do <u>not</u> have a airline associated with them.").'</div>';
94 include('airline-sub-menu.php');
95 print '<div class="column">';
96 print '<h2>'._("Most Common Departure Airports by Country").'</h2>';
97 if ($alliance) {
98 print '<p>'.sprintf(_("The statistic below shows all departure airports by Country of origin of flights from <strong>%s</strong>."),str_replace('_',' ',str_replace('alliance_','',$airline))).'</p>';
99 } else {
100 print '<p>'.sprintf(_("The statistic below shows all departure airports by Country of origin of flights from <strong>%s</strong>."),$spotter_array[0]['airline_name']).'</p>';
103 if ($alliance) {
104 $airport_country_array = $Spotter->countAllDepartureAirportCountriesByAirline('',array('alliance' => str_replace('_',' ',str_replace('alliance_','',$airline))));
105 } else {
106 $airport_country_array = $Spotter->countAllDepartureAirportCountriesByAirline($airline);
109 $airport_country_array = $Stats->countAllDepartureCountries(true,$airline);
110 print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
111 print '<script type="text/javascript" src="'.$globalURL.'/js/topojson.v2.min.js"></script>';
112 print '<script type="text/javascript" src="'.$globalURL.'/js/datamaps.world.min.js"></script>';
113 print '<div id="chartCountry" class="chart" width="100%"></div><script>';
114 print 'var series = [';
115 $country_data = '';
116 foreach($airport_country_array as $airport_item)
118 $country_data .= '[ "'.$airport_item['airport_departure_country_iso3'].'",'.$airport_item['airport_departure_country_count'].'],';
120 $country_data = substr($country_data, 0, -1);
121 print $country_data;
122 print '];';
123 print 'var dataset = {};var onlyValues = series.map(function(obj){ return obj[1]; });var minValue = Math.min.apply(null, onlyValues), maxValue = Math.max.apply(null, onlyValues);';
124 print 'var paletteScale = d3.scale.log().domain([minValue,maxValue]).range(["#EFEFFF","#001830"]);';
125 print 'series.forEach(function(item){var iso = item[0], value = item[1]; dataset[iso] = { numberOfThings: value, fillColor: paletteScale(value) };});';
126 print 'new Datamap({
127 element: document.getElementById("chartCountry"),
128 projection: "mercator", // big world map
129 fills: { defaultFill: "#F5F5F5" },
130 data: dataset,
131 responsive: true,
132 geographyConfig: {
133 borderColor: "#DEDEDE",
134 highlightBorderWidth: 2,
135 highlightFillColor: function(geo) {
136 return geo["fillColor"] || "#F5F5F5";
138 highlightBorderColor: "#B7B7B7",
139 done: function(datamap) {
140 datamap.svg.call(d3.behavior.zoom().on("zoom", redraw));
141 function redraw() {
142 datamap.svg.selectAll("g").attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
145 popupTemplate: function(geo, data) {
146 if (!data) { return ; }
147 return ['."'".'<div class="hoverinfo">'."','<strong>', geo.properties.name, '</strong>','<br>Count: <strong>', data.numberOfThings, '</strong>','</div>'].join('');
150 });";
151 print '</script>';
152 if (!empty($airport_country_array))
154 print '<div class="table-responsive">';
155 print '<table class="common-country table-striped">';
156 print '<thead>';
157 print '<th></th>';
158 print '<th>'._("Country").'</th>';
159 print '<th>'._("# of times").'</th>';
160 print '</thead>';
161 print '<tbody>';
162 $i = 1;
163 foreach($airport_country_array as $airport_item)
165 print '<tr>';
166 print '<td><strong>'.$i.'</strong></td>';
167 print '<td>';
168 print '<a href="'.$globalURL.'/country/'.strtolower(str_replace(" ", "-", $airport_item['airport_departure_country'])).'">'.$airport_item['airport_departure_country'].'</a>';
169 print '</td>';
170 print '<td>';
171 print $airport_item['airport_departure_country_count'];
172 print '</td>';
173 print '</tr>';
174 $i++;
176 print '<tbody>';
177 print '</table>';
178 print '</div>';
180 print '</div>';
181 } else {
182 $title = _("Airline Statistic");
183 require_once('header.php');
184 print '<h1>'._("Error").'</h1>';
185 print '<p>'._("Sorry, the airline does not exist in this database. :(").'</p>';
188 require_once('footer.php');