#!/usr/local/bin/perl
my $num = 5;
my %dir = (
'storage1' => ['倉庫1', 'eenie', '99', '.jpg'],
'storage2' => ['倉庫2', 'meenie', '999', '.gif'],
'storage3' => ['倉庫3', 'minie', '9999', '.png'],
'storage4' => ['倉庫4', 'moe', '00009', '.bmp'],
# 'ディレクトリ名' => ['ディレクトリのタイトル', 'ファイルの接頭語', '連番の最大番号', '拡張子'],
);
my @colors = ('blue', 'green');
#設定はここまでだから勘で設定♪して
if ($ENV{'QUERY_STRING'} eq 'kita-' && open FH, __FILE__) {
read FH, my $source, -s FH;
close FH;
print "Content-Type: text/plain\n\n$source";
exit;
}
my @dir = sort keys %dir;
my ($myself) = __FILE__ =~ /([^\\\/]+)$/;
my %in = $ENV{'QUERY_STRING'} =~ /^dir=(\w{1,256})&no=(-?\d{1,8})$/ && exists $dir{$1}
? (dir => $1, no => $2 % $dir{$1}[2]) : (dir => $dir[0], no => 0);
$in{'no'} = 0 unless int $in{'no'} / $num;
my $pad = length $dir{$in{'dir'}}[2];
my $html = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"><title>iギャラリー</title></head><body>';
$html .= qq{<p><a href="$myself?dir=$in{'dir'}&no=${\($in{'no'} - $num)}">前へ</a> <a href="$myself?dir=$in{'dir'}&no=${\($in{'no'} + $num)}">次へ</a></p>};
$html .= '<p>' . join(' ', map qq{<a href="$myself?dir=$_&no=0"><font color="$colors[$_ eq $in{'dir'}]">$dir{$_}[0]</font></a>}, @dir) . '</p>';
$html .= join ' ',
map sprintf(qq{<img src="%s/%s%0${pad}d%s" alt="%s%0${pad}d%s">}, $in{'dir'}, ($dir{$in{'dir'}}[1], $_, $dir{$in{'dir'}}[3]) x 2),
(1 + $in{'no'})..($dir{$in{'dir'}}[2] < $in{'no'} + $num ? $dir{$in{'dir'}}[2] : $in{'no'} + $num);
$html .= qq{<p><a href="$myself">最初へ</a></p>};
$html .= '</body></html>';
print 'Content-Length: ', length $html, "\n";
print "Content-Type: text/html\n\n";
print $html;