X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Finclude%2Fclass_filter.inc;h=04de2dae2c5cb13fce48ef21f3638fe6ce823937;hb=c9bd6c4d92532063a9dd8df3cfd20740d43e5841;hp=2afa3fe60685fe2e85029debd50dcb29552e9c1c;hpb=5ab7ebd28e53d52c3e6f3eddebde408550226ec2;p=gosa.git diff --git a/gosa-core/include/class_filter.inc b/gosa-core/include/class_filter.inc index 2afa3fe60..04de2dae2 100644 --- a/gosa-core/include/class_filter.inc +++ b/gosa-core/include/class_filter.inc @@ -22,12 +22,11 @@ class filter { - var $xmlData; var $searches= array(); + var $xmlSearches= array(); + var $attributes= array(); var $search; - - #FIXME - Seems to be obsolete. Categories are defined in the listing.xml - # and not in the filter.xml anymore. + var $defaultSearch; var $category= ""; var $objectStorage= array(); var $base= ""; @@ -39,16 +38,6 @@ class filter { var $converter= null; var $pid; - /* An editor which allows to create user defined ldap-filter. - * Due to the fact that it requires additional ldap schemata - * (objectClasses=gosaProperties) this is currently optional. - */ - var $filterEditor = NULL; - - /* The categories this filter is made for (e.g. ['users'] or. ['server','workstation']). - * Since this is set we are able to create user defined filters. - */ - var $categories = array(); function filter($filename) { @@ -66,34 +55,34 @@ class filter { function load($filename) { $contents = file_get_contents($filename); - $this->xmlData= xml::xml2array($contents, 1); + $xmlData= xml::xml2array($contents, 1); - if (!isset($this->xmlData['filterdef'])) { + if (!isset($xmlData['filterdef'])) { return false; } - $this->xmlData= $this->xmlData["filterdef"]; + $xmlData= $xmlData["filterdef"]; // Load filter - if (isset($this->xmlData['search'])) { + if (isset($xmlData['search'])) { // Array conversion - if (!is_array($this->xmlData['search'])) { - $searches= array($this->xmlData['search']); + if (!isset($xmlData['search'][0])) { + $searches= array($xmlData['search']); } else { - $searches= $this->xmlData['search']; + $searches= $xmlData['search']; } /* Store available searches */ - foreach ($this->xmlData['search'] as $search) { + foreach ($searches as $search) { /* Do multi conversation */ - if (!is_array($search['query'])){ + if (!isset($search['query'][0])){ $search['query']= array($search['query']); } /* Store search */ - $this->searches[$search['label']]= $search; + $this->xmlSearches[$search['tag']]= $search; } } else { @@ -101,38 +90,60 @@ class filter { } // Transfer scope - $this->scopeMode= $this->xmlData['definition']['scope']; + $this->scopeMode= $xmlData['definition']['scope']; if ($this->scopeMode == "auto") { $this->scope= "one"; } else { $this->scope= $this->scopeMode; } + // Transfer attributes + $this->attributes= $xmlData['definition']['attribute']; + if (!is_array($this->attributes)) { + $this->attributes= array($this->attributes); + } + // Transfer initial value - if (isset($this->xmlData['definition']['initial']) && $this->xmlData['definition']['initial'] == "true"){ + if (isset($xmlData['definition']['initial']) && $xmlData['definition']['initial'] == "true"){ $this->initial= true; } // Transfer category - if (isset($this->xmlData['definition']['category'])){ - $this->category= $this->xmlData['definition']['category']; + if (isset($xmlData['definition']['category'])){ + $this->category= $xmlData['definition']['category']; + } + if (!is_array($this->category)) { + $this->category= array($this->category); } - // Set default search mode - $this->setSearch($this->xmlData['definition']['default']); + // Initialize searches and default search mode + $this->defaultSearch= $xmlData['definition']['default']; + $this->reloadFilters(); + $this->setSearch($this->defaultSearch); return true; } - function setSearch($method) + function reloadFilters() { - // Move information + $this->searches= array_merge($this->xmlSearches, userFilter::getFilter($this->category)); + $this->setSearch($this->search); + } + + + function setSearch($method= null) + { + $patch= null; + + // Maybe our search method has gone? + if (!isset($this->searches[$method])) { + $method= $this->defaultSearch; + } + + // Try to use it, but bail out if there's no help... if (isset($this->searches[$method])) { $this->query= $this->searches[$method]['query']; - if (!isset($this->query[0])) { - $this->query= array($this->query); - } $this->search= $method; } else { die ("Invalid search module!"); @@ -140,19 +151,12 @@ class filter { } - function getTextfield($element) + function getTextfield($tag, $value= "", $element= null) { - $tag= $element['tag']; $size= 30; - if (isset($element['size'])){ - $size= $element['size']; - } $maxlength= 30; - if (isset($element['maxlength'])){ - $maxlength= $element['maxlength']; - } - $result= ""; - if (isset($element['autocomplete'])) { + $result= ""; + if ($element && isset($element['autocomplete'])) { $frequency= "0.5"; $characters= "1"; if (isset($element['autocomplete']['frequency'])) { @@ -166,7 +170,7 @@ class filter { "new Ajax.Autocompleter('$tag', 'autocomplete$tag', 'autocomplete.php', { minChars: $characters, frequency: $frequency });". ""; - $this->autocompleters[$tag]= $element['autocomplete']; + $this->autocompleters[$tag]= $element; } return $result; } @@ -216,23 +220,11 @@ class filter { } - function renderApply() - { - return (""); - } - - - function renderScope() - { - $checked= $this->scope == "sub"?" checked":""; - return " "; - } - function render() { - $content= "
".$this->renderFilterMenu().""; - $content.= "
". + $content= "
".$this->renderFilterMenu().""; + $content.= "
".$this->getTextfield('search_filter', $this->value, $this->searches[$this->search])."
". " 
"; // Return meta data @@ -250,10 +242,9 @@ class filter { $this->initial= true; return $result; } - // Go thru all queries and merge results foreach ($this->query as $query) { - if (!isset($query['backend']) || !isset($query['filter']) || !isset($query['attribute'])) { + if (!isset($query['backend']) || !isset($query['filter'])) { die("No backend specified in search config."); } @@ -265,12 +256,15 @@ class filter { // Load filter and attributes $filter= $query['filter']; - $attributes= $query['attribute']; // Handle converters if present if ($this->converter) { preg_match('/([^:]+)::(.*)$/', $this->converter, $m); - $filter= call_user_func(array($m[1], $m[2]), preg_replace('/\$/', $this->value, $filter)); + if ($this->value == "") { + $filter= call_user_func(array($m[1], $m[2]), preg_replace('/\$/', "*", $filter)); + } else { + $filter= call_user_func(array($m[1], $m[2]), preg_replace('/\$/', $this->value, $filter)); + } } // Do not replace escaped \$ - This is required to be able to search for e.g. windows machines. @@ -280,7 +274,7 @@ class filter { $filter= preg_replace("/\\$/", "*".normalizeLdap($this->value)."*", $filter); } - $result= array_merge($result, call_user_func(array($backend, 'query'), $this->base, $this->scope, $filter, $attributes, $this->categories, $this->objectStorage)); + $result= array_merge($result, call_user_func(array($backend, 'query'), $this->base, $this->scope, $filter, $this->attributes, $this->category, $this->objectStorage)); } return ($result); @@ -290,15 +284,24 @@ class filter { function update() { if (isset($_POST['FILTER_PID']) && $_POST['FILTER_PID'] == $this->pid) { - // Save input field if (isset($_POST['search_filter'])) { $this->value= validate($_POST['search_filter']); } // Save scope if needed - if ($this->scopeMode == "auto") { - $this->scope= isset($_POST['SCOPE'])?"sub":"one"; + if ($this->scopeMode == "auto" && isset($_POST['act']) && $_POST['act'] == "toggle-subtree") { + $this->scope= ($this->scope == "one")?"sub":"one"; + } + + // Switch filter? + if (isset($_POST['act'])) { + foreach ($this->searches as $tag => $cfg) { + if ($_POST['act'] == "filter-$tag") { + $this->setSearch($tag); + break; + } + } } } @@ -310,27 +313,30 @@ class filter { 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']; + // Load result attributes + $attributes= $config['autocomplete']['attribute']; if (!is_array($attributes)) { $attributes= array($attributes); } - // Make filter - $filter= preg_replace("/\\$/", normalizeLdap($value), $filter); - if (isset($config['base']) && isset($config['scope']) && isset($config['category'])) { - $result= call_user_func(array($backend, 'query'), $config['base'], $config['scope'], $filter, $attributes, - $config["category"], $config["objectStorage"]); - } else { - $result= call_user_func(array($backend, 'query'), $this->base, $this->scope, $filter, $attributes, - $this->categories, $this->objectStorage); + // Do the query + $result= array(); + + // Is backend available? + # FIXME + $queries= $config['query']; + if (!isset($queries[0])){ + $queries= array($queries); + } + foreach ($queries as $query) { + $backend= "filter".$query['backend']; + if (!isset($class_mapping["$backend"])) { + die("Invalid backend specified in search config."); + } + $filter= preg_replace("/\\$/", "*".normalizeLdap($value)."*", $query['filter']); + + $result= array_merge($result, call_user_func(array($backend, 'query'), $this->base, $this->scope, $filter, $attributes, + $this->category, $this->objectStorage)); } foreach ($result as $entry) { @@ -360,7 +366,7 @@ class filter { $max= 25; if(isset($this->searches[$this->search]['autocomplete'])){ - $result= $this->getCompletitionList($this->searches[$this->search]['autocomplete'], $_POST['search_filter']); + $result= $this->getCompletitionList($this->searches[$this->search], $_POST['search_filter']); $result= array_unique($result); asort($result); @@ -405,33 +411,56 @@ class filter { function renderFilterMenu() { // Load shortcut - $result= "
". - "$script"; } - - function setCategories($categories) + function getFixedFilters() { - if(!is_array($categories) && !empty($categories)){ - $categories = array($categories) ; - } - $this->categories = $categories; + return array_keys($this->searches); } + }