Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / ident-statistics-arrival-airport-country.php
blob935b0dca34ef65a2acb1db0ca7e2630c222eb41d
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['ident'])) {
6 header('Location: '.$globalURL.'/ident');
7 die();
9 $Spotter = new Spotter();
10 $sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING);
11 $ident = filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING);
12 $spotter_array = $Spotter->getSpotterDataByIdent($ident,"0,1", $sort);
14 if (!empty($spotter_array))
16 $title = sprintf(_("Most Common Arrival Airports by Country of %s"),$spotter_array[0]['ident']);
17 require_once('header.php');
18 print '<div class="info column">';
19 print '<h1>'.$spotter_array[0]['ident'].'</h1>';
20 print '<div><span class="label">'._("Ident").'</span>'.$spotter_array[0]['ident'].'</div>';
21 print '<div><span class="label">'._("Airline").'</span><a href="'.$globalURL.'/airline/'.$spotter_array[0]['airline_icao'].'">'.$spotter_array[0]['airline_name'].'</a></div>';
22 print '</div>';
24 include('ident-sub-menu.php');
25 print '<div class="column">';
26 print '<h2>'._("Most Common Arrival Airports by Country").'</h2>';
27 print '<p>'.sprintf(_("The statistic below shows all arrival airports by Country of origin of flights with the ident/callsign <strong>%s</strong>."),$spotter_array[0]['ident']).'</p>';
28 $airport_country_array = $Spotter->countAllArrivalAirportCountriesByIdent($ident);
29 print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
30 print '<script type="text/javascript" src="'.$globalURL.'/js/topojson.v2.min.js"></script>';
31 print '<script type="text/javascript" src="'.$globalURL.'/js/datamaps.world.min.js"></script>';
32 print '<div id="chartCountry" class="chart" width="100%"></div><script>';
33 print 'var series = [';
34 $country_data = '';
35 foreach($airport_country_array as $airport_item)
37 $country_data .= '[ "'.$airport_item['arrival_airport_country_iso3'].'",'.$airport_item['airport_arrival_country_count'].'],';
39 $country_data = substr($country_data, 0, -1);
40 print $country_data;
41 print '];';
42 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);';
43 print 'var paletteScale = d3.scale.log().domain([minValue,maxValue]).range(["#EFEFFF","#001830"]);';
44 print 'series.forEach(function(item){var iso = item[0], value = item[1]; dataset[iso] = { numberOfThings: value, fillColor: paletteScale(value) };});';
45 print 'new Datamap({
46 element: document.getElementById("chartCountry"),
47 projection: "mercator", // big world map
48 fills: { defaultFill: "#F5F5F5" },
49 data: dataset,
50 responsive: true,
51 geographyConfig: {
52 borderColor: "#DEDEDE",
53 highlightBorderWidth: 2,
54 highlightFillColor: function(geo) {
55 return geo["fillColor"] || "#F5F5F5";
57 highlightBorderColor: "#B7B7B7",
58 done: function(datamap) {
59 datamap.svg.call(d3.behavior.zoom().on("zoom", redraw));
60 function redraw() {
61 datamap.svg.selectAll("g").attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
64 popupTemplate: function(geo, data) {
65 if (!data) { return ; }
66 return ['."'".'<div class="hoverinfo">'."','<strong>', geo.properties.name, '</strong>','<br>Count: <strong>', data.numberOfThings, '</strong>','</div>'].join('');
69 });";
70 print '</script>';
72 if (!empty($airport_country_array))
74 print '<div class="table-responsive">';
75 print '<table class="common-country table-striped">';
76 print '<thead>';
77 print '<th></th>';
78 print '<th>'._("Country").'</th>';
79 print '<th>'._("# of times").'</th>';
80 print '</thead>';
81 print '<tbody>';
82 $i = 1;
83 foreach($airport_country_array as $airport_item)
85 print '<tr>';
86 print '<td><strong>'.$i.'</strong></td>';
87 print '<td>';
88 print '<a href="'.$globalURL.'/country/'.strtolower(str_replace(" ", "-", $airport_item['arrival_airport_country'])).'">'.$airport_item['arrival_airport_country'].'</a>';
89 print '</td>';
90 print '<td>';
91 print $airport_item['airport_arrival_country_count'];
92 print '</td>';
93 print '</tr>';
94 $i++;
96 print '<tbody>';
97 print '</table>';
98 print '</div>';
100 print '</div>';
101 } else {
102 $title = _("Ident");
103 require_once('header.php');
104 print '<h1>'._("Error").'</h1>';
105 print '<p>'._("Sorry, this ident/callsign is not in the database. :(").'</p>';
108 require_once('footer.php');