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