2 /*******************************************************************************
3 * Copyright (C) 2007 Easter-eggs
4 * http://ldapsaisie.labs.libre-entreprise.org
6 * Author: See AUTHORS file in top-level directory.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ******************************************************************************/
24 * Type d'attribut HTML select_list
26 * 'html_options' => array (
27 * 'possible_values' => array (
28 * '[LSformat de la valeur clé]' => '[LSformat du nom d'affichage]',
30 * 'OTHER_OBJECT' => array (
31 * 'object_type' => '[Type d'LSobject]',
32 * 'display_name_format' => '[LSformat du nom d'affichage des LSobjects]',
33 * 'value_attribute' => '[Nom de l'attribut clé]',
34 * 'filter' => '[Filtre de recherche des LSobject]',
35 * 'scope' => '[Scope de la recherche]',
36 * 'basedn' => '[Basedn de la recherche]'
41 * @author Benjamin Renard <brenard@easter-eggs.com>
43 class LSattr_html_select_list extends LSattr_html{
46 * Ajoute l'attribut au formualaire passer en paramètre
48 * @param[in] &$form LSform Le formulaire
49 * @param[in] $idForm L'identifiant du formulaire
50 * @param[in] $data Valeur du champs du formulaire
52 * @retval LSformElement L'element du formulaire ajouté
54 function addToForm (&$form,$idForm,$data=NULL) {
55 $possible_values=$this -> getPossibleValues();
56 $this -> config['text_possible_values'] = $possible_values;
57 $element=$form -> addElement('select', $this -> name, $this -> config['label'],$this -> config, $this);
59 LSerror :: addErrorCode('LSform_06',$this -> name);
63 $element -> setValue($data);
66 // Mise en place de la regle de verification des donnees
67 $regex_check_data='/';
68 foreach ($possible_values as $val => $text) {
69 if($regex_check_data=='/')
70 $regex_check_data.='^'.preg_quote($val,'/').'$';
72 $regex_check_data.='|^'.preg_quote($val,'/').'$';
74 $regex_check_data.='/';
75 $form -> addRule($this -> name, 'regex', array('msg'=> 'Valeur incorrect','params' => array('regex' => $regex_check_data)) );
76 // On retourne un pointeur vers l'element ajouter
81 * Retourne un tableau des valeurs possibles de la liste
83 * @author Benjamin Renard <brenard@easter-eggs.com>
85 * @retval array Tableau associatif des valeurs possible de la liste avec en clé
86 * la valeur des balises option et en valeur ce qui sera affiché.
88 function getPossibleValues() {
90 if (is_array($this -> config['html_options']['possible_values'])) {
91 foreach($this -> config['html_options']['possible_values'] as $val_name => $val) {
92 if($val_name=='OTHER_OBJECT') {
93 if ((!isset($val['object_type'])) || (!isset($val['value_attribute']))) {
94 LSerror :: addErrorCode('LSattr_html_select_list_01',$this -> name);
97 if (!LSsession :: loadLSclass('LSsearch')) {
102 'filter' => $val['filter'],
103 'basedn' => $val['basedn'],
104 'scope' => $val['scope'],
105 'displayFormat' => $val['display_name_format'],
110 if ($val['value_attribute']!='dn') {
111 $param['attributes'][] = $val['value_attribute'];
114 $LSsearch = new LSsearch($val['object_type'],'LSattr_html_select_list',$param,true);
116 if(($val['value_attribute']=='dn')||($val['value_attribute']=='%{dn}')) {
117 $retInfos = $LSsearch -> listObjectsName();
120 $list = $LSsearch -> getSearchEntries();
121 foreach($list as $entry) {
122 $key = $entry -> get($val['value_attribute']);
126 $retInfos[$key]=$entry -> displayName;
131 $val_name=$this->attribute->ldapObject->getFData($val_name);
132 $val=$this->attribute->ldapObject->getFData(__($val));
133 $retInfos[$val_name]=$val;
145 LSerror :: defineError('LSattr_html_select_list_01',
146 _("LSattr_html_select_list : Configuration data are missing to generate the select list of the attribute %{attr}.")