Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / airline-statistics-time.php
blob94e8eabb867a6200f3bf35aa791c56c1cade88ab
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['airline'])) {
7 header('Location: '.$globalURL.'/airline');
8 die();
10 $airline = urldecode(filter_input(INPUT_GET,'airline',FILTER_SANITIZE_STRING));
11 $Spotter = new Spotter();
12 $alliance = false;
13 if (strpos($airline,'alliance_') !== FALSE) {
14 $alliance = true;
15 } else {
16 $spotter_array = $Spotter->getSpotterDataByAirline($airline,"0,1","");
20 if (!empty($spotter_array) || $alliance === true)
22 if ($alliance) {
23 $title = sprintf(_("Most Common Time of Day from %s"),str_replace('_',' ',str_replace('alliance_','',$airline)));
24 } else {
25 $title = sprintf(_("Most Common Time of Day from %s (%s)"),$spotter_array[0]['airline_name'],$spotter_array[0]['airline_icao']);
27 require_once('header.php');
28 print '<div class="select-item">';
29 print '<form action="'.$globalURL.'/airline" method="post">';
30 print '<select name="airline" class="selectpicker" data-live-search="true">';
31 print '<option></option>';
32 $alliances = $Spotter->getAllAllianceNames();
33 if (!empty($alliances)) {
34 foreach ($alliances as $al) {
35 if ($alliance && str_replace('_',' ',str_replace('alliance_','',$airline)) == $al['alliance']) {
36 print '<option value="alliance_'.str_replace(' ','_',$al['alliance']).'" selected>'.$al['alliance'].'</option>';
37 } else {
38 print '<option value="alliance_'.str_replace(' ','_',$al['alliance']).'">'.$al['alliance'].'</option>';
41 print '<option disabled>────────────────</option>';
43 $Stats = new Stats();
44 $airline_names = $Stats->getAllAirlineNames();
45 if (empty($airline_names)) $airline_names = $Spotter->getAllAirlineNames();
46 foreach($airline_names as $airline_name)
48 if($airline == $airline_name['airline_icao'])
50 print '<option value="'.$airline_name['airline_icao'].'" selected="selected">'.$airline_name['airline_name'].' ('.$airline_name['airline_icao'].')</option>';
51 } else {
52 print '<option value="'.$airline_name['airline_icao'].'">'.$airline_name['airline_name'].' ('.$airline_name['airline_icao'].')</option>';
55 print '</select>';
56 print '<button type="submit"><i class="fa fa-angle-double-right"></i></button>';
57 print '</form>';
58 print '</div>';
59 print '<br />';
61 if ($airline != "NA")
63 if ($alliance === false) {
64 print '<div class="info column">';
65 print '<h1>'.$spotter_array[0]['airline_name'].' ('.$spotter_array[0]['airline_icao'].')</h1>';
66 if ($globalIVAO && @getimagesize($globalURL.'/images/airlines/'.$spotter_array[0]['airline_icao'].'.gif'))
68 print '<img src="'.$globalURL.'/images/airlines/'.$spotter_array[0]['airline_icao'].'.gif" alt="'.$spotter_array[0]['airline_name'].' ('.$spotter_array[0]['airline_icao'].')" title="'.$spotter_array[0]['airline_name'].' ('.$spotter_array[0]['airline_icao'].')" class="logo" />';
70 elseif (@getimagesize($globalURL.'/images/airlines/'.$spotter_array[0]['airline_icao'].'.png'))
72 print '<img src="'.$globalURL.'/images/airlines/'.$spotter_array[0]['airline_icao'].'.png" alt="'.$spotter_array[0]['airline_name'].' ('.$spotter_array[0]['airline_icao'].')" title="'.$spotter_array[0]['airline_name'].' ('.$spotter_array[0]['airline_icao'].')" class="logo" />';
74 print '<div><span class="label">'._("Name").'</span>'.$spotter_array[0]['airline_name'].'</div>';
75 print '<div><span class="label">'._("Country").'</span>'.$spotter_array[0]['airline_country'].'</div>';
76 print '<div><span class="label">'._("ICAO").'</span>'.$spotter_array[0]['airline_icao'].'</div>';
77 print '<div><span class="label">'._("IATA").'</span>'.$spotter_array[0]['airline_iata'].'</div>';
78 print '<div><span class="label">'._("Callsign").'</span>'.$spotter_array[0]['airline_callsign'].'</div>';
79 print '<div><span class="label">'._("Type").'</span>'.ucwords($spotter_array[0]['airline_type']).'</div>';
80 print '</div>';
81 } else {
82 print '<div class="info column">';
83 print '<h1>'.str_replace('_',' ',str_replace('alliance_','',$airline)).'</h1>';
84 if (@getimagesize($globalURL.'/images/airlines/'.str_replace('alliance_','',$airline).'.png') || getimagesize('images/airlines/'.str_replace('alliance_','',$airline).'.png'))
86 print '<img src="'.$globalURL.'/images/airlines/'.str_replace('alliance_','',$airline).'.png" alt="'.str_replace('_',' ',str_replace('alliance_','',$airline)).'" title="'.str_replace('_',' ',str_replace('alliance_','',$airline)).'" class="logo" />';
88 print '<div><span class="label">'._("Name").'</span>'.str_replace('_',' ',str_replace('alliance_','',$airline)).'</div>';
89 print '</div>';
91 } else {
92 print '<div class="alert alert-warning">'._("This special airline profile shows all flights that do <u>not</u> have a airline associated with them.").'</div>';
95 include('airline-sub-menu.php');
96 print '<div class="column">';
97 print '<h2>'._("Most Common Time of Day").'</h2>';
98 if ($alliance) {
99 print '<p>'.sprintf(_("The statistic below shows the most common time of day from <strong>%s</strong>."),str_replace('_',' ',str_replace('alliance_','',$airline))).'</p>';
100 } else {
101 print '<p>'.sprintf(_("The statistic below shows the most common time of day from <strong>%s</strong>."),$spotter_array[0]['airline_name']).'</p>';
104 if ($alliance) {
105 $hour_array = $Spotter->countAllHoursByAirline('',array('alliance' => str_replace('_',' ',str_replace('alliance_','',$airline))));
106 } else {
107 $hour_array = $Spotter->countAllHoursByAirline($airline);
110 $hour_array = $Stats->countAllHours('hour',true,$airline);
111 print '<link href="'.$globalURL.'/css/c3.min.css" rel="stylesheet" type="text/css">';
112 print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
113 print '<script type="text/javascript" src="'.$globalURL.'/js/c3.min.js"></script>';
114 print '<div id="chartHour" class="chart" width="100%"></div><script>';
115 $hour_data = '';
116 $hour_cnt = '';
117 $last = 0;
118 foreach($hour_array as $hour_item)
120 while($last != $hour_item['hour_name']) {
121 $hour_data .= '"'.$last.':00",';
122 $hour_cnt .= '0,';
123 $last++;
125 $last++;
126 $hour_data .= '"'.$hour_item['hour_name'].':00",';
127 $hour_cnt .= $hour_item['hour_count'].',';
129 $hour_data = "[".substr($hour_data, 0, -1)."]";
130 $hour_cnt = "['flights',".substr($hour_cnt,0,-1)."]";
131 print 'c3.generate({
132 bindto: "#chartHour",
133 data: {
134 columns: ['.$hour_cnt.'], types: { flights: "area"}, colors: { flights: "#1a3151"}},
135 axis: {
136 x: { type: "category", categories: '.$hour_data.'},
137 y: { label: "# of Flights"}},legend: { show: false }
138 });';
139 print '</script>';
140 if (!empty($hour_array))
142 print '<div class="table-responsive">';
143 print '<table class="common-hour table-striped">';
144 print '<thead>';
145 print '<th>'._("Hour").'</th>';
146 print '<th>'._("Number").'</th>';
147 print '</thead>';
148 print '<tbody>';
149 $i = 1;
150 foreach($hour_array as $hour_item)
152 print '<tr>';
153 print '<td>'.$hour_item['hour_name'].':00</td>';
154 print '<td>'.$hour_item['hour_count'].'</td>';
155 print '</tr>';
156 $i++;
158 print '<tbody>';
159 print '</table>';
160 print '</div>';
162 print '</div>';
163 } else {
164 $title = _("Airline Statistic");
165 require_once('header.php');
166 print '<h1>'._("Error").'</h1>';
167 print '<p>'._("Sorry, the airline does not exist in this database. :(").'</p>';
169 require_once('footer.php');