#!/usr/bin/perl

#------------------------------------------------------------------------
# Author: C. Edward Chow
# Date:   2/11/1995
# Draft:  1.0
# Simple Perl script to create class photo album home page
# based on student grade spreadsheet file
#------------------------------------------------------------------------

$course = $ARGV[0];   # e.g., CS522 with uppper case CS
$lcCourse = lc $course;  # get lower case course name for class account
$semester = $ARGV[1]; # e.g., F98 or S99 with upper case F or S
$class = $course . $semester;
print "class=$class\n";
$spreadsheet = "$class\Grade.txt";
open(CLASSSH, $spreadsheet);
system("make data; chmod 777 data") unless -e data;
open(PHOTO, ">data\/$class\Photo.html");
$col=5; # five pictures in one row
print PHOTO "<HTML><HEAD>\n";
print PHOTO "<TITLE>$class CLASS ALBUM</TITLE>\n";
print PHOTO "</HEAD><BODY BGColor=\"#ffd39b\" TEXT=\"#2222222\">\n";
print PHOTO "<H2>Click on the picture to get your classmate's home page.<H2>\n";
print PHOTO "<TABLE BORDER=2 CELLSPACING=3 CELLPADDING=3>\n";
print PHOTO "\t<TR><TH COLSPAN=\"$col\">Who is Who in $class</TH></TR>\n";

$entry=<CLASSSH>; # skip title line 
$count = 0;
print PHOTO "\t<TR>";

while ($entry=<CLASSSH>) {
	$count++;
	@fields = split(/\t/, $entry); # split grade entry, try to get login
	$login = $fields[1];
	print PHOTO "<TD Align=\"top\">\n";
	print PHOTO "\t\t<A HREF=\"http://cs.uccs.edu/~$login\/\">\n";
	print PHOTO "\t\t$fields[0]\n";
	print PHOTO "\t\t<IMG HEIGHT=200 WIDTH=180 SRC=\"images/$login.jpg\">";
	system("cp -f ~$login/public_html/$login.jpg ~$lcCourse/public_html/images/$login.jpg");
	system("cp -f ~$login/public_html/images/$login.jpg ~$lcCourse/public_html/images/$login.jpg");
	print PHOTO "</A></TD>\n";
	if ($count eq $col) { 
		print PHOTO "\t</TR>\n\t<TR>\n";
		$count = 0;
	}  # new row 
	close(CLASSHS);
}
if ($count ne $col) { print PHOTO "\t</TR>\n";}  # new row 
print PHOTO "</TABLE>\n";
print PHOTO "</BODY>\n";
print PHOTO "</HTML>\n";
close(PHOTO);
