mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-24 19:09:06 +01:00
Compare commits
No commits in common. "6cfde7f08425eb0d825f8a8ecf1b0abf3b762a00" and "24d76d6c9c3461b7781b36b3880f5d1512fb94f9" have entirely different histories.
6cfde7f084
...
24d76d6c9c
5 changed files with 161 additions and 262 deletions
|
@ -45,17 +45,11 @@ class LSattr_html_select_object extends LSattr_html{
|
|||
*
|
||||
* @return LSformElement|false L'element du formulaire ajouté, ou false
|
||||
*/
|
||||
public function addToForm (&$form, $idForm, $data=NULL) {
|
||||
public function addToForm (&$form,$idForm,$data=NULL) {
|
||||
$this -> config['attrObject'] = $this;
|
||||
$element = $form -> addElement(
|
||||
$this -> LSformElement_type,
|
||||
$this -> name,
|
||||
$this -> getLabel(),
|
||||
$this -> config,
|
||||
$this
|
||||
);
|
||||
$element=$form -> addElement($this -> LSformElement_type, $this -> name, $this -> getLabel(), $this -> config, $this);
|
||||
if(!$element) {
|
||||
LSerror :: addErrorCode('LSform_06', $this -> name);
|
||||
LSerror :: addErrorCode('LSform_06',$this -> name);
|
||||
return false;
|
||||
}
|
||||
if ($data) {
|
||||
|
@ -77,8 +71,8 @@ class LSattr_html_select_object extends LSattr_html{
|
|||
*
|
||||
* @return array La valeur formatée de l'attribut (array('DNs' => 'displayName'))
|
||||
**/
|
||||
public function refreshForm($data, $fromDNs=false) {
|
||||
return $this -> getFormValues($data, $fromDNs);
|
||||
public function refreshForm($data,$fromDNs=false) {
|
||||
return $this -> getFormValues($data,$fromDNs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,8 +174,8 @@ class LSattr_html_select_object extends LSattr_html{
|
|||
*
|
||||
* @param mixed $values array|null Array of the input values ()
|
||||
* @param boolean $fromDNs boolean If true, considered provided values as DNs (default: false)
|
||||
* @param boolean $retrieveAttrValues boolean If true, final attribute values will be returned
|
||||
* instead of selected objects info (default: false)
|
||||
* @param boolean $retrieveAttrValues boolean If true, attribute values will be returned instead
|
||||
* of selected objects info (default: false)
|
||||
*
|
||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||
*
|
||||
|
@ -199,166 +193,139 @@ class LSattr_html_select_object extends LSattr_html{
|
|||
self :: log_warning('getFormValues(): $values is not array');
|
||||
return false;
|
||||
}
|
||||
if (!LSsession :: loadLSclass("LSsearch"))
|
||||
return false;
|
||||
|
||||
// Retrieve/check selectable objects config
|
||||
$objs = [];
|
||||
$objs = array();
|
||||
$confs = $this -> getSelectableObjectsConfig($objs);
|
||||
if (!is_array($confs) || empty($confs)) {
|
||||
self :: log_warning('getFormValues(): invalid selectable objects config');
|
||||
return false;
|
||||
}
|
||||
|
||||
$selected_objects = [];
|
||||
$found_values = [];
|
||||
$unrecognizedValues = [];
|
||||
$selected_objects = array();
|
||||
$unrecognizedValues = array();
|
||||
$found_values = array();
|
||||
foreach ($confs as $conf) {
|
||||
$common_search_params = [
|
||||
"filter" => $conf['filter'],
|
||||
"attributes" => (
|
||||
$retrieveAttrValues && !in_array($conf['value_attribute'], ["dn", "%{dn}"])?
|
||||
[$conf['value_attribute']]:
|
||||
[$objs[$conf['object_type']]->rdn_attr]
|
||||
),
|
||||
"displayFormat" => (
|
||||
$conf['display_name_format']?
|
||||
$conf['display_name_format']:
|
||||
$objs[$conf['object_type']] -> getDisplayNameFormat()
|
||||
),
|
||||
];
|
||||
foreach($values as $value) {
|
||||
// Ignore empty value and value already marked as unrecognized
|
||||
if (empty($value) || in_array($value, $unrecognizedValues))
|
||||
// If we already mark its value as unrecognized, pass
|
||||
if (in_array($value, $unrecognizedValues))
|
||||
continue;
|
||||
|
||||
// Compute search params based on value attribute type (DN or attribute valued) and $fromDNs
|
||||
if($fromDNs || in_array($conf['value_attribute'], ['dn', '%{dn}'])) {
|
||||
if ($conf['onlyAccessible'] && !LSsession :: canAccess($conf['object_type'], $value)) {
|
||||
self :: log_debug(
|
||||
"getFormValues(): object {$conf['object_type']} '$value' is not accessible, pass"
|
||||
);
|
||||
// Ignore empty value
|
||||
if (empty($value))
|
||||
continue;
|
||||
|
||||
// Determine value attribute: DN/attribute valued (or force form DNs)
|
||||
if(($conf['value_attribute']=='dn') || ($conf['value_attribute']=='%{dn}') || $fromDNs) {
|
||||
// Construct resulting list from DN values
|
||||
if ($conf['onlyAccessible']) {
|
||||
if (!LSsession :: canAccess($conf['object_type'], $value)) {
|
||||
self :: log_debug("getFormValues(): ".$conf['object_type']."($value): not accessible, pass");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Load object data (with custom filter if defined)
|
||||
if(!$objs[$conf['object_type']] -> loadData($value, $conf['filter'])) {
|
||||
self :: log_debug("getFormValues(): ".$conf['object_type']."($value): not found, pass");
|
||||
continue;
|
||||
}
|
||||
$search_params = array_merge(
|
||||
$common_search_params,
|
||||
["basedn" => $value, "scope" => "base"]
|
||||
);
|
||||
}
|
||||
else {
|
||||
$filter = Net_LDAP2_Filter::create($conf['value_attribute'], 'equals', $value);
|
||||
$search_params = array_merge(
|
||||
$common_search_params,
|
||||
[
|
||||
"filter" => (
|
||||
$common_search_params["filter"]?
|
||||
LSldap::combineFilters('and', [$common_search_params["filter"], $filter]):
|
||||
$filter
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
self :: log_debug("getFormValues(): ".$conf['object_type']."($value): found");
|
||||
|
||||
// Search object
|
||||
$LSsearch = new LSsearch(
|
||||
$conf['object_type'],
|
||||
'LSattr_html_select_object::getFormValues',
|
||||
$search_params,
|
||||
true
|
||||
);
|
||||
|
||||
if(!$LSsearch -> run(false)) {
|
||||
self :: log_warning(
|
||||
"getFormValues(): error during search of object(s) {$conf['object_type']} ".
|
||||
"for value '$value', pass"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
$entries = $LSsearch -> listEntries();
|
||||
if (!is_array($entries) || empty($entries)) {
|
||||
self :: log_debug(
|
||||
"getFormValues(): value '$value' not found as {$conf['object_type']}, pass"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (count($entries) > 1) {
|
||||
self :: log_warning(
|
||||
"getFormValues(): ".count($entries)." objects {$conf['object_type']} found ".
|
||||
"for value '$value', pass: ".implode(" / ", array_keys($entries))
|
||||
);
|
||||
if (array_key_exists($value, $selected_objects))
|
||||
unset($selected_objects[$value]);
|
||||
$unrecognizedValues[] = $value;
|
||||
$found_values[$value] = (
|
||||
array_key_exists($value, $found_values)?
|
||||
array_merge($found_values[$value], array_keys($entries)):
|
||||
array_keys($entries)
|
||||
);
|
||||
break;
|
||||
}
|
||||
$entry = $entries[key($entries)];
|
||||
self :: log_debug(
|
||||
"getFormValues(): value '$value' found as {$conf['object_type']}: {$entry->dn}"
|
||||
);
|
||||
|
||||
// Check if it's the first this value match with an object
|
||||
if (array_key_exists($value, $found_values)) {
|
||||
// DN match with multiple object type
|
||||
LSerror :: addErrorCode(
|
||||
'LSattr_html_select_object_03',
|
||||
['val' => $value, 'attribute' => $this -> name]
|
||||
);
|
||||
unset($selected_objects[$value]);
|
||||
$unrecognizedValues[] = $value;
|
||||
$found_values[$value][] = $entry->dn;
|
||||
break;
|
||||
}
|
||||
$found_values[$value] = [$entry->dn];
|
||||
|
||||
if ($retrieveAttrValues) {
|
||||
// Retrieve attribute value case: $selected_objects[dn] = attribute value
|
||||
if(($conf['value_attribute']=='dn') || ($conf['value_attribute']=='%{dn}')) {
|
||||
$selected_objects[$value] = $entry->dn;
|
||||
// Check if it's the first this value match with an object
|
||||
if (isset($found_values[$value])) {
|
||||
// DN match with multiple object type
|
||||
LSerror :: addErrorCode('LSattr_html_select_object_03',array('val' => $value, 'attribute' => $this -> name));
|
||||
$unrecognizedValues[] = $value;
|
||||
unset($selected_objects[$found_values[$value]]);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
$val = ensureIsArray($entry -> get($conf['value_attribute']));
|
||||
if (!empty($val)) {
|
||||
$selected_objects[$value] = $val[0];
|
||||
$found_values[$value] = $value;
|
||||
|
||||
if ($retrieveAttrValues) {
|
||||
// Retrieve attribute value case: $selected_objects[dn] = attribute value
|
||||
if(($conf['value_attribute']=='dn') || ($conf['value_attribute']=='%{dn}')) {
|
||||
$selected_objects[$value] = $value;
|
||||
}
|
||||
else {
|
||||
LSerror :: addErrorCode(
|
||||
'LSattr_html_select_object_06',
|
||||
array(
|
||||
'name' => $entry -> displayName,
|
||||
'attr' => $this -> name
|
||||
)
|
||||
);
|
||||
$val = $objs[$conf['object_type']] -> getValue($conf['value_attribute']);
|
||||
if (!empty($val)) {
|
||||
$selected_objects[$value] = $val[0];
|
||||
}
|
||||
else {
|
||||
LSerror :: addErrorCode(
|
||||
'LSattr_html_select_object_06',
|
||||
array(
|
||||
'name' => $objs[$conf['object_type']] -> getDisplayName($conf['display_name_format']),
|
||||
'attr' => $this -> name
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// General case: $selected_objects[dn] = array(name + object_type)
|
||||
$selected_objects[$value] = array(
|
||||
'name' => $objs[$conf['object_type']] -> getDisplayName($conf['display_name_format']),
|
||||
'object_type' => $conf['object_type'],
|
||||
);
|
||||
self :: log_debug("getFormValues(): ".$conf['object_type']."($value): ".varDump($selected_objects[$value]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// General case: $selected_objects[dn] = array(name + object_type)
|
||||
$selected_objects[$value] = array(
|
||||
'name' => $entry -> displayName,
|
||||
'object_type' => $conf['object_type'],
|
||||
);
|
||||
self :: log_debug(
|
||||
"getFormValues(): object {$conf['object_type']} info for value '$value': ".
|
||||
varDump($selected_objects[$value])
|
||||
// Construct resulting list from attributes values
|
||||
$filter = Net_LDAP2_Filter::create($conf['value_attribute'], 'equals', $value);
|
||||
if (isset($conf['filter']))
|
||||
$filter = LSldap::combineFilters('and', array($filter, $conf['filter']));
|
||||
$sparams = array();
|
||||
$sparams['onlyAccessible'] = $conf['onlyAccessible'];
|
||||
$listobj = $objs[$conf['object_type']] -> listObjectsName(
|
||||
$filter,
|
||||
NULL,
|
||||
$sparams,
|
||||
$conf['display_name_format']
|
||||
);
|
||||
if (count($listobj)==1) {
|
||||
if (isset($found_values[$value])) {
|
||||
// Value match with multiple object type
|
||||
LSerror :: addErrorCode('LSattr_html_select_object_03',array('val' => $value, 'attribute' => $this -> name));
|
||||
$unrecognizedValues[] = $value;
|
||||
unset($selected_objects[$found_values[$value]]);
|
||||
break;
|
||||
}
|
||||
$dn = key($listobj);
|
||||
$selected_objects[$dn] = array(
|
||||
'name' => $listobj[$dn],
|
||||
'object_type' => $conf['object_type'],
|
||||
);
|
||||
$found_values[$value] = $dn;
|
||||
}
|
||||
else if(count($listobj) > 1) {
|
||||
LSerror :: addErrorCode('LSattr_html_select_object_03',array('val' => $value, 'attribute' => $this -> name));
|
||||
if (!in_array($value, $unrecognizedValues))
|
||||
$unrecognizedValues[] = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if all values have been found (or already considered as unrecognized)
|
||||
foreach ($values as $value) {
|
||||
if (!isset($found_values[$value]) && !in_array($value, $unrecognizedValues)) {
|
||||
self :: log_debug("getFormValues(): value '$value' not recognized");
|
||||
$unrecognizedValues[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve attribute values case: return forged array values (list of attribute values)
|
||||
if ($retrieveAttrValues)
|
||||
return array_values($selected_objects);
|
||||
|
||||
// General case
|
||||
$this -> unrecognizedValues = array_diff($values, array_keys($selected_objects));
|
||||
self :: log_debug("getFormValues(): unrecognizedValues=".varDump($this -> unrecognizedValues));
|
||||
self :: log_debug("getFormValues(): unrecognizedValues=".varDump($unrecognizedValues));
|
||||
$this -> unrecognizedValues = $unrecognizedValues;
|
||||
|
||||
self :: log_debug("getFormValues(): final values=".varDump($selected_objects));
|
||||
return $selected_objects;
|
||||
}
|
||||
|
@ -380,7 +347,7 @@ class LSattr_html_select_object extends LSattr_html{
|
|||
|
||||
|
||||
/**
|
||||
* Return array of attribute values form array of form values
|
||||
* Return array of atttribute values form array of form values
|
||||
*
|
||||
* @param mixed $values Array of form values
|
||||
*
|
||||
|
|
|
@ -140,8 +140,7 @@ class LSformElement_select_object extends LSformElement {
|
|||
$this -> attr_html -> getLSselectId(),
|
||||
$select_conf,
|
||||
boolval($this -> getParam('multiple', 0, 'int')),
|
||||
$this -> values,
|
||||
false
|
||||
$this -> values
|
||||
);
|
||||
return True;
|
||||
}
|
||||
|
|
|
@ -462,17 +462,8 @@ class LSldap extends LSlog_staticLoggerClass {
|
|||
*
|
||||
* @return boolean True if entry exists, false otherwise
|
||||
*/
|
||||
public static function exists($dn, $filter=null) {
|
||||
$entry = self :: search(
|
||||
$filter?$filter:"(objectClass=*)",
|
||||
$dn,
|
||||
[
|
||||
"scope" => "base",
|
||||
"attronly" => true,
|
||||
"attributes" => ["objectClass"],
|
||||
]
|
||||
);
|
||||
return boolval($entry);
|
||||
public static function exists($dn) {
|
||||
return is_a(self :: getLdapEntry($dn), 'Net_LDAP2_Entry');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -149,23 +149,6 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the specified object exists
|
||||
* @param string $dn Object's DN
|
||||
* @param string|Net_LDAP2_Filter|null $filter Extra LDAP that object must match (optional, default: null)
|
||||
* @return bool
|
||||
*/
|
||||
public static function exists($dn, $filter=null) {
|
||||
return LSldap::exists(
|
||||
$dn,
|
||||
(
|
||||
$filter?
|
||||
LSldap::combineFilters("and", [static :: _getObjectFilter(), $filter]):
|
||||
static :: _getObjectFilter()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load object data from LDAP
|
||||
*
|
||||
|
@ -918,43 +901,40 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return LDAP filter string of the current object type
|
||||
* Retourne le filtre correpondants aux objetcClass de l'objet courant
|
||||
*
|
||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||
*
|
||||
* @return Net_LDAP2_Filter LDAP filter as a Net_LDAP2_Filter object, or false in case of error
|
||||
* @return Net_LDAP2_Filter le filtre ldap correspondant au type de l'objet
|
||||
*/
|
||||
public function getObjectFilter() {
|
||||
return self :: _getObjectFilter($this -> type_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return object type LDAP filter string
|
||||
*
|
||||
* @param string|null $type Object type (optional, default: called class)
|
||||
* Retourne le filtre correpondants aux objetcClass de l'objet
|
||||
*
|
||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||
*
|
||||
* @return Net_LDAP2_Filter|false LDAP filter as a Net_LDAP2_Filter object, or false in case of error
|
||||
* @return Net_LDAP2_Filter|false le filtre ldap correspondant au type de l'objet, ou false
|
||||
*/
|
||||
public static function _getObjectFilter($type=null) {
|
||||
$type = $type?$type:get_called_class();
|
||||
$oc = LSconfig::get("LSobjects.$type.objectclass");
|
||||
if(!is_array($oc) || !$oc) return false;
|
||||
$filters = [];
|
||||
public static function _getObjectFilter($type) {
|
||||
$oc=LSconfig::get("LSobjects.$type.objectclass");
|
||||
if(!is_array($oc)) return false;
|
||||
$filters=array();
|
||||
foreach ($oc as $class) {
|
||||
$filters[] = Net_LDAP2_Filter::create('objectClass', 'equals', $class);
|
||||
$filters[]=Net_LDAP2_Filter::create('objectClass','equals',$class);
|
||||
}
|
||||
|
||||
$filter = LSconfig::get("LSobjects.$type.filter");
|
||||
$filter=LSconfig::get("LSobjects.$type.filter");
|
||||
if ($filter) {
|
||||
$filters[] = Net_LDAP2_Filter::parse($filter);
|
||||
$filters[]=Net_LDAP2_Filter::parse($filter);
|
||||
}
|
||||
|
||||
$filter = LSldap::combineFilters('and', $filters);
|
||||
$filter = LSldap::combineFilters('and',$filters);
|
||||
if ($filter)
|
||||
return $filter;
|
||||
LSerror :: addErrorCode('LSldapObject_30', $type);
|
||||
LSerror :: addErrorCode('LSldapObject_30',$type);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1024,40 +1004,37 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
*
|
||||
* @param Net_LDAP2_Filter|string|null $filter LDAP search filter
|
||||
* @param string|null $sbasedn Base DN of the search
|
||||
* @param array|null $sparams Search parameters (as expected by Net_LDAP2::search())
|
||||
* @param array $sparams Search parameters (as expected by Net_LDAP2::search())
|
||||
* @param string|false $displayFormat LSformat of objects's display name
|
||||
* @param bool $cache Enable/disable cache (default: true)
|
||||
*
|
||||
* @return array|false Tableau dn => name correspondant au resultat de la recherche, ou false
|
||||
*/
|
||||
public function listObjectsName($filter=NULL, $sbasedn=NULL, $sparams=null, $displayFormat=false, $cache=true) {
|
||||
public function listObjectsName($filter=NULL,$sbasedn=NULL,$sparams=array(),$displayFormat=false,$cache=true) {
|
||||
if (!LSsession :: loadLSclass('LSsearch')) {
|
||||
LSerror::addErrorCode('LSsession_05', 'LSsearch');
|
||||
LSerror::addErrorCode('LSsession_05','LSsearch');
|
||||
return false;
|
||||
}
|
||||
|
||||
$params = [
|
||||
'displayFormat' => $displayFormat?$displayFormat:$this -> getDisplayNameFormat(),
|
||||
if (!$displayFormat) {
|
||||
$displayFormat = $this -> getDisplayNameFormat();
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'displayFormat' => $displayFormat,
|
||||
'basedn' => $sbasedn,
|
||||
'filter' => $filter
|
||||
];
|
||||
|
||||
$LSsearch = new LSsearch(
|
||||
$this -> type_name,
|
||||
'LSldapObject::listObjectsName',
|
||||
(
|
||||
is_array($sparams)?
|
||||
$params = array_merge($sparams, $params):
|
||||
$sparams
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
return (
|
||||
$LSsearch -> run($cache)?
|
||||
$LSsearch -> listObjectsName():
|
||||
false
|
||||
);
|
||||
if (is_array($sparams)) {
|
||||
$params=array_merge($sparams,$params);
|
||||
}
|
||||
|
||||
$LSsearch = new LSsearch($this -> type_name,'LSldapObject::listObjectsName',$params,true);
|
||||
|
||||
$LSsearch -> run($cache);
|
||||
|
||||
return $LSsearch -> listObjectsName();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -51,10 +51,9 @@ class LSselect extends LSlog_staticLoggerClass {
|
|||
* @param boolean $multiple True if this selection permit to select more than one object, False otherwise (optional,
|
||||
* default: false)
|
||||
* @param array|null $current_selected_objects Array of current selected objects (optional, see setSelectedObjects for format specification)
|
||||
* @param bool $check_objects Check selected objects (optional, default: true)
|
||||
* @return void
|
||||
*/
|
||||
public static function init($id, $LSobjects, $multiple=false, $current_selected_objects=null, $check_objects=true) {
|
||||
public static function init($id, $LSobjects, $multiple=false, $current_selected_objects=null) {
|
||||
if ( !isset($_SESSION['LSselect']) || !is_array($_SESSION['LSselect']))
|
||||
$_SESSION['LSselect'] = array();
|
||||
$_SESSION['LSselect'][$id] = array (
|
||||
|
@ -63,11 +62,8 @@ class LSselect extends LSlog_staticLoggerClass {
|
|||
'selected_objects' => array(),
|
||||
);
|
||||
if (is_array($current_selected_objects))
|
||||
self :: setSelectedObjects($id, $current_selected_objects, $check_objects);
|
||||
self :: log_debug(
|
||||
"Initialized with id=$id: multiple=".($multiple?'yes':'no')." ".
|
||||
count($_SESSION['LSselect'][$id]['selected_objects'])." selected object(s)."
|
||||
);
|
||||
self :: setSelectedObjects($id, $current_selected_objects);
|
||||
self :: log_debug("Initialized with id=$id: multiple=".($multiple?'yes':'no')." ".count($_SESSION['LSselect'][$id]['selected_objects'])." selected object(s).");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -220,7 +216,6 @@ class LSselect extends LSlog_staticLoggerClass {
|
|||
* @param array $selected_objects Array of selectable object info with objects's DN
|
||||
* as key and array of object's info as value. Objects's
|
||||
* info currently contains only the object type (key=object_type).
|
||||
* @param bool $check_objects Check selected objects (optional, default: true)
|
||||
*
|
||||
* @return array|false Array of selectable object info with objects's DN as key
|
||||
* and array of object's info as value. Objects's info returned
|
||||
|
@ -229,37 +224,24 @@ class LSselect extends LSlog_staticLoggerClass {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setSelectedObjects($id, $selected_objects, $check_objects=true) {
|
||||
public static function setSelectedObjects($id, $selected_objects) {
|
||||
if (!self :: exists($id))
|
||||
return;
|
||||
if (!is_array($selected_objects))
|
||||
return;
|
||||
$previously_selected = $_SESSION['LSselect'][$id]['selected_objects'];
|
||||
$_SESSION['LSselect'][$id]['selected_objects'] = [];
|
||||
$_SESSION['LSselect'][$id]['selected_objects'] = array();
|
||||
foreach($selected_objects as $dn => $info) {
|
||||
if (!is_array($info) || !isset($info['object_type'])) {
|
||||
self :: log_warning("setSelectedObjects($id): invalid object info for dn='$dn'");
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
$check_objects
|
||||
&& !(
|
||||
in_array($dn, $previously_selected)
|
||||
|| self :: checkObjectIsSelectable($id, $info['object_type'], $dn)
|
||||
)
|
||||
) {
|
||||
self :: log_warning(
|
||||
"setSelectedObjects($id): object type='{$info['object_type']}' and dn='$dn' is not ".
|
||||
"selectable"
|
||||
);
|
||||
continue;
|
||||
if (self :: checkObjectIsSelectable($id, $info['object_type'], $dn))
|
||||
$_SESSION['LSselect'][$id]['selected_objects'][$dn] = $info;
|
||||
else {
|
||||
self :: log_warning("setSelectedObjects($id): object type='".$info['object_type']."' and dn='$dn' is not selectable".varDump($_SESSION['LSselect'][$id]));
|
||||
}
|
||||
$_SESSION['LSselect'][$id]['selected_objects'][$dn] = $info;
|
||||
}
|
||||
self :: log_debug(
|
||||
"setSelectedObjects($id): updated with ".
|
||||
count($_SESSION['LSselect'][$id]['selected_objects'])." selected object(s)."
|
||||
);
|
||||
self :: log_debug("id=$id: updated with ".count($_SESSION['LSselect'][$id]['selected_objects'])." selected object(s).");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -268,46 +250,29 @@ class LSselect extends LSlog_staticLoggerClass {
|
|||
* @param string $id The LSselect ID
|
||||
* @param string $object_type The object type
|
||||
* @param string $object_dn The object DN
|
||||
* @param bool $check_exists Check if object exists in LDAP (optional, default: true)
|
||||
*
|
||||
* @return boolean True if object is selectable, false otherwise
|
||||
*/
|
||||
public static function checkObjectIsSelectable($id, $object_type, $object_dn, $check_exists=true) {
|
||||
public static function checkObjectIsSelectable($id, $object_type, $object_dn) {
|
||||
if (!self :: exists($id)) {
|
||||
self :: log_warning(
|
||||
"checkObjectIsSelectable($id, $object_type, $object_dn): LSselect $id doesn't exists"
|
||||
);
|
||||
self :: log_warning("checkObjectIsSelectable($id, $object_type, $object_dn): LSselect $id doesn't exists");
|
||||
return false;
|
||||
}
|
||||
if (!array_key_exists($object_type, $_SESSION['LSselect'][$id]['LSobjects'])) {
|
||||
self :: log_warning(
|
||||
"checkObjectIsSelectable($id, $object_type, $object_dn): object type $object_type not ".
|
||||
"selectable"
|
||||
);
|
||||
self :: log_warning("checkObjectIsSelectable($id, $object_type, $object_dn): object type $object_type not selectabled");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load LSobject type
|
||||
if ( !LSsession :: loadLSobject($object_type) ) {
|
||||
self :: log_warning(
|
||||
"checkObjectIsSelectable($id, $object_type, $object_dn): fail to load object type ".
|
||||
$object_type
|
||||
);
|
||||
self :: log_warning("checkObjectIsSelectable($id, $object_type, $object_dn): fail to load object type $object_type");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check object exists
|
||||
if (
|
||||
$check_exists
|
||||
&& !$object_type :: exists(
|
||||
$object_dn,
|
||||
self :: getConfig($id, "LSobjects.$object_type.filter", null, "string")
|
||||
)
|
||||
) {
|
||||
self :: log_warning(
|
||||
"checkObjectIsSelectable($id, $object_type, $object_dn): object $object_dn not found ".
|
||||
"(or does not match with selection filter)"
|
||||
);
|
||||
// Instanciate object and load object data from DN
|
||||
$object = new $object_type();
|
||||
if (!$object -> loadData($object_dn, self :: getConfig($id, "LSobjects.$object_type.filter", null))) {
|
||||
self :: log_warning("checkObjectIsSelectable($id, $object_type, $object_dn): object $object_dn not found (or does not match with selection filter)");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue