#!/usr/bin/perl
#
# print header stuff
#
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<body background=\"nevada.gif\">\n";
#
#define stuff to grab data entered on form
#
require TripodCGI;
use CGI;
$cgi = new CGI;
#
# get the file name they want to list
#
$name=$cgi->param('name');
#
#
#open the file so we can read it and print it
#
open(ALL,"$name") or nofile();
#
#read each line in the file
#
print "<table border=\"1\">\n";
$i=0;
$k=0;
#
#read the whole file
#
while(<ALL>) {
$x=$_;
#
#rip off the carrage return
#
chomp($x);
#
#a blank line seperates each entry
#if we got a blank line go print the entry
#
if($x eq "" ) {
print_the_list();
$k=0;
}
else {
#
#remove the 3 leading xxx's
#and put each line into our array
#which we will later print when
#we get all the data
#
$x=~s/^xxx //;
$c[$k]=$x;
$k++;
}
}
#
#all done reading the file
#anything left in our buffer?
#if yes then print it
#
if ($k > 0 ) {
#
#this should never happen unless somebody
#goes in and edits the file by hand
#
print_the_list();
}
print "</table>\n";
#
#close the file
#
close(ALL);
exit;
sub nofile {
print "<h2>Error</h2>can't open file<blockquote>$name</blockquote>";
exit;
}
sub print_the_list {
#
#each entry is a new line in a table
#
print "<tr><td>";
#
#the 1st 3 lines are the name, phone, and extension
#after that each line is a comment
#
for ($i=0;$i<$k;$i++) {
if ($i == 0 ) {
#
#print the name
#
print "added at:$c[$i]<br>";
}
else {
if ($i == 1 ) {
#
#print the name
#
print "name:<i><b>$c[$i]</b></i><br>";
}
else {
if ($i == 2 ) {
#
#print the phone
#
print "phone:<b>$c[$i]</b>";
}
else {
if ($i == 3 ) {
#
#if it has an extension print it
#
if ($c[$i] !~ /^ *$/ ) {
print " ext:<b>$c[$i]</b><br>";
}
else {
#
#no extension. print a <br>
#to end phone number
#
print "<br>";
}
}
else {
if ($i == 4 ) {
#
#for 1st comment print this stupid line
#
print "<pre>";
print "comments:<br>";
}
#
#print each comment with this
#
print "$c[$i]<br>";
}
}
}
}
}
#
#print end of this table row
#
print "</pre>";
print "</td></tr>";
}