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 select d'un formulaire pour LdapSaisie
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Cette classe définis les éléments select des formulaires.
|
|
|
|
* Elle étant la classe basic LSformElement.
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
class LSformElement_select extends LSformElement {
|
|
|
|
|
2008-10-16 15:03:45 +02:00
|
|
|
var $template = 'LSformElement_select.tpl';
|
|
|
|
var $fieldTemplate = 'LSformElement_select.tpl';
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2015-07-25 18:23:06 +02:00
|
|
|
* Return display data of this element
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
2015-07-25 18:23:06 +02:00
|
|
|
* This method return display data of this element
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
2008-02-05 17:11:21 +01:00
|
|
|
* @retval array
|
2007-11-15 19:07:24 +01:00
|
|
|
*/
|
2008-02-05 17:11:21 +01:00
|
|
|
function getDisplay(){
|
2008-02-08 18:39:24 +01:00
|
|
|
$return = $this -> getLabelInfos();
|
2008-10-16 15:03:45 +02:00
|
|
|
$params = array();
|
2008-02-08 18:39:24 +01:00
|
|
|
if (!$this -> isFreeze()) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: addHelpInfos (
|
2008-11-10 04:14:13 +01:00
|
|
|
'LSformElement_select',
|
|
|
|
array(
|
2009-02-14 00:06:58 +01:00
|
|
|
'clear' => _("Reset selection.")
|
2008-11-10 04:14:13 +01:00
|
|
|
)
|
|
|
|
);
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: addJSscript('LSformElement_select.js');
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-10-16 15:03:45 +02:00
|
|
|
$params['possible_values'] = $this -> params['text_possible_values'];
|
2010-11-15 17:33:47 +01:00
|
|
|
$params['unrecognized_value_label_format'] = _("%{value} (unrecognized value)");
|
2008-10-16 15:03:45 +02:00
|
|
|
$return['html'] = $this -> fetchTemplate(NULL,$params);
|
2008-02-08 18:39:24 +01:00
|
|
|
return $return;
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
2015-07-25 18:23:06 +02:00
|
|
|
/**
|
|
|
|
* Check if a value is valid
|
|
|
|
*
|
|
|
|
* This method check if a value is correct, that mean if it's one
|
|
|
|
* of the possible values.
|
|
|
|
*
|
|
|
|
* @param[in] $value The value to check
|
|
|
|
* @param[in] $possible_values (Optional) The possible values
|
|
|
|
*
|
|
|
|
* @retval string or False The value's label or False if this value is incorrect
|
|
|
|
*/
|
|
|
|
public function isValidValue($value,$possible_values=False) {
|
2017-05-31 16:05:25 +02:00
|
|
|
if (!is_array($possible_values)) {
|
2017-06-27 15:12:29 +02:00
|
|
|
if (isset($this) && is_a($this, __CLASS__) && is_array($this -> params['text_possible_values'])) {
|
2017-05-31 16:05:25 +02:00
|
|
|
$possible_values=$this -> params['text_possible_values'];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
2015-07-25 18:23:06 +02:00
|
|
|
|
|
|
|
$ret=False;
|
|
|
|
if (is_array($possible_values) && isset($value)) {
|
|
|
|
foreach($possible_values as $key => $name) {
|
|
|
|
if (is_array($name)) {
|
|
|
|
if (!is_array($name['possible_values'])) continue;
|
|
|
|
foreach($name['possible_values'] as $k => $v) {
|
|
|
|
if ($k==$value) {
|
|
|
|
$ret=$v;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($ret) break;
|
|
|
|
}
|
|
|
|
elseif ($key==$value) {
|
|
|
|
$ret=$name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ($ret) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
|
2015-07-25 18:23:06 +02:00
|
|
|
/**
|
|
|
|
* LSformElement_select_checkIsValidValue template function
|
|
|
|
*
|
|
|
|
* This function permit to check during template processing
|
|
|
|
* if a value is valid. This function get as parameters
|
|
|
|
* (in $params) :
|
|
|
|
* - $value : the value to check
|
|
|
|
* - $possible_values : the possible values of the element
|
|
|
|
* As return, this function assign two template variables :
|
|
|
|
* - LSformElement_select_isValidValue :
|
|
|
|
* Boolean defining if the value is valid
|
|
|
|
* - LSformElement_select_isValidValue_label :
|
|
|
|
* The value's label
|
|
|
|
*
|
|
|
|
* @param[in] $params The template function parameters
|
|
|
|
* @param[in] $template Smarty object
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
**/
|
|
|
|
function LSformElement_select_checkIsValidValue($params,$template) {
|
|
|
|
extract($params);
|
|
|
|
|
|
|
|
$ret = LSformElement_select :: isValidValue($value,$possible_values);
|
|
|
|
|
|
|
|
if ($ret===False) {
|
|
|
|
$label='';
|
|
|
|
$ret=false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$label=$ret;
|
|
|
|
$ret=true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$template -> assign('LSformElement_select_isValidValue',$ret);
|
|
|
|
$template -> assign('LSformElement_select_isValidValue_label',$label);
|
|
|
|
}
|
|
|
|
LStemplate :: registerFunction('LSformElement_select_checkIsValidValue','LSformElement_select_checkIsValidValue');
|