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 ******************************************************************************/
23 LSsession :: loadLSclass('LSformElement');
26 * Element select d'un formulaire pour LdapSaisie
28 * Cette classe définis les éléments select des formulaires.
29 * Elle étant la classe basic LSformElement.
32 * // *************************************
33 * 'html_options' => array (
34 * selectable_object => array (
35 * 'object_type' => '[Type d'LSobject selectionnable]',
36 * 'display_name_format' => '[LSformat du nom d'affichage des LSobjects]',
37 * 'value_attribute' => '[LSformat de la valeur clé référant à un LSobject donnée]'
40 * // *************************************
42 * @author Benjamin Renard <brenard@easter-eggs.com>
45 class LSformElement_select_object extends LSformElement {
47 var $fieldTemplate = 'LSformElement_select_object_field.tpl';
48 var $template = 'LSformElement_select_object.tpl';
51 * Retourn les infos d'affichage de l'élément
53 * Cette méthode retourne les informations d'affichage de l'élement
57 function getDisplay($refresh=NULL){
58 LSsession :: addCssFile('LSformElement_select_object.css');
60 $this -> values = $this -> getValuesFromSession();
62 $return = $this -> getLabelInfos();
64 if (!$this -> isFreeze()) {
65 LSsession :: addJSconfigParam(
68 'object_type' => $this -> selectableObject,
69 'addBtn' => _('Modify'),
70 'deleteBtns' => _('Delete'),
71 'multiple' => (($this -> params['multiple'])?1:0),
72 'noValueLabel' => _('No set value'),
73 'noResultLabel' => _('No result')
77 LSsession :: addHelpInfos (
78 'LSformElement_select_object',
80 'searchAdd' => _("Fast Add"),
81 'add' => _("Display advanced search and selection panel."),
82 'delete' => _("Delete")
86 LSsession :: addJSscript('LSformElement_select_object_field.js');
87 LSsession :: addJSscript('LSformElement_select_object.js');
88 if (LSsession :: loadLSclass('LSselect')) {
89 LSselect :: loadDependenciesDisplay();
92 $return['html'] = $this -> fetchTemplate(NULL,array('selectableObject' => $this -> selectableObject));
97 * Retourne les valeurs de l'objet à partir de la variable Session
99 function getValuesFromSession() {
100 return $this -> attr_html -> getValuesFromSession();
104 * Défini le type d'objet sélectionnable
106 * @param[in] $object string Le type d'object
110 function setSelectableObject($object) {
111 $this -> selectableObject = $object;
115 * Exporte les valeurs de l'élément
117 * @retval Array Les valeurs de l'élement
119 function exportValues(){
120 $values = $this -> attr_html -> getValuesFromFormValues($this -> values);
125 * Définis la valeur de l'élément à partir des données
126 * envoyées en POST du formulaire
128 * Cette méthode définis la valeur de l'élément à partir des données
129 * envoyées en POST du formulaire.
131 * @author Benjamin Renard <brenard@easter-eggs.com>
133 * @param[in] [<b>required</b>] string or array La futur valeur de l'élément
135 * @retval boolean Retourne True
137 function setValueFromPostData($data) {
138 LSformElement::setValueFromPostData($data);
139 $this -> values = $this -> attr_html -> refreshForm($this -> values,true);
144 * Recherche les objets sélectionnables à partir du pattern fournis
146 * @param[in] $pattern Pattern de recherche
148 * @retval array(dn -> displayName) Les objets trouvés
150 function searchAdd ($pattern) {
151 if (is_array($this -> params['html_options']['selectable_object'])) {
152 if (LSsession :: loadLSobject($this -> params['html_options']['selectable_object']['object_type'])) {
153 $obj = new $this -> params['html_options']['selectable_object']['object_type']();
154 $ret = $obj -> getSelectArray($pattern,NULL,$this -> params['html_options']['selectable_object']['display_name_format']);
155 if (is_array($ret)) {
163 public static function ajax_refresh(&$data) {
164 if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) ) {
165 if (LSsession ::loadLSobject($_REQUEST['objecttype'])) {
166 $object = new $_REQUEST['objecttype']();
167 $form = $object -> getForm($_REQUEST['idform']);
168 $field=$form -> getElement($_REQUEST['attribute']);
169 $val = $field -> getValuesFromSession();
179 public static function ajax_searchAdd(&$data) {
180 if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['pattern'])) && (isset($_REQUEST['idform'])) ) {
181 if (LSsession ::loadLSobject($_REQUEST['objecttype'])) {
182 $object = new $_REQUEST['objecttype']();
183 $form = $object -> getForm($_REQUEST['idform']);
184 $field=$form -> getElement($_REQUEST['attribute']);
185 $data['objects'] = $field -> searchAdd($_REQUEST['pattern']);