Subversion Repositories Applications.papyrus

Rev

Rev 293 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

<?php
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
// +------------------------------------------------------------------------------------------------------+
// | PHP version 4.1                                                                                      |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
// +------------------------------------------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or                                        |
// | modify it under the terms of the GNU Lesser General Public                                           |
// | License as published by the Free Software Foundation; either                                         |
// | version 2.1 of the License, or (at your option) any later version.                                   |
// |                                                                                                      |
// | This library is distributed in the hope that it will be useful,                                      |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
// | Lesser General Public License for more details.                                                      |
// |                                                                                                      |
// | You should have received a copy of the GNU Lesser General Public                                     |
// | License along with this library; if not, write to the Free Software                                  |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id: inscription.class.php,v 1.4 2005-03-21 16:57:30 florian Exp $
/**
* Inscription
*
* Un module d'inscription, en général ce code est spécifique à
* un site web
*
*@package inscription
//Auteur original :
*@author        Alexandre GRANIER <alexandre@tela-botanica.org>
//Autres auteurs :
*@copyright     Tela-Botanica 2000-2004
*@version       $Revision: 1.4 $ $Date: 2005-03-21 16:57:30 $
// +------------------------------------------------------------------------------------------------------+
*/

// +------------------------------------------------------------------------------------------------------+
// |                                            ENTETE du PROGRAMME                                       |
// +------------------------------------------------------------------------------------------------------+

require_once 'HTML/QuickForm.php' ;

class HTML_formulaireInscription extends HTML_Quickform {

    
    /**
     *  Constructeur
     *
     * @param string formName Le nom du formulaire
     * @param string method Méthode post ou get
     * @param string action L'action du formulaire.
     * @param int target La cible.
     * @param Array attributes Les attributs HTML en plus.
     * @param bool trackSubmit ??
     * @return void
     * @access public
     */
    
    function HTML_formulaireInscription( $formName,  $method = "post",  $action,  $target = "_self",  $attributes,  $trackSubmit = false ) {
        HTML_Quickform::HTML_Quickform($formName, $method, $action, $target, $attributes, $trackSubmit) ;
    }

    /**
     * 
     *
     * @return void
     * @access public
     */
    function construitFormulaire($url, $liste_pays)
    {
        $squelette =& $this->defaultRenderer();
        $squelette->setFormTemplate("\n".'<form{attributes}>'."\n".'{content}'."\n".'</form>'."\n");
        $squelette->setElementTemplate( '<li class="liste_inscription">'."\n".'<label>{label}</label>'."\n".'{element}'."\n".
                                        '<!-- BEGIN required --><span class="symbole_obligatoire">*</span><!-- END required -->'."\n".
                                        '<!-- BEGIN error --><span class="erreur">{error}</span><!-- END error -->'."\n".
                                        '</li>'."\n");
        
        $squelette->setGroupElementTemplate('<span class="groupe_formulaire"><label>{label}</label> {element}</span>', 'groupe_cp_ville') ;
        $squelette->setGroupElementTemplate('<span class="groupe_formulaire"><label>{label}</label> {element}</span>', 'groupe_nom') ;
        $squelette->setRequiredNoteTemplate("\n".'<p>'."\n".'<span class="symbole_obligatoire">*</span> {requiredNote}'."\n".'</p>'."\n");
        
        $this->addElement('html', '<br /><h2>'.INS_AJOUT_MEMBRE.'</h2><br />');
        $fieldset_debut =    '<fieldset>'."\n".
                                '<legend>'.INS_COORD_PERSO.'</legend>'."\n".
                                '<ul>'."\n";
        $this->addElement('html', $fieldset_debut);
        $this->addElement('text', 'email', INS_EMAIL) ;
        $this->addRule('email', INS_EMAIL_REQUIS, 'required','', 'client') ;
        $this->addRule('email', INS_MAIL_INCORRECT, 'email', '', 'client') ;
        $this->registerRule('doublonmail', 'callback', 'verif_doublonMail');
        $this->addRule('email', INS_MAIL_DOUBLE, 'doublonmail', true);
        
        
        // A faire, grouper les mots de passe
        $this->addElement('password', 'mot_de_passe', INS_MOT_DE_PASSE, array ('size' => '8')) ;
        $this->addElement('password', 'mot_de_passe_repete', INS_REPETE_MOT_DE_PASSE, array ('size' => '8')) ;
        $this->addRule('mot_de_passe', INS_MOT_DE_PASSE_REQUIS, 'required', '', 'client') ;
        $this->addRule('mot_de_passe_repete', INS_MOT_DE_PASSE_REQUIS, 'required', '', 'client') ;
        $this->addRule(array ('mot_de_passe', 'mot_de_passe_repete'), INS_MOTS_DE_PASSE_DIFFERENTS, 'compare', '', 'client') ;
        
        
        $nom_prenom[] = & HTML_QuickForm::createElement('text', 'nom', INS_NOM, array ('size' => '12')) ;
        $nom_prenom[] = & HTML_QuickForm::createElement('text', 'prenom', INS_PRENOM, array ('size' => '12')) ;
        $this->addGroup($nom_prenom, 'groupe_nom', '', '', false) ;
       
        if (INS_UTILISE_WIKINI) {
            $this->addElement('text', 'nom_wikini', INS_NOM_WIKI, array ('size' => '12')) ;
            $this->addRule('nom_wikini', INS_MAUVAIS_NOM_WIKI, 'regex', '/(!?[A-Z][A-Za-z0-9]*[a-z0-9]+[A-Z][A-Za-z0-9]*)/', 'client') ;
            $this->registerRule('doublonwikini', 'callback', 'verif_doublonNomWiki');
            $this->addRule('nom_wikini', INS_NOMWIKI_DOUBLE, 'doublonwikini', true);
        }
        $this->addElement('text', 'adresse_1', INS_ADRESSE1) ;
        $this->addElement('text', 'adresse_2', INS_ADRESSE2) ;
        if (INS_CHAMPS_TELEPHONE) $this->addElement('text', 'telephone', INS_TEL, array ('size' => '12')) ;
        if (INS_CHAMPS_FAX) $this->addElement('text', 'fax', INS_FAX, array ('size' => '12')) ;
        $this->addElement('text', 'region', INS_REGION) ;
        
        $cp_ville[] = & HTML_QuickForm::createElement('text', 'cp', INS_CODE_POSTAL, array ('size' => '6')) ;
        $cp_ville[] = & HTML_QuickForm::createElement('text', 'ville', INS_VILLE) ;
        $this->addGroup($cp_ville, 'groupe_cp_ville', '', '', false) ;
        $this->addGroupRule('groupe_cp_ville', INS_CODE_POSTAL_REQUIS, 'required', '', 1, 'client') ;
        
            // L'élément pays est construit à partir du tableau liste_pays

        $this->addElement('select', 'pays', INS_PAYS, $liste_pays) ;
        
        if (INS_CHAMPS_STRUCTURE) $this->addElement('text', 'structure', INS_STRUCTURE) ;
        
        $this->addElement('text', 'site', INS_SITE_INTERNET) ;
        
           // on fait un groupe avec les boutons pour les mettres sur la même ligne
        $buttons[] = &HTML_QuickForm::createElement('button', 'annuler', INS_ANNULER, array ("onclick" => "javascript:document.location.href='".$url."'"));
        $buttons[] = &HTML_QuickForm::createElement('submit', 'valider', INS_VALIDER);
        $this->addGroup($buttons, null, null, '&nbsp;');
        
        $fieldset_fin =    '</ul>'."\n".
                            '</fieldset>'."\n";
        $this->addElement('html', $fieldset_fin);
        

        $this->setRequiredNote(INS_CHAMPS_REQUIS) ;
    } // end of member function construitFormulaire
    
    /** Modifie le formulaire pour l'adapter au cas des structures
     * 
     *
     * @return void
     * @access public
     */
    function formulaireStructure()
    {
        $this->removeElement('groupe_nom') ;
        $this->removeElement('email', false) ;
        $mail = & HTML_QuickForm::createElement('text', 'email', INS_MAIL_STRUCTURE) ;
        $this->insertElementBefore($mail, 'mot_de_passe') ;
        $nom_structure = & HTML_QuickForm::createElement('text', 'nom', INS_NOM_STRUCTURE) ;
        $this->insertElementBefore($nom_structure, 'email') ;
        $this->removeElement('site', false) ;
        $site_structure = & HTML_QuickForm::createElement('text', 'site', INS_SITE_STRUCTURE) ;
        $this->insertElementBefore($site_structure, 'pays') ;
        $this->addElement('hidden', 'est_structure', 1) ;
        $sigle_structure = & HTML_QuickForm::createElement('text', 'sigle_structure', INS_SIGLE_STRUCTURE) ;
        $this->insertElementBefore($sigle_structure, 'nom') ;
        $this->addRule('sigle_structure', INS_SIGLE_REQUIS, 'required', '', 'client') ;
    }
    /**
     * 
     *
     * @return string
     * @access public
     */
    function toHTML( )
    {
        $res = HTML_QuickForm::toHTML() ;
        return $res ;
    } // end of member function toHTML



}

class ListeDePays extends PEAR{

    var $_db ;
    /** Constructeur
     *  Vérifie l'existance de la table gen_pays_traduction
     *
     *  @param  DB  Un objet PEAR::DB
     * @return
     */
    
    function ListeDePays(&$objetDB) {
        $this->_db = $objetDB ;
        $requete = "show tables" ;
        $resultat = $objetDB->query($requete) ;
        if (DB::isError($resultat)) {
            die ("Echec de la requete : $requete<br />".$resultat->getMessage()) ;
        }
        while ($ligne = $resultat->fetchRow()) {
            if ($ligne[0] == INS_TABLE_PAYS) {
                return ;
            }
        }
        return $this->raiseError('La table gen_pays_traduction n\'est pas présente dans la base de donnée !') ;
    }
    
    /** Renvoie la liste des pays traduite
     *
     *  @param  string  une chaine de type i18n ou une chaine code iso langue (fr_FR ou fr ou FR)
     * @return  un tableau contenant en clé, le code iso du pays, en majuscule et en valeur le nom du pays traduit
     */
    
    function getListePays($i18n) {
        if (strlen($i18n) == 2) {
            $i18n = strtolower($i18n)."-".strtoupper($i18n) ;
        }
        $requete = "select ".INS_CHAMPS_ID_PAYS.", ".INS_CHAMPS_LABEL_PAYS." from ".INS_TABLE_PAYS;
        $resultat = $this->_db->query($requete) ;
        if (DB::isError($resultat)) {
            die ("Echec de la requete : $requete<br />".$resultat->getMessage()) ;
        }
        if ($resultat->numRows() == 0) {
            return $this->raiseError('Le code fourni ne correspond à aucun pays ou n\'est pas dans la table!') ;
        }
        $retour = array() ;
        while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
            $retour[$ligne[INS_CHAMPS_ID_PAYS]] = $ligne[INS_CHAMPS_LABEL_PAYS];
        }
        return $retour ;
    }
}

?>