#!/usr/bin/perl -w
#---------------------------------------------------------------------------------------------------------
# cemetery_photos.pl - this lists the contents of folders of photos as clickable thumbnails images
# written by Eric Pence
# When this script runs it is in the cgi-bin directory, so paths to items must be relative to that location.
# When the html output displays it is in the root directory, so make link paths relative to that location.
#---------------------------------------------------------------------------------------------------------
#
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);
}

use lib ( $curr_dir );
use FileHandle;

my $filename = '';
my $cemetery_photos = '';

my @dir_contents = '';
my $work_dir = $curr_dir."../pics/cemetery";

opendir(DIR,$work_dir) || die("Cannot open directory $work_dir!\n");
@dir_contents = sort readdir(DIR);
closedir(DIR);

# Display the images as clickable thumbnails
foreach $filename (@dir_contents) {
if (lc($filename) =~ /\.jpg/) {
# Extract caption from filename
$filename =~ /^(.+-)(.+)(\.jpg)/;
my $caption = $2;
$cemetery_photos = "$cemetery_photos
<a href=\"pics/cemetery/$filename\"><img src=\"pics/cemetery/$filename\" border=\"0\" hspace=\"10\" vspace=\"10\" width=\"105\" height=\"70\"
title=\"$caption\" /></a>";
}
}

print header();
print "<html>
<body background=\"../images/myback.gif\">
<table>
<tr>
<td width=\"10\"></td>
<td height=\"30\" valign=\"middle\">
<font size=\"+1\"><b>Hingham Cemetery photos...</b></font>
</td>
</tr>
<tr>
<td width=\"10\"></td>
<td valign=\"top\" style=\"{line-height: 1.25}\">
These were taken in the <a href=\"http://www.HinghamCemetery.org/\" class=\"green\">Hingham Cemetery</a> located behind the <i>Old Ship Church</i>,
and as you can see, many when the New England foliage changes color in the fall. Here is <a
href=\"http://www.stepwhere.com/maps/route/Hingham-Cemetery\" class=\"green\">my route</a>. The quality of some of the photos is a little off
because most were taken on my cellphone, but you can see that the cemetery is a beautiful park. I keep the dogs on-leash in the cemetery
because we frequently encounter other people, often with dogs and children (and they have it posted to use leashes).
<p />
Putting the mouse over the images will show more detailed information on some photos. The ones named &quot;photoa, photob, photoc,etc...&quot; are in the
order of a walk we took one day. The photo entitled &quot;Sea Lion closeup&quot; was emailed to me by someone who visited this page (and the cemetery).
</td>
</tr>
</table>
<table width=\"100%\">
<tr>
<td width=\"3%\"></td>
<td width=\"95%\">$cemetery_photos</td>
<td width=\"2%\"></td>
</tr>
</table>

<table><tr><td width=\"10\"></td><td>
This page is dynamically created in perl (<a href=\"cgi-bin/print_source.pl?src=cemetery_photos.pl\" class=\"greenul\"
onClick=\"javascript:windowOpener(this.href,this.target,'width=875,height=700,left=25,top=100,scrollbars=1');return false;\">cemetery_photos.pl</a>)
</td></tr></table>

</body>
</html>";