#! /usr/local/bin/perl

# written by: John Lewis Muir, May 14, 1998
# this script generates the list of patterns in the datebase

# Note that this script requires the script "recordviewer.cgi" to
# exist in the same directory as this.

# set where the root of the Pattern Manager is relative to where
# this script is
# Note: this is all you should have to change if you move this.
# everything else should work.
$PMRoot = "PatternManager/";

require "${PMRoot}functions.pl";

print STDOUT "Content-type: text/html\n\n";

$! = "";
open(DATA, "<${PMRoot}data.db") || &Error("Can't open ${PMRoot}data.db.", $!);
if (eof(DATA)) {
print <<EOP;
<html><body>
<center><h2>There are currently no patterns in the database.</h2></center>
</body></html>
EOP
exit;
}

print STDOUT <<EOP;
<html>
<script>
function viewRecord(aForm, aRecordId) {
  aForm.id.value = aRecordId;
  aForm.submit();
}
</script>
<body>
<center><h2>Pattern List</h2></center>
<hr width=35%>
<br>

<form name="record" action="recordviewer.cgi" method="post">
<input type="hidden" name="id" value="">
</form>

<center>
<table border=1 cellspacing=2 cellpadding=3 width=100%>
<tr>
<!-- alternate color scheme: bgcolor="#485468", font color="#ffff00" -->
<th bgcolor="#ffffff" width=50%><b>Pattern Name</b></th>
<th bgcolor="#ffffff" width=35%><b>Author</b></th>
<th bgcolor="#ffffff" width=15%><b>Date</b></th>
</tr>
EOP

while(!eof(DATA)) {
  # read in 10 lines at a time = 1 record
  $id = <DATA>;
  $patternName = <DATA>;
  $author = <DATA>;
  $notUsed = <DATA>;
  $notUsed = <DATA>;
  $notUsed = <DATA>;
  $notUsed = <DATA>;
  $notUsed = <DATA>;
  $notUsed = <DATA>;
  $date = <DATA>;

  chop($id); chop($patternName); chop($author); chop($date);
  guiFilter(*patternName);
  guiFilter(*author);
  # don't have to filter date since it is a controlled input
  ($year, $month, $day) = &getDateElements($date);

  print STDOUT "<tr>\n";
  print STDOUT "<td><a href='javascript:viewRecord(document.record, \"$id\")' onMouseOver='window.status=\"Click to view pattern.\"; return true;'>$patternName</a></td>\n";
  print STDOUT "<td>$author</td>\n";
  print STDOUT "<td><center>${monthsIntToWord{$month}}${dateDelimiter}${day}${dateDelimiter}${year}</center></td>\n";
  print STDOUT "</tr>\n";
}

print STDOUT <<EOP;
</table>
</center>
</body>
</html>
EOP

exit;


