#!/usr/bin/perl 

$databasedir = "/var/www/artflsrv03/html/mark/suppv5turner/";
$filelist = $databasedir . "suppv5.srt-prned-filelist.txt";

$THISSRV = "http://artflsrv03.uchicago.edu/cgi-bin/extras/suppv5turner.pl?";
$IMGSRVER = "http://artflsrv03.uchicago.edu/images/encyclopedie/SUP5/";

$QS = $ENV{'QUERY_STRING'};
$pageimagetoget = $QS;

print "Content-type: text/html; charset=UTF-8\n\n"; 

$header = $databasedir . "search.header.html";
open (HEADERFILE, $header);
while ($linein = <HEADERFILE>) {
      print $linein;
      }
close HEADERFILE;

$last = ""; $next = "";
open (FILELIST, $filelist);
while ($lin = <FILELIST>) {
        chop($lin);
	if ($lin =~ /$pageimagetoget/) {
		$thispage = $lin;
		$lastone = $last;
		$nextone = (<FILELIST>);
		chop($nextone);
		close (FILELIST);
		}
	else {
		$last = $lin;
		}
	}



print "<table width=95%><tr><td align=left>";
$lastimagefile = $lastone;
print "<a href=\"" . $THISSRV . $lastimagefile . "\">previous page</a>  ";
print "</td><td align=center>";
$pageimagefile = $thispage;
$identifier = "Volume 5 Page: " . $thispage;
$identifier =~ s/supplate_//;
$identifier =~ s/\.jpeg//;
$identifier =~ s/SUP_5-//;
print "<b>" . $identifier . "</b>";
print "</td><td align=right>";
$nextimagefile = $nextone;
print "<a href=\"" . $THISSRV . $nextimagefile . "\">next page</a>";
print "</td></tr></table>";
print "<center>";
print "<a href=\"" . $IMGSRVER . $pageimagefile . "\" target=pgimage>";
print "<img src=\"" . $IMGSRVER . $pageimagefile . "\"></a>";
print "</center>";
print "<table width=85%><tr><td align=left>";
print "<a href=\"" . $THISSRV . $lastimagefile . "\">previous page</a>  ";
print "</td><td align=center>";
print "<b>" . $identifier . "</b>";
print "</td><td align=right>";
print "<a href=\"" . $THISSRV . $nextimagefile . "\">next page</a>";
print "</td></tr></table>";

$footer = $databasedir . "search.footer.html";
open (FOOTERFILE, $footer);
while ($linein = <FOOTERFILE>) {
      print $linein;
      }
close FOOTERFILE;


