<?
/***************************************************************************
                          Livredor.php - Classe Livredor
                             -------------------
    begin                : Septembre  UTC 2002
    copyright            : (C) 2002 by NADAL Jean-Baptiste
    email                : jbnadal@ifrance.com
 ***************************************************************************
 *
 *  Cette classe permet de gerer un livre d'or pour le site de l'Harmonie
 *  de Montpellier-Jacou.
 *
 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************
 * $Id: Livredor.php,v 1.4 2002/12/15 20:22:29 jb Exp $
 ***************************************************************************/


if (file_exists ("conf.php"))
   require ("conf.php");
else
   require ("./Scripts/conf.php");


class Livredor {

   // =============================================================
   // Les Variables
   var $szTabTexte;     // Contient le contenu de la page du livre d'or courant
   var $nLongTexte;     // Taille du tableau du contenu de la requete
   var $nNbMsg;         // Nombre de message que contient le livre d'or
   
   var $Font_Def;       // Font utilisé pour l'affichage du livre d'or
   var $msgPARpages;    // Nombre de messages affichable par page
   var $nbrePages;      // Nombre de page que contient le livre d'or
   var $CouleurFond;    // Couleur de fond des lignes du resultat de la requete

   // =============================================================
   // Les Fonctions
   function Livredor ()
   {
      $fontFace = "verdana,arial,hevetica";// Police par défaut
      $fontSize = "2";                     // Taille de la police par défaut
      $this->Font_Def = "<font face=$fontFace size=$fontSize>";
      $this->msgPARpages = 10;
      $this->CouleurFond = "#CCCCCC";
   }
   
   function AfficheTexte ()
   {
      echo "$this->szTabTexte";
   }
   
   /* =================================================
    * Cette fonction se connecte a la base du livre d'or et affiche simplement
    * Un texte : celui dont le numero
    * est passé en paramètre.
    */
   function GetText($num_elem)
   {
      global $sql_bdd;
      
      // On se connecte sur la base du livre d'Or
      $connect_db = jb_sql_connect (false);
      $resultat = mysql_db_query ($sql_bdd,"select * from livredor where".
                                  " id=$num_elem",$connect_db);
      
      $t_pseudo = mysql_result ($resultat, $cpt, "pseudo");
      $t_email = mysql_result ($resultat, $cpt, "email");
      $t_pays = mysql_result ($resultat, $cpt, "pays");
      $t_message = mysql_result ($resultat, $cpt, "message");
      $t_date = mysql_result ($resultat, $cpt, "date");
      $t_id = mysql_result ($resultat, $cpt, "id");
      
      echo "<br><br><table width=90% border=0 cellpadding=0 cellspacing=0>\n".
         "<re><td>$this->Font_Def";
      echo "$t_date</font></td></tr><tr><td bgcolor=$this->CouleurFond> ";
      /* Si la personne qui a signe le livre d'or a donné son email, on la lie 
       * sinon, on n'affiche que le pseudo
       */
      if ($t_email)
         echo "<a href = mailto:$t_email>$this->Font_Def".
            "  $t_pseudo</font></a> , $t_pays";
      else
         echo "<b>$this->Font_Def  $t_pseudo</font></b> , $t_pays";

      // Puis On affiche le message a proprement parlé
      echo "</td></tr><tr><td> $this->Font_Def $t_message </font> </td> 
               </tr>\n</table>\n<br>\n";
      // puis on ferme la connexion avec le serveur de base de donnees
      MYSQL_CLOSE;
   }
   
   /* =================================================
    * Cette fonction supprime le texte de la base Livre d'or dont
    *  on passe l'indice en paramèrtre
    */
   function SupprimeText ($num_elem)
   {
      global $sql_bdd;
      
      /* On se connecte sur la base du livre d'Or. */
      $connect_db = jb_sql_connect (false);
      $resultat = mysql_db_query ($sql_bdd, "delete from livredor where".
                                  " id=$num_elem", $connect_db);
      if ($resultat == 1)
         echo "<br><br><center><font size=4 color=red><b>Le message".
            " $num_elem a été effacé</b></font></center><br><br>\n";
      else
         echo "<br><br><center><font size=6 color=red><b>BUG !!! suppression".
            " Impossible</b></font></center><br><br>\n";
      MYSQL_CLOSE;
   }
   
   function RecuperePage ($page, $modeAdmin)
   {
      global $racine, $page_index, $sql_bdd, $id;

      // On se connecte sur la base du livre d'Or
      $connect_db = jb_sql_connect (true);
      $resultat = mysql_db_query ($sql_bdd, "select * from livredor order by".
                                 " id desc", $connect_db);
      $nbTotalLignes = mysql_numrows ($resultat);
      $this->nNbMsg = $nbTotalLignes;
      
      // On regarde qu'il y ait au moins une ligne de résultat
      if ($nbTotalLignes != 0) {

         // On calcul les bornes des messages que l'on va récupéré ensuite
         $this->nbrePages = ceil ($nbTotalLignes / $this->msgPARpages);
         /* Si le paramètre passé a la méthode est vide, on lui affecte
          * la page 0. */
         
         if ($page == "")
            $page = "0";
         // Puis les deux bornes
         $premierMsg = ($page * $this->msgPARpages);
         $dernierMsg = ($premierMsg + $this->msgPARpages);
         
         $cpt = $premierMsg;

         // Puis on boucle pour afficher tout les messages
         while ($cpt < $dernierMsg) {
            $t_pseudo = mysql_result ($resultat, $cpt, "pseudo");
            $t_email = mysql_result ($resultat, $cpt, "email");
            $t_pays = mysql_result ($resultat, $cpt, "pays");
            $t_message = mysql_result ($resultat, $cpt, "message");
            $t_date = mysql_result ($resultat, $cpt, "date");
            $t_id = mysql_result ($resultat, $cpt, "id");
            
            $this->szTabTexte .="<table width=90% border=0 cellpadding=0".
               " cellspacing=0>\n<tr><td>$this->Font_Def";
            if ($modeAdmin)
               $this->szTabTexte .= "<b>Message $t_id</b> en date du $t_date".
                  "</font></td></tr><tr><td bgcolor=$this->CouleurFond> ";
            else
               $this->szTabTexte .= "$t_date</font></td></tr><tr><td ".
                  "bgcolor=$this->CouleurFond> ";
            /* Si la personne qui a signe le livre d'or a donné son email,
             * on la lie sinon, on n'affiche que le pseudo
             */
            if ($t_email)
               $this->szTabTexte .="<a href = mailto:$t_email>$this->Font_Def".
                  "  $t_pseudo</font></a> , $t_pays";
            else
               $this->szTabTexte .="<b>$this->Font_Def $t_pseudo</font>".
                  "</b> $t_pays";
            
            /* Puis On affiche le message a proprement parlé. */
            $this->szTabTexte .= "</td></tr><tr><td> $this->Font_Def ".
               "$t_message </font> </td> </tr>\n</table>\n<br>\n";
            if ($modeAdmin) {

               $this->szTabTexte .= "<center>\n <form action=".
                  "'$racine/$page_index?".
                  "page=SuppElemLVOR&id=$id&action=quest ' method='post'>\n";
               $this->szTabTexte .= "<input type=hidden name=num_id ".
                  "value=$t_id />\n";
               $this->szTabTexte .= "<input type=submit name=destroy value=".
                  "\"Effacer le message $t_id\" /></form><br><hr><br>\n";
            }
            
            $cpt++;
            if ($cpt == $nbTotalLignes)
               $cpt = $dernierMsg;
         } 
         
         MYSQL_CLOSE;
      }
      else
         $this->szTabTexte .= "<center>$this->Font_Def".
            "<b>Aucun message pour l'instant.</b></font></center>";
   }
   
   function GenereEntete ($page, $modeAdmin)
   {
      global $racine, $page_index, $id,$page_index;
         
      // On affiche les index sur les différentes pages
      $x = "1";
      $code .= "| ";
         
      while ($x <= $this->nbrePages) {
         if ($page != $x) {
            if ($modeAdmin)
               $code.= "<a href=\"$racine/$page_index?page=AdmLivOR&id=$id";
            else
               $code.= "<a href=\"$page_index?page=livre_or";
            $code.= "&livorPage=".($x-1)."\"><b>$x</b></a> | ";
         }
         else
            $code.= " $x | ";
            
         $x++;
      }
       
      /* On affcihe le nombre de message du livre d'or. */
      echo "$this->Font_Def <center>$code<br>
                  <hr size=1 width=\"75%\" noshade>
                  $this->nNbMsg messages";
      if (!$modeAdmin)
         echo "[ <a href=#signer> Signer le livre d'or </a> ] </font><br>\n
                 <br>\n
                 <br><center>Pour tout renseignement, voir notre rubrique 
                 <a href=\"$page_index?page=contacts\">contact</a></center>";
   }
   
   function ValideInscriptionLivre($pseudo, $email, $pays, $message, $date)
   {
      global $sql_bdd;
      
      if (strlen ($date) < 3)
         $Datelo = date('d m Y, H:i');
      else
         $Datelo=$date;
         
      $connect_db = jb_sql_connect (false);
      $query =  "insert into livredor (pseudo,email,pays,message,date) values";
      $query .= "('$pseudo', '$email', '$pays', '$message', '$date')";
      $resultat = mysql_db_query ($sql_bdd,  $query, $connect_db);

      MYSQL_CLOSE;
   }
   
   function GenereFormulaireInscription()
   {
      echo "
        <a name=signer></a>
        Pour signer le livre d'or, remplissez le formulaire ci-dessous et
        validez.<br/>
        (seules les cases \"<u>Pseudo</u>\" et \"<u>Message</u>\" 
        sont obligatoires).<br/><br/>
        <hr size=1 noshade>
        <form action=index.php?&page=SigneLOr method=post>
        <center>
        <table border=0 cellspacing=4 cellpadding=0 width=90%>
        <tr>
          <td width=25%> <p>$this->Font_Def<b> Pseudo : </b></font> </p>
          </td>
          <td width=25%> <p><input type=text name=pseudo size=18></p>
          </td>
          <td width=25%> <p>$this->Font_Def Email : </font></p>
          </td>
          <td width=25%> <p><input type=text name=email size=18> </p>
          </td>
        </tr>
        <tr>
          <td width=25%> <p>$this->Font_Def Pays : </p> </td>
          <td width=25%>
            <select name=pays>
            <option value = France selected> France
            <option value = Afghanistan> Afghanistan
            <option value = Albanie> Albanie
            <option value = Algerie> Algerie
            <option value = Andorre> Andorre
            <option value = Angola> Angola
            <option value = Anguilla> Anguilla
            <option value = Antarctique> Antarctique
            <option value = Argentine> Argentine
            <option value = Armenie> Armenie
            <option value = Aruba> Aruba
            <option value = Australie> Australie
            <option value = Autriche> Autriche
            <option value = Azerbaijan> Azerbaijan
            <option value = Bahamas> Bahamas
            <option value = Bahrain> Bahrain
            <option value = Bengladesh> Bengladesh
            <option value = Barbade> Barbade
            <option value = Bielarussie> Bielarussie
            <option value = Belgique> Belgique
            <option value = Belize> Belize
            <option value = Benin> Benin
            <option value = Bermudes> Bermudes
            <option value = Bhutan> Bhutan
            <option value = Bolivie> Bolivie
            <option value = Botswhana> Botswhana
            <option value = \"Bouvet_island\"> Bouvet_island
            <option value = Bresil> Bresil
            <option value = Bulgarie> Bulgarie
            <option value = \"Burkina_faso\"> Burkina_faso
            <option value = Burundi> Burundi
            <option value = Cambodge> Cambodge
            <option value = Cameroun> Cameroun
            <option value = Canada> Canada
            <option value = \"Cape_verde\"> Cape_verde
            <option value = \"Cayman_islands\"> Cayman_islands
            <option value = Chad> Chad
            <option value = Chile> Chile
            <option value = China> China
            <option value = \"Christmas_island\"> Christmas_island
            <option value = \"Cocos_(keeling)_islands\"> 
                    Cocos_(keeling)_islands
            <option value = Colombia> Colombia
            <option value = Comoros> Comoros
            <option value = Congo> Congo
            <option value = \"Cook_islands\"> Cook_islands
            <option value = \"Costa_rica\"> Costa_rica
            <option value = \"Cote_d\'ivoire\">Cote_d\'ivoire
            <option value = Croatia> Croatia
            <option value = Cuba> Cuba
            <option value = Cyprus> Cyprus
            <option value = \"Czech_republic\"> Czech_republic
            <option value = Denmark> Denmark
            <option value = Djibouti> Djibouti
            <option value = Dominica> Dominica
            <option value = \"Dominican_republic\"> Dominican_republic
            <option value = \"East_timor\"> East_timor
            <option value = Ecuador> Ecuador
            <option value = Egypt> Egypt
            <option value = \"El_salvador\"> El_salvador
            <option value = \"Equatorial_guinea\"> Equatorial_guinea
            <option value = Eritrea> Eritrea
            <option value = Estonia> Estonia
            <option value = Ethiopia> Ethiopia
            <option value = \"Faroe_islands\"> Faroe_islands
            <option value = Fiji> Fiji
            <option value = Finland> Finland
            <option value = France> France
            <option value = \"French_guiana\"> French_guiana
            <option value = \"French_polynesia\"> French_polynesia
            <option value = \"French_southern\"> French_southern
            <option value = Gabon> Gabon
            <option value = Gambia> Gambia
            <option value = Georgia> Georgia
            <option value = Germany> Germany
            <option value = Ghana> Ghana
            <option value = Gibraltar> Gibraltar
            <option value = Greece> Greece
            <option value = Greenland> Greenland
            <option value = Grenada> Grenada
            <option value = Guadeloupe> Guadeloupe
            <option value = Guam> Guam
            <option value = Guatemala> Guatemala
            <option value = Guinea> Guinea
            <option value = \"Guinea-bissau\"> Guinea-bissau
            <option value = Guyana> Guyana
            <option value = Haiti> Haiti
            <option value = Honduras> Honduras
            <option value = \"Hong_kong\"> Hong_kong
            <option value = Hungary> Hungary
            <option value = Iceland> Iceland
            <option value = India> India
            <option value = Indonesia> Indonesia
            <option value = Iraq> Iraq
            <option value = Ireland> Ireland
            <option value = Israel> Israel
            <option value = Italy> Italy
            <option value = Jamaica> Jamaica
            <option value = Japan> Japan
            <option value = Jordan> Jordan
            <option value = Kazakhstan> Kazakhstan
            <option value = Kenya> Kenya
            <option value = Kiribati> Kiribati
            <option value = \"Korea,_republic_of\"> Korea,_republic_of
            <option value = Kuwait> Kuwait
            <option value = Kyrgyzstan> Kyrgyzstan
            <option value = Latvia> Latvia
            <option value = Lebanon> Lebanon
            <option value = Lesotho> Lesotho
            <option value = Liberia> Liberia
            <option value = Liechtenstein> Liechtenstein
            <option value = Lithuania> Lithuania
            <option value = Luxembourg> Luxembourg
            <option value = Macau> Macau
            <option value = Madagascar> Madagascar
            <option value = Malawi> Malawi
            <option value = Malaysia> Malaysia
            <option value = Maldives> Maldives
            <option value = Mali> Mali
            <option value = Malta> Malta
            <option value = \"Marshall_islands\"> Marshall_islands
            <option value = Martinique> Martinique
            <option value = Mauritania> Mauritania
            <option value = Mauritius> Mauritius
            <option value = Mayotte> Mayotte
            <option value = Mexico> Mexico
            <option value = Monaco> Monaco
            <option value = Mongolia> Mongolia
            <option value = Montserrat> Montserrat
            <option value = Morocco> Morocco
            <option value = Mozambique> Mozambique
            <option value = Myanmar> Myanmar
            <option value = Namibia> Namibia
            <option value = Nauru> Nauru
            <option value = Nepal> Nepal
            <option value = Netherlands> Netherlands
            <option value = \"New_caledonia\"> New_caledonia
            <option value = \"New_zealand\"> New_zealand
            <option value = Nicaragua> Nicaragua
            <option value = Niger> Niger
            <option value = Nigeria> Nigeria
            <option value = Niue> Niue
            <option value = \"Norfolk_island\"> Norfolk_island
            <option value = Norway> Norway
            <option value = Oman> Oman
            <option value = Pakistan> Pakistan
            <option value = Palau> Palau
            <option value = Panama> Panama
            <option value = \"Papua_new_guinea\"> Papua_new_guinea
            <option value = Paraguay> Paraguay
            <option value = Peru> Peru
            <option value = Philippines> Philippines
            <option value = Pitcairn> Pitcairn
            <option value = Poland> Poland
            <option value = Portugal> Portugal
            <option value = \"Puerto_rico\"> Puerto_rico
            <option value = Qatar> Qatar
            <option value = Reunion> Reunion
            <option value = Romania> Romania
            <option value = \"Russian_federation\"> Russian_federation
            <option value = Rwanda> Rwanda
            <option value = \"Saint_lucia\"> Saint_lucia
            <option value = Samoa> Samoa
            <option value = \"San_marino\"> San_marino
            <option value = \"Saudi_arabia\"> Saudi_arabia
            <option value = Senegal> Senegal
            <option value = Seychelles> Seychelles
            <option value = \"Sierra_leone\"> Sierra_leone
            <option value = Singapore> Singapore
            <option value = Slovakia> Slovakia
            <option value = Slovenia> Slovenia
            <option value = \"Solomon_islands\"> Solomon_islands
            <option value = Somalia> Somalia
            <option value = \"South_africa\"> South_africa
            <option value = Spain> Spain
            <option value = \"Sri_lanka\"> Sri_lanka
            <option value = \"St._helena\"> St._helena
            <option value = Sudan> Sudan
            <option value = Suriname> Suriname
            <option value = Swaziland> Swaziland
            <option value = Sweden> Sweden
            <option value = Switzerland> Switzerland
            <option value = \"Syrian_arab_republic\"> Syrian_arab_republic
            <option value = Taiwan> Taiwan
            <option value = Tajikistan> Tajikistan
            <option value = Tanzania> Tanzania
            <option value = Thailand> Thailand
            <option value = Togo> Togo
            <option value = Tokelau> Tokelau
            <option value = Tonga> Tonga
            <option value = Tunisia> Tunisia
            <option value = Turkey> Turkey
            <option value = Turkmenistan> Turkmenistan
            <option value = Tuvalu> Tuvalu
            <option value = Uganda> Uganda
            <option value = Ukraine> Ukraine
            <option value = \"United_arab_emirates\"> United_arab_emirates
            <option value = \"United_kingdom\"> United_kingdom
            <option value = \"United_states\"> United_states
            <option value = Uruguay> Uruguay
            <option value = Uzbekistan> Uzbekistan
            <option value = Vanuatu> Vanuatu
            <option value = Venezuela> Venezuela
            <option value = \"Viet_nam\"> Viet_nam
            <option value = \"Western_sahara\"> Western_sahara
            <option value = Yemen> Yemen
            <option value = Yugoslavia> Yugoslavia
            <option value = Zambia> Zambia
            <option value = Zimbabwe> Zimbabwe
            </select>
          </td>
          <td width=25%> <p>&nbsp;</p>
          </td>
          <td width=25%> &nbsp;</p>
          </td>
        </tr>
        <tr>
          <td width> <p>$this->Font_Def <b>Message : </b></font> </p>
          </td>
        </tr>
        </table>
        <textarea name=message rows=5 cols=52 wrap=virtual></textarea>

        <hr size=1 noshade>
        <script language=\"javascript\">
            var datelo =DonneDate();
            document.write(\"<input type=hidden name=datecourante value=".
         "\"+datelo+\">\");
        </script>
        <input type=submit name=envoi value=\"Signer le livre d'or\"><br><br>
        </form>
        ";
   }
}
?>
