Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / airline-statistics-arrival-airport.php
blob80c18a95e8e674a011090ed8ec295c38a2862d75
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 Arrival Airports from %s"),str_replace('_',' ',str_replace('alliance_','',$airline)));
23 } else {
24 $title = sprintf(_("Most Common Arrival Airports 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($ariline_names)) $airline_names = $Spotter->getAllAirlineNames();
45 foreach($airline_names as $airline_name)
47 if($_GET['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 Arrival Airports").'</h2>';
97 if ($alliance) {
98 print '<p>'.sprintf(_("The statistic below shows all arrival airports of flights from <strong>%s</strong>."),str_replace('_',' ',str_replace('alliance_','',$airline))).'</p>';
99 } else {
100 print '<p>'.sprintf(_("The statistic below shows all arrival airports of flights from <strong>%s</strong>."),$spotter_array[0]['airline_name']).'</p>';
103 if ($alliance) {
104 $airport_airport_array = $Spotter->countAllArrivalAirportsByAirline('',array('alliance' => str_replace('_',' ',str_replace('alliance_','',$airline))));
105 } else {
106 $airport_airport_array = $Spotter->countAllArrivalAirportsByAirline($airline);
109 $airport_airport_array = $Stats->countAllArrivalAirports(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="chartAirport" class="chart" width="100%"></div>';
114 print '<script>';
115 print 'var series = [';
116 $airport_data = '';
117 foreach($airport_airport_array as $airport_item)
119 $airport_data .= '[ "'.$airport_item['airport_arrival_icao_count'].'", "'.$airport_item['airport_arrival_name'].' ('.$airport_item['airport_arrival_icao'].')",'.$airport_item['airport_arrival_latitude'].','.$airport_item['airport_arrival_longitude'].'],';
121 $airport_data = substr($airport_data, 0, -1);
122 print $airport_data;
123 print '];'."\n";
124 print 'var onlyValues = series.map(function(obj){ return obj[0]; });var minValue = Math.min.apply(null, onlyValues), maxValue = Math.max.apply(null, onlyValues);'."\n";
125 print 'var paletteScale = d3.scale.log().domain([minValue,maxValue]).range(["#EFEFFF","#001830"]);'."\n";
126 print 'var radiusScale = d3.scale.log().domain([minValue,maxValue]).range([0,10]);'."\n";
127 print 'var dataset = [];'."\n";
128 print 'var colorset = [];'."\n";
129 print 'colorset["defaultFill"] = "#F5F5F5";';
130 print 'series.forEach(function(item){'."\n";
131 print 'var cnt = item[0], nm = item[1], lat = item[2], long = item[3];'."\n";
132 print 'colorset[nm] = paletteScale(cnt);';
133 print 'dataset.push({ count: cnt, name: nm, radius: Math.floor(radiusScale(cnt)), latitude: lat, longitude: long, fillKey: nm });'."\n";
134 print '});'."\n";
135 print 'var bbl = new Datamap({
136 element: document.getElementById("chartAirport"),
137 projection: "mercator", // big world map
138 fills: colorset,
139 responsive: true,
140 geographyConfig: {
141 borderColor: "#DEDEDE",
142 highlightBorderWidth: 2,
143 highlightFillColor: function(geo) {
144 return geo["fillColor"] || "#F5F5F5";
146 highlightBorderColor: "#B7B7B7"},
147 done: function(datamap) {
148 datamap.svg.call(d3.behavior.zoom().on("zoom", redraw));
149 function redraw() {
150 datamap.svg.selectAll("g").attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
154 bbl.bubbles(dataset,{
155 popupTemplate: function(geo, data) {
156 if (!data) { return ; }
157 return ['."'".'<div class="hoverinfo">'."','<strong>', data.name, '</strong>','<br>Count: <strong>', data.count, '</strong>','</div>'].join('');
159 });";
160 print '</script>';
161 print '<div class="table-responsive">';
162 print '<table class="common-airport table-striped">';
163 print '<thead>';
164 print '<th></th>';
165 print '<th>'._("Airport").'</th>';
166 print '<th>'._("Country").'</th>';
167 print '<th>'._("# of times").'</th>';
168 print '<th></th>';
169 print '</thead>';
170 print '<tbody>';
171 $i = 1;
172 foreach($airport_airport_array as $airport_item)
174 print '<tr>';
175 print '<td><strong>'.$i.'</strong></td>';
176 print '<td>';
177 print '<a href="'.$globalURL.'/airport/'.$airport_item['airport_arrival_icao'].'">'.$airport_item['airport_arrival_city'].', '.$airport_item['airport_arrival_country'].' ('.$airport_item['airport_arrival_icao'].')</a>';
178 print '</td>';
179 print '<td>';
180 print '<a href="'.$globalURL.'/country/'.strtolower(str_replace(" ", "-", $airport_item['airport_arrival_country'])).'">'.$airport_item['airport_arrival_country'].'</a>';
181 print '</td>';
182 print '<td>';
183 print $airport_item['airport_arrival_icao_count'];
184 print '</td>';
185 print '<td><a href="'.$globalURL.'/search?arrival_airport_route='.$airport_item['airport_arrival_icao'].'&airline='.$airline.'">'._("Search flights").'</a></td>';
186 print '</tr>';
187 $i++;
189 print '<tbody>';
190 print '</table>';
191 print '</div>';
192 print '</div>';
193 } else {
194 $title = _("Airline Statistic");
195 require_once('header.php');
196 print '<h1>'._("Error").'</h1>';
197 print '<p>'._("Sorry, the airline does not exist in this database. :(").'</p>';
200 require_once('footer.php');