#!/usr/bin/perl

# (C)2006, Eugene Moisseenko

# This CGI script prints out thumbnails for current directory from ./thumbs
# taking filenames from ./list
# It also provides links to subdirs taking info from ./subdirs


use strict;
use CGI;
use vars qw/$cgi_data $script_dir $lang $line @row $title $descr &print_header &print_footer/;

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

$script_dir = "/home/eugene/www/photo/scripts";

$cgi_data = new CGI;
$cgi_data->import_names;

if ($Q::lang < 1 or $Q::lang > 3) {$lang = 1} else {$lang = $Q::lang}
push @INC, $script_dir;
if ($lang == 1) {require "$script_dir/messages_rus.pl"};

if (open DESCR, "descr"){
        $line = <DESCR>;
        chomp $line;
        $title = (split /\|/, $line)[$lang-1];
        $descr = <DESCR>;
        if ($lang > 1)
        {$descr = <DESCR>};
        if ($lang > 2)
        {$descr = <DESCR>};
        close DESCR;
        }

print_header;

print "<h2>$title</h2>\n";
print "<p>$descr</p>\n";

if (open SUBS, "subdirs"){
        print "<ul>\n";
        while (<SUBS>){
                $line = $_;
                chomp $line;
                @row = split /\|/, $line;
                print "<li><a href=\"$row[0]/?lang=$lang\" class=\"gallink\">$row[$lang]</li>\n";
                }
        print "</ul>";
        close SUBS;
        }

open LIST, "list" or eval{print_footer; exit};
while (<LIST>){
        $line = $_;
        chomp $line;
        @row = split /\|/, $line;
        print "<div style=\"width: 200px; height: 200px; float: left; text-align: center;\"><a href=\"$row[0]\"><img src=\"thumbs/$row[0]\" alt=\"$row[$lang+1]\" title=\"$row[$lang+1]\" style=\" border:0;\" /></a></div>\n";
        }
close LIST;

print_footer;

sub print_header
{
print <<end_of_header;
<?xml version="1.0" encoding="koi8-r"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">
<head>
 <title>$title</title>
 <link rel="top" href="/" />
 <link rel="up" href="/photo" />
</head>

<body>

end_of_header

}

sub print_footer
{
print <<end_of_footer;
</body>
</html>

end_of_footer
}
