#!/usr/bin/perl -w
use strict;

print "Content-type: text/html\n\n";


my %PresDirs;
my @dirs = sort glob("presentations/files/*");
foreach my $dir (@dirs)
{
	(my $name = $dir) =~ s%^.*[\\\/]([^\\\/]+)$%$1%;
	if ($name =~ m%^([A-Z][A-Z])\-(\d\d)\-(\d\d\d\d)%)
	{
		$PresDirs{"$1-$2-$3"} = $name;
	}
	elsif ($name =~ m%^([A-Z][A-Z])\-P\-(P\d+)%)
	{
		$PresDirs{"$1-P-$2"} = $name;
	}
}

my @files = sort glob("presentations/data/*.txt");

foreach my $file (@files)
{
  open SCHED, "< $file";
  chomp(my $date = <SCHED>);
  print <<HTML;
<h3>$date</h3>
<table border="0" id="sched1" width="100%" cellpadding="2" cellspacing="0">
HTML

  my $curSession = "";
  my $pCount = 0;
  
  while (my $line = <SCHED>)
  {
    $line =~ s%^\s*(.*?)\s*$%$1%;
    next if $line =~ m%^\s*$%;
    my @parts = split(m/\t/, $line);
    
    # Remark
    if ($parts[0] eq '*')
    {
      my $color = (($pCount) % 2 ? " bgcolor=\"#ddf0ff\"" : "");
      $pCount++;
      my $p1 = $parts[1];
      my $ucp2 = ucfirst $parts[2];
      print <<HTML;
  <tr valign="top"$color>
    <td align="right">$p1</td>
    <td colspan="2">$ucp2</td>
  </tr>
HTML

    }
    
    # Session
    elsif ($parts[0] =~ m%^SESSION%)
    {
      $pCount = 0;
      my ($junk, $sessionId, $other) = split(m/\s+/, $parts[0], 3);
      $curSession = $sessionId;
      #my $moderator = ($parts[1] eq '*' ? "" : " $parts[1]");
      print <<HTML;
  <tr>
    <td colspan="3" class="sess"><b>Session $sessionId $other</b></td>
  </tr>
HTML

    }
    
    # Presentation
    else
    {
      my $ptype = ($parts[2] =~ m%^invited% ? "(Invited) " : "");
      (my $tm = $parts[1]) =~ s%\:%%g;
      $tm = (length $tm < 4 ? "0$tm" : $tm);
      $parts[0] = (length $parts[0] < 2 ? "0$parts[0]" : $parts[0]);
      my $idStr = $curSession . "-" . $tm;
      $idStr = $curSession . "-" . $parts[0]
      	if ($parts[2] eq "poster");
      my $color = (($pCount) % 2 ? " bgcolor=\"#ddf0ff\"" : "");
      $pCount++;
      
      my $linkStr = "";
      my $textColorS = "";
      my $textColorE = "";
     	if (exists $PresDirs{$idStr})
      {
      	$linkStr = qq(<a href="presentations/index.cgi?PresID=$PresDirs{$idStr};Title=$parts[4];">$parts[4]</a>);
      }
      else
      {
        $linkStr = $parts[4];
        $textColorS = qq(<span style="color: #999;">);
        $textColorE = qq(</span>);
      }
      print <<HTML;
  <tr valign="top"$color style="font-size: 10px;">
    <td align="right">$textColorS$parts[1]$textColorE</td>
    <td width="250">$textColorS$ptype$parts[3]$textColorE</td>
    <td>$textColorS$linkStr$textColorE</td>
  </tr>
HTML
    }
  }

  print qq(</table>\n);

  close SCHED;
}


