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