#include <infodrom.style>
#include <quote.style>

<page title="Infodrom Oldenburg - Mail-Archive">

<div class="head">
Mail Archive<?
  if (strlen ($_GET["list"])> 0 && is_dir ($_GET["list"])) {
      echo " &ndash; " . $_GET["list"];
  }
?>
</div>

<ul>
<?
  /*
    ACHTUNG: - Kein Support für ausgeschriebenen Namen der Liste
             - Kein Support für Liste ohne Unterverzeichnisse 1999, 2000 etc.
  */

  function get_months ($dirname)
  {
    $dir = dir ($dirname);
    $months = array ();

    while ($dentry = $dir->read()) {
      if ($dentry != "." && $dentry != ".." && is_dir ("$dirname/$dentry") && ereg ("^[01][0-9]$", $dentry)) {
        $months[] = $dentry;
      }
    }
    $dir->close();
    sort ($months);
    return $months;
  }

  if (strlen ($_GET["list"]) > 0 && is_dir ($_GET["list"])) {
    $dirs = array ($_GET["list"]);
  } else {
    $dir = dir (".");
    $dirs = array ();
    while ($dentry = $dir->read()) {
      if ($dentry != "." && $dentry != ".." && is_dir ($dentry)
        && $dentry != "gifs" && $dentry != "stats") {
	$dirs[] = $dentry;
      }
    }
    $dir->close();
    sort ($dirs);
  }

  $max = count ($dirs);
  for ($i=0; $i < $max; $i++) {

    $file = $dirs[$i] . "/" . "index.inc";
    if (is_file ($file)) {
      $f = fopen ($file, "r");
      if ($f) {
        while (!feof ($f)) {
          $line = fgets ($f, 255);
	  print ($line);
	}
        fclose ($f);
      }
    } else {
      # Do it yourself


    printf ("<li> <strong>%s</strong><br>", $dirs[$i]);

    $dir = dir ($dirs[$i]);
    $years = array ();
    while ($dentry = $dir->read()) {
      if ($dentry != "." && $dentry != ".." && is_dir ("$dirs[$i]/$dentry")) {
        $years[] = $dentry;
      }
    }
    $dir->close();
    sort ($years);

    $ymax = count ($years);
    for ($y=0; $y < $ymax; $y++) {
      $months = get_months ("$dirs[$i]/$years[$y]");
      if (count ($months) > 0) {
        printf ("%s%s (", $y>0?", ":"", $years[$y]);
	for ($m=0; $m < count ($months); $m++) {
	  printf ("%s<a href=\"%s/%s/%s/\">%s</a>",
	    $m>0?", ":"", $dirs[$i], $years[$y], $months[$m], $months[$m]);
	}
	echo   (")");
      } else {
        printf ("%s<a href=\"%s/%s/\">%s</a>",
          $y>0?", ":"", $dirs[$i], $years[$y], $years[$y]);
      }
    }
  }  # else
  }

  if (strlen ($_GET["list"]) > 0 && is_dir ($_GET["list"])) {
    printf ("<li> <strong><a href=\"<root_prefix>stats/details.php?list=%s\">Statistics</a></strong><br>",
        $_GET["list"]);
  } else {
    echo ("<li> <strong><a href=\"<root_prefix>stats/index.php\">Statistics</a></strong><br>");
  }
?>

<li> <strong><a href="<root_prefix>search.html">Search</a></strong><br>
</ul>

<div class="fortune">
<div class="fortune-body">
<h3 class="fortune-title">Quote of the Day</h3>
<div class="fortune-content" id="fortune">
<?
  function format_cookie ($cookie, $bg)
  {
    $fsource = "<div class=\"fortune-attribution\"><span style=\"display: none;\">-- </span>%s</div>";
    $attribution = 0;
    $result = '<div class="fortune_'.$bg.'">';
    $firstchar = substr ($cookie[0], 0, 1);
    if ( ($firstchar == "<")
      || ($firstchar == ">")
      || ($firstchar == "*")
      || ($firstchar == " ")
      || ($firstchar == "[") ) {
      $pre = 1;
      $result .= "<pre class=\"smallfont\">\n";
    } else {
      $result .= "<p>\n";
    }

    for ($i=0; $i < count ($cookie); $i++) {
      $line = $cookie[$i];
      $line = ereg_replace ("<", "&lt;", $line);
      $line = ereg_replace (">", "&gt;", $line);

      if (ereg ("^		?-- ", $line)) {
	$line = ereg_replace ("^		?-- ", "", rtrim($line));
        if ($pre) {
          $pre = 0;
          $result .= "</pre>\n";
        } else {
          $result .= "</p>\n";
        }
        $result .= sprintf ($fsource, $line);
        $attribution = 1;
      } else {
        if (!$pre && substr($line, 0, 1) == ' ')
          $result .= "<br>";
        $result .= $line;
      }
    }
    if (!$attribution) {
      if ($pre) {
        $pre = 0;
        $result .= "</pre>\n";
      } else {
        $result .= "</p>\n";
      }
    }
    $result .= "</div>\n";
    return $result;
  }

  if (is_file ("../www.infodrom.org/fortune-general-en.html")) {
    $fortune = fopen ("../www.infodrom.org/fortune-general-en.html", "r");
  }
  if ($fortune) {
    $cookie = array ();
    while (!feof ($fortune)) {
      $line = fgets ($fortune, 255);
      $cookie[] = $line;
    }
    fclose ($fortune);
    echo format_cookie ($cookie, 0);
  } else {
    echo "<p>No fortune today.</p>";
  }
?>
</div>
</div>
</div>

</page>

# Local variables:
# mode: indented-text
# mode: auto-fill
# end:
