<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>D. Vrabel&apos;s/PnP/Logs</title>
  <link href="logs.css" rel="stylesheet" type="text/css"/>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
</head>

<body>
<div class="header">
<a href="..">Contents</a> / <a href=".">PnP Stuff</a> / Logs
</div>

<h1>PnP Session Logs</h1>

<?php
$log_dirs = array(
    new LogDirectory( "logs/On the Great River II", "On the Great River II" ),
    new LogDirectory( "logs/The Dark Trade", "The Dark Trade" ),
    new LogDirectory( "logs/nwc", "Northwatch Chronicles" ),
    new LogDirectory( "logs/DMed", "DMed" ),
    new LogDirectory( "logs/played", "Played" ),
    new LogDirectory( "logs/TSG", "TSG" ),
    new LogDirectory( "logs/Craig's", "Craig's" ),
    new logDirectory( "logs", "Recent" ),
    );
?>

<table>
<tr>
<?php
foreach( $log_dirs as $l ) {
    echo "<th>$l->display_name</th>\n";
}
?>
</tr>
<tr>
<?php
foreach( $log_dirs as $l ) {
    echo "<td>";
    $l->print_latest();
    echo "</td>\n";
}
?>
</tr>
<tr>
<?php
foreach( $log_dirs as $l ) {
    echo "<td>";
    $l->list_logs();
    echo "</td>\n";
}
?>
</tr>
</table>

<div class="footer">
<a href="..">Contents</a> /  <a href=".">PnP Stuff</a> / Logs
</div>

</body>

</html>

<?php
class LogDirectory {
    var $directory;
    var $display_name;
    var $logs;
    
    function LogDirectory($dir, $name)
    {
        $this->directory = $dir;
        $this->display_name = $name;
        
        $this->find_logs();
    }
    
    function find_logs()
    {
        $old_style_regex
            = "^log-[[:digit:]]{2}-[[:digit:]]{2}-[[:digit:]]{2}\.html$";
        $new_style_regex
            = "^log-[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}\.html$";
        
        $this->logs = array();
        
        $dir = dir( $this->directory );
        while( $fn = $dir->read() ) {
            if( ereg( $old_style_regex, $fn ) ) {
                $year = (int)substr( $fn, 10, 2 ) + 2000;
                $month = (int)substr( $fn, 7, 2 );
                $day = (int)substr( $fn, 4, 2 );
            } else if( ereg( $new_style_regex, $fn ) ) {
                $year = (int)substr( $fn, 4, 4 );
                $month = (int)substr( $fn, 9, 2 );
                $day = (int)substr( $fn, 12, 2 );
            } else {
                continue;
            }
            $time = mktime( 0,0,0, $month, $day, $year );
            $this->logs[$time] = $fn;
        }
        ksort($this->logs);
    }
    
    function print_latest()
    {
        if( !empty($this->logs) ) {
            end( $this->logs );
            printf( "Latest: <a href=\"whisper-strip.php?log=%s/%s\">%s</a>",
                    $this->directory,
                    current($this->logs), date("d F Y", key($this->logs)) );
        }
    }
    
    function list_logs()
    {
        if( !empty($this->logs) ) {
            echo "<ul class=\"logs\">\n";
            foreach( $this->logs as $t => $f ) {
                printf( "  <li><a href=\"whisper-strip.php?log=%s/%s\">%s</a>\n",
                        $this->directory, $f, date("d F Y", $t) );
            }
            echo "</ul>\n";
        }
    }
}
?>
