Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / owner-statistics-time.php
blobba5f8d8f6ec0c417b5986588a126ebd9434de32f
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 Time of Day 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 Time of Day").'</h2>';
38 print '<p>'.sprintf(_("The statistic below shows the most common time of day of flights owned by <strong>%s</strong>."),$spotter_array[0]['aircraft_owner']).'</p>';
40 if ($archive === false) {
41 $hour_array = $Spotter->countAllHoursByOwner($owner,$filter);
42 } else {
43 $hour_array = $SpotterArchive->countAllHoursByOwner($owner,$filter);
45 print '<link href="'.$globalURL.'/css/c3.min.css" rel="stylesheet" type="text/css">';
46 print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
47 print '<script type="text/javascript" src="'.$globalURL.'/js/c3.min.js"></script>';
48 print '<div id="chartHour" class="chart" width="100%"></div><script>';
49 $hour_data = '';
50 $hour_cnt = '';
51 $last = 0;
52 foreach($hour_array as $hour_item)
54 while($last != $hour_item['hour_name']) {
55 $hour_data .= '"'.$last.':00",';
56 $hour_cnt .= '0,';
57 $last++;
59 $last++;
60 $hour_data .= '"'.$hour_item['hour_name'].':00",';
61 $hour_cnt .= $hour_item['hour_count'].',';
63 $hour_data = "['x',".substr($hour_data, 0, -1)."]";
64 $hour_cnt = "['flights',".substr($hour_cnt,0,-1)."]";
65 print 'c3.generate({
66 bindto: "#chartHour",
67 data: {
68 x : "x",
69 xFormat: "%H:%M",
70 columns: ['.$hour_cnt.','.$hour_data.'], types: { flights: "area"}, colors: { flights: "#1a3151"}
72 axis: {
73 x: { type: "timeseries", tick: { format: "%H:%M" }},
74 y: { label: "# of Flights",tick: { format: d3.format("d") }}
76 legend: { show: false }
77 });';
78 print '</script>';
79 if (!empty($hour_array))
81 print '<div class="table-responsive">';
82 print '<table class="common-hour table-striped">';
83 print '<thead>';
84 print '<th>'._("Hour").'</th>';
85 print '<th>'._("Number").'</th>';
86 print '</thead>';
87 print '<tbody>';
88 $i = 1;
89 foreach($hour_array as $hour_item)
91 print '<tr>';
92 print '<td>'.$hour_item['hour_name'].':00</td>';
93 print '<td>'.$hour_item['hour_count'].'</td>';
94 print '</tr>';
95 $i++;
97 print '<tbody>';
98 print '</table>';
99 print '</div>';
101 print '</div>';
102 } else {
103 $title = _("Owner");
104 require_once('header.php');
105 print '<h1>'._("Error").'</h1>';
106 print '<p>'._("Sorry, this owner is not in the database. :(").'</p>';
109 require_once('footer.php');