function test() { $row = array("iata" => "AAA", "icao" => "BBBB"); $this->assertEqual(format_apcode($row), "AAA"); $row = array("iata" => null, "icao" => "BBBB"); $this->assertEqual(format_apcode($row), "BBBB"); $row = array("iata" => null, "icao" => null); $this->assertEqual(format_apcode($row), "Priv"); }
function format_airport($row) { $name = $row["name"]; $city = $row["city"]; $country = $row["country"]; if (array_key_exists("code", $row)) { $country = $code; // hack for DAFIF } $iata = format_apcode($row); // Foobar-Foobar Intl into Foobar Intl // Foo-bar-Foo Bar Intl into Foo Bar Intl if (strncasecmp(strtr($name, "-", " "), strtr($city, "-", " "), strlen($city)) == 0) { $city = ""; } else { $city = $city . "-"; } if (strlen($city . $name . $country) > 40) { $name = trim(substr($city . $name, 0, 39 - strlen($country))) . "."; $city = ""; } return $city . $name . " (" . $iata . "), " . $country; }
// "select dst_apid as apid, distance, count(*) as fid from flights where uid = $uid group by dst_apid ) as f " . // "where f.apid=a.apid $filter " . // "group by a.apid order by count desc limit $limit"; //print $sql; // // ^^^ this is even faster, but $mode has to be SUM(fid), not COUNT(fid), to count flights correctly... $sql = "select a.name, a.iata, a.icao, {$mode} as count, a.apid from airports as a, " . "(select src_apid as apid, distance, fid from flights as f where uid = {$uid} {$filter} " . " UNION ALL " . "select dst_apid as apid, distance, fid from flights as f where uid = {$uid} {$filter} ) as f " . "where f.apid=a.apid " . "group by a.apid order by count desc limit {$limit}"; $result = mysql_query($sql, $db); $first = true; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($first) { $first = false; } else { printf(":"); } $code = format_apcode($row); printf("%s,%s,%s,%s", $row["name"], $code, $row["count"], $row["apid"]); } printf("\n"); // List top 10 airlines $sql = "select a.name, {$mode} as count, a.alid from airlines as a, flights as f where f.uid={$uid} and f.alid=a.alid {$filter} group by f.alid order by count desc limit {$limit}"; $result = mysql_query($sql, $db); $first = true; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($first) { $first = false; } else { printf(":"); } printf("%s,%s,%s", $row["name"], $row["count"], $row["alid"]); }
$result = mysql_query($sql, $db); $first = true; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $count = $row["visits"]; if ($first) { $maxFlights = $count; $first = false; } $colorIndex = floor($count / $maxFlights * sizeof($airportColors)) + 1; if ($count <= 2 || $colorIndex < 0) { $colorIndex = 0; } // More than two flights: at least 2nd smallest if ($count > 2) { $colorIndex = max(1, $colorIndex); } // Max out at top color if ($colorIndex >= sizeof($airportColors)) { $colorIndex = sizeof($airportColors) - 1; } print "<Placemark>\n"; print " <name>" . format_apcode($row) . "</name>\n"; printf(" <description>\n <![CDATA[\n<b>%s</b><br><i>Elevation</i>: %s ft<br><i>Flights</i>: %s\n]]>\n </description>\n", format_airport($row), $row["elevation"], $count); print " <Point>\n"; printf(" <coordinates>%s,%s,%s</coordinates>\n", $row["x"], $row["y"], $row["elevation"]); print " </Point>\n"; print " <styleUrl>#" . $airportColors[$colorIndex] . "-pushpin</styleUrl>\n"; print "</Placemark>\n"; } print "</Folder>\n"; readfile("../kml/footer.kml");
// never show dotted lines for airport route maps } } $map = ""; // Title for this airport route data plus count of routes // (count = 0 when airport exists but has no routes) if ($type == "A") { if ($alid) { $filter = " AND r.alid={$alid}"; } else { $filter = ""; } $sql = "SELECT COUNT(src_apid) AS count, apid, x, y, name, iata, icao, city, country, timezone, dst FROM airports AS a LEFT OUTER JOIN routes AS r ON r.src_apid=a.apid {$filter} WHERE a.apid={$apid} GROUP BY src_apid"; $result = mysql_query($sql, $db); if ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { printf("%s;%s;%s (<b>%s</b>)<br><small>%s, %s<br>%s routes</small>\n", $apid, $row["count"], $row["name"], format_apcode($row), $row["city"], $row["country"], $row["count"]); } else { die('Error;No airport with ID ' . $apid . ' found'); } if ($row["count"] == 0) { // No routes, print this airport and abort printf("\n%s;%s;%s;%s;0;%s;N\n", format_apdata($row), $row["name"], $row["city"], $row["country"], format_airport($row)); exit; } } else { if ($alid) { $filter = ""; } else { $filter = " AND r.codeshare=''"; // by default, don't display codeshares }