Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / manufacturer-statistics-arrival-airport-country.php
blobf8d53570a26ac0a380f7253c3e2b3c63bc3e0ad7
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['aircraft_manufacturer'])) {
7 header('Location: '.$globalURL.'/manufacturer');
8 die();
11 $Spotter = new Spotter();
12 $manufacturer = ucwords(str_replace("-", " ", urldecode(filter_input(INPUT_GET,'aircraft_manufacturer',FILTER_SANITIZE_STRING))));
13 $sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING);
14 $spotter_array = $Spotter->getSpotterDataByManufacturer($manufacturer,"0,1", $sort);
16 if (!empty($spotter_array))
18 $title = sprintf(_("Most Common Arrival Airports by Country from %s"),$manufacturer);
20 require_once('header.php');
21 print '<div class="select-item">';
22 print '<form action="'.$globalURL.'/manufacturer" method="post">';
23 print '<select name="aircraft_manufacturer" class="selectpicker" data-live-search="true">';
24 $Stats = new Stats();
25 $all_manufacturers = $Stats->getAllManufacturers();
26 if (empty($all_manufacturers)) $all_manufacturers = $Spotter->getAllManufacturers();
27 foreach($all_manufacturers as $all_manufacturer)
29 if($_GET['aircraft_manufacturer'] == strtolower(str_replace(" ", "-", $all_manufacturer['aircraft_manufacturer'])))
31 print '<option value="'.strtolower(str_replace(" ", "-", $all_manufacturer['aircraft_manufacturer'])).'" selected="selected">'.$all_manufacturer['aircraft_manufacturer'].'</option>';
32 } else {
33 print '<option value="'.strtolower(str_replace(" ", "-", $all_manufacturer['aircraft_manufacturer'])).'">'.$all_manufacturer['aircraft_manufacturer'].'</option>';
36 print '</select>';
37 print '<button type="submit"><i class="fa fa-angle-double-right"></i></button>';
38 print '</form>';
39 print '</div>';
41 print '<div class="info column">';
42 print '<h1>'.$manufacturer.'</h1>';
43 print '</div>';
45 include('manufacturer-sub-menu.php');
46 print '<div class="column">';
47 print '<h2>'._("Most Common Arrival Airports by Country").'</h2>';
48 print '<p>'.sprintf(_("The statistic below shows all arrival airports by Country of origin of flights from <strong>%s</strong>."),$manufacturer).'</p>';
49 $airport_country_array = $Spotter->countAllArrivalAirportCountriesByManufacturer($manufacturer);
50 print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
51 print '<script type="text/javascript" src="'.$globalURL.'/js/topojson.v2.min.js"></script>';
52 print '<script type="text/javascript" src="'.$globalURL.'/js/datamaps.world.min.js"></script>';
53 print '<div id="chartCountry" class="chart" width="100%"></div><script>';
54 print 'var series = [';
55 $country_data = '';
56 foreach($airport_country_array as $airport_item)
58 $country_data .= '[ "'.$airport_item['arrival_airport_country_iso3'].'",'.$airport_item['airport_arrival_country_count'].'],';
60 $country_data = substr($country_data, 0, -1);
61 print $country_data;
62 print '];';
63 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);';
64 print 'var paletteScale = d3.scale.log().domain([minValue,maxValue]).range(["#EFEFFF","#001830"]);';
65 print 'series.forEach(function(item){var iso = item[0], value = item[1]; dataset[iso] = { numberOfThings: value, fillColor: paletteScale(value) };});';
66 print 'new Datamap({
67 element: document.getElementById("chartCountry"),
68 projection: "mercator", // big world map
69 fills: { defaultFill: "#F5F5F5" },
70 data: dataset,
71 responsive: true,
72 geographyConfig: {
73 borderColor: "#DEDEDE",
74 highlightBorderWidth: 2,
75 highlightFillColor: function(geo) {
76 return geo["fillColor"] || "#F5F5F5";
78 highlightBorderColor: "#B7B7B7",
79 done: function(datamap) {
80 datamap.svg.call(d3.behavior.zoom().on("zoom", redraw));
81 function redraw() {
82 datamap.svg.selectAll("g").attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
85 popupTemplate: function(geo, data) {
86 if (!data) { return ; }
87 return ['."'".'<div class="hoverinfo">'."','<strong>', geo.properties.name, '</strong>','<br>Count: <strong>', data.numberOfThings, '</strong>','</div>'].join('');
90 });";
91 print '</script>';
93 if (!empty($airport_country_array))
95 print '<div class="table-responsive">';
96 print '<table class="common-country table-striped">';
97 print '<thead>';
98 print '<th></th>';
99 print '<th>'._("Country").'</th>';
100 print '<th>'._("# of times").'</th>';
101 print '</thead>';
102 print '<tbody>';
103 $i = 1;
104 foreach($airport_country_array as $airport_item)
106 print '<tr>';
107 print '<td><strong>'.$i.'</strong></td>';
108 print '<td>';
109 print '<a href="'.$globalURL.'/country/'.strtolower(str_replace(" ", "-", $airport_item['arrival_airport_country'])).'">'.$airport_item['arrival_airport_country'].'</a>';
110 print '</td>';
111 print '<td>';
112 print $airport_item['airport_arrival_country_count'];
113 print '</td>';
114 print '</tr>';
115 $i++;
117 print '<tbody>';
118 print '</table>';
119 print '</div>';
121 print '</div>';
122 } else {
123 $title = _("Manufacturer");
124 require_once('header.php');
125 print '<h1>'._("Error").'</h1>';
126 print '<p>'._("Sorry, the aircraft manufacturer does not exist in this database. :(").'</p>';
129 require_once('footer.php');