#!/usr/bin/perl -w
#--------------------------------------------------------------------------
# skip.pl - creates clickable thumbnails out of images in folder
# written by Eric Pence
#--------------------------------------------------------------------------
use strict;
use CGI qw(-oldstyle_urls :standard);
use CGI::Carp qw(fatalsToBrowser);

# Define global variables
use vars qw($curr_dir $log_file);

#--------------------------------------------------------------------------
# Grab the current directory from $0. The following regular expression
# looks for 'CURR_DIR\xxxxx.xxx' or 'CURR_DIR/xxxxx.xxx'. Place it in
# the BEGIN block so we can use it to include modules
#--------------------------------------------------------------------------
BEGIN {
$0 =~ '(.*[\\\/])\w+\.\w+$';
$curr_dir = $1 || "./";

# Set up error log file
$log_file = "error_log.txt";
use CGI::Carp qw(carpout);
open(LOG, ">>${curr_dir}${log_file}")
or die "Unable to append to error log: $!";
carpout(*LOG);
}

my $images = '';

my @dir_contents = '';
my $image_dir = "../payette/skip";
opendir(DIR,$image_dir) || die("Cannot open directory !\n");
@dir_contents = sort readdir(DIR);
closedir(DIR);

# Format the images as clickable thumbnails
foreach my $filename (@dir_contents) {
if (lc($filename) =~ /\.jpg/) {
my $shortname = $filename;
$shortname =~ s/\.jpg//;
$shortname =~ s/sc//;
$images="$images
<a href=\"$image_dir/$filename\"><img src=\"$image_dir/$filename\" width=\"90\" hspace=\"5\" vspace=\"5\"
border=\"0\" title=\"$shortname\"></img></a>";
}
}

print header();
print "<center>
<table width='80%'><tr><td>
These are Skip Cockerum's PHS 35th Reunion photos&#8212;click on an image to see fullsize.<br />
$images
</td></tr></table>
</center>
<p>
<img src=\"images/grnbar1.gif\" height=\"5\" width=\"100%\" vspace=\"2\">";

exit;