Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / owner-statistics-departure-airport-country.php
blob60cec3e132bc01246f787ffc5d7a0715e8052eb5
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 Departure Airports by Owner 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>';
34 include('owner-sub-menu.php');
35 print '<div class="column">';
36 print '<h2>'._("Most Common Departure Airports by Country").'</h2>';
37 print '<p>'.sprintf(_("The statistic below shows all departure airports by Country of origin of flights owned by <strong>%s</strong>."),$spotter_array[0]['aircraft_owner']).'</p>';
38 if ($archive === false) {
39 $airport_country_array = $Spotter->countAllDepartureAirportCountriesByOwner($owner,$filter);
40 } else {
41 $airport_country_array = $SpotterArchive->countAllDepartureAirportCountriesByOwner($owner,$filter);
43 print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
44 print '<script type="text/javascript" src="'.$globalURL.'/js/topojson.v2.min.js"></script>';
45 print '<script type="text/javascript" src="'.$globalURL.'/js/datamaps.world.min.js"></script>';
46 print '<div id="chartCountry" class="chart" width="100%"></div><script>';
47 print 'var series = [';
48 $country_data = '';
49 foreach($airport_country_array as $airport_item)
51 $country_data .= '[ "'.$airport_item['airport_departure_country_iso3'].'",'.$airport_item['airport_departure_country_count'].'],';
53 $country_data = substr($country_data, 0, -1);
54 print $country_data;
55 print '];';
56 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);';
57 print 'var paletteScale = d3.scale.log().domain([minValue,maxValue]).range(["#EFEFFF","#001830"]);';
58 print 'series.forEach(function(item){var iso = item[0], value = item[1]; dataset[iso] = { numberOfThings: value, fillColor: paletteScale(value) };});';
59 print 'new Datamap({
60 element: document.getElementById("chartCountry"),
61 projection: "mercator", // big world map
62 fills: { defaultFill: "#F5F5F5" },
63 data: dataset,
64 responsive: true,
65 geographyConfig: {
66 borderColor: "#DEDEDE",
67 highlightBorderWidth: 2,
68 highlightFillColor: function(geo) {
69 return geo["fillColor"] || "#F5F5F5";
71 highlightBorderColor: "#B7B7B7",
72 done: function(datamap) {
73 datamap.svg.call(d3.behavior.zoom().on("zoom", redraw));
74 function redraw() {
75 datamap.svg.selectAll("g").attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
78 popupTemplate: function(geo, data) {
79 if (!data) { return ; }
80 return ['."'".'<div class="hoverinfo">'."','<strong>', geo.properties.name, '</strong>','<br>Count: <strong>', data.numberOfThings, '</strong>','</div>'].join('');
83 });";
84 print '</script>';
85 if (!empty($airport_country_array))
87 print '<div class="table-responsive">';
88 print '<table class="common-country table-striped">';
89 print '<thead>';
90 print '<th></th>';
91 print '<th>'._("Country").'</th>';
92 print '<th>'._("# of times").'</th>';
93 print '</thead>';
94 print '<tbody>';
95 $i = 1;
96 foreach($airport_country_array as $airport_item)
98 print '<tr>';
99 print '<td><strong>'.$i.'</strong></td>';
100 print '<td>';
101 print '<a href="'.$globalURL.'/country/'.strtolower(str_replace(" ", "-", $airport_item['departure_airport_country'])).'">'.$airport_item['departure_airport_country'].'</a>';
102 print '</td>';
103 print '<td>';
104 print $airport_item['airport_departure_country_count'];
105 print '</td>';
106 print '</tr>';
107 $i++;
109 print '<tbody>';
110 print '</table>';
111 print '</div>';
113 print '</div>';
114 } else {
115 $title = _("Owner");
116 require_once('header.php');
117 print '<h1>'._("Error").'</h1>';
118 print '<p>'._("Sorry, this owner is not in the database. :(").'</p>';
121 require_once('footer.php');