2007-11-15 19:07:24 +01: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.
|
|
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Element d'un formulaire pour LdapSaisie
|
|
|
|
|
*
|
|
|
|
|
* Cette classe g<EFBFBD>re les <EFBFBD>l<EFBFBD>ments des formulaires.
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class LSformElement {
|
|
|
|
|
|
|
|
|
|
var $name;
|
|
|
|
|
var $label;
|
|
|
|
|
var $params;
|
|
|
|
|
var $values = array();
|
|
|
|
|
var $_required = false;
|
|
|
|
|
var $_freeze = false;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructeur
|
|
|
|
|
*
|
|
|
|
|
* Cette methode construit l'objet et d<EFBFBD>finis sa configuration de base.
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @param[in] &$form [<b>required</b>] LSform L'objet LSform parent
|
|
|
|
|
* @param[in] $name [<b>required</b>] string Le nom de r<EFBFBD>f<EFBFBD>rence de l'<EFBFBD>l<EFBFBD>ment
|
|
|
|
|
* @param[in] $label [<b>required</b>] string Le label de l'<EFBFBD>l<EFBFBD>ment
|
|
|
|
|
* @param[in] $params mixed Param<EFBFBD>tres suppl<EFBFBD>mentaires
|
|
|
|
|
*
|
|
|
|
|
* @retval true
|
2008-02-12 18:59:44 +01:00
|
|
|
|
*/
|
|
|
|
|
function LSformElement (&$form, $name, $label, $params){
|
2007-11-15 19:07:24 +01:00
|
|
|
|
$this -> name = $name;
|
2008-02-12 18:59:44 +01:00
|
|
|
|
$this -> label = $label;
|
|
|
|
|
$this -> params = $params;
|
|
|
|
|
$this -> form = $form;
|
|
|
|
|
return true;
|
2007-11-15 19:07:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* D<EFBFBD>finis la valeur de l'<EFBFBD>l<EFBFBD>ment
|
|
|
|
|
*
|
|
|
|
|
* Cette m<EFBFBD>thode d<EFBFBD>finis la valeur de l'<EFBFBD>l<EFBFBD>ment
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @param[in] [<b>required</b>] string or array La futur valeur de l'<EFBFBD>l<EFBFBD>ment
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean Retourne True
|
|
|
|
|
*/
|
|
|
|
|
function setValue($data) {
|
2008-02-12 18:59:44 +01:00
|
|
|
|
if (!is_array($data)) {
|
|
|
|
|
$data=array($data);
|
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
|
$this -> values = $data;
|
|
|
|
|
return true;
|
2007-11-15 19:07:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
|
/**
|
2007-11-15 19:07:24 +01:00
|
|
|
|
* Ajoute une valeur <EFBFBD> l'<EFBFBD>l<EFBFBD>ment
|
|
|
|
|
*
|
|
|
|
|
* Cette m<EFBFBD>thode ajoute une valeur <EFBFBD> l'<EFBFBD>l<EFBFBD>ment
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @param[in] [<b>required</b>] string or array La futur valeur de l'<EFBFBD>l<EFBFBD>ment
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
|
|
|
|
function addValue($data) {
|
2008-02-12 18:59:44 +01:00
|
|
|
|
if (is_array($data)) {
|
|
|
|
|
$this -> values = array_merge($this -> values, $data);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$this -> values[] = $data;
|
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
|
/**
|
|
|
|
|
* Test si l'<EFBFBD>l<EFBFBD>ment est <EFBFBD>ditable
|
|
|
|
|
*
|
|
|
|
|
* Cette m<EFBFBD>thode test si l'<EFBFBD>l<EFBFBD>ment est <EFBFBD>ditable
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean
|
|
|
|
|
*/
|
|
|
|
|
function isFreeze(){
|
|
|
|
|
return $this -> _freeze;
|
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Freeze l'<EFBFBD>l<EFBFBD>ment
|
|
|
|
|
*
|
|
|
|
|
* Rend l'<EFBFBD>l<EFBFBD>ment non-editable
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
|
|
|
|
function freeze() {
|
2008-02-12 18:59:44 +01:00
|
|
|
|
$this -> _freeze = true;
|
2007-11-15 19:07:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* D<EFBFBD>fini la propri<EFBFBD>t<EFBFBD> required de l'<EFBFBD>l<EFBFBD>ment.
|
|
|
|
|
*
|
|
|
|
|
* param[in] $isRequired boolean true si l'<EFBFBD>l<EFBFBD>ment est requis, false sinon
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
|
|
|
|
function setRequired($isRequired=true) {
|
2008-02-12 18:59:44 +01:00
|
|
|
|
$this -> _required = $isRequired;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Test si l'<EFBFBD>l<EFBFBD>ment est requis
|
|
|
|
|
*
|
|
|
|
|
* Cette m<EFBFBD>thode test si l'<EFBFBD>l<EFBFBD>ment est requis
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean
|
|
|
|
|
*/
|
|
|
|
|
function isRequired(){
|
|
|
|
|
return $this -> _required;
|
2007-11-15 19:07:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
|
/**
|
|
|
|
|
* Affiche le label de l'<EFBFBD>lement
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
|
|
|
|
function displayLabel() {
|
|
|
|
|
if ($this -> isRequired()) {
|
|
|
|
|
$required=" <span class='required_elements'>*</span>";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$required="";
|
|
|
|
|
}
|
|
|
|
|
echo "\t\t<td>".$this -> getLabel()."$required</td>\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne le label de l'<EFBFBD>lement
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
|
|
|
|
function getLabelInfos() {
|
|
|
|
|
if ($this -> isRequired()) {
|
|
|
|
|
$return['required']=true;
|
|
|
|
|
}
|
|
|
|
|
$return['label'] = $this -> getLabel();
|
|
|
|
|
return $return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Recup<EFBFBD>re la valeur de l'<EFBFBD>lement pass<EFBFBD>e en POST
|
|
|
|
|
*
|
|
|
|
|
* Cette m<EFBFBD>thode v<EFBFBD>rifie la pr<EFBFBD>sence en POST de la valeur de l'<EFBFBD>l<EFBFBD>ment et la r<EFBFBD>cup<EFBFBD>re
|
|
|
|
|
* pour la mettre dans le tableau passer en param<EFBFBD>tre avec en clef le nom de l'<EFBFBD>l<EFBFBD>ment
|
|
|
|
|
*
|
|
|
|
|
* @param[] array Pointeur sur le tableau qui recup<EFBFBD>rera la valeur.
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean true si la valeur est pr<EFBFBD>sente en POST, false sinon
|
|
|
|
|
*/
|
|
|
|
|
function getPostData(&$return) {
|
|
|
|
|
if($this -> isFreeze()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (isset($_POST[$this -> name])) {
|
|
|
|
|
if(!is_array($_POST[$this -> name])) {
|
|
|
|
|
$_POST[$this -> name] = array($_POST[$this -> name]);
|
|
|
|
|
}
|
|
|
|
|
foreach($_POST[$this -> name] as $key => $val) {
|
|
|
|
|
$return[$this -> name][$key] = $val;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$return[$this -> name] = array();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne le label de l'<EFBFBD>lement
|
|
|
|
|
*
|
|
|
|
|
* Retourne $this -> label, ou $this -> params['label'], ou $this -> name
|
|
|
|
|
*
|
|
|
|
|
* @retval string Le label de l'<EFBFBD>l<EFBFBD>ment
|
|
|
|
|
*/
|
|
|
|
|
function getLabel() {
|
|
|
|
|
if ($this -> label != "") {
|
|
|
|
|
return $this -> label;
|
|
|
|
|
}
|
|
|
|
|
else if ($this -> params['label']) {
|
|
|
|
|
return $this -> params['label'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return $this -> name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne l'HTML pour les boutons d'ajout et de suppression de champs du formulaire LSform
|
|
|
|
|
*
|
|
|
|
|
* @retval string Le code HTML des boutons
|
|
|
|
|
*/
|
|
|
|
|
function getMultipleData() {
|
|
|
|
|
if ($this -> params['multiple'] == true ) {
|
|
|
|
|
return "<img src='templates/images/add.png' id='LSform_add_field_btn_".$this -> name."_".rand()."' class='LSform-add-field-btn' alt='"._('Ajouter')."'/><img src='templates/images/remove.png' class='LSform-remove-field-btn' alt='"._('Supprimer')."'/>";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|