Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / aircraft-statistics-airline-country.php
blobe0d7fae188286029d8b9bd1f48225c4184249693
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 $Spotter = new Spotter();
8 if (!isset($_GET['aircraft_type'])) {
9 header('Location: '.$globalURL.'/aircraft');
10 die();
12 $aircraft_type = filter_input(INPUT_GET,'aircraft_type',FILTER_SANITIZE_STRING);
13 $spotter_array = $Spotter->getSpotterDataByAircraft($aircraft_type,"0,1","");
16 if (!empty($spotter_array))
18 $title = sprintf(_("Most Common Airlines by Country from %s (%s)"),$spotter_array[0]['aircraft_name'],$spotter_array[0]['aircraft_type']);
19 require_once('header.php');
21 print '<div class="select-item">';
22 print '<form action="'.$globalURL.'/aircraft" method="get">';
23 print '<select name="aircraft_type" class="selectpicker" data-live-search="true">';
24 print '<option></option>';
25 $Stats = new Stats();
26 $aircraft_types = $Stats->getAllAircraftTypes();
27 if (empty($aircraft_types)) $aircraft_types = $Spotter->getAllAircraftTypes();
28 foreach($aircraft_types as $aircrafttype)
30 if($aircraft_type == $aircrafttype['aircraft_icao'])
32 print '<option value="'.$aircrafttype['aircraft_icao'].'" selected="selected">'.$aircrafttype['aircraft_name'].' ('.$aircrafttype['aircraft_icao'].')</option>';
33 } else {
34 print '<option value="'.$aircrafttype['aircraft_icao'].'">'.$aircrafttype['aircraft_name'].' ('.$aircrafttype['aircraft_icao'].')</option>';
37 print '</select>';
38 print '<button type="submit"><i class="fa fa-angle-double-right"></i></button>';
39 print '</form>';
40 print '</div>';
41 print '<br />';
43 if ($aircraft_type != "NA")
45 print '<div class="info column">';
46 print '<h1>'.$spotter_array[0]['aircraft_name'].' ('.$spotter_array[0]['aircraft_type'].')</h1>';
47 print '<div><span class="label">Name</span>'.$spotter_array[0]['aircraft_name'].'</div>';
48 print '<div><span class="label">ICAO</span>'.$spotter_array[0]['aircraft_type'].'</div>';
49 print '<div><span class="label">Manufacturer</span><a href="'.$globalURL.'/manufacturer/'.strtolower(str_replace(" ", "-", $spotter_array[0]['aircraft_manufacturer'])).'">'.$spotter_array[0]['aircraft_manufacturer'].'</a></div>';
50 print '</div>';
51 } else {
52 print '<div class="alert alert-warning">'._("This special aircraft profile shows all flights in where the aircraft type is unknown.").'</div>';
54 include('aircraft-sub-menu.php');
55 print '<div class="column">';
56 print '<h2>'._("Most Common Airlines by Country").'</h2>';
57 print '<p>'.sprintf(_("The statistic below shows the most common airlines by Country of origin of flights from <strong>%s (%s)</strong>."),$spotter_array[0]['aircraft_name'],$spotter_array[0]['aircraft_type']).'</p>';
59 $airline_array = $Spotter->countAllAirlineCountriesByAircraft($aircraft_type);
60 print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
61 print '<script type="text/javascript" src="'.$globalURL.'/js/topojson.v2.min.js"></script>';
62 print '<script type="text/javascript" src="'.$globalURL.'/js/datamaps.world.min.js"></script>';
63 print '<div id="chartCountry" class="chart" width="100%"></div><script>';
64 print 'var series = [';
65 $country_data = '';
66 foreach($airline_array as $airline_item)
68 $country_data .= '[ "'.$airline_item['airline_country_iso3'].'",'.$airline_item['airline_country_count'].'],';
70 $country_data = substr($country_data, 0, -1);
71 print $country_data;
72 print '];';
73 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);';
74 print 'var paletteScale = d3.scale.log().domain([minValue,maxValue]).range(["#EFEFFF","#001830"]);';
75 print 'series.forEach(function(item){var iso = item[0], value = item[1]; dataset[iso] = { numberOfThings: value, fillColor: paletteScale(value) };});';
76 print 'new Datamap({
77 element: document.getElementById("chartCountry"),
78 projection: "mercator", // big world map
79 fills: { defaultFill: "#F5F5F5" },
80 data: dataset,
81 responsive: true,
82 geographyConfig: {
83 borderColor: "#DEDEDE",
84 highlightBorderWidth: 2,
85 highlightFillColor: function(geo) {
86 return geo["fillColor"] || "#F5F5F5";
88 highlightBorderColor: "#B7B7B7",
89 done: function(datamap) {
90 datamap.svg.call(d3.behavior.zoom().on("zoom", redraw));
91 function redraw() {
92 datamap.svg.selectAll("g").attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
95 popupTemplate: function(geo, data) {
96 if (!data) { return ; }
97 return ['."'".'<div class="hoverinfo">'."','<strong>', geo.properties.name, '</strong>','<br>Count: <strong>', data.numberOfThings, '</strong>','</div>'].join('');
100 });";
101 print '</script>';
102 if (!empty($airline_array))
104 print '<div class="table-responsive">';
105 print '<table class="common-country">';
106 print '<thead>';
107 print '<th></th>';
108 print '<th>'._("Country").'</th>';
109 print '<th>'._("# of times").'</th>';
110 print '</thead>';
111 print '<tbody>';
112 $i = 1;
113 foreach($airline_array as $airline_item)
115 print '<tr>';
116 print '<td><strong>'.$i.'</strong></td>';
117 print '<td>';
118 print '<a href="'.$globalURL.'/country/'.strtolower(str_replace(" ", "-", $airline_item['airline_country'])).'">'.$airline_item['airline_country'].'</a>';
119 print '</td>';
120 print '<td>';
121 print $airline_item['airline_country_count'];
122 print '</td>';
123 print '</tr>';
124 $i++;
126 print '<tbody>';
127 print '</table>';
128 print '</div>';
130 print '</div>';
131 } else {
132 $title = _("Aircraft Type");
133 require_once('header.php');
134 print '<h1>'._("Error").'</h1>';
135 print '<p>'._("Sorry, the aircraft type does not exist in this database. :(").'</p>';
137 require_once('footer.php');