#!/usr/bin/perl #################################################################### # # Show.cgi # # Displays the guestbook # # License and contact information can be found at www.danpromote.dk/int/ # Copyright 2000 DanPromote # Last modified 10/14/2000 #################################################################### # Reads the template $tplfile="template.html"; open(FILE,"$tplfile") || die "Cant open $tplfile !\n"; @TEMPLATE = ; close(FILE); # Locates ##LOOP-START## and ##LOOP-END## $tempsize=@TEMPLATE; for($n=0; $n<$tempsize; $n++) { $line=$TEMPLATE[$n]; if($line =~ /##LOOP-START##/i) { $loopstart=$n; } if($line =~ /##LOOP-END##/i) { $loopend=$n; } } # prints the top of the page print "Content-type: text/html\n\n"; for($n=0; $n<$loopstart; $n++) { $line=$TEMPLATE[$n]; print $line; } # Reads from datafile $filename = "data.txt"; open(FILE,"$filename") || die "Cant open $filename !\n"; @DATA = ; close(FILE); $datasize=@DATA; # Loops throug the records for($n=0; $n<$datasize; $n++) { $line=$DATA[$n]; chop($line); @LP=split(/\|/, $line); $time=$LP[0]; $name=$LP[1]; $email=$LP[2]; $website=$LP[3]; $message=$LP[4]; # Calculates DAY, MONTH & YEAR (DD MM YY / YYYY) ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time); $dd = $mday; $mm = $mon+1; $yyyy = $year + 1900; $yy = substr($yyyy,2,2); # Prints this record looping throug the template for($tpline=$loopstart; $tpline<$loopend; $tpline++) { $line=$TEMPLATE[$tpline]; $line =~ s/##DD##/$dd/gi; $line =~ s/##MM##/$mm/gi; $line =~ s/##YY##/$yy/gi; $line =~ s/##YYYY##/$yyyy/gi; $line =~ s/##NAME##/$name/gi; $line =~ s/##EMAIL##/$email/gi; $line =~ s/##WEBSITE##/$website/gi; $line =~ s/##MESSAGE##/$message/gi; print $line; } } # Prints the rest of the page for($n=$loopend; $n<$tempsize; $n++) { $line=@TEMPLATE[$n]; print $line; } exit;