} else { $sql .= " ORDER BY src_date DESC, src_time DESC"; } // Execute! $result = mysql_query($sql, $db) or die('Error;Query ' . print_r($_GET, true) . ' caused database error ' . $sql . ', ' . mysql_error()); $first = true; if ($export == "export" || $export == "backup") { // Start with byte-order mark to try to clue Excel into realizing that this is UTF-8 print "Date,From,To,Flight_Number,Airline,Distance,Duration,Seat,Seat_Type,Class,Reason,Plane,Registration,Trip,Note,From_OID,To_OID,Airline_OID,Plane_OID\r\n"; } $gcmap_city_pairs = ''; // list of city pairs when doing gcmap export. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $note = $row["note"]; if ($route) { $row["distance"] = gcPointDistance(array("x" => $row["sx"], "y" => $row["sy"]), array("x" => $row["dx"], "y" => $row["dy"])); $row["duration"] = gcDuration($row["distance"]); $row["code"] = $row["al_name"] . " (" . $row["code"] . ")"; $note = ""; if ($row["stops"] == "0") { $note = "Direct"; } else { $note = $row["stops"] . " stops"; } if ($row["codeshare"] == "Y") { $note = "Codeshare"; } } if ($first) { $first = false; } else {
function gcPath($startPoint, $endPoint, $distance, $threed) { global $GC_STEP, $ASCENT_STEP, $ASCENT_SPEED, $MAGIC_NUMBER, $CRUISE_ALTITUDE; $pointList = array(); $pointList[] = $startPoint; $wayPoint = $startPoint; $distance = gcPointDistance($startPoint, $endPoint); $elevation = 0; if ($threed) { $step = $ASCENT_STEP; $elevation = $startPoint["z"]; $delta = 1; // Ascending // Calculate distance at which to start descent $ascentspeed = ($CRUISE_ALTITUDE - $startPoint["z"]) / $ASCENT_SPEED; $descentspeed = ($CRUISE_ALTITUDE - $endPoint["z"]) / $ASCENT_SPEED; $descentpoint = $distance - $MAGIC_NUMBER * $ASCENT_STEP; if ($descentpoint < $distance / 2) { $descentpoint = $distance / 2; } } else { $step = $GC_STEP; } $d = 0; // And... action! while ($d + 1 < $distance) { //printf("%s of %s: from %s,%s now at %s,%s step %s bearing %s target %s,%s\n", $d, $distance, $startPoint["x"], $startPoint["y"], $step, $bearing, $wayPoint["x"], $wayPoint["y"], $endPoint["x"], $endPoint["y"]); // Cruising, but increase step resolution near the poles if ($threed && $delta != 0) { $step = $ASCENT_STEP; } else { if (abs($wayPoint["y"]) > 60) { $step = $GC_STEP / 2; } else { $step = $GC_STEP; } } if ($threed) { // Ascending if ($delta > 0) { if ($elevation < ($CRUISE_ALTITUDE - $startPoint["z"]) / 2 + $startPoint["z"]) { $delta += $ascentspeed; } else { $delta -= $ascentspeed; } if ($elevation >= $CRUISE_ALTITUDE || $delta < 0) { $elevation = $CRUISE_ALTITUDE; $delta = 0; } } // Descending if ($d + $step >= $descentpoint) { if ($d >= $descentpoint) { if ($elevation > ($CRUISE_ALTITUDE - $endPoint["z"]) / 2 + $endPoint["z"]) { $delta -= $descentspeed; } else { $delta += $descentspeed; } $step = $ASCENT_STEP; } else { // Prepare for descent! $step = $descentpoint - $d; } if ($elevation < $endPoint["z"]) { $delta = 0; $elevation = $endPoint["z"]; } } $elevation += $delta; } $bearing = gcBearingTo($wayPoint, $endPoint); // degrees, clockwise from 0 deg at north $wayPoint = gcWaypoint($wayPoint, $step, $bearing); if ($threed) { $wayPoint["z"] = $elevation; } if ($wayPoint["x"] > -180 && $wayPoint["x"] < 180) { $pointList[] = $wayPoint; } else { // Flip paths crossing the edge of the map if ($wayPoint["x"] < -180 && $bearing > 180) { $pointList[] = array("x" => -180, "y" => $wayPoint["y"], "z" => $elevation); $wayPoint["x"] += 360; $pointList[] = null; // break mark $pointList[] = array("x" => 180, "y" => $wayPoint["y"], "z" => $elevation); } if ($wayPoint["x"] > 180 && $bearing < 180) { $pointList[] = array("x" => 180, "y" => $wayPoint["y"], "z" => $elevation); $wayPoint["x"] -= 360; $pointList[] = null; // break mark $pointList[] = array("x" => -180, "y" => $wayPoint["y"], "z" => $elevation); } } $d = gcPointDistance($startPoint, $wayPoint); } $pointList[] = $endPoint; return $pointList; }
// We need these variables to be able scale the long/lat coordinates. $scale_x = imagesx($im); $scale_y = imagesy($im); // Now we convert the long/lat coordinates into screen coordinates $result = mysql_query($sql, $db); $count = 0; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $count++; if ($count % 100 == 0) { fwrite($stderr, "{$count} "); } $x1 = $row["sx"]; $y1 = $row["sy"]; $x2 = $row["dx"]; $y2 = $row["dy"]; $distance = gcPointDistance(array("x" => $x1, "y" => $y1), array("x" => $x2, "y" => $y2)); if ($distance > $GC_MIN) { // Plot great circle curve $points = gcPath(array("x" => $x1, "y" => $y1), array("x" => $x2, "y" => $y2), $distance, false); } else { // Draw straight lines $points = straightPath(array("x" => $x1, "y" => $y1), array("x" => $x2, "y" => $y2)); } $oldpt = null; foreach ($points as $loc) { if ($loc == null) { $oldpt = null; continue; } $newpt = getlocationcoords($loc["y"], $loc["x"], $scale_x, $scale_y); if ($oldpt) {
} else { die('Error;No airline with ID ' . $apid . ' found'); } if ($row["count"] == 0) { // No routes, abort printf("\n\n\n\n\n\n"); exit; } $alname = $row["iata"]; } // List of all flights FROM this airport $sql = "SELECT DISTINCT s.apid,s.x,s.y,d.apid,d.x,d.y,count(rid),0,{$codeshare} AS future,'F' AS mode FROM routes AS r, airports AS s, airports AS d WHERE {$condition} AND r.src_apid=s.apid AND r.dst_apid=d.apid 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)) { $row[7] = gcPointDistance(array("x" => $row[1], "y" => $row[2]), array("x" => $row[4], "y" => $row[5])); 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 with flights FROM this airport if ($type == "A") { $apcond = "(r.src_apid=a.apid OR r.dst_apid=a.apid)"; // include source airport } else { $apcond = "r.src_apid=a.apid"; // prevent double-counting