#!/usr/bin/perl
# How many postings should be displayed at each page ?
$postsperpage=15;
# Define links to previous and next
# at runtime # is auto-replaced with correct number
$prev="vorige Seite";
$next="nächste Seite";
# Grabs the startnumber from the auery string
$first=$ENV{QUERY_STRING};
# Reads the template
$ip_template_lfile="../gaestebuch.html";
open(FILE,"$ip_template_lfile") || die "Cant open $ip_template_lfile !\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
$date_filename = "plaudern_data.txt";
open(FILE,"$date_filename") || die "Cant open $date_filename !\n";
@DATA = ;
close(FILE);
$datasize=@DATA;
# Loops throug the records
$last=$first+$postsperpage;
if($last > $datasize) { $last=$datasize; }
for($n=$first; $n<$last; $n++) {
$line=$DATA[$n];
chop($line);
@LP=split(/\|/, $line);
$time=$LP[0];
$name=$LP[1];
$message=$LP[2];
# Calculates DAY, MONTH & YEAR (DD MM YY / YYYY)
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
$hh = $hour;
$mi = $min;
$ss = $sec;
$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/##HH##/$hh/gi;
$line =~ s/##MI##/$mi/gi;
$line =~ s/##SS##/$ss/gi;
$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/##MESSAGE##/$message/gi;
print $line; }
}
# Sets previous and next links
if($first==0) {
$prev=""; }
else {
$back=$first-$postsperpage;
if($back<0) { $back=0; }
$prev =~ s/#/$back/;
}
if($first+$postsperpage > $datasize-1) {
$next = ""; }
else {
$forw=$first+$postsperpage;
$next =~ s/#/$forw/;
}
# Prints the rest of the page
for($n=$loopend; $n<$tempsize; $n++) {
$line=@TEMPLATE[$n];
$line =~ s/##PREV##/$prev/gi;
$line =~ s/##NEXT##/$next/gi;
print $line; }
exit;