Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / country-statistics-time.php
blob57f99317b8c6c741a66a680bd71673b6ff063a5e
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['country'])) {
6 header('Location: '.$globalURL.'/country');
7 die();
9 $Spotter = new Spotter();
10 $country = ucwords(str_replace("-", " ", urldecode(filter_input(INPUT_GET,'country',FILTER_SANITIZE_STRING))));
11 $sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING);
13 if (isset($_GET['sort'])) {
14 $spotter_array = $Spotter->getSpotterDataByCountry($country, "0,1", $sort);
15 } else {
16 $spotter_array = $Spotter->getSpotterDataByCountry($country, "0,1", '');
19 if (!empty($spotter_array))
21 $title = sprintf(_("Most Common Time of Day from %s"),$country);
22 require_once('header.php');
23 print '<div class="select-item">';
24 print '<form action="'.$globalURL.'/country" method="post">';
25 print '<select name="country" class="selectpicker" data-live-search="true">';
26 print '<option></option>';
27 $all_countries = $Spotter->getAllCountries();
28 foreach($all_countries as $all_country)
30 if($country == $all_country['country'])
32 print '<option value="'.strtolower(str_replace(" ", "-", $all_country['country'])).'" selected="selected">'.$all_country['country'].'</option>';
33 } else {
34 print '<option value="'.strtolower(str_replace(" ", "-", $all_country['country'])).'">'.$all_country['country'].'</option>';
37 print '</select>';
38 print '<button type="submit"><i class="fa fa-angle-double-right"></i></button>';
39 print '</form>';
40 print '</div>';
42 if ($_GET['country'] != "NA")
44 print '<div class="info column">';
45 print '<h1>'.sprintf(_("Airports &amp; Airlines from %s"),$country).'</h1>';
46 print '</div>';
47 } else {
48 print '<div class="alert alert-warning">'._("This special country profile shows all flights that do <u>not</u> have a country of a airline or departure/arrival airport associated with them.").'</div>';
51 include('country-sub-menu.php');
52 print '<div class="column">';
53 print '<h2>'._("Most Common Time of Day").'</h2>';
54 print '<p>'.sprintf(_("The statistic below shows the most common time of day of airports &amp; airlines from <strong>%s</strong>."),$country).'</p>';
55 $hour_array = $Spotter->countAllHoursByCountry($country);
56 print '<link href="'.$globalURL.'/css/c3.min.css" rel="stylesheet" type="text/css">';
57 print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
58 print '<script type="text/javascript" src="'.$globalURL.'/js/c3.min.js"></script>';
59 print '<div id="chartHour" class="chart" width="100%"></div><script>';
60 $hour_data = '';
61 $hour_cnt = '';
62 $last = 0;
63 foreach($hour_array as $hour_item)
65 while($last != $hour_item['hour_name']) {
66 $hour_data .= '"'.$last.':00",';
67 $hour_cnt .= '0,';
68 $last++;
70 $last++;
71 $hour_data .= '"'.$hour_item['hour_name'].':00",';
72 $hour_cnt .= $hour_item['hour_count'].',';
74 $hour_data = "['x',".substr($hour_data, 0, -1)."]";
75 $hour_cnt = "['flights',".substr($hour_cnt,0,-1)."]";
76 print 'c3.generate({
77 bindto: "#chartHour",
78 data: {
79 x : "x",
80 xFormat: "%H:%M",
81 columns: ['.$hour_cnt.','.$hour_data.'], types: { flights: "area"}, colors: { flights: "#1a3151"}
83 axis: {
84 x: { type: "timeseries", tick: { format: "%H:%M" }},
85 y: { label: "# of Flights",tick: { format: d3.format("d") }}
87 legend: { show: false }
88 });';
89 print '</script>';
90 if (!empty($hour_array))
92 print '<div class="table-responsive">';
93 print '<table class="common-hour table-striped">';
94 print '<thead>';
95 print '<th>'._("Hour").'</th>';
96 print '<th>'._("Number").'</th>';
97 print '</thead>';
98 print '<tbody>';
99 $i = 1;
100 foreach($hour_array as $hour_item)
102 print '<tr>';
103 print '<td>'.$hour_item['hour_name'].':00</td>';
104 print '<td>'.$hour_item['hour_count'].'</td>';
105 print '</tr>';
106 $i++;
108 print '<tbody>';
109 print '</table>';
110 print '</div>';
112 print '</div>';
113 } else {
114 $title = _("Country");
115 require_once('header.php');
116 print '<h1>'._("Error").'</h1>';
117 print '<p>'._("Sorry, the country does not exist in this database. :(").'</p>';
120 require_once('footer.php');