#!/usr/local/bin/perl # # guestbook.cgi - guest book viewer # # This script is used to re-direct the guestbook database to the web. # ############################################################################# # # Setup Section # ############################################################################# # # $cfgpath # full and complete unix path of the configuration file $cfgpath='/opt2/midtn/httpd/htdocs/spiritrecords/guestbook/gbkcfg.txt'; ############################################################################# # End of Setup Section ############################################################################# require 5; require $cfgpath; # read guestbook data from database open (GBK, $guestsrc); @GBKDATA=; close (GBK); # count the total number of pages $count=0; foreach $rec (@GBKDATA){ if ($rec =~ //){ $count++; } } $maxpage=int($count/$entryno); if ($count/$entryno != int($count/$entryno)){ $maxpage++; } if ($maxpage < 1){ $maxpage=1; } # print html header print "Content-type: text/html\n\n"; # read header template open (HEAD, $headersrc); @DATA1=; close (HEAD); # printer header template foreach $item (@DATA1){ print $item; } $temp=0; $stop=0; $more=0; $flag=0; $con=0; $currpage = 0; # operation mode detection, count the number of entries to be print if ($ARGV[0] eq ""){ # print the first page, default mode $min=0; $max=$entryno; $currpage = 1; } if ($ARGV[0] ne ""){ # print specific page $min=(($ARGV[0]-1)*$entryno)+1; $max=$ARGV[0]*$entryno; $currpage = $ARGV[0]; } # start printing guestbook data foreach $item (@GBKDATA){ chomp($item); if ($stop == 1){ $more=1; break; } if ($temp >=$min -1 && $temp <=$max -1){ print "
$item
\n"; $flag=1; } if ($item eq ""){ if ($temp>=$min -1 && $temp <=$max-1){ print "

"; } $temp++; if ($temp >= $max){ $stop=1; } } } # compose the 'back to home' link and navigation bar $noentry=''; $backlink=''; $navbar=''; if ($flag == 0){ $noentry= "
This is a brand new guestbook. Please honor us with the first entry...

Thanks!


"; if ($ontop1==0){ $backlink= "
Back to Home
"; } if ($ontop1==1){ $backlink= "
Back to Home
"; } $navbar= "[Previous | Page 0 of 0 | Next]"; $con=1; } if ($con==0){ if ($ontop1==0){ $backlink= "Back to Home"; } if ($ontop1==1){ $backlink= "Back to Home"; } if ($ARGV[0] eq ""){ $navbar=&bar(1,$maxpage); }else{ $navbar=&bar($ARGV[0],$maxpage); } } # print footer # read footer template open (FOOT, $guestfooter); @DATA2=; close (FOOT); # printer footer template foreach $item (@DATA2){ chomp($item); $item =~ s/\[Null\]/$noentry/i; $item =~ s/\[Link\]/$backlink/i; $item =~ s/\[Bar\]/$navbar/i; $item =~ s/\[PageNo\]/Page $currpage of $maxpage/i; print "$item\n"; } sub bar{ local ($i)=0; local ($output)=""; $curr_page=$_[0]; $max_page=$_[1]; $first=int($curr_page/10)*10+1; $last=$first+9; if ($curr_page < $first){ $first=$first-10; $last=$last-10; } if ($last > $max_page){ $last=$max_page; } $output = "["; if ($first > 1){ $prev_page=$first-1; $pi=$prev_page-9; $output = $output . "$pi - $prev_page |"; } for($i=$first;$i<=$last;$i++){ if ($i != $curr_page){ $output=$output." $i "; }else{ $output=$output . " $i "; } if ($i<$last){ $output=$output . "|"; } } if ($last < $max_page){ $next_page=$last+1; $pi = $next_page+9; $output=$output . "\n |\n $next_page - $pi"; } $output = $output . "]"; return ($output); }