2008-02-26 18:40:05 +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.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
2009-02-20 15:05:22 +01:00
|
|
|
LSsession :: loadLSclass('LSformElement');
|
2008-02-26 18:40:05 +01:00
|
|
|
|
|
|
|
/**
|
2010-04-26 16:31:57 +02:00
|
|
|
* Select object element for LdapSaisie form
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
2010-04-26 16:31:57 +02:00
|
|
|
* This class define select elements for form. It extends the generic class LSformElement.
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
2010-04-26 16:31:57 +02:00
|
|
|
* HTML options :
|
2009-02-11 17:01:21 +01:00
|
|
|
* // *************************************
|
|
|
|
* 'html_options' => array (
|
|
|
|
* selectable_object => array (
|
2010-04-26 16:31:57 +02:00
|
|
|
* 'object_type' => '[Type of LSobject witch is selectable]',
|
|
|
|
* 'display_name_format' => '[LSformat of the display name of the LSobjects]',
|
|
|
|
* 'value_attribute' => '[The attribute name whitch is used as the key value of one LSobject]'
|
2009-02-11 17:01:21 +01:00
|
|
|
* )
|
|
|
|
* ),
|
|
|
|
* // *************************************
|
|
|
|
*
|
2008-02-26 18:40:05 +01:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
class LSformElement_select_object extends LSformElement {
|
|
|
|
|
2008-10-16 17:35:20 +02:00
|
|
|
var $fieldTemplate = 'LSformElement_select_object_field.tpl';
|
|
|
|
var $template = 'LSformElement_select_object.tpl';
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2010-04-26 16:31:57 +02:00
|
|
|
* Return display informations of the element
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
2010-04-26 16:31:57 +02:00
|
|
|
* This method return the display informations of the element.
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
|
|
|
* @retval array
|
|
|
|
*/
|
|
|
|
function getDisplay($refresh=NULL){
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: addCssFile('LSformElement_select_object.css');
|
2008-02-26 18:40:05 +01:00
|
|
|
if ($refresh) {
|
2008-11-06 11:14:14 +01:00
|
|
|
$this -> values = $this -> getValuesFromSession();
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
|
|
|
$return = $this -> getLabelInfos();
|
2008-10-16 17:35:20 +02:00
|
|
|
|
2008-02-26 18:40:05 +01:00
|
|
|
if (!$this -> isFreeze()) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: addJSconfigParam(
|
2008-10-16 17:35:20 +02:00
|
|
|
$this -> name,
|
|
|
|
array(
|
|
|
|
'object_type' => $this -> selectableObject,
|
2009-02-14 00:06:58 +01:00
|
|
|
'addBtn' => _('Modify'),
|
|
|
|
'deleteBtns' => _('Delete'),
|
2015-01-21 16:35:23 +01:00
|
|
|
'up_label' => _('Move up'),
|
|
|
|
'down_label' => _('Move down'),
|
|
|
|
'ordered' => (($this -> params['html_options']['ordered'])?1:0),
|
2008-11-06 11:14:14 +01:00
|
|
|
'multiple' => (($this -> params['multiple'])?1:0),
|
2013-11-15 18:59:50 +01:00
|
|
|
'filter64' => (($this -> params['html_options']['selectable_object']['filter'])?base64_encode($this -> params['html_options']['selectable_object']['filter']):''),
|
2009-03-12 19:01:31 +01:00
|
|
|
'noValueLabel' => _('No set value'),
|
2009-02-14 00:06:58 +01:00
|
|
|
'noResultLabel' => _('No result')
|
2008-10-16 17:35:20 +02:00
|
|
|
)
|
|
|
|
);
|
2008-11-10 04:23:29 +01:00
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: addHelpInfos (
|
2008-11-10 04:23:29 +01:00
|
|
|
'LSformElement_select_object',
|
|
|
|
array(
|
2009-02-14 00:06:58 +01:00
|
|
|
'searchAdd' => _("Fast Add"),
|
|
|
|
'add' => _("Display advanced search and selection panel."),
|
|
|
|
'delete' => _("Delete")
|
2008-11-10 04:23:29 +01:00
|
|
|
)
|
|
|
|
);
|
2008-10-16 17:35:20 +02:00
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: addJSscript('LSformElement_select_object_field.js');
|
|
|
|
LSsession :: addJSscript('LSformElement_select_object.js');
|
2009-02-20 15:05:22 +01:00
|
|
|
if (LSsession :: loadLSclass('LSselect')) {
|
|
|
|
LSselect :: loadDependenciesDisplay();
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
2014-09-30 16:26:12 +02:00
|
|
|
|
2015-01-21 16:35:23 +01:00
|
|
|
if ((!isset($this -> params['html_options']['sort']) || $this -> params['html_options']['sort']) && !$this -> params['html_options']['ordered']) {
|
2014-09-30 16:26:12 +02:00
|
|
|
uasort($this -> values,array($this,'_sortTwoValues'));
|
|
|
|
}
|
|
|
|
|
2012-10-03 12:23:49 +02:00
|
|
|
$return['html'] = $this -> fetchTemplate(NULL,array(
|
|
|
|
'selectableObject' => $this -> selectableObject,
|
|
|
|
'unrecognizedValues' => $this -> attr_html -> unrecognizedValues,
|
|
|
|
'unrecognizedValueLabel' => _("%{value} (unrecognized value)")
|
|
|
|
));
|
2008-02-26 18:40:05 +01:00
|
|
|
return $return;
|
|
|
|
}
|
2014-09-30 16:26:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function use with uasort to sort two values
|
|
|
|
*
|
|
|
|
* @param[in] $va string One value
|
|
|
|
* @param[in] $vb string One value
|
|
|
|
*
|
|
|
|
* @retval int Value for uasort
|
|
|
|
**/
|
|
|
|
private function _sortTwoValues(&$va,&$vb) {
|
|
|
|
if (isset($this -> params['html_options']['sortDirection']) && $this -> params['html_options']['sortDirection']=='DESC') {
|
|
|
|
$dir=-1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$dir=1;
|
|
|
|
}
|
|
|
|
if ($va == $vb) return 0;
|
|
|
|
$val = strcoll(strtolower($va), strtolower($vb));
|
|
|
|
return $val*$dir;
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
|
2008-11-06 11:14:14 +01:00
|
|
|
/*
|
2010-04-26 16:31:57 +02:00
|
|
|
* Return the values of the object form the session variable
|
2008-11-06 11:14:14 +01:00
|
|
|
*/
|
|
|
|
function getValuesFromSession() {
|
|
|
|
return $this -> attr_html -> getValuesFromSession();
|
|
|
|
}
|
|
|
|
|
2008-02-26 18:40:05 +01:00
|
|
|
/**
|
2010-04-26 16:31:57 +02:00
|
|
|
* Defined the type of object witch is selectionable
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
2010-04-26 16:31:57 +02:00
|
|
|
* @param[in] $object string The type of object
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
**/
|
|
|
|
function setSelectableObject($object) {
|
|
|
|
$this -> selectableObject = $object;
|
|
|
|
}
|
2008-07-18 16:02:46 +02:00
|
|
|
|
|
|
|
/**
|
2010-04-26 16:31:57 +02:00
|
|
|
* Export the values of the element
|
2008-07-18 16:02:46 +02:00
|
|
|
*
|
2010-04-26 16:31:57 +02:00
|
|
|
* @retval Array The values of the element
|
2008-07-18 16:02:46 +02:00
|
|
|
*/
|
|
|
|
function exportValues(){
|
2008-10-07 14:17:50 +02:00
|
|
|
$values = $this -> attr_html -> getValuesFromFormValues($this -> values);
|
|
|
|
return $values;
|
2008-07-18 16:02:46 +02:00
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
|
2008-10-07 14:44:49 +02:00
|
|
|
/**
|
2010-04-26 16:31:57 +02:00
|
|
|
* Defined the value of the element from the data sent in POST with the form.
|
2008-10-07 14:44:49 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2010-04-26 16:31:57 +02:00
|
|
|
* @param[in] [<b>required</b>] string or array The new value of the element
|
2008-10-07 14:44:49 +02:00
|
|
|
*
|
2010-04-26 16:31:57 +02:00
|
|
|
* @retval boolean Return True
|
2008-10-07 14:44:49 +02:00
|
|
|
*/
|
|
|
|
function setValueFromPostData($data) {
|
|
|
|
LSformElement::setValueFromPostData($data);
|
2008-10-07 14:53:43 +02:00
|
|
|
$this -> values = $this -> attr_html -> refreshForm($this -> values,true);
|
2008-10-07 14:44:49 +02:00
|
|
|
return true;
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
|
2008-11-05 15:57:19 +01:00
|
|
|
/**
|
2010-04-26 16:31:57 +02:00
|
|
|
* Search the selectionable objects with a pattern
|
2008-11-05 15:57:19 +01:00
|
|
|
*
|
2010-04-26 16:31:57 +02:00
|
|
|
* @param[in] $pattern The pattern of the search
|
2008-11-05 15:57:19 +01:00
|
|
|
*
|
2010-04-26 16:31:57 +02:00
|
|
|
* @retval array(dn -> displayName) Found objects
|
2008-11-05 15:57:19 +01:00
|
|
|
*/
|
|
|
|
function searchAdd ($pattern) {
|
2009-01-28 09:13:36 +01:00
|
|
|
if (is_array($this -> params['html_options']['selectable_object'])) {
|
|
|
|
if (LSsession :: loadLSobject($this -> params['html_options']['selectable_object']['object_type'])) {
|
|
|
|
$obj = new $this -> params['html_options']['selectable_object']['object_type']();
|
2017-03-23 16:29:33 +01:00
|
|
|
$sparams = array();
|
|
|
|
$sparams['onlyAccessible'] = (isset($this -> params['html_options']['selectable_object']['onlyAccessible'])?$this -> params['html_options']['selectable_object']['onlyAccessible']:FALSE);
|
|
|
|
$ret = $obj -> getSelectArray($pattern,NULL,$this -> params['html_options']['selectable_object']['display_name_format'],false,true,(isset($this -> params['html_options']['selectable_object']['filter'])?$this -> params['html_options']['selectable_object']['filter']:NULL),$sparams);
|
2008-11-05 15:57:19 +01:00
|
|
|
if (is_array($ret)) {
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return array();
|
|
|
|
}
|
2010-04-26 16:31:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This ajax method is used to refresh the value display
|
|
|
|
* in the form element after the modify window is closed.
|
|
|
|
*
|
|
|
|
* @param[in] $data The address to the array of data witch will be return by the ajax request
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
**/
|
2009-02-20 15:05:22 +01:00
|
|
|
public static function ajax_refresh(&$data) {
|
|
|
|
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) ) {
|
|
|
|
if (LSsession ::loadLSobject($_REQUEST['objecttype'])) {
|
|
|
|
$object = new $_REQUEST['objecttype']();
|
|
|
|
$form = $object -> getForm($_REQUEST['idform']);
|
|
|
|
$field=$form -> getElement($_REQUEST['attribute']);
|
|
|
|
$val = $field -> getValuesFromSession();
|
|
|
|
if ( $val ) {
|
|
|
|
$data = array(
|
|
|
|
'objects' => $val
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-26 16:31:57 +02:00
|
|
|
/**
|
|
|
|
* This ajax method is used by the search-and-add function of the form element.
|
|
|
|
*
|
|
|
|
* @param[in] $data The address to the array of data witch will be return by the ajax request
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
**/
|
2009-02-20 15:05:22 +01:00
|
|
|
public static function ajax_searchAdd(&$data) {
|
|
|
|
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['pattern'])) && (isset($_REQUEST['idform'])) ) {
|
|
|
|
if (LSsession ::loadLSobject($_REQUEST['objecttype'])) {
|
|
|
|
$object = new $_REQUEST['objecttype']();
|
|
|
|
$form = $object -> getForm($_REQUEST['idform']);
|
|
|
|
$field=$form -> getElement($_REQUEST['attribute']);
|
|
|
|
$data['objects'] = $field -> searchAdd($_REQUEST['pattern']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|