#!/usr/bin/perl
######################################
# galeria


# simplify your life using cgi
use CGI qw/:standard/;

# we understand series and picno
(param('series')) and $series=param('series');
(param('picno')) and $picno=param('picno');

# don't acceppt illegal chars
($series!~/[a-z]+/) and wrong();
($picno and $picno!~/[0-9]+/) and wrong();
($picno and $picno<0) and wrong();


# vars
$config="/mnt/kw2/03/955/00000018/htdocs/cgi-data/gal.conf";
$rootpath="/mnt/kw2/03/955/00000018/htdocs";
$cgipath="/mnt/kw2/03/955/00000018/htdocs/cgi-bin";
$httppath="/mnt/kw2/03/955/00000018/htdocs";
$galpath="$httppath/galerie/";


$footer=qq(<BR><hr style="color:#808080">
<DIV ALIGN=right><B><FONT FACE="Arial,Helvetica"><FONT COLOR="#FFCC00"><FONT SIZE=-1><a href="../galerie-copy.html">&copy; Frank Bechhaus</a></FONT></FONT></FONT></B></div>);

sub wrong
{
	print header;
	print start_html(-title=>"404",-bgcolor=>"#ff8080");
	print $contheader;
	print h1("404 Galeria not found.");
	print "<hr><br>";
	print "Eine Galerie dieses Namens existiert leider nicht.  Vielleicht liegt ein Schreibfehler vor?";
	print "$_[0]";
	print end_html;
	exit 0;
}

# slurp config
##############################################################
open IN,"<$config" or die;
while(<IN>){ (/([a-z]+) ([0-9]+)/) and $galeria{$1}=$2 }
close IN;
##############################################################

# don't accept illegal galeries and pic numbers
(!$galeria{$series}) and wrong();
($picno and $galeria{$series}<$picno) and wrong();


# start html output
print   header;

print   start_html(-title=>"Galerie von www.bechhaus.de",-bgcolor=>'#404040',-LINK=>"#FFFFFF",-VLINK=>"#e0e0e0",-ALINK=>"#000000");


if($picno){
	$previousc=$picno-1;
	$nextc=$picno+1;
	($picno>1) and $previous=qq(<td bgcolor="#808080"><div align="center"><font face="Arial,Helvetica"><i><a href="http://www.bechhaus.de/cgi-bin/gl?series=$series&picno=$previousc" style="text-decoration:none">zur&uuml;ck</a></i></font></div></td>);	
	($picno<$galeria{$series}) and $next=qq(<td bgcolor="#808080"><div align="center"><font face="Arial,Helvetica"><i><a href="http://www.bechhaus.de/cgi-bin/gl?series=$series&picno=$nextc" style="text-decoration:none">vor</a></i></font></div></td>);	
	$contheadersingle=qq(<table border=0 cellpadding=5><tr valign=top><td bgcolor="#808080"><div align="center"><font face="Arial,Helvetica"><i><a href="http://www.bechhaus.de/cgi-bin/gl?series=$series" style="text-decoration:none">Serie</a></i></font></div></td>$next$previous</table><br><table border=0"><tr><td><B><FONT SIZE=-1 color=#808080>galerie @ <a href="http://www.bechhaus.de">bechhaus.de</a></FONT><FONT SIZE=+2></FONT></B></td></table><br><hr style="color:#808080">);

	print $contheadersingle;
	$nr=sprintf("%02d",$picno);
	print qq(<div align="center">);
	print "<img src=\"http://www.bechhaus.de/galerie/$series$nr.jpg\">";
	print "</div>";
}else{
	$contheader=qq(<table border=0 cellpadding=5><tr valign=top><td bgcolor="#808080"><div align="center"><font face="Arial,Helvetica"><i><a href="../galerie.html" style="text-decoration:none}">zum foyer</a></i></font></div></td><tr><td><B><FONT SIZE=-1 color=#808080>galerie @ <a href="http://www.bechhaus.de">bechhaus.de</a></FONT><FONT SIZE=+2></FONT></B></td></table><br><hr style="color:#808080>);
	print $contheader;

	print qq(<div align="center"><table width=80% border=0 cellpadding=30><tr align="center">\n);

	for($i=1;$i<=$galeria{$series};$i++){
		$nr=sprintf("%02d",$i);
		$picname=$series.$nr."i";
		print qq(<td><a href="http://www.bechhaus.de/cgi-bin/gl?series=$series&picno=$i"><img src="http://www.bechhaus.de/galerie/$series$nr); print qq(i.jpg" Border=0><br></a></td>\n);
	}
	print qq(</div></tr></table>);
}

print  $footer;
print   end_html;
exit 0;

