Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / date-statistics-departure-airport.php
blob7215ba220510e4f5e30066144c4c2e247117d287
1 <?php
2 require_once('require/class.Connection.php');
3 require_once('require/class.Spotter.php');
4 require_once('require/class.Language.php');
6 $Spotter = new Spotter();
7 $sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING);
8 $date = filter_input(INPUT_GET,'date',FILTER_SANITIZE_STRING);
9 $spotter_array = $Spotter->getSpotterDataByDate($date,"0,1", $sort);
11 if (!empty($spotter_array))
13 $title = sprintf(_("Most Common Departure Airports on %s"),date("l F j, Y", strtotime($spotter_array[0]['date_iso_8601'])));
15 require_once('header.php');
16 print '<div class="select-item">';
17 print '<form action="'.$globalURL.'/date" method="post" class="form-inline">';
18 print '<div class="form-group">';
19 print '<label for="datepickeri">'._("Select a Date").'</label>';
20 print '<div class="input-group date" id="datepicker">';
21 print '<input type="text" class="form-control" id="datepickeri" name="date" value="" />';
22 print '<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>';
23 print '</div>';
24 print '<button type="submit"><i class="fa fa-angle-double-right"></i></button>';
25 print '</div>';
26 print '</form>';
27 print '</div>';
28 print '<script type="text/javascript">$(function () { $("#datepicker").datetimepicker({ format: "YYYY-MM-DD", defaultDate: "'.$date.'" }); }); </script>';
29 print '<br />';
30 print '<div class="info column">';
31 print '<h1>'.sprintf(_("Flights from %s"),date("l F j, Y", strtotime($spotter_array[0]['date_iso_8601']))).'</h1>';
32 print '</div>';
34 include('date-sub-menu.php');
35 print '<div class="column">';
36 print '<h2>'._("Most Common Departure Airports").'</h2>';
37 print '<p>'.sprintf(_("The statistic below shows all departure airports of flights on <strong>%s</strong>."),date("l F j, Y", strtotime($spotter_array[0]['date_iso_8601']))).'</p>';
38 $airport_airport_array = $Spotter->countAllDepartureAirportsByDate($date);
39 print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
40 print '<script type="text/javascript" src="'.$globalURL.'/js/topojson.v2.min.js"></script>';
41 print '<script type="text/javascript" src="'.$globalURL.'/js/datamaps.world.min.js"></script>';
42 print '<div id="chartAirport" class="chart" width="100%"></div>';
43 print '<script>';
44 print 'var series = [';
45 $airport_data = '';
46 foreach($airport_airport_array as $airport_item)
48 $airport_data .= '[ "'.$airport_item['airport_departure_icao_count'].'", "'.$airport_item['airport_departure_icao'].'",'.$airport_item['airport_departure_latitude'].','.$airport_item['airport_departure_longitude'].'],';
50 $airport_data = substr($airport_data, 0, -1);
51 print $airport_data;
52 print '];'."\n";
53 print 'var onlyValues = series.map(function(obj){ return obj[0]; });var minValue = Math.min.apply(null, onlyValues), maxValue = Math.max.apply(null, onlyValues);'."\n";
54 print 'var paletteScale = d3.scale.log().domain([minValue,maxValue]).range(["#EFEFFF","#001830"]);'."\n";
55 print 'var radiusScale = d3.scale.log().domain([minValue,maxValue]).range([2,20]);'."\n";
56 print 'var dataset = [];'."\n";
57 print 'var colorset = [];'."\n";
58 print 'colorset["defaultFill"] = "#F5F5F5";';
59 print 'series.forEach(function(item){'."\n";
60 print 'var cnt = item[0], nm = item[1], lat = item[2], long = item[3];'."\n";
61 print 'colorset[nm] = paletteScale(cnt);';
62 print 'dataset.push({ count: cnt, name: nm, radius: Math.floor(radiusScale(cnt)), latitude: lat, longitude: long, fillKey: nm });'."\n";
63 print '});'."\n";
64 print 'var bbl = new Datamap({
65 element: document.getElementById("chartAirport"),
66 projection: "mercator", // big world map
67 fills: colorset,
68 responsive: true,
69 geographyConfig: {
70 borderColor: "#DEDEDE",
71 highlightBorderWidth: 2,
72 highlightFillColor: function(geo) {
73 return geo["fillColor"] || "#F5F5F5";
75 highlightBorderColor: "#B7B7B7"},
76 done: function(datamap) {
77 datamap.svg.call(d3.behavior.zoom().on("zoom", redraw));
78 function redraw() {
79 datamap.svg.selectAll("g").attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
82 });
83 bbl.bubbles(dataset,{
84 popupTemplate: function(geo, data) {
85 if (!data) { return ; }
86 return ['."'".'<div class="hoverinfo">'."','<strong>', data.name, '</strong>','<br>Count: <strong>', data.count, '</strong>','</div>'].join('');
88 });";
89 print '</script>';
90 print '<div class="table-responsive">';
91 print '<table class="common-airport table-striped">';
92 print '<thead>';
93 print '<th></th>';
94 print '<th>'._("Airport").'</th>';
95 print '<th>'._("Country").'</th>';
96 print '<th>'._("# of times").'</th>';
97 print '<th></th>';
98 print '</thead>';
99 print '<tbody>';
100 $i = 1;
101 foreach($airport_airport_array as $airport_item)
103 print '<tr>';
104 print '<td><strong>'.$i.'</strong></td>';
105 print '<td>';
106 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>';
107 print '</td>';
108 print '<td>';
109 print '<a href="'.$globalURL.'/country/'.strtolower(str_replace(" ", "-", $airport_item['airport_departure_country'])).'">'.$airport_item['airport_departure_country'].'</a>';
110 print '</td>';
111 print '<td>';
112 print $airport_item['airport_departure_icao_count'];
113 print '</td>';
114 print '<td><a href="'.$globalURL.'/search?departure_airport_route='.$airport_item['airport_departure_icao'].'&start_date='.$date.'+00:00&end_date='.$date.'+23:59">'._("Search flights").'</a></td>';
115 print '</tr>';
116 $i++;
118 print '<tbody>';
119 print '</table>';
120 print '</div>';
121 print '</div>';
122 } else {
123 $title = _("Unknown Date");
124 require_once('header.php');
125 print '<h1>'._("Error").'</h1>';
126 print '<p>'._("Sorry, this date does not exist in this database. :(").'</p>';
129 require_once('footer.php');