Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / country-statistics-arrival-airport-country.php
blob0390b31261668452b11f41861b69b3e58776f3b5
1 <?php
2 require_once('require/class.Connection.php');
3 require_once('require/class.Spotter.php');
4 require_once('require/class.Language.php');
5 if (!isset($_GET['country'])) {
6 header('Location: '.$globalURL.'/country');
7 die();
9 $Spotter = new Spotter();
10 $country = ucwords(str_replace("-", " ", urldecode(filter_input(INPUT_GET,'country',FILTER_SANITIZE_STRING))));
11 $sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING);
13 if (isset($_GET['sort'])) {
14 $spotter_array = $Spotter->getSpotterDataByCountry($country, "0,1", $sort);
15 } else {
16 $spotter_array = $Spotter->getSpotterDataByCountry($country, "0,1", '');
19 if (!empty($spotter_array))
21 $title = sprintf(_("Most Common Arrival Airports by Country from %s"),$country);
22 require_once('header.php');
23 print '<div class="select-item">';
24 print '<form action="'.$globalURL.'/country" method="post">';
25 print '<select name="country" class="selectpicker" data-live-search="true">';
26 print '<option></option>';
27 $all_countries = $Spotter->getAllCountries();
28 foreach($all_countries as $all_country)
30 if($country == $all_country['country'])
32 print '<option value="'.strtolower(str_replace(" ", "-", $all_country['country'])).'" selected="selected">'.$all_country['country'].'</option>';
33 } else {
34 print '<option value="'.strtolower(str_replace(" ", "-", $all_country['country'])).'">'.$all_country['country'].'</option>';
37 print '</select>';
38 print '<button type="submit"><i class="fa fa-angle-double-right"></i></button>';
39 print '</form>';
40 print '</div>';
42 if ($_GET['country'] != "NA")
44 print '<div class="info column">';
45 print '<h1>'.sprintf(_("Airports &amp; Airlines from %s"),$country).'</h1>';
46 print '</div>';
47 } else {
48 print '<div class="alert alert-warning">'._("This special country profile shows all flights that do <u>not</u> have a country of a airline or departure/arrival airport associated with them.").'</div>';
51 include('country-sub-menu.php');
52 print '<div class="column">';
53 print '<h2>'._("Most Common Arrival Airports by Country").'</h2>';
54 print '<p>'.sprintf(_("The statistic below shows all arrival airports by Country of origin of flights of airports &amp; airlines from <strong>%s</strong>."),$country).'</p>';
56 $airport_country_array = $Spotter->countAllArrivalAirportCountriesByCountry($country);
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>';
61 print '<div id="chartCountry" class="chart" width="100%"></div><script>';
62 print 'var series = [';
63 $country_data = '';
64 foreach($airport_country_array as $airport_item)
66 $country_data .= '[ "'.$airport_item['arrival_airport_country_iso3'].'",'.$airport_item['airport_arrival_country_count'].'],';
68 $country_data = substr($country_data, 0, -1);
69 print $country_data;
70 print '];';
71 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);';
72 print 'var paletteScale = d3.scale.log().domain([minValue,maxValue]).range(["#EFEFFF","#001830"]);';
73 print 'series.forEach(function(item){var iso = item[0], value = item[1]; dataset[iso] = { numberOfThings: value, fillColor: paletteScale(value) };});';
74 print 'new Datamap({
75 element: document.getElementById("chartCountry"),
76 projection: "mercator", // big world map
77 fills: { defaultFill: "#F5F5F5" },
78 data: dataset,
79 responsive: true,
80 geographyConfig: {
81 borderColor: "#DEDEDE",
82 highlightBorderWidth: 2,
83 highlightFillColor: function(geo) {
84 return geo["fillColor"] || "#F5F5F5";
86 highlightBorderColor: "#B7B7B7",
87 done: function(datamap) {
88 datamap.svg.call(d3.behavior.zoom().on("zoom", redraw));
89 function redraw() {
90 datamap.svg.selectAll("g").attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
93 popupTemplate: function(geo, data) {
94 if (!data) { return ; }
95 return ['."'".'<div class="hoverinfo">'."','<strong>', geo.properties.name, '</strong>','<br>Count: <strong>', data.numberOfThings, '</strong>','</div>'].join('');
98 });";
99 print '</script>';
101 if (!empty($airport_country_array))
103 print '<div class="table-responsive">';
104 print '<table class="common-country table-striped">';
105 print '<thead>';
106 print '<th></th>';
107 print '<th>'._("Country").'</th>';
108 print '<th>'._("# of times").'</th>';
109 print '</thead>';
110 print '<tbody>';
111 $i = 1;
112 foreach($airport_country_array as $airport_item)
114 print '<tr>';
115 print '<td><strong>'.$i.'</strong></td>';
116 print '<td>';
117 print '<a href="'.$globalURL.'/country/'.strtolower(str_replace(" ", "-", $airport_item['arrival_airport_country'])).'">'.$airport_item['arrival_airport_country'].'</a>';
118 print '</td>';
119 print '<td>';
120 print $airport_item['airport_arrival_country_count'];
121 print '</td>';
122 print '</tr>';
123 $i++;
125 print '<tbody>';
126 print '</table>';
127 print '</div>';
129 print '</div>';
130 } else {
131 $title = _("Country");
132 require_once('header.php');
133 print '<h1>'._("Error").'</h1>';
134 print '<p>'._("Sorry, the country does not exist in this database. :(").'</p>';
137 require_once('footer.php');