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
|
|
|
|
2010-11-17 19:00:09 +01:00
|
|
|
var $dataEntryForm = NULL;
|
|
|
|
var $dataEntryFormConfig = NULL;
|
|
|
|
|
2010-11-17 15:15:56 +01:00
|
|
|
var $warnings = array();
|
|
|
|
|
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
|
|
|
*/
|
2009-02-17 15:04:35 +01:00
|
|
|
function LSform (&$ldapObject,$idForm,$submit=NULL){
|
2007-03-29 18:10:14 +02:00
|
|
|
$this -> idForm = $idForm;
|
2009-02-17 15:04:35 +01:00
|
|
|
if (!$submit) {
|
|
|
|
$this -> submit = _("Validate");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$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') {
|
2011-05-20 15:56:19 +02:00
|
|
|
self :: loadDependenciesDisplayView($this -> $ldapObject);
|
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');
|
2009-02-20 15:05:22 +01:00
|
|
|
LSsession :: addCssFile('LSform.css');
|
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
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2013-06-17 23:39:22 +02:00
|
|
|
LStemplate :: assign('LSform_action',$_SERVER['PHP_SELF']);
|
2008-02-08 18:39:24 +01:00
|
|
|
$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
|
|
|
);
|
2013-06-17 23:39:22 +02:00
|
|
|
LStemplate :: assign('LSform_object',$LSform_object);
|
2008-11-03 20:25:22 +01:00
|
|
|
|
2009-03-25 18:46:48 +01:00
|
|
|
$layout_config=LSconfig :: get("LSobjects.".$LSform_object['type'].".LSform.layout");
|
2010-11-17 19:00:09 +01:00
|
|
|
|
|
|
|
if (!isset($this -> dataEntryFormConfig['disabledLayout']) || $this -> dataEntryFormConfig['disabledLayout']==false) {
|
|
|
|
if (is_array($layout_config)) {
|
2013-06-17 23:39:22 +02:00
|
|
|
LStemplate :: assign('LSform_layout',$layout_config);
|
|
|
|
LStemplate :: assign('LSform_layout_nofield_label',_('No field.'));
|
2010-11-17 19:00:09 +01:00
|
|
|
}
|
2008-11-03 20:25:22 +01:00
|
|
|
}
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
$fields = array();
|
2010-11-17 19:00:09 +01:00
|
|
|
if (!isset($this -> dataEntryFormConfig['displayedElements']) && !is_array($this -> dataEntryFormConfig['displayedElements'])) {
|
|
|
|
foreach($this -> elements as $element) {
|
|
|
|
$field = array();
|
|
|
|
$field = $element -> getDisplay();
|
|
|
|
if (isset($this -> _elementsErrors[$element -> name])) {
|
|
|
|
$field['errors']= $this -> _elementsErrors[$element -> name];
|
|
|
|
}
|
|
|
|
$fields[$element -> name] = $field;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2010-11-17 19:00:09 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach($this -> dataEntryFormConfig['displayedElements'] as $elementName) {
|
|
|
|
if (!isset($this -> elements[$elementName])) {
|
|
|
|
LSerror :: addErrorCode('LSform_09',$elementName);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$element = $this -> elements[$elementName];
|
2010-11-29 12:36:35 +01:00
|
|
|
if ((isset($this -> dataEntryFormConfig['requiredAllAttributes']) && $this -> dataEntryFormConfig['requiredAllAttributes']) || isset($this -> dataEntryFormConfig['requiredAttributes']) && is_array($this -> dataEntryFormConfig['requiredAttributes']) && in_array($elementName,$this -> dataEntryFormConfig['requiredAttributes'])) {
|
2010-11-29 12:05:20 +01:00
|
|
|
$element -> setRequired();
|
|
|
|
}
|
2010-11-17 19:00:09 +01:00
|
|
|
$field = array();
|
|
|
|
$field = $element -> getDisplay();
|
|
|
|
if (isset($this -> _elementsErrors[$element -> name])) {
|
|
|
|
$field['errors']= $this -> _elementsErrors[$element -> name];
|
|
|
|
}
|
|
|
|
$fields[$element -> name] = $field;
|
|
|
|
}
|
|
|
|
// Add warning for other elements errors
|
|
|
|
foreach(array_keys($this -> elements) as $name) {
|
|
|
|
if (isset($this -> _elementsErrors[$name]) && !isset($fields[$name])) {
|
|
|
|
foreach ($this -> _elementsErrors[$name] as $error) {
|
|
|
|
$this -> addWarning("$name : $error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$LSform_header .= "\t<input type='hidden' name='LSform_dataEntryForm' value='".$this -> dataEntryForm."'/>\n";
|
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";
|
|
|
|
}
|
2013-06-17 23:39:22 +02:00
|
|
|
LStemplate :: assign('LSform_header',$LSform_header);
|
2008-02-26 18:40:05 +01:00
|
|
|
|
2013-06-17 23:39:22 +02:00
|
|
|
LStemplate :: assign('LSform_fields',$fields);
|
2010-11-17 14:44:52 +01:00
|
|
|
|
|
|
|
$JSconfig = array (
|
|
|
|
'ajaxSubmit' => ((isset($this -> config['LSform']['ajaxSubmit']))?$this -> config['LSform']['ajaxSubmit']:1)
|
|
|
|
);
|
|
|
|
|
2010-11-17 15:15:56 +01:00
|
|
|
if (!empty($this -> warnings)) {
|
|
|
|
$JSconfig['warnings']=$this -> warnings;
|
|
|
|
}
|
|
|
|
|
2010-11-17 14:44:52 +01:00
|
|
|
LSsession :: addJSconfigParam('LSform_'.$this -> idForm,$JSconfig);
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
if($this -> can_validate) {
|
2013-06-17 23:39:22 +02:00
|
|
|
LStemplate :: assign('LSform_submittxt',$this -> submit);
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
|
2009-02-20 15:05:22 +01:00
|
|
|
/*
|
|
|
|
* Méthode chargeant les dépendances d'affichage d'une LSview
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
*/
|
2011-05-20 15:56:19 +02:00
|
|
|
public static function loadDependenciesDisplayView($ldapObject=false) {
|
2009-02-20 15:05:22 +01:00
|
|
|
LSsession :: addCssFile('LSform.css');
|
|
|
|
LSsession :: addJSscript('LSform.js');
|
2011-05-20 15:56:19 +02:00
|
|
|
$customActionLabels = array ();
|
|
|
|
if (is_a($ldapObject,'LSldapObject')) {
|
|
|
|
$objectname=$ldapObject -> getDisplayName();
|
|
|
|
$customActionsConfig = LSconfig :: get('LSobjects.'.$ldapObject->type_name.'.customActions');
|
|
|
|
if (is_array($customActionsConfig)) {
|
|
|
|
foreach($customActionsConfig as $name => $config) {
|
|
|
|
if (isset($config['question_format'])) {
|
|
|
|
$customActionLabels['custom_action_'.$name.'_confirm_text'] = getFData(__($config['question_format']),$objectname);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$customActionLabels['custom_action_'.$name.'_confirm_text'] = getFData(
|
|
|
|
_('Do you really want to execute custom action %{customAction} on %{objectname} ?'),
|
|
|
|
array(
|
|
|
|
'objectname' => $objectname,
|
|
|
|
'customAction' => $name
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LSsession :: addJSconfigParam('LSview_labels', array_merge(array(
|
2009-02-20 15:05:22 +01:00
|
|
|
'delete_confirm_text' => _("Do you really want to delete"),
|
|
|
|
'delete_confirm_title' => _("Caution"),
|
|
|
|
'delete_confirm_validate' => _("Delete")
|
2011-05-20 15:56:19 +02:00
|
|
|
),$customActionLabels));
|
2009-02-20 15:05:22 +01:00
|
|
|
if (LSsession :: loadLSclass('LSconfirmBox')) {
|
|
|
|
LSconfirmBox :: loadDependenciesDisplay();
|
|
|
|
}
|
|
|
|
LSsession :: addJSscript('LSview.js');
|
|
|
|
}
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
/**
|
|
|
|
* Affiche la vue
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
*/
|
|
|
|
function displayView(){
|
2011-05-20 15:56:19 +02:00
|
|
|
self :: loadDependenciesDisplayView($this -> ldapObject);
|
2009-02-17 14:18:36 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
$LSform_object = array(
|
|
|
|
'type' => $this -> ldapObject -> getType(),
|
|
|
|
'dn' => $this -> ldapObject -> getDn()
|
|
|
|
);
|
2013-06-17 23:39:22 +02:00
|
|
|
LStemplate :: assign('LSform_object',$LSform_object);
|
2008-02-08 18:39:24 +01:00
|
|
|
$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
|
|
|
}
|
2013-06-17 23:39:22 +02:00
|
|
|
LStemplate :: assign('LSform_fields',$fields);
|
2008-11-03 20:25:22 +01:00
|
|
|
|
2009-03-25 18:46:48 +01:00
|
|
|
$layout_config=LSconfig :: get("LSobjects.".$LSform_object['type'].".LSform.layout");
|
|
|
|
if (is_array($layout_config)) {
|
2013-06-17 23:39:22 +02:00
|
|
|
LStemplate :: assign('LSform_layout',$layout_config);
|
|
|
|
LStemplate :: 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;
|
|
|
|
}
|
2012-09-03 10:22:18 +02:00
|
|
|
if (!isset($this -> _rules[$element]) || !is_array($this -> _rules[$element]))
|
2008-02-08 18:39:24 +01:00
|
|
|
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() {
|
2010-11-17 19:00:09 +01:00
|
|
|
if (is_null($this -> dataEntryForm)) {
|
|
|
|
foreach($this -> elements as $element_name => $element) {
|
|
|
|
if( !($element -> getPostData($this -> _postData)) ) {
|
|
|
|
LSerror :: addErrorCode('LSform_02',$element_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$elementsList = $this -> dataEntryFormConfig['displayedElements'];
|
|
|
|
if (isset($this -> dataEntryFormConfig['defaultValues']) && is_array($this -> dataEntryFormConfig['defaultValues'])) {
|
|
|
|
$this -> setPostData($this -> dataEntryFormConfig['defaultValues']);
|
|
|
|
$elementsList = array_merge($elementsList,array_keys($this -> dataEntryFormConfig['defaultValues']));
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($elementsList as $elementName) {
|
|
|
|
if (!isset($this -> elements[$elementName])) {
|
|
|
|
LSerror :: addErrorCode('LSform_09',$elementName);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$element = $this -> elements[$elementName];
|
2010-11-29 12:36:35 +01:00
|
|
|
if ((isset($this -> dataEntryFormConfig['requiredAllAttributes']) && $this -> dataEntryFormConfig['requiredAllAttributes']) || isset($this -> dataEntryFormConfig['requiredAttributes']) && is_array($this -> dataEntryFormConfig['requiredAttributes']) && in_array($elementName,$this -> dataEntryFormConfig['requiredAttributes'])) {
|
2010-11-29 12:05:20 +01:00
|
|
|
$element -> setRequired();
|
|
|
|
}
|
2010-11-17 19:00:09 +01:00
|
|
|
if( !($element -> getPostData($this -> _postData)) ) {
|
|
|
|
LSerror :: addErrorCode('LSform_02',$element_name);
|
|
|
|
return;
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2010-11-17 19:00:09 +01:00
|
|
|
/**
|
|
|
|
* Applique un masque de saisie au formulaire
|
|
|
|
*
|
|
|
|
* @param[in] $dataEntryForm string Le nom du masque de saisie
|
|
|
|
*
|
|
|
|
* @retval boolean True si le masque de saisie a été appliqué, False sinon
|
|
|
|
**/
|
|
|
|
function applyDataEntryForm($dataEntryForm) {
|
|
|
|
$dataEntryForm=(string)$dataEntryForm;
|
|
|
|
$objType = $this -> ldapObject -> getType();
|
|
|
|
$config=LSconfig :: get("LSobjects.".$objType.".LSform.dataEntryForm.".$dataEntryForm);
|
|
|
|
if (is_array($config)) {
|
|
|
|
if (!is_array($config['displayedElements'])) {
|
|
|
|
LSerror :: addErrorCode('LSform_08',$dataEntryForm);
|
|
|
|
}
|
|
|
|
$this -> dataEntryForm = $dataEntryForm;
|
|
|
|
$this -> dataEntryFormConfig = $config;
|
2013-03-18 12:57:39 +01:00
|
|
|
|
|
|
|
// Set default value of displayed elements
|
|
|
|
if(is_array($config['defaultValues'])) {
|
|
|
|
foreach($config['displayedElements'] as $el) {
|
|
|
|
if (isset($config['defaultValues'][$el])) {
|
|
|
|
if (isset($this -> elements[$el])) {
|
|
|
|
$this -> elements[$el] -> setValueFromPostData($config['defaultValues'][$el]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-17 19:00:09 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
LSerror :: addErrorCode('LSform_07',$dataEntryForm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Liste les dataEntryForm disponible pour un type d'LSldapObject
|
|
|
|
*
|
|
|
|
* @param[in] $type string Le type d'LSldapObject
|
|
|
|
*
|
|
|
|
* @retval array Tableau contenant la liste de dataEntryForm disponible pour ce type d'LSldapObject (nom => label)
|
|
|
|
**/
|
|
|
|
public static function listAvailableDataEntryForm($type) {
|
|
|
|
$retval=array();
|
|
|
|
if (LSsession ::loadLSobject($type)) {
|
|
|
|
$config=LSconfig :: get("LSobjects.".$type.".LSform.dataEntryForm");
|
|
|
|
if (is_array($config)) {
|
|
|
|
foreach($config as $name => $conf) {
|
|
|
|
if (isset($conf['label'])) {
|
|
|
|
$retval[$name]=__($conf['label']);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$retval[$name]=__($name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $retval;
|
|
|
|
}
|
|
|
|
|
2010-11-17 15:15:56 +01:00
|
|
|
/**
|
|
|
|
* Ajoute un avertissement au sujet du formulaire
|
|
|
|
*
|
|
|
|
* @param[in] $txt string Le texte de l'avertissement
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
**/
|
|
|
|
function addWarning($txt) {
|
|
|
|
$this -> warnings[]=$txt;
|
|
|
|
}
|
2009-02-20 15:05:22 +01:00
|
|
|
|
2010-11-17 14:47:06 +01:00
|
|
|
/**
|
|
|
|
* Méthode Ajax permetant de retourner le code HTML d'un élément du formulaire vide
|
|
|
|
*
|
|
|
|
* @param[in] &$data Variable de retour
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
**/
|
2009-02-20 15:05:22 +01:00
|
|
|
public static function ajax_onAddFieldBtnClick(&$data) {
|
|
|
|
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) && (isset($_REQUEST['fieldId'])) ) {
|
|
|
|
if (LSsession ::loadLSobject($_REQUEST['objecttype'])) {
|
|
|
|
$object = new $_REQUEST['objecttype']();
|
|
|
|
$object -> loadData($_REQUEST['objectdn']);
|
|
|
|
$form = $object -> getForm($_REQUEST['idform']);
|
|
|
|
$emptyField=$form -> getEmptyField($_REQUEST['attribute']);
|
|
|
|
if ( $emptyField ) {
|
|
|
|
$data = array(
|
|
|
|
'html' => $form -> getEmptyField($_REQUEST['attribute']),
|
|
|
|
'fieldId' => $_REQUEST['fieldId'],
|
|
|
|
'fieldtype' => get_class($form -> getElement($_REQUEST['attribute']))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
);
|
2010-11-17 19:00:09 +01:00
|
|
|
LSerror :: defineError('LSform_07',
|
|
|
|
_("LSform : The data entry form %{name} doesn't exist.")
|
|
|
|
);
|
|
|
|
LSerror :: defineError('LSform_08',
|
|
|
|
_("LSform : The data entry form %{name} is not correctly configured.")
|
|
|
|
);
|
|
|
|
LSerror :: defineError('LSform_09',
|
|
|
|
_("LSform : The element %{name}, listed as displayed in data entry form configuration, doesn't exist.")
|
|
|
|
);
|
2007-11-15 19:07:24 +01:00
|
|
|
?>
|