예제 #1
0
 function test()
 {
     $row = array("name" => "Airport", "city" => "City", "country" => "Country", "iata" => "AAA", "icao" => "BBBB");
     $this->assertEqual(format_airport($row), "City-Airport (AAA), Country");
     $row = array("name" => "City Intl", "city" => "City", "country" => "Country", "iata" => "AAA", "icao" => "BBBB");
     $this->assertEqual(format_airport($row), "City Intl (AAA), Country");
     $row = array("name" => "Hong-kong Intl", "city" => "Hong Kong", "country" => "Country", "iata" => "AAA", "icao" => "BBBB");
     $this->assertEqual(format_airport($row), "Hong-kong Intl (AAA), Country");
     $row = array("name" => "Obscure Regional", "city" => "Inaka", "country" => "Country", "iata" => "", "icao" => "BBBB");
     $this->assertEqual(format_airport($row), "Inaka-Obscure Regional (BBBB), Country");
     $row = array("name" => "Really Long Airport Name", "city" => "Really Long City Name", "country" => "Country", "iata" => "AAA", "icao" => "BBBB");
     $this->assertEqual(format_airport($row), "Really Long City Name-Really Lon. (AAA), Country");
 }
예제 #2
0
if ($row = mysql_fetch_array($result2, MYSQL_NUM)) {
    $max = $row[0];
}
$response = array("status" => 1, "offset" => $offset, "max" => $max);
// Fetch airport data
$sql .= " ORDER BY name LIMIT 10 OFFSET " . $offset;
$result = mysql_query($sql, $db) or die(json_encode(array("status" => 0, "message" => 'Operation ' . $param . ' failed: ' . $sql)));
while ($rows[] = mysql_fetch_assoc($result)) {
}
array_pop($rows);
foreach ($rows as &$row) {
    if ($dbname == "airports_dafif" || $dbname == "airports_oa") {
        $row["country"] = $row["code"];
    }
    if ($row["uid"] || $uid == $OF_ADMIN_UID) {
        if ($row["uid"] == $uid || $uid == $OF_ADMIN_UID) {
            $row["ap_uid"] = "own";
            // editable
        } else {
            $row["ap_uid"] = "user";
            // added by another user
        }
    } else {
        $row["ap_uid"] = null;
        // in DB
    }
    $row["ap_name"] = format_airport($row);
    unset($row["uid"]);
}
$response['airports'] = $rows;
print json_encode($response);
예제 #3
0
$sql = "SELECT * FROM airports WHERE apid IN (SELECT DISTINCT src_apid\n\t    FROM routes) ORDER BY iata";
$result = mysql_query($sql, $db);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $iata = $row['iata'];
    if (ctype_alnum($iata)) {
        $label = format_airport($row);
        print "<a href='/airport/{$iata}'>{$label}</a>, ";
    }
}
print "<h2>Airport route maps (by ICAO code)</h2>";
$sql = "SELECT * FROM airports WHERE apid IN (SELECT DISTINCT src_apid\n\t    FROM routes) ORDER BY iata";
$result = mysql_query($sql, $db);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $icao = $row['icao'];
    if (ctype_alnum($icao)) {
        $label = format_airport($row);
        print "<a href='/airport/{$icao}'>{$label}</a>, ";
    }
}
?>
	  </div>
	</div>
	<div id="sideBar">
<?php 
include "../sidebar.html";
include "ad-sidebar.html";
?>
	  
	</div>

      </div> <!-- end sidebarwrapper -->
예제 #4
0
//         <latitude>40.71417</latitude>
//         <longitude>-74.00639</longitude>
//     </location>
//     <offset>-5</offset>
//     <suffix>R</suffix>
//     <localtime>4 Dec 2005 12:06:56</localtime>
//     <isotime>2005-12-04 12:06:56 -0500</isotime>
//     <utctime>2005-12-04 17:06:56</utctime>
//     <dst>False</dst>
// </timezone>
$db = mysql_connect("localhost", "openflights");
mysql_select_db("flightdb2", $db);
$sql = "select * from airports where timezone is null";
$result = mysql_query($sql, $db) or die('Database error: ' . $sql . ', error ' . mysql_error());
while ($row = mysql_fetch_assoc($result)) {
    $name = format_airport($row);
    $lon = $row["x"];
    $lat = $row["y"];
    $apid = $row["apid"];
    $html = file_get_html("http://www.earthtools.org/timezone/{$lat}/{$lon}");
    $tz = $html->find('offset', 0)->plaintext;
    $dst = $html->find('dst', 0)->plaintext;
    $count++;
    print "{$count}: {$name} ({$lon}, {$lat}): Timezone {$tz}, DST {$dst}";
    switch ($dst) {
        case "True":
            $dstcode = "E";
            // European
            break;
        case "False":
            $dstcode = "N";
예제 #5
0
}
// List of all flights (unique by airport pair)
$sql = "SELECT DISTINCT s.apid,s.x,s.y,d.apid,d.x,d.y,count(fid),distance AS times,IF(MIN(src_date)>NOW(), 'Y', 'N') AS future,f.mode FROM flights AS f, airports AS s, airports AS d WHERE f.src_apid=s.apid AND f.dst_apid=d.apid AND f.uid=" . $uid . " " . $filter . " GROUP BY s.apid,d.apid";
$result = mysql_query($sql, $db) or die('Error;Database error ' . $sql . ', ' . mysql_error());
$first = true;
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    if ($first) {
        $first = false;
    } else {
        $map .= "\t";
    }
    $map .= sprintf("%s;%s;%s;%s;%s;%s;%s;%s;%s;%s", $row[0], $row[1], $row[2], $row[3], $row[4], $row[5], $row[6], $row[7], $row[8], $row[9]);
}
$map .= "\n";
// List of all airports
$sql = "SELECT DISTINCT a.apid,x,y,name,iata,icao,city,country,timezone,dst,count(name) AS visits,IF(MIN(src_date)>NOW(), 'Y', 'N') AS future FROM flights AS f, airports AS a WHERE (f.src_apid=a.apid OR f.dst_apid=a.apid) AND f.uid=" . $uid . $filter . " GROUP BY CONCAT(name,city) ORDER BY visits ASC";
$result = mysql_query($sql, $db) or die('Error;Database error ' . $sql . ', ' . mysql_error());
$first = true;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    if ($first) {
        $first = false;
    } else {
        $map .= "\t";
    }
    $map .= sprintf("%s;%s;%s;%s;%s;%s;%s", format_apdata($row), $row["name"], $row["city"], $row["country"], $row["visits"], format_airport($row), $row["future"]);
}
print $map . "\n";
// When running for the first time, load up possible filter settings for this user
if ($init == "true") {
    loadFilter($db, $uid, $trid, $logged_in);
}
예제 #6
0
$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");
예제 #7
0
function resolve_airport($iata_code)
{
    global $dbh;
    if (empty($iata_code)) {
        return null;
    }
    try {
        $sth = $dbh->prepare("SELECT * FROM airports WHERE iata=?");
        $sth->execute(array($iata_code));
        if ($sth->rowCount()) {
            $result = $sth->fetch();
            return array("id" => $result["apid"], "name" => htmlentities(format_airport($result)));
        } else {
            return null;
        }
    } catch (PDOException $e) {
        die(_("Database error."));
    }
}
예제 #8
0
                $sql = sprintf("%s OR name LIKE '%s%%') ORDER BY city,name LIMIT %s", $sql, $query, $limit);
            } else {
                $sql = sprintf("%s) ORDER BY city,name LIMIT %s", $sql, $limit);
            }
            break;
    }
    if ($limit > 1) {
        print "<ul class='autocomplete'>";
    }
    $rs = mysql_query($sql);
    if (mysql_num_rows($rs) > 0) {
        while ($row = mysql_fetch_assoc($rs)) {
            if ($limit > 1) {
                printf("<li class='autocomplete' origin='%s' id='%s'>%s</li>\n", $ap, format_apdata($row), format_airport($row));
            } else {
                printf("%s;%s", format_apdata($row), format_airport($row));
                exit;
                // match found, do not fall thru to airlines
            }
        }
    }
}
if (!$query || $multi) {
    // Autocompletion for airlines
    // 2 chars: match on IATA or name (major airlines only)
    // 3 chars: match on ICAO or name (major airlines only)
    // >3 chars: match on name (any airline)
    $airlines = array("qs", "airline", "airline1", "airline2", "airline3", "airline4");
    foreach ($airlines as $al) {
        if ($_POST[$al]) {
            $query = mysql_real_escape_string($_POST[$al]);