#!/perl/bin/perl

# entries.pl
# Displays guest book entries in an HTML document
# that includes form checkboxes to flag an entry
# or multiple entries for deletion.

# Get the header file; complain and exit if it can't be
# found. Otherwise, define the title string and the Perl
# script that will do the deletion.
 
    require ("c:/Program Files/Sambar/cgi-bin/GuestBook.pm") || 
        die ("Can't find GuestBook header file: $!\n");
 
    $Title = "Editing the guest book";
    $DelScript = "/cgi-bin/delguest.pl";
 
# Attempt to open the guest book file. Again, this is
# a fatal error if it doesn't succeed.
 
    open (GUEST_LOG, $GuestBookPath) || 
        die "Can't open guest book: $!";
 
# Set up the HTML document as a form this time.

    &HTML_Header ($Title);
    print "<BODY>\n";
    print "<H1 ALIGN=\"CENTER\">$Title</H1>\n";
    print "<HR>\n";
    print "<FORM ACTION=\"$DelScript\" METHOD=\"POST\">\n";

# Do a limited display of the records -- name and entry time --
# along with a checkbox given the index of the record as its
# value.

    $index = 0;        # An index counter.

    while (read (GUEST_LOG, $buffer, $GuestEntrySize))
        {
        @InfoArray = unpack ($GuestEntryStruct, $buffer);
        for ($n = 0; $n < ($NumElements - 1); $n++)
            {
            $InfoArray[$n] =~ s/\0//g;
            }
 
    # Get all of the fields, though we'll only use three
    # of them here.

        ($FirstName, $LastName, $City, $State, $Country, $Email,
            $Comments, $NumAccessTime) = @InfoArray;

    # Display the name and formatted time.

        print "<STRONG>$FirstName $LastName<BR>\n";
        ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)
            = localtime ($NumAccessTime);
         
        print "$WeekDay[$wday], $Month[$mon] $mday, ", $year + 1900;
        print " at $hour:";
        if ($min < 10)
            {
            print "0";
            }
        print "$min:";
        if ($sec < 10)
            {
            print "0";
            }
            print "$sec </STRONG><BR>\n";

    # Set a checkbox to $n.

        print "Delete? <INPUT TYPE=\"checkbox\"\n";
        print "NAME=\"delete\" VALUE=\"$index\">\n";
        print "<HR>\n";
        $index++;            # Increment $index for the next pass.
        }            # End while (read...)

# Form submit and reset buttons at the bottom.

    print "<INPUT TYPE=\"submit\" VALUE=\"Delete\">\n";
    print "<INPUT TYPE=\"reset\" VALUE=\"Clear\">\n";

# Clean up the HTML and file and exit.

    print "</FORM>\n</BODY>\n";
    &HTML_Footer;
    close (GUEST_LOG);

#                    End entries.pl
