#!/usr/bin/perl
#############################################################
# Guestbook                     Version 2.3.1                                                #
# Copyright 1996 Matt Wright    mattw@worldwidemart.com                   # 
# Created 4/21/95               Last Modified 10/29/95                              #
# Scripts Archive at:           http://www.worldwidemart.com/scripts/        #
##########################################################
# COPYRIGHT NOTICE                                                                    #
# Copyright 1996 Matthew M. Wright  All Rights Reserved.                   #
#                                                                                                       #
# Guestbook may be used and modified free of charge by anyone so long as     #
# this copyright notice and the comments above remain intact.  By using this #
# code you agree to indemnify Matthew M. Wright from any liability that      #  
# might arise from it's use.                                                 #  
#                                                                            #
# Selling the code for this program without prior written consent is         #
# expressly forbidden.  In other words, please ask first before you try and  #
# make money off of my program.                                              #
#                                                                            #
# Obtain permission before redistributing this software over the Internet or #
# in any other medium.	In all cases copyright and header must remain intact.#
##############################################################################
# Set Variables

$guestbookurl = "http://vtt.citeglobe.com/annonces.html";
$guestbookreal = "../annonces.html";
$guestbookthanx = "http://www.geocities.com/techxc/annonces/merci.html";
$guestbookerror = "http://www.geocities.com/techxc/annonces/erreur.html";
$guestlog = "../log_annonces.html";
$cgiurl = "http://vtt.citeglobe.com/cgi-bin/annonces.pl";
$date_command = "/bin/date";

# Set Your Options:
$mail = 0;                         # 1 = Yes; 0 = No
$uselog = 0;                     # 1 = Yes; 0 = No
$linkmail = 1;                    # 1 = Yes; 0 = No
$separator = 1;                 # 1 = <hr>; 0 = <p>
$redirection = 0;               # 1 = Yes; 0 = No
$entry_order = 1;             # 1 = Newest entries added first;
                                      # 0 = Newest Entries added last.
$remote_mail = 0;            # 1 = Yes; 0 = No
$allow_html = 0;               # 1 = Yes; 0 = No
$line_breaks = 1;	          # 1 = Yes; 0 = No


# Done
##############################################################################

# Get the Date for Entry
$date = `$date_command +"%A, %B %d, %Y at %T (%Z)"`; chop($date);
$shortdate = `$date_command +"%D"`; chop($shortdate);

# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
   ($name, $value) = split(/=/, $pair);

   # Un-Webify plus signs and %-encoding
   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $value =~ s/<!--(.|\n)*-->//g;

   if ($allow_html != 1) {
      $value =~ s/<([^>]|\n)*>//g;
   }

   $FORM{$name} = $value;
}

if ($FORM{'nom'} eq '') {
print "Location: $guestbookerror\n\n";
exit;
      }
      else {
}

if ($FORM{'prenom'} eq '') {
print "Location: $guestbookerror\n\n";
exit;
      }
      else {
}

if ($FORM{'courriel'} eq '') {
print "Location: $guestbookerror\n\n";
exit;
      }
      else {
}

if ($FORM{'telephone'} eq '') {
print "Location: $guestbookerror\n\n";
exit;
      }
      else {
}

if ($FORM{'ville'} eq '') {
print "Location: $guestbookerror\n\n";
exit;
      }
      else {
}

if ($FORM{'pays'} eq '') {
print "Location: $guestbookerror\n\n";
exit;
      }
      else {
}

if ($FORM{'article'} eq '') {
print "Location: $guestbookerror\n\n";
exit;
      }
      else {
}

if ($FORM{'prix'} eq '') {
print "Location: $guestbookerror\n\n";
exit;
      }
      else {
}

if ($FORM{'description'} eq '') {
print "Location: $guestbookerror\n\n";
exit;
      }
      else {
}

# Begin the Editing of the Guestbook File
open (FILE,"$guestbookreal") || die "Can't Open $guestbookreal: $!\n";
@LINES=<FILE>;
close(FILE);
$SIZE=@LINES;

# Open Link File to Output
open (GUEST,">$guestbookreal") || die "Can't Open $guestbookreal: $!\n";

for ($i=0;$i<=$SIZE;$i++) {
   $_=$LINES[$i];
   if (/<!--begin-->/) { 

      if ($entry_order eq '1') {
         print GUEST "<!--begin-->\n";
      }
         
      if ($line_breaks == 1) {
         $FORM{'description'} =~ s/\cM\n/<br>\n/g;
      }

print GUEST "<b><strong><font face=\"arial, ms sans serif\" size=2";
print GUEST "color=\"#FFFFFF\">$shortdate</strong></b></font><br>";
print GUEST "<table border=0 cellpadding=2 cellspacing=0 width=500>";
print GUEST "<tr><td valign=top bgcolor=#009900><font face=\"arial,";
print GUEST "ms sans serif\" size=2>$FORM{'prenom'} $FORM{'nom'}</font></td>";
print GUEST "<td align=right valign=top bgcolor=#009900>";
print GUEST "<font face=\"arial, ms sans serif\" size=2>";
print GUEST "$FORM{'telephone'} - <a href=\"mailto:$FORM{'courriel'}\">Email</font>";
print GUEST "</a></td></tr><tr><td valign=top bgcolor=#cccc99>";
print GUEST "<font face=\"arial, ms sans serif\" size=2>Prix: ";
print GUEST "$FORM{'prix'}</font></td><td align=right valign=top>";
print GUEST "<font face=\"arial, ms sans serif\" size=2>";
print GUEST "$FORM{'ville'}, $FORM{'pays'}</font></td></tr><tr><td align=center ";
print GUEST "valign=top colspan=2 bgcolor=\"#009900\">";
print GUEST "<font face=\"arial, ms sans serif\" size=2>";
print GUEST "$FORM{'article'}</font></td></tr><tr><td colspan=2>";
print GUEST "<font face=\"arial, ms sans serif\" size=2>";
print GUEST "$FORM{'description'}</font></td></tr></table><br><br>";
	  
      if ($entry_order eq '0') {
         print GUEST "<!--begin-->\n";
      }

   }
   else {
      print GUEST $_;
   }
}

close (GUEST);

print "Location: $guestbookthanx\n\n";

exit;
