Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / airline-statistics-route.php
blob0a2d5336f78de46b165f8c516a2c987ad6aa3fe5
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","");
19 if (!empty($spotter_array) || $alliance === true)
21 if ($alliance) {
22 $title = sprintf(_("Most Common Routes from %s"),str_replace('_',' ',str_replace('alliance_','',$airline)));
23 } else {
24 $title = sprintf(_("Most Common Routes from %s (%s)"),$spotter_array[0]['airline_name'],$spotter_array[0]['airline_icao']);
26 require_once('header.php');
27 print '<div class="select-item">';
28 print '<form action="'.$globalURL.'/airline" method="post">';
29 print '<select name="airline" class="selectpicker" data-live-search="true">';
30 print '<option></option>';
31 $alliances = $Spotter->getAllAllianceNames();
32 if (!empty($alliances)) {
33 foreach ($alliances as $al) {
34 if ($alliance && str_replace('_',' ',str_replace('alliance_','',$airline)) == $al['alliance']) {
35 print '<option value="alliance_'.str_replace(' ','_',$al['alliance']).'" selected>'.$al['alliance'].'</option>';
36 } else {
37 print '<option value="alliance_'.str_replace(' ','_',$al['alliance']).'">'.$al['alliance'].'</option>';
40 print '<option disabled>───────────────────</option>';
42 $Stats = new Stats();
43 $airline_names = $Stats->getAllAirlineNames();
44 if (empty($airline_names)) $airline_names = $Spotter->getAllAirlineNames();
45 foreach($airline_names as $airline_name)
47 if($airline == $airline_name['airline_icao'])
49 print '<option value="'.$airline_name['airline_icao'].'" selected="selected">'.$airline_name['airline_name'].' ('.$airline_name['airline_icao'].')</option>';
50 } else {
51 print '<option value="'.$airline_name['airline_icao'].'">'.$airline_name['airline_name'].' ('.$airline_name['airline_icao'].')</option>';
54 print '</select>';
55 print '<button type="submit"><i class="fa fa-angle-double-right"></i></button>';
56 print '</form>';
57 print '</div>';
58 print '<br />';
60 if ($airline != "NA")
62 if ($alliance === false) {
63 print '<div class="info column">';
64 print '<h1>'.$spotter_array[0]['airline_name'].' ('.$spotter_array[0]['airline_icao'].')</h1>';
65 if ($globalIVAO && @getimagesize($globalURL.'/images/airlines/'.$spotter_array[0]['airline_icao'].'.gif'))
67 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" />';
69 elseif (@getimagesize($globalURL.'/images/airlines/'.$spotter_array[0]['airline_icao'].'.png'))
71 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" />';
73 print '<div><span class="label">'._("Name").'</span>'.$spotter_array[0]['airline_name'].'</div>';
74 print '<div><span class="label">'._("Country").'</span>'.$spotter_array[0]['airline_country'].'</div>';
75 print '<div><span class="label">'._("ICAO").'</span>'.$spotter_array[0]['airline_icao'].'</div>';
76 print '<div><span class="label">'._("IATA").'</span>'.$spotter_array[0]['airline_iata'].'</div>';
77 print '<div><span class="label">'._("Callsign").'</span>'.$spotter_array[0]['airline_callsign'].'</div>';
78 print '<div><span class="label">'._("Type").'</span>'.ucwords($spotter_array[0]['airline_type']).'</div>';
79 print '</div>';
80 } else {
81 print '<div class="info column">';
82 print '<h1>'.str_replace('_',' ',str_replace('alliance_','',$airline)).'</h1>';
83 if (@getimagesize($globalURL.'/images/airlines/'.str_replace('alliance_','',$airline).'.png') || @getimagesize('images/airlines/'.str_replace('alliance_','',$airline).'.png'))
85 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" />';
87 print '<div><span class="label">'._("Name").'</span>'.str_replace('_',' ',str_replace('alliance_','',$airline)).'</div>';
88 print '</div>';
90 } else {
91 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>';
94 include('airline-sub-menu.php');
95 print '<div class="column">';
96 print '<h2>'._("Most Common Routes").'</h2>';
97 if ($alliance) {
98 print '<p>'.sprintf(_("The statistic below shows the most common routes from <strong>%s</strong>."),str_replace('_',' ',str_replace('alliance_','',$airline))).'</p>';
99 } else {
100 print '<p>'.sprintf(_("The statistic below shows the most common routes from <strong>%s</strong>."),$spotter_array[0]['airline_name']).'</p>';
102 if ($alliance) {
103 $route_array = $Spotter->countAllRoutesByAirline('',array('alliance' => str_replace('_',' ',str_replace('alliance_','',$airline))));
104 } else {
105 $route_array = $Spotter->countAllRoutesByAirline($airline);
107 if (!empty($route_array))
109 print '<div class="table-responsive">';
110 print '<table class="common-routes table-striped">';
111 print '<thead>';
112 print '<th></th>';
113 print '<th>'._("Departure Airport").'</th>';
114 print '<th>'._("Arrival Airport").'</th>';
115 print '<th>'._("# of times").'</th>';
116 print '<th></th>';
117 print '<th></th>';
118 print '</thead>';
119 print '<tbody>';
120 $i = 1;
121 foreach($route_array as $route_item)
123 print '<tr>';
124 print '<td><strong>'.$i.'</strong></td>';
125 print '<td>';
126 print '<a href="'.$globalURL.'/airport/'.$route_item['airport_departure_icao'].'">'.$route_item['airport_departure_city'].', '.$route_item['airport_departure_country'].' ('.$route_item['airport_departure_icao'].')</a>';
127 print '</td>';
128 print '<td>';
129 print '<a href="'.$globalURL.'/airport/'.$route_item['airport_arrival_icao'].'">'.$route_item['airport_arrival_city'].', '.$route_item['airport_arrival_country'].' ('.$route_item['airport_arrival_icao'].')</a>';
130 print '</td>';
131 print '<td>';
132 print $route_item['route_count'];
133 print '</td>';
134 print '<td>';
135 print '<a href="'.$globalURL.'/search?airline='.$airline.'&departure_airport_route='.$route_item['airport_departure_icao'].'&arrival_airport_route='.$route_item['airport_arrival_icao'].'">'._("Search Flights").'</a>';
136 print '</td>';
137 print '<td>';
138 print '<a href="'.$globalURL.'/route/'.$route_item['airport_departure_icao'].'/'.$route_item['airport_arrival_icao'].'">'._("Route Profile").'</a>';
139 print '</td>';
140 print '</tr>';
141 $i++;
143 print '<tbody>';
144 print '</table>';
145 print '</div>';
147 print '</div>';
148 } else {
149 $title = _("Airline Statistic");
150 require_once('header.php');
151 print '<h1>'._("Error").'</h1>';
152 print '<p>'._("Sorry, the airline does not exist in this database. :(").'</p>';
154 require_once('footer.php');