#!/usr/local/bin/perl

# The line above MUST point to the location of Perl 5 on your server if
# you are running this program on a Unix server.  Windows NT users can
# almost always ignore this line.

#####################################################################
#
# e-Classifieds(TM) Free Edition
# Version 3.1
# Last Modified: 6/19/2000
# Copyright © Hagen Software Inc. All rights reserved.
#
# By purchasing, installing, copying, downloading, accessing or otherwise
# using the SOFTWARE PRODUCT, or by viewing, copying, creating derivative
# works from, appropriating, or otherwise altering all or any part of its
# source code (including this notice), you agree to be bound by the terms
# of the EULA that accompanied this product, as amended from time to time
# by Hagen Software Inc.  The EULA can also be viewed online at
# "http://www.e-classifieds.net/support/license.html"
#
# As explained in the EULA, Hagen Software offers absolutely
# no warranties on this product, which is sold and/or distributed
# "as is".  You, and not Hagen Software, assume all risks
# associated with using this product, including but not limited
# to the risk of failure of the product to install or to operate
# successfully on your server, and responsibility for all content
# created by users of this product.
#
# This product, including all source code, is copyrighted by
# Hagen Software, and it is protected under both United States law
# and international laws and treaties.  You may not redistribute this
# software, in whole or any part thereof, or use any part of the source
# code contained within this software to create derivative works,
# without the prior express written consent of Hagen Software.
# Nor may you remove any of the copyright notices contained
# either within the source code or on the HTML pages generated
# by the program.  Doing so constitutes a criminal offense
# punishable by imprisonment.
# We prosecute all violators via both civil legal actions and in
# cooperation with U.S. and international criminal authorities.
# YOU HAVE BEEN WARNED! 
#
# The Hagen Software web site is located at the following URL:
# http://www.hagensoftware.com 
#
#####################################################################

# The user-configurable variables are listed below.  You need to define these
# before uploading the program, or it will not work properly.
# Most of these variables are in the following format:

# $variable = "value";

# The # symbol will not be in front of the actual variables, however, as this
# is used to "comment out" lines in Perl.  In other words, lines that begin with
# the # symbol are ignored by Perl when it executes the program.  The $ sign
# is used to indicate variables in Perl, while the items in between the quotation
# marks represent the assigned value of that variable.  The semicolon indicates
# the end of the statement.  Therefore, in the example above, if you wanted to
# change the value for that variable, the only thing that you should change is
# the portion in between the quotation marks. For example, to change the value
# of the variable $variable to "red", you would edit it as follows:

# $variable = "red";

# Again, you would not put the # symbol in front of $variable.  We did that
# here only because this is an example that we do not want the program to 
# actually execute.

# Two other things you should note are that if you use quotation marks as part
# of the value (in other words, inside of the quotation marks that define the
# value), then you must "comment them out" by putting a back slash symbol (the
# "\" symbol) in front of them.  For example:

# $variable = "The \"red\" light";

# Also, if you use the @ symbol in any of your value statements, you must
# similarly comment it out by putting a backslash symbol in front of it,
# such as in the following:

# $my_email_address = "me\@mydomain.com";

#################################################################
# The variables are defined below.

# $script_url should be set to the full URL of this classifieds program on your
# server.
#sur certain serveur renommer classifieds.cgi en classifieds.pl

$script_url = "http://www.agora-aqua.com/cgi-bin/classifieds/classifieds.pl";

# $master_admin_email_address should be set to your e-mail address

$master_admin_email_address="jermarti\@club-internet.fr";

# $admin_name should be set to the name of the administrator

$admin_name = "Jerome MARTIN";

# $sitename should be set to the name of your web site

$sitename = "Agora de l'aquariophilie";

# $siteurl should be set to the full URL of your web site

$siteurl = "http://www.agora-aqua.com";

# $slogan should be set to whatever slogan or catchphrase you use for your site

$slogan = "";

# $sendmail should be set to the full server path to sendmail on your Unix server
# By default, this is set to "/usr/sbin/sendmail", but on many Unix systems, it is
# located at "/usr/lib/sendmail".  If you don't know this, you might try typing 
# "whereis sendmail" or "which sendmail" from a Telnet prompt.
# If you are running this program on Windows NT, you should set this to "".  You
# will not be able to use the e-mail routines for this program on a Windows NT
# server.  The commercial versions of the program include e-mail routines for
# both Windows NT and Unix.
#sur un serveur NT pensez aussi à donner les permissions spéciales RWXD dans le répertoire classifieds

$sendmail = "";

# The following variable specifies the administrative password.  You can
# (and should) change this to whatever you want.

$admin_password = "X1263996";

# The following variable specifies the special multiplier that will be
# used to generate a unique password for each ad.  Please change this from
# the default so that other users of this program will not be able to guess
# your users' passwords.  Also, we recommend against setting this to a round
# number such as 1000, etc.  It's much better to use a random number such as
# 2748, etc.

$password_multiplier = "1499";

# If set equal to "on", $notify_add will cause the program to notify the administrator
# by e-mail anytime that an ad is posted to the system

$notify_add = "off";

# If set equal to "on", $reply_user will cause the program to send a reply e-mail
# to the user who just posted an ad thanking them and reminding them of their ad
# number so that they can delete their ad in the future

$reply_user = "off";

# If set equal to "on", $notify_delete will cause the program to notify the
# administrator by e-mail anytime someone deletes an ad

$notify_delete = "off";

# If set equal to "on", $notify_delete_all will cause the program to notify the
# administrator by e-mail anytime someone uses the administrative function to delete
# all ads in a category.  Normally, you would receive this message after deleting the
# ads yourself, but this could be useful for informing you if someone obtains your
# administrative password and deletes all ads in a particular category without your
# knowledge or permission.

$notify_delete_all = "off";

# $classdir should point to the full server path of the new directory that you created
# for this program where the ads.counter file and the HTML pages for the ads will be
# stored.  For Unix servers, this new directory should have its permissions set to 777.
# For Windows NT users, this should point to the full server path to this directory,
# beginning with the drive letter and using forward slashes instead of backslashes,
# such as "d:/InetPub/wwwroot/ads".

#$classdir = "/usr/www/users/you/classifieds";
$classdir = "d:/wwwroot/agora-aqua.com/cgi-bin/classifieds";

# $htmldir should point to the full URL of the new directory that you created for
# this program where the ads.counter file and the HTML pages for the ads will be
# stored.  You should also store the e-Classifieds logo graphic here, as the license
# for this free product requires you to display this logo in order to protect our
# trademark rights, intellectual property rights, and other legal rights.
# Do *not* include the trailing slash ("/") at the end.

$htmldir = "http://www.agora-aqua.com/cgi-bin/classifieds";

# The @categories array defines the ad categories that the program will use.  For each
# category, you need to list it in the following format:
# "Long Name of Category|shortname|Description", where the long name is the name that will be displayed
# at the top of pages in that category.  This can contain several words and spaces.  The
# short name can contain only one word with no spaces, as this is used internally by the
# program for keeping track of the categories.  The Description will be listed underneath
# this category on the front page of the classifieds.

@categories = ("Annonces évènements|Evenements|Annonces pour des portes-ouvertes, bourses, congrès et rencontres aquariophiles", "Vente aquarium|v_aqua|Aquarium à vendre, avec ou sans matériel (à préciser dans l'annonce)", "Vente poissons|v_poisson|Poissons à vendre", "Vente plantes|v_plante|Plantes pour aquariums (eau chaude, eau froide), et bassins", "Vente matériel|v_materiel|Matériel neuf ou d'occasion", "Vente livres|v_livres|Documentations diverses sur l'aquariophilie (livres, magazines, ...)", "Vente autres|v_autres|Autre type de vente, à préciser dans l'annonce", "Recherche aquarium|r_aqua|Recherche d'aquarium (avec ou sans matériel)", "Recherche poissons|r_poissons|Recherche de poissons", "Recherche plantes|r_plantes|Recherche de plantes", "Recherche matériel|r_materiel|Recherche de matériel", "Recherche livres|r_livres|Recherche de documentation", "Recherche autres|r_autre|Recherche autres", "Echange|echange|Echange de matériel, poissons ou plantes", "Pub web|pub_web|Pub pour des sites web, des listes de discussions, des chats");


# This subroutine defines the HTML for the pages that store the ads for each category.
# Please be careful to modify only the HTML in between the "qq~" and
# the "~;" code, or you will cause a syntax error that will break the program.

sub print_default_html {
print HTMLFILE qq~
  <HTML>
  <HEAD>
  <TITLE>Annonces $sitename - $long_category_name</TITLE>
$head_code
  </HEAD>
<BODY bgcolor="$bgcolor" background="$background" text="$text_color" link="$link_color" vlink="$vlink_color" alink="$alink_color">
<table width=620 border=0 cellpadding=0 cellspacing=0>
<tr>
<td valign=top>
<table align=left width=120 border=0 cellpadding=0 cellspacing=0>
<tr>
<td align=center>

$upper_left_corner

<table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ddddff">
      <tr>
        <td align="center" bgcolor="#8080ff"><table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#00056C">
          <tr>
            <td align="left"><img src="$htmldir/top_left_corner.gif" alt="left" WIDTH="7" HEIGHT="7"></td>
            <td align="right"><img src="$htmldir/top_right_corner.gif" alt="right" WIDTH="7" HEIGHT="7"></td>
          </tr>
        </table>
        </td>
      </tr>

      <tr>
        <td align="center" bgcolor="#00056C"><font color="#FFFFFF" size="1" face="MS SANS SERIF"><b>Options de Recherche</b></font></td>
      </tr>
      <tr>

        <td valign="middle" height="20" align=center>
<font size="1" face="MS SANS SERIF" color="941403"><p align="center"><a href="$script_url">Consultation des Annonces</a></font>
</td>
      </tr>
</form>

      <tr>
        <td align="center" bgcolor="#00056C"><font color="#FFFFFF" size="1" face="MS SANS SERIF"><b>Annonces</b></font> </td>
      </tr>
      <tr>
        <td bgcolor="#ddeeee" valign="middle" height="20"><font size="1" face="MS SANS SERIF" color="941403"><p align="center"><a href="$script_url?place_ads">Mettre une Annonce</a></font></td>
      </tr>
      <tr>
        <td bgcolor="#ddeeee" valign="middle" height="20"><font size="1" face="MS SANS SERIF" color="941403"><p align="center"><a href="$script_url?delete_ads">Effacer une Annonce</a></font></td>
      </tr>
	<tr>
        <td align="center" bgcolor="#00056C"><b><font color="#FFFFFF" size="1" face="MS SANS SERIF">Autres options</font></b> </td>
      </tr>
      <tr>
        <td valign="middle" height="20"><font size="1" face="MS SANS SERIF" color="941403"><p align="center"><a href="$script_url?admin">Administrateur</a></font></td>
      </tr>

      <tr>
        <td valign="middle" height="20"><font size="1" face="MS SANS SERIF" color="941403"><p align="center"><a href="$script_url">Accueil Annonces</a></font></td>
      </tr>

      <tr>
        <td align="center" bgcolor="#00056C" height=5><font color="#00056C" size=1>&#151;</td>
      </tr>

      <tr>
        <td align="center" bgcolor="#ddeeee">
            <!-- eStat -->
            <SCRIPT LANGUAGE="JavaScript">
			<!--
			var _UJS=0;
			//-->
			</SCRIPT>
            <SCRIPT LANGUAGE="JavaScript" SRC="http://perso.estat.com/js/m.js"></SCRIPT>
            <SCRIPT LANGUAGE="JavaScript">
			<!--
			if(_UJS) _estat('10401123623','Annonces','Agora');
			//-->
			</SCRIPT>
            <!-- /eStat -->
            </td>
      </tr>


    </table>
    <table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#00056C">
      <tr>
        <td align="left" valign="top"><img src="$htmldir/bot_left_corner.gif" alt="left" WIDTH="7" HEIGHT="7"></td>
        <td align="right" valign="top"><img src="$htmldir/bot_right_corner.gif" alt="right" WIDTH="7" HEIGHT="7"></td>
      </tr>
    </table>


</center>
<p>

</td></tr></table>
</td>
<td>
<table width=12 border=0><tr><td></td></tr></table>
</td>
<td valign=top>
<table width=480 border=0>
<tr>
<td align=center>
$header
</td></tr>
<tr>
<td><center>
<font face=arial size=2>
<H2><font color="#0000ff">$long_category_name</font></H2>

<!--Do not edit past this line-->

<center>
<p>
$footer
</td></tr></table>
</td></tr></table></td></tr></table></body></html>~;
}

# End of user-configurable variables.  You should not edit anything past this line.

# The following variable defines any special HTML code that you want to place in
# between the <HEAD> and </HEAD> tags on each page.  This could include meta tags
# or JavaScript, but in most cases, you'll probably just want to leave this set
# equal to "".  Be sure to put a backslash in front of any quotation marks that
# appear inside of your header code, and in front of the @ symbol anywhere that
# it appears.

$head_code = "";

# The following variable defines the background color of all pages.

$bgcolor = "#ffffff";

# The following variable defines the background graphic (if any) to be used on
# all pages.

$background = "http://www.agora-aqua.com/images/back/Classic2.jpg";

# The following variable defines the default text color.

$text_color = "#000000";

# The following variable defines the color for hypertext links.

$link_color = "#0000ff";

# The following variable defines the color for visited links.

$vlink_color = "#ff0000";

# The following variable defines the color for active links.

$alink_color = "#ffff00";

# The following variable defines the HTML that will appear in the upper left hand
# corner of the pages.  Please begin your HTML code on the
# line after the <<END_OF_HTML; code, and end it on the line just above the
# END_OF_HTML code.  Also, please be sure to "comment
# out" any @ symbols in your HTML by placing the
# backslash symbol ("\") in front of them.
# You might set this to use a text link to your site's home page (the
# default setting below) or to display a small logo that would link to your
# site's main home page.  If you use a logo here, it should be no larger than about
# 110 pixels in width, or it may cause distortion of the display for some users
# viewing your site using resolutions of 640 x 480 or less.

$upper_left_corner = <<END_OF_HTML;
<center><a href="http://www.agora-aqua.com" target='_top'>Agora de l'aquariophilie</a></center><p>
END_OF_HTML

# The following variable defines the HTML that will appear at
# the top of the main section of the pages.  Please begin your HTML code on the
# line after the <<END_OF_HTML; code, and end it on the line just above the
# END_OF_HTML code.  Also, please be sure to "comment
# out" any @ symbols in your HTML by placing the
# backslash symbol ("\") in front of them.
# This is where you would put your logo or banner that you wanted to display
# at the top of the pages if you wanted to replace the large e-Classifieds
# logo that is there by default.

$header = <<END_OF_HTML;
END_OF_HTML

# The following variable defines the HTML that will appear at
# the bottom of the main section of the pages.  Please begin your HTML code on the
# line after the <<END_OF_HTML; code, and end it on the line just above the
# END_OF_HTML code.  Also, please be sure to "comment
# out" any @ symbols in your HTML by placing the
# backslash symbol ("\") in front of them.
# You might want to put your copyright notice or other information here.

# ATTENTION: Please do not alter or remove the e-Classifieds copyright notice from the $footer variable.
# IF YOU REMOVE THE E-CLASSIFIEDS COPYRIGHT NOTICE FROM THE $footer VARIABLE, OR EVEN IF YOU ALTER IT IN
# ANY WAY WHATSOEVER, NOT ONLY IS THIS A MATERIAL BREACH OF THE LICENSE AGREEMENT, BUT THE PROGRAM WILL
# NO LONGER FUNCTION.  PLEASE HEED THIS ADVICE!  THANK YOU FOR YOUR COOPERATION.

$footer = <<END_OF_HTML;
<p>
<font size=1>
<i>Content copyright &copy; 2001 <a
href="$siteurl">$sitename</a>. Tous droits réservés.<br>
SVP, envoyez vos questions, commentaires, ou signalez nous des erreurs en écrivant au <a
href="mailto:$master_admin_email_address">Webmaster</a>.<p>
Powered by <a href="http://www.e-classifieds.net/">e-Classifieds.net</a>. Copyright © 1995-2001 Hagen Software Inc. All rights reserved.
</i></font></center>
END_OF_HTML

# The following subroutine (pagesetup) defines the HTML that will appear at
# the beginning of every page created by this program.  You should modify
# only the text in between the "print qq~" and the "~;" statements.

sub pagesetup
{
  local ($title) = @_;

print qq~
  <HTML>
  <HEAD>
  <TITLE>$title</TITLE>
$head_code
  </HEAD>
<BODY bgcolor="$bgcolor" background="$background" text="$text_color" link="$link_color" vlink="$vlink_color" alink="$alink_color">
<table width=620 border=0 cellpadding=0 cellspacing=0>
<tr>
<td valign=top>
<table align=left width=120 border=0 cellpadding=0 cellspacing=0>
<tr>
<td align=center>

$upper_left_corner

<table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ddddff">
      <tr>
        <td align="center" bgcolor="#8080ff"><table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#00056C">
          <tr>
            <td align="left"><img src="$htmldir/top_left_corner.gif" alt="left" WIDTH="7" HEIGHT="7"></td>
            <td align="right"><img src="$htmldir/top_right_corner.gif" alt="right" WIDTH="7" HEIGHT="7"></td>
          </tr>
        </table>
        </td>
      </tr>

      <tr>
        <td align="center" bgcolor="#00056C"><font color="#FFFFFF" size="1" face="MS SANS SERIF"><b>Options de Recherche</b></font></td>
      </tr>
      <tr>

        <td valign="middle" height="20" align=center>
<font size="1" face="MS SANS SERIF" color="941403"><p align="center"><a href="$script_url">Consultation des annonces</a></font>
</td>
      </tr>
</form>

      <tr>
        <td align="center" bgcolor="#00056C"><font color="#FFFFFF" size="1" face="MS SANS SERIF"><b>Annonces</b></font> </td>
      </tr>
      <tr>
        <td bgcolor="#ddeeee" valign="middle" height="20"><font size="1" face="MS SANS SERIF" color="941403"><p align="center"><a href="$script_url?place_ads">Mettre une annonce</a></font></td>
      </tr>
      <tr>
        <td bgcolor="#ddeeee" valign="middle" height="20"><font size="1" face="MS SANS SERIF" color="941403"><p align="center"><a href="$script_url?delete_ads">Effacer une annonce</a></font></td>
      </tr>
	<tr>
        <td align="center" bgcolor="#00056C"><b><font color="#FFFFFF" size="1" face="MS SANS SERIF">Autres options</font></b> </td>
      </tr>
      <tr>
        <td valign="middle" height="20"><font size="1" face="MS SANS SERIF" color="941403"><p align="center"><a href="$script_url?admin">Administrateur</a></font></td>
      </tr>

      <tr>
        <td valign="middle" height="20"><font size="1" face="MS SANS SERIF" color="941403"><p align="center"><a href="$script_url">Accueil Annonces</a></font></td>
      </tr>

      <tr>
        <td align="center" bgcolor="#00056C" height=5><font color="#00056C" size=1>&#151;</td>
      </tr>

      <tr>
        <td align="center" bgcolor="#ddeeee">
            <!-- eStat -->
            <SCRIPT LANGUAGE="JavaScript">
			<!--
			var _UJS=0;
			//-->
			</SCRIPT>
            <SCRIPT LANGUAGE="JavaScript" SRC="http://perso.estat.com/js/m.js"></SCRIPT>
            <SCRIPT LANGUAGE="JavaScript">
			<!--
			if(_UJS) _estat('10401123623','Annonces','Agora');
			//-->
			</SCRIPT>
            <!-- /eStat -->
            </td>
      </tr>


    </table>
    <table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#00056C">
      <tr>
        <td align="left" valign="top"><img src="$htmldir/bot_left_corner.gif" alt="left" WIDTH="7" HEIGHT="7"></td>
        <td align="right" valign="top"><img src="$htmldir/bot_right_corner.gif" alt="right" WIDTH="7" HEIGHT="7"></td>
      </tr>
    </table>


</center>
<p>

</td></tr></table>
</td>
<td>
<table width=12 border=0><tr><td></td></tr></table>
</td>
<td valign=top>
<table width=480 border=0>
<tr>
<td align=center>
$header
</td></tr>
<tr>
<td><center>
<font face=arial size=2>~;
}

# The following subroutine (pageclose) defines the HTML that will appear
# at the end of every page created by this program.  You should modify
# only the text in between the "print qq~" and the "~;" statements.

sub pageclose
{
print qq~
<center>
<p>
$footer
</td></tr></table>
</td></tr></table></td></tr></table></body></html>~;
}

########################################################################

sub print_header {
print "Content-type: text/html\n\n";
}

#######################################################################
#               Read and Parse Form Data                              #
#######################################################################

   # 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;
      }
      else {
         unless ($name eq 'body') {
	    $value =~ s/<([^>]|\n)*>//g;
         }
      }

      $in{$name} = $value;
   }

$current_date = &get_date;
&get_required_files;

if (($in{'add_item_button'} ne "") || ($ENV{'QUERY_STRING'} =~ /place_ads/))
  {
  &print_header;
  &pagesetup("Post Classified Ad Form");
  &generic_form_header;
  &add_entry_form;
  &pageclose;
  exit;
  }

elsif ($in{'post_ad_button'} ne "") {
  &print_header;
	&post_ad;
	}

elsif (($in{'delete_item_button'} ne "") || ($ENV{'QUERY_STRING'} =~ /delete_ads/))
  {
  &print_header;
  &pagesetup("Delete Classified Ad Form");
  &generic_form_header;
  &delete_search_form;
  &pageclose;
  exit;
  } 

elsif ($in{'delete_button'} ne "") {
  &print_header;
	&delete;
	}

elsif (($in{'admin_button'} ne "") || ($ENV{'QUERY_STRING'} =~ /admin/))
  {
  &print_header;
  &pagesetup("Admin Logon");
  &generic_form_header;
  &delete_all_form;
  &pageclose;
  exit;
  } 


elsif ($in{'delete_all_button'} ne "") {
  &print_header;
	&delete_all;
	}

elsif ($in{'view_ads_button'} ne "") {
	&view_ads;
	}

else  {
  &print_header;
  &pagesetup;
  &display_frontpage;
  &pageclose;
	}

sub view_ads {
	if ($in{'category'} eq "") {
  &print_header;
	&category_error;
	}
	if (-e "$classdir/$in{'category'}.html") {
#	print "<meta http-equiv=\"refresh\" content=\"1; # url=$htmldir/$in{'category'}.html\">\n";
	print "Location: $htmldir/$in{'category'}.html\n\n";
	}
	else {
  &print_header;
	&no_ads_message;
	}
	exit;
	}

sub no_ads_message
  {
  &pagesetup("Pas d'annonces à votre demande");
  print qq~<center><h2>Pas d'annonces à votre demande</h2></center>
  <BLOCKQUOTE>
  Nous sommes désolés mais nous n'avons pas d'annonce dans la catégorie demandée.  SVP, retournez en arrière et essayez une autre catégorie.
  </BLOCKQUOTE><p><center>
<form>
<input type=button value="<< Retour " onClick="history.go(-1)"></form></center>~;
&pageclose;
  }

sub add_entry_form {
print qq~

<table border=0 cellpadding=4 cellspacing=4 width=470>
<tr>
<td bgcolor="#e8e8e8">
<center><font size=4>Information - Contact</font></center><p>
SVP remplissez les champs Informations-Contacts qui suivent.  Les champs obligatoires sont signalés par une *.<p>
<table><tr><td colspan=2>Votre Nom*<br><input type=text name=name size=20 maxlength=20 value="$fields[0]"></td>
</tr>
<tr><td colspan=2>Adresse<br><input type=text name=street size=40 maxlength=40 value="$fields[1]"></td></tr>
<tr><td>Ville<br><input type=text name=city size=20 maxlength=40 value="$fields[2]">
</td>
<td>Etat/Province<br><input type=text name=state size=20 maxlength=40 value="$fields[3]">
</td></tr>
<tr><td>Code Postal<br><input type=text name=zip size=20 maxlength=20 value="$fields[4]"></td>
<td>Pays<br>
<input type=text name=country size=20 maxlength=20 value="$fields[5]">
</td></tr>
<tr>
<td>Numéro de téléphone<br>
<input type=text name=phone size=20 maxlength=20 value="$fields[5]">
</td>
<td>Addresse E-mail*<br><input type=text name=email size=20 maxlength=40 value="$fields[6]"></td>
</tr>
<tr><td colspan=2>adresse de votre site WEB<br><input type=text name=url size=50 maxlength=50 value="$fields[7]"></td></tr>
<tr><td colspan=2>
<INPUT TYPE="checkbox" NAME="display_address"> Cochez ici si vous voulez afficher votre adresse postale et votre numéro de téléphone dans votre annonce</td>
</tr>
</table>
</td></tr></table>
<p>

<table border=0 cellpadding=4 cellspacing=4 width=470>
<tr>
<td bgcolor="#ccccff">
<center><font size=4>Votre annonce</font></center><p>
SVP, remplissez en détails votre annonce.  Les champs obligatoires sont signalés par une *.<p>
<table width=100%><tr><td>

<TABLE width=100% BORDER="0">
  <TR>
  <TD COLSPAN = "3"><P><CENTER><B>Catégories</B>*</CENTER>

SVP, cochez la catégorie dans laquelle vous voulez placer votre annonce</TD>
  </TR>~;

foreach $category (@categories) {
    	@fields = split (/\|/, $category);
print qq~
<tr>
<td><INPUT TYPE="radio" NAME="category" VALUE="$category"> $fields[0]</td></tr>~;
  }

print qq~
</table>
<p>
</td></tr>
<tr>
<td>Si aucune des catégories ci-dessus ne correspond pas à votre annonce, quelle catégorie voudriez-vous que nous ajoutions à ce site?<br><input type=text name=category_wanted size=50 maxlength=50 value="$fields[10]"></td></tr>

<tr>
<td>Titre de votre annonce*<br><input type=text name=caption size=50 maxlength=50 value="$fields[10]"></td></tr>
<tr>
<td>Texte de votre annonce (le code HTML n'est pas autorisé.  Appuyez sur la touche retour une fois pour un retour à la ligne, deux fois pour un nouveau paragraphe) TEXTE OBLIGATOIRE*<br>
<TEXTAREA NAME="text" ROWS=5 COLS=50 wrap=physical>$fields[11]</TEXTAREA><p>
</td></tr>
<p>
</table>
</td></tr></table>
<p>
<input type=submit name="post_ad_button" value="Envoyez mon annonce">
<input type=reset value="Annulez tout"><p>
</form>~;
}

sub post_ad {

$counter = 0;

if (($in{'name'} eq "") || ($in{'email'} eq "") || ($in{'category'} eq "") || ($in{'caption'} eq "") || ($in{'text'} eq "")) {
	&required_error;
}

@fields = split (/\|/, $in{'category'});
$long_category_name = $fields[0];
$short_category_name = $fields[1];
$in{'text'} =~ s/\n/<br>/g;

# Lock the file for security so the file is not damaged if more than one user tries to access it at the same time.
		
 $quit = 0;
 while ($quit != 1) {
	if (-e "$classdir/$short_category_name.lock") {
		# The file exists, time to take a nap
		sleep(1);
	}
	else {
	
	# Create the lock file, thereby locking the Classified Ad file
	open (LOCK,">$classdir/$short_category_name.lock");
	close LOCK;
	}
	
	# Open the data file to read the number of the last post
	open (ADFILE, "$classdir/ads.counter");
	$old_counter = <ADFILE>;
	# chop $old_counter;

	# Update the Ad Number by one
	$old_counter++;
	$new_counter = $old_counter;
	
	# Rewrite the data file
	open (ADFILE, ">$classdir/ads.counter");
	print ADFILE "$new_counter";
	close(ADFILE);

$password = $new_counter * $password_multiplier + 13;

# If it doesn't already exist, create the HTML file where the ads will be
# stored for this category

	unless (-e "$classdir/$short_category_name.html") {
	open (HTMLFILE,"+>$classdir/$short_category_name.html");
	&print_default_html;
	close (HTMLFILE);	
	}

	# Append the user's ad and description to the ad file

	open(ADFILE,"$classdir/$short_category_name.html") || die $!;
		@main = <ADFILE>;
		close(ADFILE);
	open(ADFILE,">$classdir/$short_category_name.html") || die $!;
	      foreach $main_line (@main) {
	         if ($main_line =~ /<!--Do not edit past this line-->/) {

	            	print ADFILE "<!--Do not edit past this line-->\n";
			print ADFILE "<!-- $new_counter $in{'name'} $in{'email'} $current_date -->\n";

  print ADFILE qq~<TABLE BORDER="1" CELLPADDING=2 cellspacing=2 width="470">
  <TR BGCOLOR="#000F99" background="$htmldir/blueblack.gif"><th colspan=2><FONT FACE="Arial" SIZE="3" COLOR="#ffffff">$in{'caption'}</FONT></th></tr><TR>
<TD>
<TABLE BORDER=0 cellpadding=2 CELLSPACING=1 WIDTH=460>
<TR>
	<TD WIDTH=60 VALIGN="TOP"><FONT FACE="Arial" SIZE="2" COLOR="#008000">Annonce Numéro:</FONT></TD>
	<TD WIDTH=160 VALIGN="TOP"><FONT FACE="Arial" SIZE="2" COLOR="#CC0000"><B>$new_counter</B></FONT></TD>
	<TD WIDTH=60 VALIGN="TOP"><FONT FACE="Arial" SIZE="2" COLOR="#008000">Posté le:</FONT></TD>
	<TD WIDTH=160 VALIGN="TOP"><FONT FACE="Arial" SIZE="2" COLOR="#CC0000"><B>$current_date</B></FONT></TD>

</TD>
</TR>
<TR>
	<TD VALIGN="TOP" WIDTH=60 rowspan=2><FONT FACE="Arial" SIZE="2" COLOR="#008000">Contact:</FONT></TD>
	<TD WIDTH=160 VALIGN="TOP" rowspan=2><FONT FACE="Arial" SIZE="2">$in{'name'}<br>~;
if ($in{'display_address'} eq "on") {
  print ADFILE qq~
$in{'street'}<br>
$in{'city'}, $in{'state'} $in{'zip'}<br>
$in{'country'}~;
  }

print ADFILE qq~
</font></td>
	<TD WIDTH=60 VALIGN="TOP"><FONT FACE="Arial" COLOR="#008000" SIZE="2">Téléphone:</FONT></TD>
	<TD WIDTH=160 VALIGN="TOP"><FONT FACE="Arial" SIZE="2">~;
if ($in{'display_address'} eq "on") {
  print ADFILE qq~
$in{'phone'}~;
  }

print ADFILE qq~
</FONT></TD>
</tr>
<TR>
	<TD WIDTH=60 VALIGN="TOP"><FONT FACE="Arial" COLOR="#008000" SIZE="2">E-mail:</FONT></TD>
	<TD WIDTH=160 VALIGN="TOP"><FONT FACE="Arial" SIZE="2"><a href="mailto:$in{'email'}">$in{'email'}</a></FONT></TD>
</TR>
<TR>
	<TD WIDTH=60><FONT FACE="Arial" COLOR="#008000" SIZE="2">Site Internet:</FONT></TD>
	<TD COLSPAN=3><FONT FACE="Arial" SIZE="2"><a href="$in{'url'}">$in{'url'}</a><br></FONT></TD>
</TR>
</table>
<br>
	<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=460><TR>
	<TD><FONT FACE="Arial" SIZE="2" COLOR="#000F99"><B>Description</B></FONT><BR>
	<FONT FACE="Arial" SIZE="2">$in{'text'}</FONT></td>
	</tr></TABLE></TD>
	</TR>	
</table><p>\n
~;
			print ADFILE "<!-- end $new_counter -->\n";
	         }
	         else {
	            print ADFILE "$main_line";
	         }
	      }

	# unlock the lock file
	unlink("$classdir/$short_category_name.lock");

if (($reply_user eq "on") && ($sendmail ne "")) {

      open( MAIL, "|$sendmail -t " )
         || die "can't open sendmail: $email: $!\n";
      print MAIL "To: $in{'email'}\n";
      print MAIL "From: $master_admin_email_address\n";
      print MAIL "Subject: $sitename Annonces\n";
      print MAIL "Reply-to: $master_admin_email_address\n\n";

      print MAIL "Merci pour avoir soumis votre annonce dans la $long_category_name section of the $sitename Annonces.  Votre annonce a été envoyée et apparaît ainsi:\n\n";
	print MAIL "Annonce Numéro: $new_counter\n";
	print MAIL "Sujet: $in{'caption'}\n";
	print MAIL "Posté sur: $current_date\n";
	print MAIL "Répondre à: $in{'name'} at $in{'email'}\n";
	print MAIL "Texte de l'annonce: $in{'text'}\n";
	print MAIL "Adresse de votre site si vous en avez une: $in{'url'}\n\n";
	print MAIL "Vous pouvez revenir à tout moment et effacer votre envoi si c'est nécessaire. Nous vous souahitons une agréable visite sur notre site $sitename Classified Ads et revenez souvent nous voir.

Nous avons assigné à votre annonce un mot de passe pour que vous puissiez éventuellement en modifier les caractéristiques.  SVP prenez bien note du chiffre et de votre mot de passe maintenant, qui vous servira  comme référence future. Vous en aurez besoin si vous voulez effacer votre annonce classée. Voici le chiffre et le mot passe qui s'attachent à votre annonce, notez-les bien :

Annonce numéro: $new_counter
Mot de passe: $password

Si vous n'avez pas posté une annonce sur notre site $sitename et que vous croyez que vous avez reçu ce message par erreur, SVP, acceptez nos excuses et informez-nous immédiatement.   Par mesure de sécurité vous avez reçu ce message parceque quelqu'un a utilisé votre adresse Email quand il a posté une annonce sur notre site $sitename Annonces.\n\n";
	print MAIL "Sincèrement,\n\n";
	print MAIL "$admin_name, Webmaster\n";
	print MAIL "$sitename\n";
	print MAIL "$siteurl\n";
	print MAIL "$slogan\n";
	close(MAIL);
  }

if (($master_admin_email_address ne "") && ($notify_add eq "on") && ($sendmail ne ""))
{
      open( MAIL, "|$sendmail -t " )
         || die "can't open sendmail notify: $master_admin_email_address: $!\n";
      print MAIL "To: $master_admin_email_address\n";
      print MAIL "From: $master_admin_email_address\n";
      print MAIL "Subject: Nouvelle Annonce\n";
      print MAIL "L'annonce classée suivante a été ajoutée dans la catégorie $long_category_name à la section suivante $sitename Annonces par $in{'name'}:\n\n";
	print MAIL "Numéro annonce: $new_counter\n";
	print MAIL "Mot de passe: $password\n";
	print MAIL "Sujet: $in{'caption'}\n";
	print MAIL "Posté sur: $current_date\n";
	print MAIL "Répondre à: $in{'name'} at $in{'email'}\n";
	print MAIL "Texte de l'annonce: $in{'text'}\n";
	print MAIL "Adresse de votre site si vous en avez une: $in{'url'}\n\n";
	print MAIL "Nouvelles catégories recommandées (ceci restera en blanc si vous ne faites aucune suggestion): $in{'category_wanted'}";
	close(MAIL);
}

	&successful_addition_message;
	$quit = 1;
}

} # End of sub post_ad

sub successful_addition_message
  {

  &pagesetup("Succès: Votre annonce a été postée avec succès à notre site Annonces classées");
  print qq~
  <h3>Votre annonce a été postée avec succès!</h3></center>
Nous avons assigné à votre annonce un numéro et un mot de passe pour que vous puissiez éventuellement effacer votre annonce vous-même. Voici le Numéro et le mot passe qui s'attachent à votre annonce, notez-les bien :
<blockquote>
Numéro: <b>$new_counter</b><br>
Mot de passe: <b>$password</b>
</blockquote>
  <P>~;
  &pageclose;
  }

sub required_error
  {
&pagesetup("Champ non rempli");

  print qq~
<center><h1>Champ(s) non rempli()s</h1></center>\n
Nous sommes désolés, mais vous n'avez sélectionné aucune valeur dans un champ obligatoire. Tous les champs obligatoires doivent être remplis.  SVP, retournez en arrière et assurez-vous que vous avez sélectionné tous les champs requis.  Merci.
<center>
<form>
<input type=button value="<< Retour " onClick="history.go(-1)"></form></center>
~;
&pageclose;
      exit;
  }  

sub delete_search_form {

  print qq~
<h2>Effacer votre Annonce</h2><p></center>
Pour effacer votre annonce, SVP remplissez tousles champs du formulaire ci-dessous et cliquez surle bouton "Effacer cette annonce".  Pour effacer votre annonce, vous devez sélectionner la catégorie dans laquelle elle apparaît et entrer votre nom et votre adresse Email exactement comme ils apparaissent dans votre annonce.  Vous devez ensuite entrer le numéro et le mot de passe qui vous ont été attribué quand vous avez posté votre annonce.  Si le formulaire est incomplet, votre annonce ne sera pas effacée.<P>

<table border=0 cellpadding=4 cellspacing=4 width=470>
<tr>
<td bgcolor="#e8e8e8">
<center><font size=4>Information Annonce</font></center><p>
<table><tr><td>SVP, sélectionnez la catégorie dans laquelle votre annonce est située:<br>
<SELECT NAME = "category">~;
foreach $category (@categories) {
    	@fields = split (/\|/, $category);
print qq~<OPTION value="$fields[1]">$fields[0]~;
   }
print qq~
</select>
</td>
</tr>
<tr><td>Votre nom<br><input type=text name=name size=40 maxlength=40></td></tr>
<tr><td>Votre adresse E-mail <br><input type=text name=email size=40 maxlength=40></td>
</tr>
<tr><td>Votre numéro d'annonce<br><input type=text name=addno size=10 maxlength=50></td></tr>
<tr><td>Votre mot de passe<br><input type=password name=password size=20 maxlength=50></td></tr>
<tr><td align=center><input type=submit name="delete_button" value="Effacer cette annonce">
<input type=reset value="Effacer tout"></td></tr>
</table>
</td></tr></table>
<p>
</form>
<HR>~;
}

sub delete {
if (($in{'name'} eq "") || ($in{'email'} eq "") || ($in{'addno'} eq "") || ($in{'password'} eq "")  || ($in{'category'} eq "")) {
	&required_error;
}

	unless (-e "$classdir/$in{'category'}.html") {
	&no_ads_message;
	exit;
	}

# Lock the file for security so the file is not damaged if more than one user tries to access it at the same time.
		
$quit = 0;
while ($quit != 1) {
	if (-e "$classdir/$in{'category'}.lock") {
		# The file exists, time to take a nap
		sleep(1);
	}
	else {
	
	# Create the lock file, thereby locking the Classified Ad file
	open (LOCK,">$classdir/$in{'category'}.lock");
	close LOCK;
	}

	# Delete the user's ad and description from the ad file

	open(ADFILE,"$classdir/$in{'category'}.html") || die $!;
		@main = <ADFILE>;
		close(ADFILE);

	$ad_to_delete = "0";
	$deleted_ad_found = "0";
	open(ADFILE,">$classdir/$in{'category'}.html") || die $!;
	      foreach $main_line (@main) {
	         if ($main_line =~ /<!-- $in{'addno'} $in{'name'} $in{'email'}/) {

		if (($in{'password'} eq "$admin_password") || ($in{'password'} == ($in{'addno'} * $password_multiplier + 13))) {
			$ad_to_delete = "1";
			$deleted_ad_found = "1";
				}
		else {
			$deleted_ad_found = "1";
			$incorrect_password = "1";
		}

		   }
		   if ($ad_to_delete eq "1"){
		$deleted_ad .= "$main_line";
			if ($main_line =~ /<!-- end $in{'addno'} -->/) {
				$ad_to_delete = "0";
			}
	         }
	         else {
	            print ADFILE "$main_line";
	         }
	      }
		close(ADFILE);

	# unlock the lock file
	unlink("$classdir/$in{'category'}.lock");

	if ($incorrect_password eq "1"){
	&password_error;
	}
	elsif ($deleted_ad_found eq "0"){
	&unsuccessful_modification_message;
	}
	else {
	&successful_deletion_message;

if (($master_admin_email_address ne "") && ($notify_delete eq "on") && ($sendmail ne ""))
{
      open( MAIL, "|$sendmail -t " )
         || die "can't open sendmail notify: $master_admin_email_address: $!\n";
      print MAIL "To: $master_admin_email_address\n";
      print MAIL "From: $master_admin_email_address\n";
      print MAIL "Subject: L' annonce a été effacée\n";
      print MAIL "Reply-to: $in{'email'}\n\n";
      print MAIL "Annonce Numéro $in{'addno'} a été effacée dans la $in{'category'} catégorie dans la section suivante $sitename Annonces par $in{'name'}.\n\n";
	close(MAIL);
}
	}
	$quit = 1;
} # End of while ($quit != 1)
exit;
}

sub password_error
  {
&pagesetup("Erreur: Mot de passe incorrect");

  print qq~
<center><h1>Erreur: Mot de passe incorrect</h1></center>\n
Nous sommes désolés mais vous n'avez pas entré le bon mot de passe.  SVP, retournez en arrière et assurez-vous que vous avez entré le bon mot de passe.  Merci.<p>
<center>
<form>
<input type=button value="<< Retour " onClick="history.go(-1)"></form></center>
~;
&pageclose;
  }  

sub unsuccessful_modification_message
  {
  &pagesetup("Erreur: Annonce non trouvée");
  print qq~<center><h3>Erreur: Annonce non trouvée</h3></center>
  L'annonce que vous avez choisie n'a pas été trouvée.  SVP, assurez-vous que vous avez entré dans le formumaire votre nom et votre adresse E-mail ainsi que le numéro correspondant à votre annonce.  Merciu.~;
  &pageclose;
  }

sub successful_deletion_message
  {
  &pagesetup("Success: Votre annonce a été effacée avec succès de notre site");
  print qq~
  <center><h3>Votre annonce a été effacée avec succès de notre site!</h3>
  L'annonce suivante a bien été effacée:<p>
$deleted_ad
  <P>~;
  &pageclose;
  }

sub delete_all_form {

  print qq~
<h2>Effacer toutes les annonces dans une catégorie</h2><p></center>
Si vous êtes administrateur, vous pouvez effacer toutes les annonces dans une catégorie en particulier en utilisant le formulaire ci-dessous. Vous aurez besoin de votre mot de passe Administrateur pour le faire. SVP, choisissez la catégorie que vous souhaitez effacer et entrez votre mot de passe administrateur dans le formulaire ci-dessous et cliquez sur le boutton "Effacer toutes les Annonces"<P>

<table border=0 cellpadding=4 cellspacing=4 width=470>
<tr>
<td bgcolor="#e8e8e8">
<center><font size=4>Informations - Annonces</font></center><p>
<table><tr><td>SVP, sélectionnez la catégorie que vous souhaitez effacer:<br>
<SELECT NAME = "category">~;
foreach $category (@categories) {
    	@fields = split (/\|/, $category);
print qq~<OPTION value="$fields[1]">$fields[0]~;
   }
print qq~
</select>
</td>
</tr>
<tr><td>Mot de passe administrateur<br><input type=text name=password size=40 maxlength=40></td></tr>
<tr><td align=center><input type=submit name="delete_all_button" value="Effacer toutes les Annonces">
</td></tr>
</table>
</td></tr></table>
<p>
</form>
<HR>~;
}

sub delete_all {
if ($in{'category'} eq "") {
	&required_error;
}

unless ($in{'password'} eq "$admin_password") {
	&admin_password_error;
}

	unless (-e "$classdir/$in{'category'}.html") {
	&no_ads_message;
	exit;
	}

	unlink("$classdir/$in{'category'}.html");

  &pagesetup("Succès: Annonces effacées");
  print qq~
  <h3>Annonces effacées</h3></center>
 Toutes les annonces dans la catégorie $in{'category'} ont été effacées.
  <P>~;
  &pageclose;

if (($master_admin_email_address ne "") && ($notify_delete_all eq "on") && ($sendmail ne ""))
{
      open( MAIL, "|$sendmail -t " )
         || die "Ouverture de la notification Email impossible: $master_admin_email_address: $!\n";
      print MAIL "To: $master_admin_email_address\n";
      print MAIL "From: $master_admin_email_address\n";
      print MAIL "Subject: Vos annonces ont été effacées\n";
      print MAIL "Ceci est une simple notification que toutes vos annonces dans la $in{'category'} catégorie du site $sitename ont été effacées.  Si vous n'arrivez pas à effacer vos annonces, c'est que quelqu'un a obtenu votre mot de passe et a effacé vos annonces du site.\n\n";
	close(MAIL);
	}

exit;

}

sub display_frontpage
  {
print qq~
</center><i>
Pour visualiser les annonces, choisissez parmi l'une des catégories ci-dessous.  Les catégories qui ne sont pas en hypertexte ne comportent aucune annonce.  Vous pouvez aussi choisir parmi les options du menu à votre gauche. 
</i><center>
<p>
<font size=4 face="arial">Annonces aquariophiles classées par catégories</font><br></f></center>
<ul>~;
&generic_form_header;

foreach $category (@categories) {
    	@fields = split (/\|/, $category);

	if (-e "$classdir/$fields[1].html") {
print qq~
<li><font face="arial" size=2><b><a href="$htmldir/$fields[1].html">$fields[0]</a></b><br>
<font size=1>$fields[2]</font>~;
}

else {
print qq~
<li><font face="arial" size=2><b>$fields[0]</b><br>
<font size=1>$fields[2]</font>~;
  }
}

print qq~
</ul>
<P>
</form>
<P>~;
}

sub generic_form_header
  {
  print qq~
  <FORM METHOD = "post" ACTION = "$script_url">~;
  }

sub get_date
  {

  local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$date);   
  local (@days, @months);

  @days = ('Dimanche','Lundi','Mardi','Mercredi','Jeudi',
           'Vendredi','Smadi');
  @months = ('Janvier','Fevrier','Mars','Avril','Mai','Juin','Juillet', 
             'Aout','Septembre','Octobre','Novembre','Decembre');

$time = time;
    
  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
  
  $year = (1900 + $year);

  if ($mon < 10)
    {
    $mon = "0$mon";
    }
  if ($mday < 10)
    {
    $mday = "0$mday";
    }
  $mon++;
$date = "$mday/$mon/$year";
  return $date;
  }

sub get_required_files {
unless ($footer =~ /Powered by <a href="http:\/\/www.e-classifieds.net\/">e-Classifieds.net<\/a>. Copyright © 1995-2001 Hagen Software Inc. All rights reserved./) {
exit;
}
}

sub category_error
  {
&pagesetup("Erreur: Vous n'avez pas choisi de catégorie");

  print qq~
<center><h1>Erreur: Vous n'avez pas choisi de catégorie</h1></center>\n
Nous sommes désolés, mais vous n'avez pas choisi de catégorie.  SVP, retournez en arrière et assurez-vous que vous avez bien sélectionné une catégorie.  Merci.<p>
<center>
<form>
<input type=button value="<< Retour " onClick="history.go(-1)"></form></center>
~;
&pageclose;
      exit;
  }  

sub admin_password_error
  {
&pagesetup("Erreur: Mot de passe incorrect");

  print qq~
<center><h1>Erreur: Mot de passe incorrect</h1></center>\n
Nous sommes désolés, mais vous n'avez pas entré le mot de passe administrateur correct. Si vous êtes administrateur, SVP, retournez en arrière et assurez-vous que vous avez bien entré le bon mot de passe administrateur.  Merci.<p>
<center>
<form>
<input type=button value="<< retour " onClick="history.go(-1)"></form></center>
~;
&pageclose;
      exit;
  }  
