From ec2b2c99f539fd4d77ba41316b441fd12a70cc61 Mon Sep 17 00:00:00 2001 From: cajus Date: Mon, 10 Aug 2009 09:05:47 +0000 Subject: [PATCH] Updated filters git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14022 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/class_filter.inc | 126 ++++++++++++++---- .../admin/users/class_userManagement.inc | 3 +- .../admin/users/user-filter.tpl} | 0 .../admin/users}/user-filter.xml | 7 +- 4 files changed, 105 insertions(+), 31 deletions(-) rename gosa-core/{ihtml/themes/default/filter/users.tpl => plugins/admin/users/user-filter.tpl} (100%) rename gosa-core/{contrib/filters => plugins/admin/users}/user-filter.xml (93%) diff --git a/gosa-core/include/class_filter.inc b/gosa-core/include/class_filter.inc index a82994293..dd3c9b335 100644 --- a/gosa-core/include/class_filter.inc +++ b/gosa-core/include/class_filter.inc @@ -14,6 +14,7 @@ class filter { var $bases= array(); var $scope= ""; var $query; + var $initial= false; var $baseMode= false; var $scopeMode= "auto"; var $alphabet= null; @@ -53,6 +54,11 @@ class filter { return false; } + // Transfer initial value + if (isset($this->xmlData['definition']['initial']) && $this->xmlData['definition']['initial'] == "true"){ + $this->initial= true; + } + // Generate formular data if (isset($this->xmlData['element'])) { if (!isset($this->xmlData['element'][0])){ @@ -133,13 +139,55 @@ class filter { function getCombobox($element) { $result= ""; return $result; @@ -296,7 +344,7 @@ class filter { } // Load template - return ("".$smarty->fetch(get_template_path("filter/".$this->xmlData['definition']['template']))); + return ("".$smarty->fetch(get_template_path($this->xmlData['definition']['template'], true))); } @@ -401,6 +449,51 @@ class filter { } + function getCompletitionList($config, $tag, $value="*") + { + global $class_mapping; + $res= array(); + + // Is backend available? + $backend= "filter".$config['backend']; + if (!isset($class_mapping["$backend"])) { + die("Invalid backend specified in search config."); + } + + // Load filter and attributes + $filter= $config['filter']; + $attributes= $config['attribute']; + if (!is_array($attributes)) { + $attributes= array($attributes); + } + + // Make filter + $filter= preg_replace("/\\$$tag/", normalizeLDAP($value), $filter); + if (isset($config['base']) && isset($config['scope']) + && isset($config['category']) && isset($config['objectbase']) ) { + $result= call_user_func(array($backend, 'query'), $config['base'], $config['scope'], $filter, $attributes, + $config["category"], $config["objectbase"]); + } else { + $result= call_user_func(array($backend, 'query'), $this->base, $this->scope, $filter, $attributes, + $this->category, $this->objectStorage, $this->objectBase); + } + + foreach ($result as $entry) { + foreach ($attributes as $attribute) { + if (is_array($entry[$attribute])) { + for ($i= 0; $i<$entry[$attribute]['count']; $i++) { + $res[]= $entry[$attribute][$i]; + } + } else { + $res[]= $entry[$attribute]; + } + } + } + + return $res; + } + + function processAutocomplete() { global $class_mapping; @@ -408,36 +501,11 @@ class filter { foreach ($this->autocompleters as $tag => $config) { if(isset($_POST[$tag])){ - - // Is backend available? - $backend= "filter".$config['backend']; - if (!isset($class_mapping["$backend"])) { - die("Invalid backend specified in search config."); - } - - // Load filter and attributes - $filter= $config['filter']; - $attributes= $config['attribute']; - if (!is_array($attributes)) { - $attributes= array($attributes); - } - - // Make filter - $filter= preg_replace("/\\$$tag/", normalizeLDAP($_POST[$tag]), $filter); - $result= call_user_func(array($backend, 'query'), $this->base, $this->scope, $filter, $attributes, - $this->category, $this->objectStorage, $this->objectBase); + $result= $this->getCompletitionList($config, $tag, $_POST[$tag]); echo ''; diff --git a/gosa-core/plugins/admin/users/class_userManagement.inc b/gosa-core/plugins/admin/users/class_userManagement.inc index 1d1a6e98c..9b4d57f82 100644 --- a/gosa-core/plugins/admin/users/class_userManagement.inc +++ b/gosa-core/plugins/admin/users/class_userManagement.inc @@ -979,11 +979,12 @@ class userManagement extends plugin $this->DivListUsers->setEntries($this->list); # FILTER Test ################################################# - #$filter = new filter(CONFIG_DIR."/filters/user-filter.xml"); + #$filter = new filter(get_template_path("user-filter.xml", true)); #$filter->setObjectStorage(get_people_ou()); #$filter->setCategory("users"); #$filter->setCurrentBase($this->DivListUsers->selectedBase); #$filter->update(); + #session::set('autocomplete', $filter); #if (!$filter->isValid()){ # msg_dialog::display(_("Filter error"), _("The filter is uncomplete!"), ERROR_DIALOG); #} else { diff --git a/gosa-core/ihtml/themes/default/filter/users.tpl b/gosa-core/plugins/admin/users/user-filter.tpl similarity index 100% rename from gosa-core/ihtml/themes/default/filter/users.tpl rename to gosa-core/plugins/admin/users/user-filter.tpl diff --git a/gosa-core/contrib/filters/user-filter.xml b/gosa-core/plugins/admin/users/user-filter.xml similarity index 93% rename from gosa-core/contrib/filters/user-filter.xml rename to gosa-core/plugins/admin/users/user-filter.xml index 6c12d70f3..f20b928af 100644 --- a/gosa-core/contrib/filters/user-filter.xml +++ b/gosa-core/plugins/admin/users/user-filter.xml @@ -3,7 +3,8 @@ users - + + true @@ -101,6 +102,10 @@ LDAP + dc=gonicus,dc=de + sub + roles + ou=roles (objectClass=organizationalRole) cn cn -- 2.30.2