Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / airport.php
blobe13f0562ec7b8ae55e07bae4fd7c271d7420b114
1 <?php
2 require_once('require/class.Connection.php');
3 require_once('require/class.Spotter.php');
4 require_once('require/class.Common.php');
5 require_once('require/class.Language.php');
6 require_once('require/class.Stats.php');
8 if (isset($_POST['airport']))
10 header('Location: '.$globalURL.'/airport/'.filter_input(INPUT_POST,'airport',FILTER_SANITIZE_STRING));
11 } else if (isset($_GET['airport'])){
12 $Spotter = new Spotter();
13 //calculuation for the pagination
14 if($_GET['limit'] == "")
16 $limit_start = 0;
17 $limit_end = 25;
18 $absolute_difference = 25;
19 } else {
20 $limit_explode = explode(",", $_GET['limit']);
21 $limit_start = $limit_explode[0];
22 $limit_end = $limit_explode[1];
23 if (!ctype_digit(strval($limit_start)) || !ctype_digit(strval($limit_end))) {
24 $limit_start = 0;
25 $limit_end = 25;
28 $absolute_difference = abs($limit_start - $limit_end);
29 $limit_next = $limit_end + $absolute_difference;
30 $limit_previous_1 = $limit_start - $absolute_difference;
31 $limit_previous_2 = $limit_end - $absolute_difference;
33 $airport = filter_input(INPUT_GET,'airport',FILTER_SANITIZE_STRING);
34 $sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING);
35 $page_url = $globalURL.'/airport/'.$airport;
36 $airport_array = $Spotter->getAllAirportInfo($airport);
38 if (!empty($airport_array))
40 $spotter_array = $Spotter->getSpotterDataByAirport($airport,$limit_start.",".$absolute_difference, $sort);
41 $title = $airport_array[0]['city'].', '.$airport_array[0]['name'].' ('.$airport_array[0]['icao'].')';
43 require_once('header.php');
45 print '<div class="select-item">';
46 print '<form action="'.$globalURL.'/airport" method="post">';
47 print '<select name="airport" class="selectpicker" data-live-search="true">';
48 print '<option></option>';
49 $Stats = new Stats();
50 $airport_names = $Stats->getAllAirportNames();
51 if (empty($airport_names)) {
52 $airport_names = $Spotter->getAllAirportNames();
54 ksort($airport_names);
55 foreach($airport_names as $airport_name)
57 if($airport == $airport_name['airport_icao'])
59 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>';
60 } else {
61 print '<option value="'.$airport_name['airport_icao'].'">'.$airport_name['airport_city'].', '.$airport_name['airport_name'].', '.$airport_name['airport_country'].' ('.$airport_name['airport_icao'].')</option>';
64 print '</select>';
65 print '<button type="submit"><i class="fa fa-angle-double-right"></i></button>';
66 print '</form>';
67 print '</div>';
70 if ($airport != "NA")
72 print '<div class="info column">';
73 print '<h1>'.$airport_array[0]['city'].', '.$airport_array[0]['name'].' ('.$airport_array[0]['icao'].')</h1>';
74 print '<div><span class="label">'._("Name").'</span>'.$airport_array[0]['name'].'</div>';
75 print '<div><span class="label">'._("City").'</span>'.$airport_array[0]['city'].'</div>';
76 print '<div><span class="label">'._("Country").'</span>'.$airport_array[0]['country'].'</div>';
77 print '<div><span class="label">'._("ICAO").'</span>'.$airport_array[0]['icao'].'</div>';
78 print '<div><span class="label">'._("IATA").'</span>'.$airport_array[0]['iata'].'</div>';
79 print '<div><span class="label">'._("Altitude").'</span>'.$airport_array[0]['altitude'].'</div>';
80 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>';
81 print '</div>';
82 } else {
83 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>';
86 include('airport-sub-menu.php');
87 print '<div class="table column">';
88 if ($airport_array[0]['iata'] != "NA")
90 print '<p>'.sprintf(_("The table below shows the route(s) aircraft have used to/from <strong>%s</strong>, sorted by the most recent one."),$airport_array[0]['name']).'</p>';
93 include('table-output.php');
94 print '<div class="pagination">';
95 if ($limit_previous_1 >= 0)
97 print '<a href="'.$page_url.'/'.$limit_previous_1.','.$limit_previous_2.'/'.$sort.'">&laquo;'._("Previous Page").'</a>';
99 if ($spotter_array[0]['query_number_rows'] == $absolute_difference)
101 print '<a href="'.$page_url.'/'.$limit_end.','.$limit_next.'/'.$sort.'">'._("Next Page").'&raquo;</a>';
103 print '</div>';
104 print '</div>';
105 } else {
106 $title = _("Airport");
107 require_once('header.php');
108 print '<h1>'._("Error").'</h1>';
109 print '<p>'._("Sorry, the airport does not exist in this database. :(").'</p>';
111 } else {
112 $Spotter= new Spotter();
113 $Stats = new Stats();
114 $Common = new Common();
115 $title = _("Airports");
116 require_once('header.php');
117 print '<div class="column">';
118 print '<h1>'._("Airports").'</h1>';
119 $airport_names = $Stats->getAllAirportNames();
120 if (empty($airport_names)) {
121 $airport_names = $Spotter->getAllAirportNames();
123 ksort($airport_names);
124 $previous = null;
125 print '<div class="alphabet-legend">';
126 foreach($airport_names as $value) {
127 $firstLetter = strtoupper($Common->replace_mb_substr($value['airport_city'], 0, 1));
128 if($previous !== $firstLetter)
130 if ($previous !== null){
131 print ' | ';
133 print '<a href="#'.$firstLetter.'">'.$firstLetter.'</a>';
135 $previous = $firstLetter;
137 print '</div>';
138 $previous = null;
139 foreach($airport_names as $value) {
140 $firstLetter = strtoupper($Common->replace_mb_substr($value['airport_city'], 0, 1));
141 if ($firstLetter != "")
143 if($previous !== $firstLetter)
145 if ($previous !== null){
146 print '</div>';
148 print '<a name="'.$firstLetter.'"></a><h4 class="alphabet-header">'.$firstLetter.'</h4><div class="alphabet">';
150 $previous = $firstLetter;
151 print '<div class="alphabet-item">';
152 print '<a href="'.$globalURL.'/airport/'.$value['airport_icao'].'">';
153 print $value['airport_city'].', '.$value['airport_name'].', '.$value['airport_country'].' ('.$value['airport_icao'].')';
154 print '</a>';
155 print '</div>';
158 print '</div>';
161 require_once('footer.php');