#! e:\perl\bin\perl -w # Script to generate the BPAS Guestbook webpage containing the messages stored # in the guestbook table in the BPAS database # # Copyright (C) 2004 Craig Nicholas # This program is free software; you can redistribute it and/or modify it under the terms of the GNU # General Public License as published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU General Public License for more details. # You should have received a copy of the GNU General Public License along with this program; # if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA # # Craig Nicholas # Website: www.britishplate.org.uk use strict; use POSIX "strftime"; use CGI qw/:standard *div *table *Tr *center *td/; use DBI; use bpas; use Win32; # set debug mode my ($debug) = (0); # locations of files my ($dbConnect,$outputFile) = ( "DBI:ODBC:BPAS", "Guestbook.html"); my $gbStatement = qq(SELECT format(MessageDate,'DD/MM/YYYY'), Name, email, OtherGroupInd, OtherGroupName, BpasInfoInd, Message FROM Guestbook ORDER BY MessageDate DESC); my ($tableWidth) = ("670"); my ($bCGI,$key,$Date,$Name,$Email,$OtherGroupInd,$OtherGroupName,$BpasInfoInd,$Message); ############################################## # subroutine to write table row of guestbook # ############################################## # sub WebRecord(*) { my ($rec) = shift; # split out fields my ($Date,$Name,$Email,$OtherGroupInd,$OtherGroupName,$BpasInfoInd,$Message) = (@$rec); # escape any sneaky HTML in the fields $Name = escapeHTML($Name); $OtherGroupName = escapeHTML($OtherGroupName) if ($OtherGroupName); $Email = escapeHTML($Email) if ($Email); $Message = escapeHTML($Message); $Message =~ s/\n/
/g; # convert '\n' to actual carrage return $OtherGroupName = "" unless($OtherGroupName); PrintWeb ("\n\n"); PrintWeb (start_Tr(), start_td({-width=>$tableWidth,align=>"center"}), p( {-align=>"left"}, strong("Date: "),u($Date),strong(" Name: "),u($Name),strong(" Group: "),u($OtherGroupName)), p( {-align=>"left"}, strong("Message:"))); PrintWeb (start_div({-align=>"left"}), start_table({-border=>"1",cellspacing=>"0",width=>"669",bgcolor=>"#FFFFFF"})); PrintWeb (Tr(td({-width=>"665"}, "$Message"))); PrintWeb (end_table, end_div(), end_td(), end_Tr()); } ################################################# # subroutine to write out top of guestbook page # ################################################# sub WebHeader() { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # start the html PrintWeb (start_html({-title=>"Guestbook", stylesrc=>"index.htm" })); PrintWeb ("\n"); #print the page header and guestbook form PrintWeb (<

BPAS banner [Click to go to home page]

Guestbook

If you'd like to sign our guestbook , fill in this form and Click Submit.
Only Name and the Message are mandatory.

Name:  E-mail: 

Are you a member of another re-enactment group?   if so which one:

Are you interested in BPAS membership?

Your Message (Max 10 lines)

 

END ); # previous messages title PrintWeb (h3({-align=>"center"}, font({color=>"#800000"},u("Previous Messages (",$mday,"/",$mon+1,"/",$year+1900, ")")) )); # start the previous messages table PrintWeb (start_div({-align=>"center"}), start_center(), start_table({-border=>"3",bordercolorlight=>"#000080",bordercolordark=>"#000080", cellpadding=>"2",cellspacing=>"0",width=>$tableWidth}), "\n"); } ################################################# # subroutine to write out end of guestbook page # ################################################# sub WebFooter() { # end of previous entries table PrintWeb ("\n",end_table(), end_center(), end_div()); PerlFooter($tableWidth); # end of html PrintWeb ("\n", end_html()); } ################################################## # Main processing to Generate Guestbook Web page # ################################################## SetDebug($debug); # get output dir from environment my $outputDir = $ENV{'FRONTPAGE_DIR'}; if (!defined ($outputDir)) { die "FRONTPAGE_DIR environment variable not defined"; } # connect to the database my $dbh = DBI->connect($dbConnect, "", "", {PrintError=>0, RaiseError=>1}); # set required params for the DB $dbh->{LongReadLen} = 10000; $dbh->{FetchHashKeyName} = 'NAME_lc'; # work out required output. If running as CGI then use stdout # otherwise use configured output file $bCGI = SetOut("$outputDir\\$outputFile"); DbgPrint "\nConnected\n"; # prepare the main guestbook query my $gbSth = $dbh->prepare ( $gbStatement ) ; #execute the show query $gbSth->execute() ; # now go through show list and create web table DbgPrint("BEGINNING WEB OUTPUT:\n"); WebHeader(); while (my $gbArr = $gbSth->fetchrow_arrayref()) { DbgPrint "## Adding Guestbook line... \n"; WebRecord($gbArr); } WebFooter(); CloseOut(); unless ($bCGI) { Win32::MsgBox("### Web page '$outputDir\\$outputFile' generated ###",MB_ICONINFORMATION,"Guestbook Generation Finished"); #print "\nGuestbook webpage generated, press ENTER to exit"; #read (STDIN, $key,1); }