diff --git a/include/class_objects.inc b/include/class_objects.inc index c0fae81ef829a61655ec951e83216d864bf4f514..48fea29e12fe298182b5c1f1fe495550ea0ab079 100644 --- a/include/class_objects.inc +++ b/include/class_objects.inc @@ -352,7 +352,7 @@ class objects return static::open('new', $type); } - static function infos ($type) + static function &infos ($type) { global $config; @@ -395,11 +395,7 @@ class objects { global $config; - if (!isset($config->data['OBJECTS'][strtoupper($type)])) { - throw new NonExistingObjectTypeException('Non-existing type "'.$type.'"'); - } - - $infos =& $config->data['OBJECTS'][strtoupper($type)]; + $infos =& static::infos($type); if (!isset($infos['filterObject'])) { $infos['filterObject'] = ldapFilter::parse($infos['filter']); @@ -407,6 +403,20 @@ class objects return $infos['filterObject']; } + /* This method allows to cache searched attributes list in objectTypes */ + static function getSearchedAttributes ($type) + { + global $config; + + $infos =& static::infos($type); + + if (!isset($infos['searchAttributes'])) { + $infos['searchAttributes'] = array_unique(array($infos['mainAttr'], $infos['nameAttr'])); + } + + return $infos['searchAttributes']; + } + static function types () { global $config; diff --git a/include/management/class_managementFilter.inc b/include/management/class_managementFilter.inc index 279b5fddc8f4d008d93e339b1e528a89cd7aa4ae..25bb7a5c597d03d1741a132658ff9caff61575e8 100644 --- a/include/management/class_managementFilter.inc +++ b/include/management/class_managementFilter.inc @@ -25,7 +25,7 @@ class managementFilter { protected $types; - protected $searchAttributes = array('cn', 'description'); + protected $searchAttributes = array(); protected $scope = 'one'; protected $showTemplates = FALSE; @@ -61,6 +61,7 @@ class managementFilter 'filters' => array(), 'infos' => objects::infos($type), ); + $this->searchAttributes = array_unique(array_merge($this->searchAttributes, objects::getSearchedAttributes($type))); } $this->filterElements = array( @@ -132,15 +133,6 @@ class managementFilter { global $ui; - $elementFilters = array(); - if (!empty($this->search)) { - if (preg_match('/^\(.+\)$/', $this->search)) { - $elementFilters[] = $this->search; - } else { - $elementFilters[] = '(|('.implode('=*'.$this->search.'*)(', $this->searchAttributes).'=*'.$this->search.'*))'; - } - } - $objectTypeCount = array(); $entries = array(); $row = 0; @@ -171,6 +163,15 @@ class managementFilter } } + $elementFilters = array(); + if (!empty($this->search)) { + if (preg_match('/^\(.+\)$/', $this->search)) { + $elementFilters[] = $this->search; + } else { + $elementFilters[] = '(|('.implode('=*'.$this->search.'*)(', objects::getSearchedAttributes($type)).'=*'.$this->search.'*))'; + } + } + $typeElementFilters = $elementFilters; foreach ($this->filterElements as $element) { $skip = $element->getFilters($type, $typeElementFilters);