#! /usr/local/bin/perl

# 6.837
# Created by Seth Teller and JP Mellor for Fall 1995
# Modified by KB (kaybee@graphics.lcs.mit.edu) for Fall 1996
# Modified by JL (legakis@graphics.lcs.mit.edu) for Fall 1996
# Modified by JL (jslevene@graphics.lcs.mit.edu) for Fall 1997


# Make an associative array to look up month characters to value use it
# in pack.  Fix test in sort?  Expand names.  Generate HTML.

%longmonth = (
 'jan', 'January',
 'feb', 'February',
 'mar', 'March',
 'apr', 'April',
 'may', 'May',
 'jun', 'June',
 'jul', 'July',
 'aug', 'August',
 'sep', 'September',
 'oct', 'October',
 'nov', 'November',
 'dec', 'December');

%valmonth = (
 'jan', '01',
 'feb', '02',
 'mar', '03',
 'apr', '04',
 'may', '05',
 'jun', '06',
 'jul', '07',
 'aug', '08',
 'sep', '09',
 'oct', '10',
 'nov', '11',
 'dec', '12');

$locpath="/u2/graphics/WWW/classes/6.837/F97/handouts";
$handpath="/u2/graphics/WWW/classes/6.837/F97/handouts";

if (!-e "$locpath/handouts.html" || -M "$locpath" < -M "$locpath/handouts.html")
{

  if (-e "$locpath/handouts.html") {
     system 'rm $locpath/handouts.html';
}

opendir(THISDIR, "$handpath");
@allfiles = grep(/^.*\.ps$/, readdir(THISDIR));
closedir(THISDIR);


$count = 0;

foreach $file (@allfiles) {
 (@title[$count], @ext[$count]) = split(/\./, $file);
 @allfiles[$count] = "@title[$count]";
 @title[$count] =~ s/_/ /g;
 $count++;
}
$count--;


open(HANDOUTS, "> $locpath/handouts.html") || die "Can't open handouts.html: $!\n";


print HANDOUTS <<EOF;
Content-type: text/html

<title>6.837--Computer Graphics Handouts</title>

<center><img src=http://graphics.lcs.mit.edu/classes/6.837/F97/gifs/6.837_new.gif></center><p>

<h1>Handouts</h1><p>
EOF

open(HANDOUTS, ">> $locpath/handouts.html") || die "Can't open handouts.html: $!\n";



if ($count == -1) {
    print HANDOUTS "There are no handouts available now. Try again later.\n";
}

else {
#   foreach $ind (@sorteddate) {
    foreach $ind (@allfiles) {
		$nicetitle = $ind;
 		$nicetitle =~ s/_/ /g;
		
        print HANDOUTS "\n<li><a href=\"http://graphics.lcs.mit.edu/classes/6.837/F97/handouts/$ind.ps\">\n";
        print HANDOUTS "$nicetitle</a><p>\n";
    }
}

print HANDOUTS <<EOF;

<hr>

This page is generated automatically on-demand.
<p>
If you experience difficulty
please contact 6.837-staff\@mit.edu<p>

EOF

}

open(HANDOUTS, "< $locpath/handouts.html") || die "Can't open handouts.html: $!\n";


while (<HANDOUTS>) {
 print;
}

close(HANDOUTS);
