New file |
0,0 → 1,224 |
<?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.1 2005-09-22 14:02:49 ddelon 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.1 $ $Date: 2005-09-22 14:02:49 $ |
// +------------------------------------------------------------------------------------------------------+ |
*/ |
|
// +------------------------------------------------------------------------------------------------------+ |
// | ENTETE du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
|
require_once 'HTML/QuickForm.php' ; |
|
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 ; |
} |
} |
|
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) |
{ |
$squelette =& $this->defaultRenderer(); |
$squelette->setFormTemplate("\n".'<form {attributes}>'."\n".'{content}'."\n".'</form>'."\n"); |
$squelette->setElementTemplate( '<li class="liste_inscription">'."\n".'{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}{element}</span>', 'groupe_mot_de_passe') ; |
$squelette->setGroupElementTemplate('<span class="groupe_formulaire">{label}{element}</span>', 'groupe_cp_ville') ; |
$squelette->setGroupElementTemplate('<span class="groupe_formulaire">{label}{element}</span>', 'groupe_nom') ; |
$squelette->setRequiredNoteTemplate("\n".'<p>'."\n".'<span class="symbole_obligatoire">*</span> {requiredNote}'."\n".'</p>'."\n"); |
|
$fieldset_debut = '<br /><fieldset>'."\n". |
'<h2>'.INS_AJOUT_MEMBRE.'</h2>'."\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) ; |
$this->addElement('password', 'mot_de_passe_repete', INS_REPETE_MOT_DE_PASSE) ; |
$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') ; |
$this->addElement('text', 'nom', INS_NOM) ; |
$this->addRule('nom', INS_NOM_REQUIS, 'required', '', 'client') ; |
$this->addElement('text', 'prenom', INS_PRENOM) ; |
$this->addRule('prenom', INS_PRENOM_REQUIS, 'required', '', 'client') ; |
$this->addElement('text', 'adresse_1', INS_ADRESSE_1) ; |
$this->addElement('text', 'adresse_2', INS_ADRESSE_2) ; |
$this->addElement('text', 'cp', INS_CODE_POSTAL) ; |
$this->addRule('cp', INS_CODE_POSTAL_REQUIS, 'required', '', 'client') ; |
$this->addElement('text', 'ville', INS_VILLE) ; |
// L'élément pays est construit à partir du tableau liste_pays |
$liste_pays = new ListeDePays($GLOBALS['ins_db']) ; |
$this->addElement('select', 'pays', INS_PAYS, $liste_pays->getListePays(INS_LANGUE_DEFAUT)) ; |
$this->addElement('text', 'telephone', INS_TELEPHONE) ; |
$this->addElement('text', 'fax', INS_FAX) ; |
$this->addElement('text', 'site', INS_SITE_INTERNET) ; |
$this->addElement('checkbox', 'lettre',INS_LETTRE) ; |
$this->addElement('checkbox', 'visible',INS_VISIBLE) ; |
$this->addElement('hidden', 'est_structure', 0) ; |
$defauts=array ('lettre'=>1,'pays'=>'FR'); |
|
$this->setDefaults($defauts); |
|
// 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, ' '); |
$this->setRequiredNote(INS_CHAMPS_REQUIS) ; |
$fieldset_fin = '</ul></fieldset>'."\n"; |
$this->addElement('html', $fieldset_fin); |
} // end of member function construitFormulaire |
|
/** Modifie le formulaire pour l'adapter au cas des structures |
* |
* |
* @return void |
* @access public |
*/ |
function formulaireStructure() |
{ |
$this->removeElement('nom', false) ; |
$this->removeElement('prenom') ; |
$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->addRule('nom', INS_NOM_REQUIS, 'required', '', 'client') ; |
$sigle_structure = & HTML_QuickForm::createElement('text', 'sigle_structure', INS_SIGLE_STRUCTURE) ; |
$this->insertElementBefore($sigle_structure, 'email') ; |
$this->addRule('sigle_structure', INS_SIGLE_REQUIS, 'required', '', 'client') ; |
$num_agrement = & HTML_QuickForm::createElement('text', 'num_agrement', INS_NUM_AGREMENT) ; |
$this->insertElementBefore($num_agrement, 'email') ; |
$this->removeElement('site', false) ; |
$site_structure = & HTML_QuickForm::createElement('text', 'site', INS_SITE_STRUCTURE) ; |
$this->insertElementBefore($site_structure, 'lettre') ; |
$this->removeElement('est_structure', false) ; |
$this->addElement('hidden', 'est_structure', 1) ; |
$this->addElement('hidden', 'form_structure', 1) ; |
|
} |
/** |
* |
* |
* @return string |
* @access public |
*/ |
function toHTML( ) |
{ |
$res = HTML_QuickForm::toHTML() ; |
return $res ; |
} // end of member function toHTML |
} |
|
?> |