#!/usr/bin/perl
# Prints an HTML page that has links to all the requirements tests

@dirs = ("week6", "week7", "week8", "week9");
$numDirs = @dirs."";
@files;

#
# Print the top portion of the HTML document
#
print "Content-type: text/html\n\n";
print <<EOF ;

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="content-type"
 content="text/html; charset=ISO-8859-1">
  <title>Team Bang</title>
EOF

# substitute for SSI
open HEADER, "../../head.html";
@header = <HEADER>;
print "@header";

print <<EOF ;
</head>
<body class="test_req">
EOF

# substitute for SSI
open TOP, "../../top.html";
@top = <TOP>;
print "@top";

#
# Print the first part of the table
#
print <<EOF ;
<h2>Requirements Inspection Testing</h2>
<p>
Here are the results for the Requirements Inspection Tests. 
They are broken down by the week number. 
The testing is carried out per the conventions documented in the CSC 205
<a href="http://www.csc.calpoly.edu/~gfisher/classes/205/handouts/sop-testing.html">
standard operating procedures</a> on testing.
</p>
<table border=\"0\" cellpadding=\"8\" cellspacing=\"8\">
<tbody>
EOF

#
# Print the names of the folders
#
#print "<tr>\n";
#for ($col = 0; $col < $numDirs; $col++) {
#    $dir = $dirs[$col];
#    print "  <th>$dir</th>\n";
#}
#print "</tr>\n";

#
# Print the links to the test files
#
for ($col = 0; $col < $numDirs; $col++) {
    print "<tr>\n";
    print "  <th>Week ";
    
    $weekNum = $col + 6;
    print "$weekNum</th>\n";
    
    print "</tr>\n";
    print "<tr>\n";
    print "  <td>\n";
    $dir = $dirs[$col];
    
    opendir DIR, "./$dir";
    @thisFiles = readdir(DIR);
    closedir DIR;	
    $thisFileSize = @thisFiles."";
    
    for ($ndx = 0; $ndx < $thisFileSize; $ndx++) {
        $file = $thisFiles[$ndx];
        next if substr($file, 0, 1) eq "." || $file eq "CVS";
        
        #$text =~ s/.html//;
        print "    <a href=\"$dir/$file\">$file</a><br>\n";
    }
    
    print "  </td>\n";
    print "</tr>\n";
}

#
# Close the table
#
print "</tbody>\n";
print "</table>\n";

#
# Print the bottom portion of the HTML document
#
open BOTTOM, "../../bottom.html";
@bottom = <BOTTOM>;
print "@bottom";
print "</body>\n";
print "</html>\n";