#!/usr/bin/perl #------------------------------------------------------------------ # required modules #------------------------------------------------------------------ use strict; use warnings; use CGI; #------------------------------------------------------------------ # the global constants #------------------------------------------------------------------ my $TRUE = -1; my $FALSE = 0; #------------------------------------------------------------------ # the global objects #------------------------------------------------------------------ my $g_oCGI = new CGI; #------------------------------------------------------------------ # expected form variables #------------------------------------------------------------------ my $lImageID = getRequestString( 'image_id', '0' ); my $sAction = getRequestString( 'action', 'view' ); #------------------------------------------------------------------ # the gallery images #------------------------------------------------------------------ my @g_aGallery = ( #============================================================== # Image 1 #============================================================== { Caption => q{ The Capital City of Gondor, Minas Tirith is referred to as the White City. }, ImageName => q{ } }, #============================================================== # Image 2 #============================================================== { Caption => q{ Carved out of the mountainside, the White City is the most fortified in Middle-earth. }, ImageName => q{ } }, #============================================================== # Image 3 #============================================================== { Caption => q{ Gandalf and Pippin ride toward the Great Hall of Minas Tirith. }, ImageName => q{ } }, #============================================================== # Image 4 #============================================================== { Caption => q{ Gandalf and Pippin are confronted by The Witchking. }, ImageName => q{ } }, #============================================================== # Image 5 #============================================================== { Caption => q{ Sauron's armies wage war on Minas Tirith from Pelennor Fields. }, ImageName => q{ } } ); #------------------------------------------------------------------ # format the image send form #------------------------------------------------------------------ sub formatImageSendForm { my $lImageID = shift; my $sTemplate =<<_HTML_EOF_;

Your Name:
Your Email:
Friend's Name:
Friend's Email:



_HTML_EOF_ return $sTemplate; } #------------------------------------------------------------------ # format the image sent #------------------------------------------------------------------ sub formatImageSent { my $lImageID = shift; my $lNextImageID = $lImageID + 1; my $lPrevImageID = $lImageID - 1; my $sImage = $g_aGallery[ $lImageID ]{ "Caption" }; my $sCaption = "Thank you.

The image has been sent
"; if( $lNextImageID == @g_aGallery ) { $lNextImageID = 0; } if( $lPrevImageID == -1 ) { $lPrevImageID = @g_aGallery - 1; } my $sTemplate =<<_HTML_EOF_;

$sCaption





_HTML_EOF_ return $sTemplate; } #------------------------------------------------------------------ # format the image view #------------------------------------------------------------------ sub formatImageView { my $lImageID = shift; my $lNextImageID = $lImageID + 1; my $lPrevImageID = $lImageID - 1; my $sImage = $g_aGallery[ $lImageID ]{ "Caption" }; my $sCaption = $g_aGallery[ $lImageID ]{ "Caption" }; if( $lNextImageID == @g_aGallery ) { $lNextImageID = 0; } if( $lPrevImageID == -1 ) { $lPrevImageID = @g_aGallery - 1; } $sCaption =~ s/The Lord of the Rings: The Return of the King./The Lord of the Rings: The Return of the King.<\/b>/g; my $sTemplate =<<_HTML_EOF_;

$sCaption







_HTML_EOF_ return $sTemplate; } #------------------------------------------------------------------ # format the image #------------------------------------------------------------------ sub formatGalleryImage { my $lImageID = shift; my $sMode = shift; my $sCaption = ''; if( $sMode eq 'send' ) { $sCaption = formatImageSendForm( $lImageID ); } elsif( $sMode eq 'sent' ) { $sCaption = formatImageSent( $lImageID ); } else { $sCaption = formatImageView( $lImageID ); } my $sTemplate =<<_HTML_EOF_;
$sCaption
_HTML_EOF_ return $sTemplate; } #------------------------------------------------------------------ # getRequestString - get a string from the httpd request #------------------------------------------------------------------ sub getRequestString { my( $sParameter, $sDefault ) = ( shift, shift ); my $sValue = getRequestParameter( $sParameter, $sDefault ); return $sValue; } #------------------------------------------------------------------ # getRequestParameter - get a general parameter from the httpd request #------------------------------------------------------------------ sub getRequestParameter { my( $sParameter, $sDefault ) = ( shift, shift ); my( $sValue ) = $sDefault; for( $g_oCGI->param ) { if( $_ eq $sParameter ) { $sValue = $g_oCGI->param( $sParameter ); } } return $sValue; } #------------------------------------------------------------------ # printHeader - outputs the httpd header #------------------------------------------------------------------ sub printHeader { print $g_oCGI->header( -type=>"text/html" ); } #------------------------------------------------------------------ # redirect - redirects to a specific url #------------------------------------------------------------------ sub redirect { print $g_oCGI->redirect( shift ); } #------------------------------------------------------------------ # htmlEncode - encodes a string in html format #------------------------------------------------------------------ sub htmlEncode { return CGI::escape( shift ); } #------------------------------------------------------------------ # html template #------------------------------------------------------------------ sub htmlTemplate { my $sImage = shift; my $sTemplate =<<_HTML_EOF_; Lord of the Rings: The Return of the King
$sImage
_HTML_EOF_ return $sTemplate; } #------------------------------------------------------------------ # main script body #------------------------------------------------------------------ printHeader(); my $sImage = formatGalleryImage( $lImageID, $sAction ); print htmlTemplate( $sImage );