2007-03-29 18:10:14 +02:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
|
|
|
* http://ldapsaisie.labs.libre-entreprise.org
|
|
|
|
*
|
|
|
|
* Author: See AUTHORS file in top-level directory.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formulaire pour LdapSaisie
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Cette classe gère les formulaires
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
class LSform {
|
2007-11-15 19:07:24 +01:00
|
|
|
var $ldapObject;
|
2007-03-29 18:10:14 +02:00
|
|
|
var $idForm;
|
2007-11-15 19:07:24 +01:00
|
|
|
var $can_validate = true;
|
|
|
|
var $elements = array();
|
|
|
|
var $_rules = array();
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
var $_postData = array();
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
var $_elementsErrors = array();
|
|
|
|
var $_isValidate = false;
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
var $_notUpdate = array();
|
2008-02-26 18:40:05 +01:00
|
|
|
|
|
|
|
var $maxFileSize = NULL;
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
/**
|
2007-03-29 18:10:14 +02:00
|
|
|
* Constructeur
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Cette methode construit l'objet et définis la configuration.
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $idForm [<b>required</b>] string L'identifiant du formulaire
|
|
|
|
* @param[in] $submit string La valeur du bouton submit
|
|
|
|
*
|
|
|
|
* @retval void
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
2007-11-15 19:07:24 +01:00
|
|
|
function LSform (&$ldapObject,$idForm,$submit="Envoyer"){
|
2007-03-29 18:10:14 +02:00
|
|
|
$this -> idForm = $idForm;
|
|
|
|
$this -> submit = $submit;
|
2008-02-08 18:39:24 +01:00
|
|
|
$this -> ldapObject = $ldapObject;
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: loadLSclass('LSformElement');
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Affiche le formualaire
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval void
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
function display(){
|
2008-02-08 18:39:24 +01:00
|
|
|
if ($this -> idForm == 'view') {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: addJSscript('LSview.js');
|
|
|
|
LSsession :: addJSscript('LSform.js');
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: addJSscript('LSformElement_field.js');
|
|
|
|
LSsession :: addJSscript('LSformElement.js');
|
|
|
|
LSsession :: addJSscript('LSform.js');
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-11-14 18:37:37 +01:00
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: addHelpInfos(
|
2008-11-14 18:37:37 +01:00
|
|
|
'LSform',
|
|
|
|
array(
|
2009-02-12 13:38:56 +01:00
|
|
|
'addFieldBtn' => _('Add a field to add another values.'),
|
|
|
|
'removeFieldBtn' => _('Delete this field.')
|
2008-11-14 18:37:37 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: addCssFile('LSform.css');
|
2008-02-08 18:39:24 +01:00
|
|
|
$GLOBALS['Smarty'] -> assign('LSform_action',$_SERVER['PHP_SELF']);
|
|
|
|
$LSform_header = "\t<input type='hidden' name='validate' value='LSform'/>\n
|
|
|
|
\t<input type='hidden' name='idForm' id='LSform_idform' value='".$this -> idForm."'/>\n
|
|
|
|
\t<input type='hidden' name='LSform_objecttype' id='LSform_objecttype' value='".$this -> ldapObject -> getType()."'/>\n
|
2008-02-26 18:40:05 +01:00
|
|
|
\t<input type='hidden' name='LSform_objectdn' id='LSform_objectdn' value='".$this -> ldapObject -> getValue('dn')."'/>\n";
|
|
|
|
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
$LSform_object = array(
|
|
|
|
'type' => $this -> ldapObject -> getType(),
|
2008-02-12 18:59:44 +01:00
|
|
|
'dn' => $this -> ldapObject -> getValue('dn')
|
2008-02-08 18:39:24 +01:00
|
|
|
);
|
|
|
|
$GLOBALS['Smarty'] -> assign('LSform_object',$LSform_object);
|
2008-11-03 20:25:22 +01:00
|
|
|
|
|
|
|
if (is_array($GLOBALS['LSobjects'][$LSform_object['type']]['LSform']['layout'])) {
|
|
|
|
$GLOBALS['Smarty'] -> assign('LSform_layout',$GLOBALS['LSobjects'][$LSform_object['type']]['LSform']['layout']);
|
|
|
|
$GLOBALS['Smarty'] -> assign('LSform_layout_nofield_label',_('Aucun champ.'));
|
|
|
|
}
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
$fields = array();
|
|
|
|
foreach($this -> elements as $element) {
|
|
|
|
$field = array();
|
|
|
|
$field = $element -> getDisplay();
|
|
|
|
if (isset($this -> _elementsErrors[$element -> name])) {
|
|
|
|
$field['errors']= $this -> _elementsErrors[$element -> name];
|
|
|
|
}
|
2008-11-03 20:25:22 +01:00
|
|
|
$fields[$element -> name] = $field;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
|
|
|
|
if ($this -> maxFileSize) {
|
|
|
|
$LSform_header.="\t<input type='hidden' name='MAX_FILE_SIZE' value='".$this -> maxFileSize."'/>\n";
|
|
|
|
}
|
|
|
|
$GLOBALS['Smarty'] -> assign('LSform_header',$LSform_header);
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
$GLOBALS['Smarty'] -> assign('LSform_fields',$fields);
|
|
|
|
if($this -> can_validate) {
|
|
|
|
$GLOBALS['Smarty'] -> assign('LSform_submittxt',$this -> submit);
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
/**
|
|
|
|
* Affiche la vue
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
*/
|
|
|
|
function displayView(){
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: addCssFile('LSform.css');
|
|
|
|
LSsession :: addJSscript('LSform.js');
|
2009-02-17 09:41:21 +01:00
|
|
|
LSsession :: addJSconfigParam('LSview_delete_label',_("Do you really want to delete"));
|
2008-02-08 18:39:24 +01:00
|
|
|
$LSform_object = array(
|
|
|
|
'type' => $this -> ldapObject -> getType(),
|
|
|
|
'dn' => $this -> ldapObject -> getDn()
|
|
|
|
);
|
|
|
|
$GLOBALS['Smarty'] -> assign('LSform_object',$LSform_object);
|
|
|
|
$fields = array();
|
|
|
|
foreach($this -> elements as $element) {
|
|
|
|
$field = $element -> getDisplay();
|
2008-11-03 20:25:22 +01:00
|
|
|
$fields[$element -> name] = $field;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
$GLOBALS['Smarty'] -> assign('LSform_fields',$fields);
|
2008-11-03 20:25:22 +01:00
|
|
|
|
|
|
|
if (is_array($GLOBALS['LSobjects'][$LSform_object['type']]['LSform']['layout'])) {
|
|
|
|
$GLOBALS['Smarty'] -> assign('LSform_layout',$GLOBALS['LSobjects'][$LSform_object['type']]['LSform']['layout']);
|
2009-02-12 13:38:56 +01:00
|
|
|
$GLOBALS['Smarty'] -> assign('LSform_layout_nofield_label',_('No field.'));
|
2008-11-03 20:25:22 +01:00
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Défini l'erreur sur un champ
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $attr [<b>required</b>] string Le nom du champ
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] $msg Le format du message d'erreur à afficher (pouvant comporter
|
|
|
|
* des valeurs %{[n'importe quoi]} qui seront remplacé par le label
|
|
|
|
* du champs concerné.
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @retval void
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
function setElementError($attr,$msg=NULL) {
|
|
|
|
if($msg!='') {
|
|
|
|
$msg_error=getFData($msg,$attr->getLabel());
|
|
|
|
}
|
|
|
|
else {
|
2009-02-12 13:38:56 +01:00
|
|
|
$msg_error=getFData(_("%{label} attribute data is not valid."),$attr->getLabel());
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
$this -> _elementsErrors[$attr->name][]=$msg_error;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
|
2008-02-26 18:40:05 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Savoir si des erreurs son définie pour un élement du formulaire
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] $element [<b>required</b>] string Le nom de l'élement
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
|
|
|
* @retval boolean
|
|
|
|
*/
|
2008-11-10 00:20:34 +01:00
|
|
|
function definedError($element=NULL) {
|
|
|
|
if ($element) {
|
|
|
|
return isset($this -> _elementsErrors[$element]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return !empty($this -> _elementsErrors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne le tableau des erreurs
|
|
|
|
*
|
|
|
|
* @retval Array array(element => array(errors))
|
|
|
|
*/
|
|
|
|
function getErrors() {
|
|
|
|
return $this -> _elementsErrors;
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Verifie si le formulaire a été validé et que les données sont valides.
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si le formulaire a été validé et que les données ont été validées, false sinon
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
function validate(){
|
2007-11-15 19:07:24 +01:00
|
|
|
if(!$this -> can_validate)
|
|
|
|
return;
|
|
|
|
if ($this -> isSubmit()) {
|
2008-02-08 18:39:24 +01:00
|
|
|
if (!$this -> getPostData()) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSform_01');
|
2008-02-08 18:39:24 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-07-18 16:02:46 +02:00
|
|
|
$this -> setValuesFromPostData();
|
2008-04-25 16:09:27 +02:00
|
|
|
//Validation des données ici !!! ///
|
2008-02-08 18:39:24 +01:00
|
|
|
if (!$this -> checkData()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-02-12 13:38:56 +01:00
|
|
|
LSdebug("Data are checked up");
|
2008-02-08 18:39:24 +01:00
|
|
|
$this -> _isValidate = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Vérifier les données du formulaire à partir des régles définis sur les champs
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval boolean true si toutes la saisie est OK, false sinon
|
|
|
|
*/
|
|
|
|
function checkData() {
|
|
|
|
$retval=true;
|
|
|
|
foreach ($this -> _postData as $element => $values) {
|
|
|
|
if(!is_array($values)) {
|
|
|
|
$values=array($values);
|
|
|
|
}
|
|
|
|
if ($this -> elements[$element] -> isRequired()) {
|
|
|
|
if (!$this -> checkRequired($values)) {
|
2009-02-12 13:38:56 +01:00
|
|
|
$this -> setElementError($this -> elements[$element],_("Mandatory field"));
|
2008-02-08 18:39:24 +01:00
|
|
|
$retval=false;
|
|
|
|
}
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
foreach($values as $value) {
|
|
|
|
if (empty($value)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!is_array($this -> _rules[$element]))
|
|
|
|
continue;
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: loadLSclass('LSformRule');
|
2008-02-08 18:39:24 +01:00
|
|
|
foreach($this -> _rules[$element] as $rule) {
|
|
|
|
$ruleType="LSformRule_".$rule['name'];
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: loadLSclass($ruleType);
|
2008-02-26 18:40:05 +01:00
|
|
|
if (! call_user_func(array( $ruleType,'validate') , $value, $rule['options'], $this -> getElement($element))) {
|
2008-02-08 18:39:24 +01:00
|
|
|
$retval=false;
|
|
|
|
$this -> setElementError($this -> elements[$element],$rule['options']['msg']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $retval;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Vérifie si au moins une valeur est présente dans le tableau
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $data array tableau de valeurs
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si au moins une valeur est présente, false sinon
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function checkRequired($data) {
|
|
|
|
foreach($data as $val) {
|
2008-09-26 15:57:11 +02:00
|
|
|
if (!empty($val)||(is_string($val)&&($val=="0")))
|
2008-02-08 18:39:24 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Verifie si la saisie du formulaire est présente en POST
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si la saisie du formulaire est présente en POST, false sinon
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
2007-11-15 19:07:24 +01:00
|
|
|
function isSubmit() {
|
|
|
|
if( (isset($_POST['validate']) && ($_POST['validate']=='LSform')) && (isset($_POST['idForm']) && ($_POST['idForm'] == $this -> idForm)) )
|
|
|
|
return true;
|
2008-02-08 18:39:24 +01:00
|
|
|
return;
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
|
2008-06-05 15:21:18 +02:00
|
|
|
/**
|
|
|
|
* Défini arbitrairement des données en POST
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $data array('attr' => array(values)) Tableau des données du formulaire
|
|
|
|
* @param[in] $consideredAsSubmit Définie si on force le formualaire comme envoyer
|
|
|
|
*
|
|
|
|
* @retval boolean true si les données ont été définies, false sinon
|
|
|
|
*/
|
|
|
|
function setPostData($data,$consideredAsSubmit=false) {
|
|
|
|
if (is_array($data)) {
|
|
|
|
foreach($data as $key => $values) {
|
|
|
|
if (!is_array($values)) {
|
|
|
|
$values = array($values);
|
|
|
|
}
|
|
|
|
$_POST[$key] = $values;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($consideredAsSubmit) {
|
|
|
|
$_POST['validate']='LSform';
|
|
|
|
$_POST['idForm']=$this -> idForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Récupère les valeurs postées dans le formulaire
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si les valeurs ont bien été récupérées, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function getPostData() {
|
|
|
|
foreach($this -> elements as $element_name => $element) {
|
|
|
|
if( !($element -> getPostData($this -> _postData)) ) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSform_02',$element_name);
|
2008-02-08 18:39:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Ajoute un élément au formulaire
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Ajoute un élément au formulaire et définis les informations le concernant.
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] $type string Le type de l'élément
|
|
|
|
* @param[in] $name string Le nom de l'élément
|
|
|
|
* @param[in] $label string Le label de l'élément
|
|
|
|
* @param[in] $param mixed Paramètres supplémentaires
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @retval LSformElement
|
|
|
|
*/
|
2008-05-14 16:43:23 +02:00
|
|
|
function addElement($type,$name,$label,$params=array(),&$attr_html) {
|
2008-02-08 18:39:24 +01:00
|
|
|
$elementType='LSformElement_'.$type;
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: loadLSclass($elementType);
|
2008-02-08 18:39:24 +01:00
|
|
|
if (!class_exists($elementType)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSform_05',array('type' => $type));
|
2008-02-08 18:39:24 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
$element=$this -> elements[$name] = new $elementType($this,$name,$label,$params,$attr_html);
|
2008-02-08 18:39:24 +01:00
|
|
|
if ($element) {
|
|
|
|
return $element;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unset ($this -> elements[$name]);
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSform_06',array('element' => $name));
|
2008-02-08 18:39:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Ajoute une règle sur un élément du formulaire
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] $element string Le nom de l'élément conserné
|
|
|
|
* @param[in] $rule string Le nom de la règle à ajouter
|
2008-02-08 18:39:24 +01:00
|
|
|
* @param[in] $options array Options (facultative)
|
|
|
|
*
|
|
|
|
* @retval boolean
|
|
|
|
*/
|
|
|
|
function addRule($element, $rule, $options=array()) {
|
|
|
|
if ( isset($this ->elements[$element]) ) {
|
|
|
|
if ($this -> isRuleRegistered($rule)) {
|
|
|
|
$this -> _rules[$element][]=array(
|
|
|
|
'name' => $rule,
|
|
|
|
'options' => $options
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_03',array('attr' => $element,'rule'=>$rule));
|
2008-02-08 18:39:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSform_04',array('element' => $element));
|
2008-02-08 18:39:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Définis comme requis un élément
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] $element string Le nom de l'élément conserné
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @retval boolean
|
|
|
|
*/
|
|
|
|
function setRequired($element) {
|
|
|
|
if (isset( $this -> elements[$element] ) )
|
|
|
|
return $this -> elements[$element] -> setRequired();
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Détermine la valider de la règle
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Devra déterminer si la règle passez en paramètre est correcte
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] $element string Le nom de l'élément conserné
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function isRuleRegistered($rule) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: loadLSclass('LSformRule');
|
|
|
|
LSsession :: loadLSclass('LSformRule_'.$rule);
|
2008-02-08 18:39:24 +01:00
|
|
|
return class_exists('LSformRule_'.$rule);
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Retourne les valeurs validés du formulaire
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval mixed Les valeurs validés du formulaire, ou false si elles ne le sont pas
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function exportValues() {
|
|
|
|
if ($this -> _isValidate) {
|
2008-07-18 16:02:46 +02:00
|
|
|
$retval=array();
|
|
|
|
foreach($this -> _postData as $element => $values) {
|
|
|
|
$retval[$element] = $this -> elements[$element] -> exportValues();
|
|
|
|
}
|
|
|
|
return $retval;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Retourn un élement du formulaire
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] string $element Nom de l'élement voulu
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval LSformElement L'élement du formulaire voulu
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function getElement($element) {
|
|
|
|
return $this -> elements[$element];
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Défini les valeurs des élements à partir des valeurs postées
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean True si les valeurs ont été définies, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function setValuesFromPostData() {
|
|
|
|
if (empty($this -> _postData)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
foreach($this -> _postData as $element => $values) {
|
2008-05-14 16:43:23 +02:00
|
|
|
$this -> elements[$element] -> setValueFromPostData($values);
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
/**
|
|
|
|
* Retourne le code HTML d'un champ vide.
|
|
|
|
*
|
|
|
|
* @param[in] string Le nom du champ du formulaire
|
|
|
|
*
|
|
|
|
* @retval string Le code HTML du champ vide.
|
|
|
|
*/
|
|
|
|
function getEmptyField($element) {
|
|
|
|
$element = $this -> getElement($element);
|
|
|
|
if ($element) {
|
|
|
|
return $element -> getEmptyField();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Défini la taille maximal pour les fichiers envoyés par le formualaire
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
|
|
|
* @param[in] $size La taille maximal en octets
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
**/
|
|
|
|
function setMaxFileSize($size) {
|
|
|
|
$this -> maxFileSize = $size;
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
|
2009-01-02 17:00:25 +01:00
|
|
|
/**
|
|
|
|
* Error Codes
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSform_01',
|
|
|
|
_("LSform : Error during the recovery of the values of the form.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSform_02',
|
|
|
|
_("LSform : Error durring the recovery of the value of the field '%{element}'.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
|
|
|
// No longer used
|
2009-01-25 15:37:03 +01:00
|
|
|
/*LSerror :: defineError(203,
|
|
|
|
_("LSform : Data of the field %{element} are not validate.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);*/
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSform_04',
|
|
|
|
_("LSform : The field %{element} doesn't exist.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSform_05',
|
|
|
|
_("LSfom : Field type unknow (%{type}).")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSform_06',
|
|
|
|
_("LSform : Error during the creation of the element '%{element}'.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
|
|
|
// No longer used
|
2009-01-25 15:37:03 +01:00
|
|
|
/*LSerror :: defineError(207,
|
|
|
|
_("LSform : No value has been entered into the field '%{element}'.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);*/
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
?>
|