#! /usr/local/bin/perl

# 6.837
# Created by Justin Legakis for Fall 1996, from directory.doit script
# Modified by Jon Levene for Fall 1997
# Modified by Damian Isla for Fall 1999


chdir "/u2/graphics/WWW/classes/6.837/F99/";

if (!-e "thumbnails/thumbnails.html" ||
	-M "./data" < -M "thumbnails/thumbnails.html" ||
	-M "./thumbnails" < -M "thumbnails/thumbnails.html")
{

if (-e "thumbnails/thumbnails.html") {
 system 'rm thumbnails/thumbnails.html';
}

opendir(THISDIR, "./data");
@allfiles = grep(!/^\.\.?|(.*)\.html.?|(.*)~/, readdir(THISDIR));
closedir(THISDIR);

$count = 0;
foreach $file (@allfiles) {
    open(FILE, "data/@allfiles[$count]") || die "can't open file data/@allfiles[$count]";
    @lines = <FILE>;
    (@fullname[$count]) = @lines[0] =~ /^full name: (.*)$/;
    (@name[$count]) = @lines[1] =~ /^prefered name: (.*)$/;
    (@email[$count]) = @lines[4] =~ /^email: (.*)$/;
    (@url[$count]) = @lines[5] =~ /^url: (.*)$/;
    (@picture[$count]) = @lines[26] =~ /^picture: (.*)$/;
    (@incpic[$count]) = @lines[27] =~ /^incpic: (.*)$/;

    (@thumb[$count], $domain) = split(/\@/, @email[$count]);

    $count++;
}
$count--;

sub namesub { @name[$a] gt @name[$b] }
@sorted = sort(namesub (0..$count));

$count++;

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

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

<title>6.837--Computer Graphics Class Thumbnail Directory</title>

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

<center><h1>Class Thumbnail Directory</h1></center><p>

<hr>
<br>

There are currently $count people in this thumbnail directory.<p>

Click on the students's name to send email.<p>

<hr>
EOF

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


print DIRECTORY "<table>\n";
print DIRECTORY "<tr>\n";


$column = 0;

#foreach $index (@sorted) {

for ($index = 0; $index < $count; $index++) {

 if ($column eq 0) {
     print DIRECTORY "<tr>\n";
 }

 print DIRECTORY "<td>\n";

 if (@incpic[$index] eq 'yes') {
	print DIRECTORY "<center><img width=96 height=96 src=\"@picture[$index]\"></center>\n";
 }
 else {
	print DIRECTORY "<center><img src=\"http://graphics.lcs.mit.edu/classes/6.837/F99/thumbnails/white.gif\"></center>\n";
 }


 print DIRECTORY "<center><a href=\"mailto:@email[$index]\">";

 if (@name[$index]) {
     print DIRECTORY "@name[$index]";
 }
 else {
     print DIRECTORY "@fullname[$index]";
 }

 print DIRECTORY "</a></center>\n";

 print DIRECTORY "</td>";

 $column++;
 if ($column eq 5) {
     print DIRECTORY "</tr>\n";
     $column = 0;
 }
}

if ($column gt 0) {
     print DIRECTORY "</tr>\n";
}
print DIRECTORY "</table>\n";

print DIRECTORY <<EOF;

<br>
<hr>
<br>

If you experience difficulty with this page, please contact naimad\@graphics.lcs.mit.edu.

EOF
}

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

while (<DIRECTORY>) {
 print;
}

close(DIRECTORY);




