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