$flight->incViews();
//show limited info to non friends
if ($flight->private == 4 && !$flight->flightIsViewableByUser($userID)) {
    require dirname(__FILE__) . '/GUI_flight_show_ext.php';
    return;
}
if ($flight->externalFlightType & SYNC_INSERT_FLIGHT_LINK) {
    require dirname(__FILE__) . '/GUI_flight_show_ext.php';
    return;
}
$Ltemplate->set_filenames(array('body' => 'flight_show.html'));
$geUrl = getDownloadLink(array('type' => 'kml_trk', 'flightID' => $flightID, 'lang' => $lng));
// $moduleRelPath."/download.php?lang=$lng&type=kml_trk";
$clientIP = getClientIpAddr();
$directIGCLink = 1;
if ($flight->belongsToUser($userID) || L_auth::isModerator($userID) || L_auth::canDownloadIGC($clientIP)) {
    $directIGCLink = 1;
    $base_name = md5(basename($flight->getIGCRelPath()));
    $_SESSION['di' . $base_name] = 1;
    // echo 'downloadigc'+$base_name;
    $igcLink = "<a href='" . $flight->getIGCRelPath() . "' >IGC</a>";
} else {
    $directIGCLink = 0;
    $igcLink = " <a href='javascript:nop()' onClick='toggleIgcDownload();return false;' id='IgcDownloadPos'>IGC</a>";
}
//experiment with google static maps
if (0) {
    list($min_lat, $min_lon, $max_lat, $max_lon) = $flight->getBounds();
    $cLat = $min_lat + ($max_lat - $min_lat) / 2;
    $cLon = $min_lon + ($max_lon - $min_lon) / 2;
    $sLat = ($max_lat - $min_lat) / 2;
    exit;
}
$clientIP = getClientIpAddr();
if ($flightID) {
    $flight = new flight();
    $flight->getFlightFromDB($flightID);
    $authOK = 0;
    if ($flight->belongsToUser($userID) || L_auth::isModerator($userID) || L_auth::canDownloadIGC($clientIP)) {
        $authOK = 1;
    }
} else {
    if ($filename) {
        $authOK = 0;
        $base_name = basename($filename);
        // echo $base_name."#";
        if (L_auth::isModerator($userID) || L_auth::canDownloadIGC($clientIP) || $_SESSION['di' . $base_name]) {
            $authOK = 1;
        }
    }
}
if ($authOK) {
    $type = 'igc';
    require_once dirname(__FILE__) . '/download_igc.php';
    return;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php 
echo $CONF_ENCODING;