2007-03-29 18:10:14 +02:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
2021-04-13 18:04:19 +02:00
|
|
|
* https://ldapsaisie.org
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type d'attribut HTML select_list
|
|
|
|
*
|
2009-02-11 17:01:21 +01:00
|
|
|
* 'html_options' => array (
|
|
|
|
* 'possible_values' => array (
|
|
|
|
* '[LSformat de la valeur clé]' => '[LSformat du nom d'affichage]',
|
|
|
|
* ...
|
|
|
|
* 'OTHER_OBJECT' => array (
|
|
|
|
* 'object_type' => '[Type d'LSobject]',
|
|
|
|
* 'display_name_format' => '[LSformat du nom d'affichage des LSobjects]',
|
|
|
|
* 'value_attribute' => '[Nom de l'attribut clé]',
|
|
|
|
* 'filter' => '[Filtre de recherche des LSobject]',
|
|
|
|
* 'scope' => '[Scope de la recherche]',
|
|
|
|
* 'basedn' => '[Basedn de la recherche]'
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* ),
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2007-03-29 18:10:14 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
|
|
|
class LSattr_html_select_list extends LSattr_html{
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2023-01-03 12:51:45 +01:00
|
|
|
var $LSformElement_type = 'select';
|
2014-06-18 00:13:06 +02:00
|
|
|
|
2008-02-26 18:40:05 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Ajoute l'attribut au formualaire passer en paramètre
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param LSform &$form Le formulaire
|
|
|
|
* @param string $idForm L'identifiant du formulaire
|
|
|
|
* @param array|string|null $data Valeur du champs du formulaire
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return LSformElement L'element du formulaire ajouté
|
2008-02-26 18:40:05 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function addToForm (&$form,$idForm,$data=NULL) {
|
2007-11-15 19:07:24 +01:00
|
|
|
$possible_values=$this -> getPossibleValues();
|
2008-02-26 18:40:05 +01:00
|
|
|
$this -> config['text_possible_values'] = $possible_values;
|
2014-06-18 00:13:06 +02:00
|
|
|
$element=parent::addToForm($form,$idForm,$data);
|
2014-06-10 16:51:12 +02:00
|
|
|
|
2014-06-18 00:13:06 +02:00
|
|
|
if ($element) {
|
|
|
|
// Mise en place de la regle de verification des donnees
|
2015-07-25 18:23:06 +02:00
|
|
|
$form -> addRule($this -> name, 'LSformElement_select_validValue', array('msg'=> _('Invalid value'),'params' => array('possible_values' => $possible_values)) );
|
2014-06-18 00:13:06 +02:00
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
return $element;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2014-06-18 00:13:06 +02:00
|
|
|
|
2019-03-12 12:00:58 +01:00
|
|
|
/**
|
2020-09-10 15:53:19 +02:00
|
|
|
* Return array of possible values with translated labels (if enabled)
|
2019-03-12 12:00:58 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return array Associative array with possible values as key and corresponding
|
2020-09-10 15:53:19 +02:00
|
|
|
* translated label as value.
|
2019-03-12 12:00:58 +01:00
|
|
|
*/
|
|
|
|
protected function getPossibleValues() {
|
2019-05-21 18:32:12 +02:00
|
|
|
return static :: _getPossibleValues(
|
2019-03-12 12:00:58 +01:00
|
|
|
$this -> getConfig('html_options'),
|
|
|
|
$this -> name,
|
|
|
|
$this->attribute->ldapObject
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
2020-09-10 15:53:19 +02:00
|
|
|
* Return array of possible values with translated labels (if enabled)
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param array|false $options Attribute HTML options (optional)
|
|
|
|
* @param string|false $name Attribute name (optional)
|
|
|
|
* @param LSldapObject|false &$ldapObject Related LSldapObject (optional)
|
2017-05-03 01:10:10 +02:00
|
|
|
*
|
2007-03-29 18:10:14 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return array Associative array with possible values as key and corresponding
|
2020-09-10 15:53:19 +02:00
|
|
|
* translated label as value.
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2020-09-22 15:04:31 +02:00
|
|
|
public static function _getPossibleValues($options=false, $name=false, &$ldapObject=false) {
|
|
|
|
// Handle get_possible_values parameter
|
|
|
|
$retInfos = self :: getCallablePossibleValues($options, $name, $ldapObject);
|
|
|
|
if (!is_array($retInfos))
|
|
|
|
$retInfos = array();
|
|
|
|
|
|
|
|
// Handle other configured possible values
|
|
|
|
if (is_array($options) && isset($options['possible_values']) && is_array($options['possible_values'])) {
|
|
|
|
$translate_labels = LSconfig :: get('translate_labels', true, 'bool', $options);
|
2017-05-03 01:10:10 +02:00
|
|
|
foreach($options['possible_values'] as $val_key => $val_label) {
|
2015-07-25 18:23:06 +02:00
|
|
|
if($val_key==='OTHER_OBJECT') {
|
2019-05-21 18:32:12 +02:00
|
|
|
$objInfos=static :: getLSobjectPossibleValues($val_label,$options,$name);
|
|
|
|
$retInfos=static :: _array_merge($retInfos,$objInfos);
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2018-04-26 12:18:16 +02:00
|
|
|
elseif($val_key==='OTHER_ATTRIBUTE') {
|
2019-05-21 18:32:12 +02:00
|
|
|
$attrInfos=static :: getLSattributePossibleValues($val_label, $options, $name, $ldapObject);
|
|
|
|
$retInfos=static :: _array_merge($retInfos,$attrInfos);
|
2018-04-26 12:18:16 +02:00
|
|
|
}
|
2021-06-10 18:45:00 +02:00
|
|
|
elseif (is_array($val_label)) {
|
|
|
|
if (!isset($val_label['possible_values']) || !is_array($val_label['possible_values']) || !isset($val_label['label']))
|
|
|
|
continue;
|
|
|
|
$subRetInfos=array();
|
|
|
|
foreach($val_label['possible_values'] as $vk => $vl) {
|
|
|
|
if ($vk==='OTHER_OBJECT') {
|
|
|
|
$objInfos=static :: getLSobjectPossibleValues($vl,$options,$name);
|
|
|
|
$subRetInfos=static :: _array_merge($subRetInfos,$objInfos);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$vk = $ldapObject->getFData($vk);
|
|
|
|
$vl = $ldapObject->getFData(($translate_labels?__($vl):$vl));
|
|
|
|
$subRetInfos[$vk] = $vl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static :: _sort($subRetInfos,$options);
|
|
|
|
$subRetLabel = $ldapObject->getFData(($translate_labels?__($val_label['label']):$val_label['label']));
|
|
|
|
$retInfos[] = array (
|
|
|
|
'label' => $subRetLabel,
|
|
|
|
'possible_values' => $subRetInfos
|
|
|
|
);
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
else {
|
2020-09-10 15:53:19 +02:00
|
|
|
$val_key = $ldapObject->getFData($val_key);
|
|
|
|
$val_label = $ldapObject->getFData(($translate_labels?__($val_label):$val_label));
|
|
|
|
$retInfos[$val_key] = $val_label;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-30 14:46:36 +02:00
|
|
|
|
2020-09-22 15:04:31 +02:00
|
|
|
static :: _sort($retInfos, $options);
|
2015-07-25 18:23:06 +02:00
|
|
|
|
|
|
|
return $retInfos;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Merge arrays preserving keys (string or numeric)
|
|
|
|
*
|
|
|
|
* As array_merge PHP function, this function merge arrays but
|
|
|
|
* this method permit to preverve key even if it's numeric key.
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return array Merged array
|
2015-07-25 18:23:06 +02:00
|
|
|
**/
|
2019-03-12 12:28:15 +01:00
|
|
|
protected static function _array_merge() {
|
2015-07-25 18:23:06 +02:00
|
|
|
$ret=array();
|
|
|
|
foreach(func_get_args() as $a) {
|
|
|
|
foreach($a as $k => $v) {
|
|
|
|
$ret[$k]=$v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply sort feature on possible values if this feature is enabled
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param array &$retInfos Possible values array reference to sort
|
|
|
|
* @param array|false $options Attribute HTML options
|
2015-07-25 18:23:06 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return void
|
2015-07-25 18:23:06 +02:00
|
|
|
**/
|
2020-09-22 15:04:31 +02:00
|
|
|
public static function _sort(&$retInfos, $options) {
|
2017-05-03 01:10:10 +02:00
|
|
|
if (!isset($options['sort']) || $options['sort']) {
|
|
|
|
if (isset($options['sortDirection']) && $options['sortDirection']=='DESC') {
|
|
|
|
uasort($retInfos,array('LSattr_html_select_list','_sortTwoValuesDesc'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uasort($retInfos,array('LSattr_html_select_list','_sortTwoValuesAsc'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function use with uasort to sort two values in ASC order
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param string $va One value
|
|
|
|
* @param string $va One value
|
2017-05-03 01:10:10 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return int Value for uasort
|
2017-05-03 01:10:10 +02:00
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
protected static function _sortTwoValuesAsc(&$va,&$vb) {
|
2017-05-03 01:10:10 +02:00
|
|
|
if (is_array($va)) {
|
2022-12-07 17:11:17 +01:00
|
|
|
// Force sub-options at the end
|
|
|
|
$nva='ZZZZ'.$va['label'];
|
2017-05-03 01:10:10 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$nva=$va;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($vb)) {
|
2022-12-07 17:11:17 +01:00
|
|
|
// Force sub-options at the end
|
|
|
|
$nvb='ZZZZ'.$vb['label'];
|
2014-09-30 14:46:36 +02:00
|
|
|
}
|
2017-05-03 01:10:10 +02:00
|
|
|
else {
|
|
|
|
$nvb=$vb;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($nva == $nvb) return 0;
|
|
|
|
|
|
|
|
return strcoll(strtolower($nva), strtolower($nvb));
|
2015-07-25 18:23:06 +02:00
|
|
|
}
|
|
|
|
|
2017-05-03 01:10:10 +02:00
|
|
|
/**
|
|
|
|
* Function use with uasort to sort two values in DESC order
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param string $va One value
|
|
|
|
* @param string $va One value
|
2017-05-03 01:10:10 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return int Value for uasort
|
2017-05-03 01:10:10 +02:00
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
protected static function _sortTwoValuesDesc(&$va,&$vb) {
|
2019-05-21 18:32:12 +02:00
|
|
|
return (-1 * static :: _sortTwoValuesAsc($va,$vb));
|
2017-05-03 01:10:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-25 18:23:06 +02:00
|
|
|
/**
|
|
|
|
* Retourne un tableau des valeurs possibles d'un type d'objet
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param array $conf OTHER_OBJECT configuration array
|
|
|
|
* @param array|false $options Attribute HTML options
|
|
|
|
* @param string $name Attribute name
|
2017-05-03 01:10:10 +02:00
|
|
|
*
|
2015-07-25 18:23:06 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2023-01-02 01:17:46 +01:00
|
|
|
* @return array|false Tableau associatif des valeurs possible de la liste avec en clé
|
|
|
|
* la valeur des balises option et en valeur ce qui sera affiché.
|
|
|
|
* False en cas d'erreur.
|
2015-07-25 18:23:06 +02:00
|
|
|
*/
|
2019-03-12 12:04:42 +01:00
|
|
|
protected static function getLSobjectPossibleValues($conf, $options, $name) {
|
2015-07-25 18:23:06 +02:00
|
|
|
$retInfos = array();
|
|
|
|
|
2015-08-27 18:28:13 +02:00
|
|
|
if ((!isset($conf['object_type'])) || ((!isset($conf['value_attribute'])) && (!isset($conf['values_attribute'])))) {
|
2017-05-03 01:10:10 +02:00
|
|
|
LSerror :: addErrorCode('LSattr_html_select_list_01',$name);
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2015-07-25 18:23:06 +02:00
|
|
|
}
|
|
|
|
if (!LSsession :: loadLSclass('LSsearch')) {
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2015-07-25 18:23:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$param=array(
|
|
|
|
'filter' => (isset($conf['filter'])?$conf['filter']:null),
|
|
|
|
'basedn' => (isset($conf['basedn'])?$conf['basedn']:null),
|
|
|
|
'scope' => (isset($conf['scope'])?$conf['scope']:null),
|
|
|
|
'displayFormat' => (isset($conf['display_name_format'])?$conf['display_name_format']:null),
|
2017-03-23 16:29:33 +01:00
|
|
|
'onlyAccessible' => (isset($conf['onlyAccessible'])?$conf['onlyAccessible']:False),
|
2015-07-25 18:23:06 +02:00
|
|
|
);
|
|
|
|
|
2015-08-27 18:28:13 +02:00
|
|
|
if (isset($conf['value_attribute']) && $conf['value_attribute']!='dn') {
|
2015-07-25 18:23:06 +02:00
|
|
|
$param['attributes'][] = $conf['value_attribute'];
|
|
|
|
}
|
2015-08-27 18:28:13 +02:00
|
|
|
if (isset($conf['values_attribute'])) {
|
|
|
|
$param['attributes'][] = $conf['values_attribute'];
|
|
|
|
}
|
2015-07-25 18:23:06 +02:00
|
|
|
|
|
|
|
$LSsearch = new LSsearch($conf['object_type'],'LSattr_html_select_list',$param,true);
|
|
|
|
$LSsearch -> run();
|
2016-08-16 13:57:56 +02:00
|
|
|
if (isset($conf['value_attribute'])) {
|
2015-08-27 18:28:13 +02:00
|
|
|
if(($conf['value_attribute']=='dn')||($conf['value_attribute']=='%{dn}')) {
|
|
|
|
$retInfos = $LSsearch -> listObjectsName();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$list = $LSsearch -> getSearchEntries();
|
|
|
|
foreach($list as $entry) {
|
|
|
|
$key = $entry -> get($conf['value_attribute']);
|
|
|
|
if(is_array($key)) {
|
|
|
|
$key = $key[0];
|
|
|
|
}
|
|
|
|
$retInfos[$key]=$entry -> displayName;
|
|
|
|
}
|
|
|
|
}
|
2015-07-25 18:23:06 +02:00
|
|
|
}
|
2015-08-27 18:28:13 +02:00
|
|
|
if (isset($conf['values_attribute'])) {
|
2015-07-25 18:23:06 +02:00
|
|
|
$list = $LSsearch -> getSearchEntries();
|
|
|
|
foreach($list as $entry) {
|
2015-08-27 18:28:13 +02:00
|
|
|
$keys = $entry -> get($conf['values_attribute']);
|
2020-11-30 19:43:52 +01:00
|
|
|
foreach (ensureIsArray($keys) as $key) {
|
2015-08-27 18:28:13 +02:00
|
|
|
$retInfos[$key]=$key;
|
2015-07-25 18:23:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-21 18:32:12 +02:00
|
|
|
static :: _sort($retInfos,$options);
|
2014-09-30 14:46:36 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
return $retInfos;
|
|
|
|
}
|
2018-04-26 12:18:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne un tableau des valeurs possibles d'un autre attribut
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param string|array $attr OTHER_ATTRIBUTE configuration value
|
|
|
|
* @param array|false $options Attribute HTML options
|
|
|
|
* @param string $name Attribute name
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param LSldapObject &$ldapObject The related LSldapObject reference
|
2018-04-26 12:18:16 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return array Tableau associatif des valeurs possible de la liste avec en clé
|
2018-04-26 12:18:16 +02:00
|
|
|
* la valeur des balises option et en valeur ce qui sera affiché.
|
|
|
|
*/
|
2022-12-31 02:01:17 +01:00
|
|
|
protected static function getLSattributePossibleValues($attr, $options ,$name ,&$ldapObject) {
|
2018-04-26 12:18:16 +02:00
|
|
|
$retInfos=array();
|
|
|
|
if (is_string($attr)) {
|
|
|
|
if (isset($ldapObject->attrs[$attr]) && $ldapObject->attrs[$attr] instanceof LSattribute) {
|
2020-11-30 19:43:52 +01:00
|
|
|
$attr_values = ensureIsArray($ldapObject->attrs[$attr]->getValue());
|
2018-09-19 18:56:47 +02:00
|
|
|
if (isset($options['translate_labels']) && !$options['translate_labels']) {
|
|
|
|
foreach($attr_values as $attr_value)
|
|
|
|
$retInfos[$attr_value] = $attr_value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach($attr_values as $attr_value)
|
|
|
|
$retInfos[$attr_value] = __($attr_value);
|
|
|
|
}
|
2018-04-26 12:18:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
LSerror :: addErrorCode('LSattr_html_select_list_02',$attr);
|
|
|
|
}
|
|
|
|
elseif (is_array($attr)) {
|
|
|
|
if (isset($attr['attr'])) {
|
|
|
|
if (isset($ldapObject->attrs[$attr['attr']]) && $ldapObject->attrs[$attr['attr']] instanceof LSattribute) {
|
|
|
|
if (isset($attr['json_component_key'])) {
|
|
|
|
if (get_class($ldapObject->attrs[$attr['attr']]->html) == 'LSattr_html_jsonCompositeAttribute') {
|
2020-11-30 19:43:52 +01:00
|
|
|
$attr_values = ensureIsArray($ldapObject->attrs[$attr['attr']]->getValue());
|
2018-04-26 12:18:16 +02:00
|
|
|
foreach($attr_values as $attr_value) {
|
|
|
|
$value_data = @json_decode($attr_value, true);
|
|
|
|
if (!isset($value_data[$attr['json_component_key']])) {
|
|
|
|
LSerror :: addErrorCode('LSattr_html_select_list_05', array('attr' => $attr['attr'], 'value' => $attr_value, 'component' => $attr['json_component_key']));
|
|
|
|
return $retInfos;
|
|
|
|
}
|
|
|
|
$key = $value_data[$attr['json_component_key']];
|
|
|
|
|
|
|
|
if (isset($attr['json_component_label'])) {
|
|
|
|
if (!isset($value_data[$attr['json_component_label']])) {
|
|
|
|
LSerror :: addErrorCode('LSattr_html_select_list_05', array('attr' => $attr['attr'], 'value' => $attr_value, 'component' => $attr['json_component_label']));
|
|
|
|
return $retInfos;
|
|
|
|
}
|
|
|
|
$label = $value_data[$attr['json_component_label']];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$label = $key;
|
|
|
|
|
|
|
|
$retInfos[$key] = $label;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
LSerror :: addErrorCode('LSattr_html_select_list_03',$attr['attr']);
|
|
|
|
}
|
|
|
|
else
|
2019-05-21 18:32:12 +02:00
|
|
|
$retInfos = static :: getLSattributePossibleValues($attr['attr'], $options ,$name ,$ldapObject);
|
2018-04-26 12:18:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
LSerror :: addErrorCode('LSattr_html_select_list_02',$attr['attr']);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach($attr as $sub_attr => $sub_label) {
|
2019-05-21 18:32:12 +02:00
|
|
|
$subRetInfos = static :: getLSattributePossibleValues($sub_attr, $options ,$name ,$ldapObject);
|
|
|
|
static :: _sort($subRetInfos,$options);
|
2018-04-26 12:18:16 +02:00
|
|
|
$retInfos[] = array (
|
|
|
|
'label' => $sub_label,
|
|
|
|
'possible_values' => $subRetInfos
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-21 18:32:12 +02:00
|
|
|
static :: _sort($retInfos,$options);
|
2018-04-26 12:18:16 +02:00
|
|
|
return $retInfos;
|
|
|
|
}
|
|
|
|
|
2020-09-22 15:04:31 +02:00
|
|
|
/**
|
|
|
|
* Return array of possible values with translated labels (if enabled)
|
|
|
|
* by using specify callable
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param array $options Attribute HTML options
|
|
|
|
* @param string $name Attribute name
|
|
|
|
* @param LSldapObject &$ldapObject Related LSldapObject
|
2020-09-22 15:04:31 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return array|false Associative array with possible values as key and corresponding
|
2020-09-22 15:04:31 +02:00
|
|
|
* translated label as value, or false in case of error.
|
|
|
|
*/
|
|
|
|
public static function getCallablePossibleValues($options, $name, &$ldapObject) {
|
|
|
|
// Handle get_possible_values parameter
|
|
|
|
$get_possible_values = LSconfig :: get('get_possible_values', null, null, $options);
|
|
|
|
if (!$get_possible_values)
|
|
|
|
return array();
|
|
|
|
|
|
|
|
// Check callable
|
|
|
|
if (!is_callable($get_possible_values)) {
|
|
|
|
LSerror :: addErrorCode('LSattr_html_select_list_06', $name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run callable
|
|
|
|
try {
|
|
|
|
$retInfos = call_user_func_array(
|
|
|
|
$get_possible_values,
|
|
|
|
array($options, $name, $ldapObject)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
catch (Exception $er) {
|
2022-12-31 02:01:17 +01:00
|
|
|
self :: log_exception($er, get_called_class()." -> _getPossibleValues(): exception occured running ".format_callable($get_possible_values));
|
2020-09-22 15:04:31 +02:00
|
|
|
$retInfos = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check result
|
|
|
|
if (!is_array($retInfos)) {
|
|
|
|
LSerror :: addErrorCode(
|
|
|
|
'LSattr_html_select_list_07',
|
|
|
|
array(
|
|
|
|
'attr' => $name,
|
|
|
|
'callable' => format_callable($get_possible_values)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $retInfos;
|
|
|
|
}
|
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
|
2009-01-02 17:00:25 +01:00
|
|
|
/*
|
|
|
|
* Error Codes
|
|
|
|
*/
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSattr_html_select_list_01',
|
2020-09-22 15:04:31 +02:00
|
|
|
___("LSattr_html_select_list: Configuration data are missing to generate the select list of the attribute %{attr}.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2018-04-26 12:18:16 +02:00
|
|
|
LSerror :: defineError('LSattr_html_select_list_02',
|
2020-09-22 15:04:31 +02:00
|
|
|
___("LSattr_html_select_list: Invalid attribute %{attr} reference as OTHER_ATTRIBUTE possible values.")
|
2018-04-26 12:18:16 +02:00
|
|
|
);
|
|
|
|
LSerror :: defineError('LSattr_html_select_list_03',
|
2020-09-22 15:04:31 +02:00
|
|
|
___("LSattr_html_select_list: Attribute %{attr} referenced as OTHER_ATTRIBUTE possible values is not a jsonCompositeAttribute.")
|
2018-04-26 12:18:16 +02:00
|
|
|
);
|
|
|
|
LSerror :: defineError('LSattr_html_select_list_04',
|
2020-09-22 15:04:31 +02:00
|
|
|
___("LSattr_html_select_list: Fail to decode the following attribute %{attr} value as JSON : %{value}")
|
2018-04-26 12:18:16 +02:00
|
|
|
);
|
|
|
|
LSerror :: defineError('LSattr_html_select_list_05',
|
2020-09-22 15:04:31 +02:00
|
|
|
___("LSattr_html_select_list: No component %{component} found in the following attribute %{attr} JSON value : %{value}")
|
|
|
|
);
|
|
|
|
LSerror :: defineError('LSattr_html_select_list_06',
|
|
|
|
___("LSattr_html_select_list: Invalid get_possible_values parameter found in configuration of attribute %{attr}: must be a callable.")
|
|
|
|
);
|
|
|
|
LSerror :: defineError('LSattr_html_select_list_07',
|
2021-08-25 18:02:37 +02:00
|
|
|
___("LSattr_html_select_list: fail to retrieve possible values of attribute %{attr} using configured function %{callable}.")
|
2018-04-26 12:18:16 +02:00
|
|
|
);
|