#!/usr/bin/perl -i.bak #classlist.cgi #change this to change the data file-the if statement conditionalizes #it to work under both Solaris and NT (which have different ideas #about the directory in which CGI scripts run. if ($ENV{"DOCUMENT_ROOT"}){ #APACHE $datafile = "data/comp3410.txt"; } else { #NT $datafile = "c:/wwwroot/comp3410/data/comp3410.txt"; } #create a CGI object use CGI; $query = new CGI; $query->import_names('R'); #CGI header function print $query->header; #Do we need to update the data file? if ($R::email) { rename("$datafile","$datafile.old"); open IN, "<$datafile.old" or print "Could not open data file: $datafile\n"; open OUT, ">$datafile" or print "Could not open data file: $datafile to write\n"; #we should flock the file...oh well. $flag=1; while (){ @fields = split(/,/,$_); if ($flag && ! /^#/) { $flag= 0; @due = @fields; } if ($fields[2] eq $R::email){ #print "Found! $_
"; #print join ",",@R::box; for ($i=3,$j=1; $i<= $#due; $i++,$j++){ $fields[$i]=0; foreach $b (@R::box){ if ($j == $b){ $fields[$i]=1; } } } print OUT join (",", @fields) . "\n"; } else { print OUT "$_"; } } close IN; close OUT; } #Input data file stuff, definitions open IN, "<$datafile" or print "Could not open data file: $datafile\n"; @colors = ("#FF0000", "#00FF00"); #red for due/done green for not due/not done @checked = ("", "checked"); #loop through it, put results in a table print <

COMP 3410 Class list

(this text is within a 'HERE' document. Anything inside of this block defined by the 'print <<EOF;'
until 'EOF' appears by itself on a line goes straight out...in this case to the browser.)
EOF $flag=1; while (){ #ignore comment lines, blank lines next if (/^#/); next if (/^\s*$/); #get rid of newline chomp; @fields = split(/,/,$_); print ""; if ($flag) { #header #print the class number and name in the email/student name locations print ""; @due = @fields; #print already due/due in future deal for assignments for ($i=3,$j=1; $i<= $#fields; $i++,$j++){ print "" } print ""; } else { #students #print name, short name, email print ""; print ""; #have I done that assignment? #test cgi print ""; print ""; print ""; for ($i=3,$j=1; $i<= $#due; $i++,$j++){ print ""; } print ""; print ""; } print "\n"; # print "line: $. $_
\n"; $flag = 0 if $flag; } print "
$fields[0] $fields[1] $fields[2] #$j (record changes)$fields[0] $fields[1] $fields[2] 
\n"; print <
due! Assignment is DUE or DONE!
relax Assignment not yet due/done
EOF