<?php

require 'cgi-bin/functions.php';
require 'cgi-bin/vars.php';
opening_html();
echo "<h3>Welcome to {$orginization}'s history page!</h3>\n\nFeel free to browse using the links below.<br />\n<br />\n<a href=\"year.php\">Search by year</a><br />\n<br />\n<a href=\"trips.php\">List all trips</a><br />\n<br />\n<a href=\"about.php\">About this site</a>";
navlinks(array());
closing_html();
        if ($dir_handler = opendir($activitiesdir . $year . "/")) {
            while (($file = readdir($dir_handler)) !== false) {
                if (!is_dir($activitiesdir . $year . "/" . $file)) {
                    // && preg_match($file, "/\.(ini)/")) {
                    $filename_exp = explode(".", $file);
                    if ($filename_exp[0] != "") {
                        echo "<li><a href=\"activity.php?activity=" . $filename_exp[0] . "&year={$year}\">" . ucfirst($filename_exp[0]) . "</a></li>\r";
                    }
                }
            }
            closedir($dir_handler);
        }
    }
    echo "</ul>\n\t<hr>";
}
echo "Please choose a year:\n<form action=\"year.php\" method=\"get\">\n<select name=\"year\">";
if (is_dir($activitiesdir)) {
    if ($dir_handler = opendir($activitiesdir)) {
        while (($file = readdir($dir_handler)) !== false) {
            if (is_dir($activitiesdir . $file)) {
                if ($file != "." && $file != ".." && $file != "0000") {
                    echo "<option value=\"{$file}\">" . $file . "</option>\r";
                }
            }
        }
        closedir($dir_handler);
    }
}
echo "</select>\n<input type=\"submit\" value=\"Search\">\n</form>";
navlinks(array(array("index.php", "Return Home")));
closing_html();
echo "<br />\n";
if (is_dir("{$location}/{$year}/{$activity}")) {
    $count = 0;
    echo "<hr>\n<H3>Images</H3>\r";
    if ($dir_handler = opendir("{$location}/{$year}/{$activity}/")) {
        while (($file = readdir($dir_handler)) !== false) {
            if (!is_dir("{$location}/{$year}/{$activity}/" . $file)) {
                $fileexp = explode(".", $file);
                $ext = strtolower($fileexp[1]);
                if ($ext == "jpg" || $ext == "gif" || $ext == "png" || $ext == "jpeg") {
                    echo "<a href=\"image_view.php?file=" . urlencode("{$location}/{$year}/{$activity}/{$file}") . "\"><img src=\"{$location}/{$year}/{$activity}/{$file}\" width=\"300\" style=\"border:0;\" alt=\"{$file}\"/></a><br /><br />";
                    $count++;
                }
            }
        }
        closedir($dir_handler);
    }
    if ($count == 0) {
        echo "No images found, sorry.";
    }
}
$navs = array();
if ($year != "0000" && $year != "" && isset($year)) {
    $navs[0] = array("year.php?year={$year}", "View other trips this year");
} else {
    $navs[0] = array("year.php", "Search trips by year");
}
$navs[1] = array("trips.php", "View all trips");
$navs[2] = array("index.php", "Return home");
navlinks($navs);
closing_html();