#!/bin/perl
# pics.pl

use strict;

use CGI qw(:standard);
use myHTML;

my $b_folder   = my_button_folder;
my $b_back     = my_button_back;
my $b_next     = my_button_next;
my $b_home     = my_button_home;
my $b_help     = my_button_help;
my $b_checked  = my_checked;
my $b_first    = my_button_first;
my $b_last     = my_button_last;
my $b_back_off = my_button_back_off;
my $b_next_off = my_button_next_off;
my $b_info     = my_button_info;
my $b_noinfo   = my_button_no_info;
my $b_google   = my_button_google;
my $b_save     = my_button_save;
my $b_slide    = my_button_slide;
my $pic_breite = my_pic_breite;
my $infop      = my_inf_path;

my $ind = param('ind');
my $act = param('act');
my $let = param('let');
my $target = param('target');

my $url="pics.pl?ind=$ind&act=$act&let=$let";
my $border=0;

#print header();
if ($let ne "" and $ind eq "") {
	# $let
	# Leere Seite für Letter
}

p2 "<html>",
	"<head>";


p2 "<title>Bildergallerie</title>",
		"<style type='text/css'>",
			"select { font-size:10pt }",
			"td { font-size:10pt }",
			"input { font:10pt }",
			"a { font-size:10pt }",
			"zz { font-size:14pt }",
		"</style>",
	"</head>",
	"<body marginwidth='5' marginheight='0' topmargin='0' leftmargin='5'>";

ins_dirs;

	p2 "<table border='$border' cellspacing='0' cellpadding='0' width='100%'>",
		"<tr>",
			"<td width='200' valign='top'>";
				# Liste der Girls anzeigen
				p "<table border='$border'>";
					foreach my $girl (sort keys %dirs) { # Durchlaufe alle angegebenen Verzeichnisse
					my $directory = "$dirs{$girl}";
					if (opendir DH, $directory) { # Wenn nicht vorhanden, überspringen
					unless (-e "$directory/content") { # Wird nur aktiv wenn zw. letztem aufruf von top.pl und
										# anklicken eines speziellen namens die content-datei zu diesem namen
										# gelöscht wurde. Dadurch bekommen alle Namensverzeichnisse die keine
										# content datei haben wieder eine.
					my_create_content ("$directory");
					}
					if ($girl =~ /^$let/ or ($let eq "all")) { # wenn vorhanden und Anfangsbuchstabe der
					# beschreibung mit parameter let übereinstimmt, dann Symbol "Ordner" anzeigen!
					# Anfangsbuchstabe ist gewählt!!
					p2 "<tr>",
						"<td>",
							"<a target='$target' href='pics.pl?act=$girl&ind=0&let=$let'><img alt='Open' border='0' width='16' src='$b_folder'>$girl</a>",
						"</td>",

						"<td>";
							if ($act eq $girl) { p "<img border='0' src='$b_checked'>"; }
							else { ; }
						p2 "</td>",
					"</tr>";
					}
					}
					closedir DH;
					}
				p "</table>";

			p2 "</td>",

			"<td valign='top' align='center'>";
				my $breite = 120 + $pic_breite;
				p2 "<table border='$border' width='$breite' cellspacing='0' cellpadding='0'>",
					"<tr align='center'>",
						"<td>",
							#"1a",
						"</td>",
						"<td>";

							if ($act ne "") { # Wenn $act angegeben, dann Bilder anzeigen
							my $found = 0;
							# in $act steht Beschreibung! Name!
							# in $dirs{$act} steht verzeichnis!
							my $directory = $dirs{"$act"};

							if (my_always_create() == 1) {
							# Bei jedem Klick auf vor, zurück, anfang, ende wird
							# content neu erstellt! Ebenso wenn name ausgewählt wurde
							my_create_content("$directory");
							}
							open CONTENT, "<$directory/content";
							my @tmp=<CONTENT>;
							my $max=@tmp - 1;
							close CONTENT;

							my $sind=$ind+1;
							my $smax=$max+1;

							p2 "<b><font size='+1'>$act Bild $sind / $smax</font></b><br>",
						"</td>",

						"<td>",
							#"1c",
						"</td>",

					"</tr>",

					"<tr>",
						"<td>",
							#"2a",
						"</td>",
						"<td>",
							#"2b",
						"</td>",
						"<td>",
							#"2c",
						"</td>",
					"</tr>",

					"<tr>",
						"<td>",
							#"3a",
						"</td>",

						"<td align='center'>";
							if (-e "$infop/$act.html") { 
							# href='pics.pl?act=$act&let=$let&target=$target&ind=$ind'
							p2 "<a href='info.pl?act=$act&info=j' onclick=\"window.open(this.href,'_target','width=700,height=400,left=0,top=0'); return false\">",
							"<img border='0' alt='Infos über $act' src='$b_info'>",
							"</a>";
							}
							else { 
p2 "<a href='info.pl?act=$act&info=n' onclick=\"window.open(this.href,'_target','width=700,height=300,left=0,top=0'); return false\"><img border='0' alt='So kannst du Infos +ber $act einschicken' src='$b_noinfo'></a>";
							}
p2 "<a href='google.pl?q=$act' onclick=\"window.open(this.href,'_google',''); return false\"><img border='0' alt='Durchsuche Google nach $act' src='$b_google'></a>",
   "<a href='download.pl?act=$act' onclick=\"window.open(this.href,'new','width=500,height=200,left=0,top=0'); return false\"><img border='0' alt='Speichere $act Archiv' src='$b_save'></a>",
						"</td>",
						"<td>",
							#"3c",
						"</td>",
						"<td>",
					"</tr>",
					"<tr>",
						"<td>",
							#"4a",
						"</td>",
						"<td>",
							"<table border='$border' width='100%'>",

								"<tr>",
									"<td bgcolor='#ffff00' width='60' align='center'>",
										"Vote",
									"</td>";

									open CONTENT, "<$directory/content";
									my @cont_t=<CONTENT>;
									close CONTENT;
									$found=0;
									my $voted_pic;
									foreach (@cont_t) {
										chomp;
										my ($nr,$file) = split /,/,$_;
										if ($ind == $nr) { # wenn gefunden anzeigen
											$voted_pic=$file;
											$found = 1;
										}
										last if($found == 1);
									}

									for(my $i=1;$i<=10;$i++) {
										my $color = 0xff - $i * 10;
										my $hex = sprintf("%X", $color);
										$color="#00"."$hex"."00"; 
											chomp $voted_pic;
p2 "<td bgcolor='$color' align='center' width='20'><a href='voting.pl?act=$act&pic=$voted_pic&value=$i' onclick=\"window.open(this.href,'new','width=400,height=400,left=0,top=0'); return false\">$i</a></td>";
									}
p2 "<td bgcolor='#ffff00' width='60' align='center'><a href='voting.pl?act=$act&value=0' onclick=\"window.open(this.href,'new','width=400,height=400,left=0,top=0'); return false\">Ergebnis</a>",
   "</td>",
								"</tr>",
							"</table>",
						"</td>",

						"<td>",
							#"4c",
						"</td>",
					"</tr>",
					
					"<tr valign='top'>",
						"<td width='60' align='center'>";
							if ($ind == 0) { # wenn erstes bild in der anzeige, dann geht nicht zurück
							p "<p><img border='0' width='50' src='$b_back_off'></p>";
							p "<p><img border='0' width='50' src='$b_back_off'></p>";
							}
							if ($ind > 0) { # wenn nicht erstes bild, dann zurück anzeigen
							my $lower = $ind - 1;
p2 "<p><a target='$target' href='pics.pl?act=$act&ind=$lower&let=$let'><img alt='Vorheriges' border='0' width='50' src='$b_back'></a></p>",
   "<p><a target='$target' href='pics.pl?act=$act&ind=0&let=$let'><img alt='Erstes' border='0' width='50' src='$b_first'></a></p>";
							}###########
						p2 "</td>",
						"<td>";

							open CONTENT, "<$directory/content";
							my @cont=<CONTENT>;
							close CONTENT;
							$found=0;
							foreach (@cont) {
							chomp;
							my ($nr,$file) = split /,/,$_;
							if ($ind == $nr) { # wenn gefunden anzeigen
							# write_log("bild","$directory/$file");
							p2 "<p align='center'>",
							"<a href='show_big_pic.pl?pic=$directory/$file' onclick=\"window.open(this.href,'bigpic','left=0,top=0,resizeable=yes,scrollbars=yes,status=no'); return false\">",
							"<img alt='$act' width='$pic_breite' src='$directory/$file'>",
							"</a>",
							"</p>";
							$found = 1;
							}
							last if($found == 1);
							}

						p2 "</td>",
						"<td width='60' align='center'>";
							if ($ind == $max) { # wenn letztes bild angezeigt wird, dann geht nicht weiter
							p "<p><img border='0' width='50' src='$b_next_off'></p>";
							p "<p><img border='0' width='50' src='$b_next_off'></p>";
							}
							if ($ind < $max) { # wenn nicht letztes bild, dann geht weiter
							my $higher = $ind + 1;
p2 "<p><a target='$target' href='pics.pl?act=$act&ind=$higher&let=$let'><img alt='N&auml;chstes' border='0' width='50' src='$b_next'></a></p>",
   "<p><a target='$target' href='pics.pl?act=$act&ind=$max&let=$let'><img alt='Letztes' border='0' width='50' src='$b_last'></a></p>";
							}
						
#p2 "<p><a href='slide.pl?act=$act&num=0' onclick=\"window.open(this.href,'_slide','height=600,width=800'); return false\"><img alt='Slideshow' border='0' width='50' src='$b_slide'></a></p>";
p2 "<p><a href='slide.pl?act=$act&num=$ind&target=$target' target='$target'><img alt='Slideshow' border='0' width='50' src='$b_slide'></a></p>";
						}
						p2 "</td>",
					"</tr>",
				"</table>";

			p2 "</td>",
			"<td width='200' valign='top'>",
				"<table width='100%' border='$border'>",
					"<tr>",
						"<td>",
							# "r",
						"</td>",
					"</tr>",
				"</table>",
			"</td>",
		"</tr>",
	"</table>";
myHTML::end_html;
