Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / manufacturer-statistics-departure-airport.php
blob0c359a92b4d3d295251baee7dc76151f3f4f3131
1 <?php
2 require_once('require/class.Connection.php');
3 require_once('require/class.Spotter.php');
4 require_once('require/class.Stats.php');
5 require_once('require/class.Language.php');
6 if (!isset($_GET['aircraft_manufacturer'])) {
7 header('Location: '.$globalURL.'/manufacturer');
8 die();
10 $Spotter = new Spotter();
11 $manufacturer = ucwords(str_replace("-", " ", urldecode(filter_input(INPUT_GET,'aircraft_manufacturer',FILTER_SANITIZE_STRING))));
12 $sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING);
13 $spotter_array = $Spotter->getSpotterDataByManufacturer($manufacturer,"0,1", $sort);
15 if (!empty($spotter_array))
17 $title = sprintf(_("Most Common Departure Airports from %s"),$manufacturer);
19 require_once('header.php');
20 print '<div class="select-item">';
21 print '<form action="'.$globalURL.'/manufacturer" method="post">';
22 print '<select name="aircraft_manufacturer" class="selectpicker" data-live-search="true">';
23 $Stats = new Stats();
24 $all_manufacturers = $Stats->getAllManufacturers();
25 if (empty($all_manufacturers)) $all_manufacturers = $Spotter->getAllManufacturers();
26 foreach($all_manufacturers as $all_manufacturer)
28 if($_GET['aircraft_manufacturer'] == strtolower(str_replace(" ", "-", $all_manufacturer['aircraft_manufacturer'])))
30 print '<option value="'.strtolower(str_replace(" ", "-", $all_manufacturer['aircraft_manufacturer'])).'" selected="selected">'.$all_manufacturer['aircraft_manufacturer'].'</option>';
31 } else {
32 print '<option value="'.strtolower(str_replace(" ", "-", $all_manufacturer['aircraft_manufacturer'])).'">'.$all_manufacturer['aircraft_manufacturer'].'</option>';
35 print '</select>';
36 print '<button type="submit"><i class="fa fa-angle-double-right"></i></button>';
37 print '</form>';
38 print '</div>';
40 print '<div class="info column">';
41 print '<h1>'.$manufacturer.'</h1>';
42 print '</div>';
44 include('manufacturer-sub-menu.php');
45 print '<div class="column">';
46 print '<h2>'._("Most Common Departure Airports").'</h2>';
47 print '<p>'.sprintf(_("The statistic below shows all departure airports of flights from <strong>%s</strong>."),$manufacturer).'</p>';
48 $airport_airport_array = $Spotter->countAllDepartureAirportsByManufacturer($manufacturer);
49 print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
50 print '<script type="text/javascript" src="'.$globalURL.'/js/topojson.v2.min.js"></script>';
51 print '<script type="text/javascript" src="'.$globalURL.'/js/datamaps.world.min.js"></script>';
52 print '<div id="chartAirport" class="chart" width="100%"></div>';
53 print '<script>';
54 print 'var series = [';
55 $airport_data = '';
56 foreach($airport_airport_array as $airport_item)
58 $airport_data .= '[ "'.$airport_item['airport_departure_icao_count'].'", "'.$airport_item['airport_departure_icao'].'",'.$airport_item['airport_departure_latitude'].','.$airport_item['airport_departure_longitude'].'],';
60 $airport_data = substr($airport_data, 0, -1);
61 print $airport_data;
62 print '];'."\n";
63 print 'var onlyValues = series.map(function(obj){ return obj[0]; });var minValue = Math.min.apply(null, onlyValues), maxValue = Math.max.apply(null, onlyValues);'."\n";
64 print 'var paletteScale = d3.scale.log().domain([minValue,maxValue]).range(["#EFEFFF","#001830"]);'."\n";
65 print 'var radiusScale = d3.scale.log().domain([minValue,maxValue]).range([0,10]);'."\n";
66 print 'var dataset = [];'."\n";
67 print 'var colorset = [];'."\n";
68 print 'colorset["defaultFill"] = "#F5F5F5";';
69 print 'series.forEach(function(item){'."\n";
70 print 'var cnt = item[0], nm = item[1], lat = item[2], long = item[3];'."\n";
71 print 'colorset[nm] = paletteScale(cnt);';
72 print 'dataset.push({ count: cnt, name: nm, radius: Math.floor(radiusScale(cnt)), latitude: lat, longitude: long, fillKey: nm });'."\n";
73 print '});'."\n";
74 print 'var bbl = new Datamap({
75 element: document.getElementById("chartAirport"),
76 projection: "mercator", // big world map
77 fills: colorset,
78 responsive: true,
79 geographyConfig: {
80 borderColor: "#DEDEDE",
81 highlightBorderWidth: 2,
82 highlightFillColor: function(geo) {
83 return geo["fillColor"] || "#F5F5F5";
85 highlightBorderColor: "#B7B7B7"},
86 done: function(datamap) {
87 datamap.svg.call(d3.behavior.zoom().on("zoom", redraw));
88 function redraw() {
89 datamap.svg.selectAll("g").attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
92 });
93 bbl.bubbles(dataset,{
94 popupTemplate: function(geo, data) {
95 if (!data) { return ; }
96 return ['."'".'<div class="hoverinfo">'."','<strong>', data.name, '</strong>','<br>Count: <strong>', data.count, '</strong>','</div>'].join('');
98 });";
99 print '</script>';
100 print '<div class="table-responsive">';
101 print '<table class="common-airport table-striped">';
102 print '<thead>';
103 print '<th></th>';
104 print '<th>'._("Airport").'</th>';
105 print '<th>'._("Country").'</th>';
106 print '<th>'._("# of times").'</th>';
107 print '<th></th>';
108 print '</thead>';
109 print '<tbody>';
110 $i = 1;
111 foreach($airport_airport_array as $airport_item)
113 print '<tr>';
114 print '<td><strong>'.$i.'</strong></td>';
115 print '<td>';
116 print '<a href="'.$globalURL.'/airport/'.$airport_item['airport_departure_icao'].'">'.$airport_item['airport_departure_city'].', '.$airport_item['airport_departure_country'].' ('.$airport_item['airport_departure_icao'].')</a>';
117 print '</td>';
118 print '<td>';
119 print '<a href="'.$globalURL.'/country/'.strtolower(str_replace(" ", "-", $airport_item['airport_departure_country'])).'">'.$airport_item['airport_departure_country'].'</a>';
120 print '</td>';
121 print '<td>';
122 print $airport_item['airport_departure_icao_count'];
123 print '</td>';
124 print '<td><a href="'.$globalURL.'/search?departure_airport_route='.$airport_item['airport_departure_icao'].'&manufacturer='.$manufacturer.'">'._("Search flights").'</a></td>';
125 print '</tr>';
126 $i++;
128 print '<tbody>';
129 print '</table>';
130 print '</div>';
131 print '</div>';
132 } else {
133 $title = _("Manufacturer");
134 require_once('header.php');
135 print '<h1>'._("Error").'</h1>';
136 print '<p>'._("Sorry, the aircraft manufacturer does not exist in this database. :(").'</p>';
139 require_once('footer.php');