Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / airport-statistics-route.php
blob017ddaf7c6da9b0909dfdd48b8c9bee56c3c1cbf
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['airport'])) {
7 header('Location: '.$globalURL.'/airport');
8 die();
10 $airport = filter_input(INPUT_GET,'airport',FILTER_SANITIZE_STRING);
11 $Spotter = new Spotter();
12 //$spotter_array = $Spotter->getSpotterDataByAirport($airport,"0,1","");
13 $airport_array = $Spotter->getAllAirportInfo($airport);
15 if (!empty($airport_array))
17 $title = sprintf(_("Most Common Routes to/from %s, %s (%s)"),$airport_array[0]['city'],$airport_array[0]['name'],$airport_array[0]['icao']);
19 require_once('header.php');
20 print '<div class="select-item">';
21 print '<form action="'.$globalURL.'/airport" method="post">';
22 print '<select name="airport" class="selectpicker" data-live-search="true">';
23 print '<option></option>';
24 $Stats = new Stats();
25 $airport_names = $Stats->getAllAirportNames();
26 if (empty($airport_names)) $airport_names = $Spotter->getAllAirportNames();
27 ksort($airport_names);
28 foreach($airport_names as $airport_name)
30 if($airport == $airport_name['airport_icao'])
32 print '<option value="'.$airport_name['airport_icao'].'" selected="selected">'.$airport_name['airport_city'].', '.$airport_name['airport_name'].', '.$airport_name['airport_country'].' ('.$airport_name['airport_icao'].')</option>';
33 } else {
34 print '<option value="'.$airport_name['airport_icao'].'">'.$airport_name['airport_city'].', '.$airport_name['airport_name'].', '.$airport_name['airport_country'].' ('.$airport_name['airport_icao'].')</option>';
37 print '</select>';
38 print '<button type="submit"><i class="fa fa-angle-double-right"></i></button>';
39 print '</form>';
40 print '</div>';
41 print '<br />';
43 if ($airport != "NA")
45 print '<div class="info column">';
46 print '<h1>'.$airport_array[0]['city'].', '.$airport_array[0]['name'].' ('.$airport_array[0]['icao'].')</h1>';
47 print '<div><span class="label">'._("Name").'</span>'.$airport_array[0]['name'].'</div>';
48 print '<div><span class="label">'._("City").'</span>'.$airport_array[0]['city'].'</div>';
49 print '<div><span class="label">'._("Country").'</span>'.$airport_array[0]['country'].'</div>';
50 print '<div><span class="label">'._("ICAO").'</span>'.$airport_array[0]['icao'].'</div>';
51 print '<div><span class="label">'._("IATA").'</span>'.$airport_array[0]['iata'].'</div>';
52 print '<div><span class="label">'._("Altitude").'</span>'.$airport_array[0]['altitude'].'</div>';
53 print '<div><span class="label">'._("Coordinates").'</span><a href="http://maps.google.ca/maps?z=10&t=k&q='.$airport_array[0]['latitude'].','.$airport_array[0]['longitude'].'" target="_blank">Google Map<i class="fa fa-angle-double-right"></i></a></div>';
54 print '</div>';
55 } else {
56 print '<div class="alert alert-warning">'._("This special airport profile shows all flights that do <u>not</u> have a departure and/or arrival airport associated with them.").'</div>';
59 include('airport-sub-menu.php');
60 print '<div class="column">';
61 print '<h2>'._("Most Common Routes").'</h2>';
62 print '<p>'.sprintf(_("The statistic below shows the most common routes to/from <strong>%s, %s (%s)</strong>."),$airport_array[0]['city'],$airport_array[0]['name'],$airport_array[0]['icao']).'</p>';
64 $route_array = $Spotter->countAllRoutesByAirport($airport);
65 if (!empty($route_array))
67 print '<div class="table-responsive">';
68 print '<table class="common-routes table-striped">';
69 print '<thead>';
70 print '<th></th>';
71 print '<th>'._("Departure Airport").'</th>';
72 print '<th>'._("Arrival Airport").'</th>';
73 print '<th>'._("# of times").'</th>';
74 print '<th></th>';
75 print '</thead>';
76 print '<tbody>';
77 $i = 1;
78 foreach($route_array as $route_item)
80 print '<tr>';
81 print '<td><strong>'.$i.'</strong></td>';
82 print '<td>';
83 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>';
84 print '</td>';
85 print '<td>';
86 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>';
87 print '</td>';
88 print '<td>';
89 print $route_item['route_count'];
90 print '</td>';
91 print '<td>';
92 print '<a href="'.$globalURL.'/route/'.$route_item['airport_departure_icao'].'/'.$route_item['airport_arrival_icao'].'">'._("Route Profile").'</a>';
93 print '</td>';
94 print '</tr>';
95 $i++;
97 print '<tbody>';
98 print '</table>';
99 print '</div>';
101 print '</div>';
102 } else {
103 $title = _("Airport");
104 require_once('header.php');
105 print '<h1>'._("Error").'</h1>';
106 print '<p>'._("Sorry, the airport does not exist in this database. :(").'</p>';
109 require_once('footer.php');