Skip to content

Commit

Permalink
Add image on empty airports
Browse files Browse the repository at this point in the history
  • Loading branch information
Ysurac committed Dec 21, 2017
1 parent eac4f33 commit 3eb940c
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 20 deletions.
42 changes: 24 additions & 18 deletions airport-detailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

$sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING);
$airport_array = $Spotter->getAllAirportInfo($airport_icao);

if (!empty($airport_array))
{
if ($sort != '') {
Expand Down Expand Up @@ -96,6 +95,8 @@
print '</div>';
print '<div><span class="label">'._("Coordinates").'</span><a href="http://maps.google.com/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>';
print '<div><span class="label">'._("Live Air Traffic").'</span><a href="http://www.liveatc.net/search/?icao='.$airport_array[0]['icao'].'" target="_blank">LiveATC.net<i class="fa fa-angle-double-right"></i></a></div>';
if (isset($airport_array[0]['home_link']) && $airport_array[0]['home_link'] != '') print '<div><a href="'.$airport_array[0]['home_link'].'"><i class="fa fa-home"></i></a></div>';
if (isset($airport_array[0]['wikipedia_link']) && $airport_array[0]['wikipedia_link'] != '') print '<div><a href="'.$airport_array[0]['wikipedia_link'].'"><i class="fa fa-wikipedia-w"></i></a></div>';
if (isset($airport_array[0]['diagram_pdf']) && $airport_array[0]['diagram_pdf'] != '') print '<div><span class="label">'._("Diagram").'</span><a href="'.$airport_array[0]['diagram_pdf'].'" target="_blank">'.$airport_array[0]['icao'].'<i class="fa fa-angle-double-right"></i></a></div>';
print '</div>';

Expand Down Expand Up @@ -190,24 +191,29 @@
} else {
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>';
}
include('airport-sub-menu.php');
print '<div class="table column">';
if ($airport_array[0]['iata'] != "NA")
{
print '<p>'.sprintf(_("The table below shows the detailed information of all flights to/from <strong>%s, %s (%s)</strong>."),$airport_array[0]['city'],$airport_array[0]['name'],$airport_array[0]['icao']).'</p>';
}
include('table-output.php');
print '<div class="pagination">';
if ($limit_previous_1 >= 0)
{
print '<a href="'.$page_url.'/'.$limit_previous_1.','.$limit_previous_2.'/'.$sort.'">&laquo;'._("Previous Page").'</a>';
}
if (isset($spotter_array[0]['query_number_rows']) && $spotter_array[0]['query_number_rows'] == $absolute_difference)
{
print '<a href="'.$page_url.'/'.$limit_end.','.$limit_next.'/'.$sort.'">'._("Next Page").'&raquo;</a>';
if (!empty($spotter_array)) {
include('airport-sub-menu.php');
print '<div class="table column">';
if ($airport_array[0]['iata'] != "NA")
{
print '<p>'.sprintf(_("The table below shows the detailed information of all flights to/from <strong>%s, %s (%s)</strong>."),$airport_array[0]['city'],$airport_array[0]['name'],$airport_array[0]['icao']).'</p>';
}
include('table-output.php');
print '<div class="pagination">';
if ($limit_previous_1 >= 0)
{
print '<a href="'.$page_url.'/'.$limit_previous_1.','.$limit_previous_2.'/'.$sort.'">&laquo;'._("Previous Page").'</a>';
}
if (isset($spotter_array[0]['query_number_rows']) && $spotter_array[0]['query_number_rows'] == $absolute_difference)
{
print '<a href="'.$page_url.'/'.$limit_end.','.$limit_next.'/'.$sort.'">'._("Next Page").'&raquo;</a>';
}
print '</div>';
print '</div>';
} else {
if (isset($airport_array[0]['image']) && $airport_array[0]['image'] != '') print '<center><img src="'.$airport_array[0]['image'].'" /></center>';
print '<p>'._("Sorry, no flights used the airport in this database.").'</p>';
}
print '</div>';
print '</div>';
} else {
$title = "Airport";
require_once('header.php');
Expand Down
78 changes: 78 additions & 0 deletions install/class.update_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,32 @@ public static function translation_fam() {
return '';
}

public static function diagrams_fam() {
global $tmp_dir, $globalTransaction;
$header = NULL;
$delimiter = " ";
$Connection = new Connection();
if (($handle = fopen($tmp_dir.'diagramspdf', 'r')) !== FALSE)
{
$Connection->db->beginTransaction();
while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
{
$query = 'UPDATE airport SET diagram_pdf = :diagrampdf, diagram_png = :diagrampng WHERE icao = :icao';
$icao = str_replace('.pdf','',$data[2]);
try {
$sth = $Connection->db->prepare($query);
$sth->execute(array(':icao' => $icao,':diagrampdf' => 'https://data.flightairmap.com/data/diagrams/'.$icao.'.pdf',':diagrampng' => 'https://data.flightairmap.com/data/diagrams/'.$icao.'.png'));
} catch(PDOException $e) {
echo "error : ".$e->getMessage();
return "error : ".$e->getMessage();
}
}
fclose($handle);
$Connection->db->commit();
}
return '';
}

/*
* This function use FAA public data.
* With the help of data from other source, Mfr id is added to manufacturer table. Then ModeS with ICAO are added based on that.
Expand Down Expand Up @@ -2655,6 +2681,31 @@ public static function update_satellite_fam() {
}
return '';
}
public static function update_diagrams_fam() {
global $tmp_dir, $globalDebug;
update_db::download('http://data.flightairmap.com/data/diagrams/diagramspdf.md5',$tmp_dir.'diagramspdf.md5');
if (file_exists($tmp_dir.'diagramspdf.md5')) {
$diagrams_md5_file = explode(' ',file_get_contents($tmp_dir.'diagramspdf.md5'));
$diagrams_md5 = $diagrams_md5_file[0];
if (!update_db::check_diagrams_version($diagrams_md5)) {
if ($globalDebug) echo "Airports diagrams from FlightAirMap website : Download...";
update_db::download('http://data.flightairmap.com/data/diagrams/diagramspdf',$tmp_dir.'diagramspdf');
if (file_exists($tmp_dir.'diagramspdf')) {
if (md5_file($tmp_dir.'diagramspdf') == $diagrams_md5) {
if ($globalDebug) echo "Add to DB...";
$error = update_db::diagrams_fam();
} else $error = "File ".$tmp_dir.'diagramspdf'." md5 failed. Download failed.";
} else $error = "File ".$tmp_dir.'diagramspdf'." doesn't exist. Download failed.";
if ($error != '') {
return $error;
} else {
update_db::insert_diagrams_version($diagrams_md5);
if ($globalDebug) echo "Done\n";
}
}
}
return '';
}
public static function update_banned_fam() {
global $tmp_dir, $globalDebug;
if ($globalDebug) echo "Banned airlines in Europe from FlightAirMap website : Download...";
Expand Down Expand Up @@ -3296,6 +3347,19 @@ public static function check_satellite_version($version) {
if ($row['nb'] > 0) return true;
else return false;
}
public static function check_diagrams_version($version) {
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'diagrams_version' AND value = :version";
try {
$Connection = new Connection();
$sth = $Connection->db->prepare($query);
$sth->execute(array(':version' => $version));
} catch(PDOException $e) {
return "error : ".$e->getMessage();
}
$row = $sth->fetch(PDO::FETCH_ASSOC);
if ($row['nb'] > 0) return true;
else return false;
}

public static function check_airlines_version($version) {
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'airlines_version' AND value = :version";
Expand Down Expand Up @@ -3396,6 +3460,17 @@ public static function insert_satellite_version($version) {
return "error : ".$e->getMessage();
}
}
public static function insert_diagrams_version($version) {
$query = "DELETE FROM config WHERE name = 'diagrams_version';
INSERT INTO config (name,value) VALUES ('diagrams_version',:version);";
try {
$Connection = new Connection();
$sth = $Connection->db->prepare($query);
$sth->execute(array(':version' => $version));
} catch(PDOException $e) {
return "error : ".$e->getMessage();
}
}

public static function check_last_notam_update() {
global $globalDBdriver;
Expand Down Expand Up @@ -3814,6 +3889,7 @@ public static function update_all() {
echo update_db::fix_icaotype();
echo update_db::update_banned_fam();
echo update_db::update_block_fam();
echo update_db::update_diagrams();
//echo update_db::update_celestrak();
//echo update_db::delete_duplicatemodes();
} else {
Expand All @@ -3829,6 +3905,7 @@ public static function update_all() {
//echo update_db::delete_duplicatemodes();
echo update_db::update_banned_fam();
echo update_db::update_block_fam();
echo update_db::update_diagrams();
}
}
}
Expand Down Expand Up @@ -3865,5 +3942,6 @@ public static function update_all() {
//echo update_db::update_celestrak();
//echo update_db::update_aircraft();
//echo update_db::update_block_fam();
//echo update_db::update_diagrams_fam();

?>
3 changes: 3 additions & 0 deletions js/map.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ function dynamicSortMultiple() {
function map2dlimit(limit) {
createCookie('map_2d_limit',limit,9999);
}
function map3dlimit(limit) {
createCookie('map_3d_limit',limit,9999);
}

function mapType(selectObj) {
var idx = selectObj.selectedIndex;
Expand Down
4 changes: 2 additions & 2 deletions require/class.Spotter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2190,9 +2190,9 @@ public function getAllAirportInfo($airport = '')
if ($airport == 'NA') {
return array(array('name' => 'Not available','city' => 'N/A', 'country' => 'N/A','iata' => 'NA','icao' => 'NA','altitude' => NULL,'latitude' => 0,'longitude' => 0,'type' => 'NA','home_link' => '','wikipedia_link' => '','image_thumb' => '', 'image' => ''));
} elseif ($airport == '') {
$query = "SELECT airport.name, airport.city, airport.country, airport.iata, airport.icao, airport.latitude, airport.longitude, airport.altitude, airport.type, airport.home_link, airport.wikipedia_link, airport.image_thumb, airport.image FROM airport";
$query = "SELECT airport.name, airport.city, airport.country, airport.iata, airport.icao, airport.latitude, airport.longitude, airport.altitude, airport.type, airport.home_link, airport.wikipedia_link, airport.image_thumb, airport.image, airport.diagram_pdf, airport.diagram_png FROM airport";
} else {
$query = "SELECT airport.name, airport.city, airport.country, airport.iata, airport.icao, airport.latitude, airport.longitude, airport.altitude, airport.type, airport.home_link, airport.wikipedia_link, airport.image_thumb, airport.image FROM airport WHERE airport.icao = :airport LIMIT 1";
$query = "SELECT airport.name, airport.city, airport.country, airport.iata, airport.icao, airport.latitude, airport.longitude, airport.altitude, airport.type, airport.home_link, airport.wikipedia_link, airport.image_thumb, airport.image, airport.diagram_pdf, airport.diagram_png FROM airport WHERE airport.icao = :airport LIMIT 1";
$query_values = array(':airport' => $airport);
}

Expand Down

0 comments on commit 3eb940c

Please sign in to comment.