From c212c6ca3e0bb738fa1d86777407e7cd73e48eec Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 12 Mar 2010 14:17:33 +0000 Subject: [PATCH] Updated filter stuff to support new user filter types git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@16491 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/class_filter.inc | 87 +++++++++++++++----------- gosa-core/include/class_userFilter.inc | 8 +-- 2 files changed, 53 insertions(+), 42 deletions(-) diff --git a/gosa-core/include/class_filter.inc b/gosa-core/include/class_filter.inc index 8733435bf..558c58943 100644 --- a/gosa-core/include/class_filter.inc +++ b/gosa-core/include/class_filter.inc @@ -61,6 +61,11 @@ class filter { $this->xmlData= $this->xmlData["filterdef"]; + // Transfer category + if (isset($this->xmlData['definition']['category'])){ + $this->category= $this->xmlData['definition']['category']; + } + // Load filter if (isset($this->xmlData['search'])) { @@ -85,9 +90,12 @@ class filter { } /* Store search */ + $search['fixed'] = TRUE; $this->searches[$search['tag']]= $search; - } + + $this->reloadUserFilter(); + } else { return false; } @@ -105,34 +113,43 @@ class filter { $this->initial= true; } - // Transfer category - if (isset($this->xmlData['definition']['category'])){ - $this->category= $this->xmlData['definition']['category']; - } - // Set default search mode $this->setSearch($this->xmlData['definition']['default']); return true; } + function reloadUserFilter() + { + // First remove all user filters + foreach($this->searches as $k => $s) { + if(!$s['fixed']) unset($this->searches[$k]); + } + + // Readd user filter. + foreach(userFilter::getFilter(array($this->category)) as $filter){ + $tmp = array(); + $tmp['tag'] = $filter['name']; + $tmp['label'] = $filter['description']; + $tmp['query'] = array(); + foreach($filter['queries'] as $query){ + if(isset($this->searches[$filter['parent']]['query']['attribute'])){ + $query['attribute'] = $this->searches[$filter['parent']]['query']['attribute']; + }else{ + $query['attribute'] = $this->searches[$filter['parent']]['query'][0]['attribute']; + } + $tmp['query'][] = $query; + } + $tmp['autocomplete'] = $this->searches[$filter['parent']]['autocomplete']; + $tmp['fixed'] = FALSE; + $this->searches[$tmp['tag']] = $tmp; + } + } + function setSearch($method) { $patch= null; - if (is_array($this->category)) { - $categories= $this->category; - } else { - $categories= array($this->category); - } - $userfilters= userFilter::getFilter($categories); - - // User filter selected? - if (isset($userfilters[$method])){ - $usermethod= $method; - $patch= $userfilters[$method]['filter']; - $method= $userfilters[$method]['parent']; - } // Move information if (isset($this->searches[$method])) { @@ -141,12 +158,6 @@ class filter { $this->query= array($this->query); } - // Patch first filter? - if ($patch) { - $this->query[0]['filter']= $patch; - $method= $usermethod; - } - $this->search= $method; } else { die ("Invalid search module!"); @@ -226,6 +237,9 @@ class filter { function render() { + + $this->reloadUserFilter(); + $content= "
".$this->renderFilterMenu().""; $content.= "
".$this->getTextfield('search_filter', $this->value, $this->searches[$this->search])."
". " 
"; @@ -296,15 +310,8 @@ class filter { $this->scope= ($this->scope == "one")?"sub":"one"; } - // Switch filter? - if (is_array($this->category)) { - $categories= $this->category; - } else { - $categories= array($this->category); - } - - if (isset($_POST['act'])) { - foreach (array_merge($this->searches, userFilter::getFilter($categories)) as $tag => $cfg) { + if (isset($_POST['act'])){ + foreach ($this->searches as $tag => $cfg) { if ($_POST['act'] == "filter-$tag") { $this->setSearch($tag); break; @@ -427,6 +434,9 @@ class filter { // Build in filters foreach ($this->searches as $tag => $config) { + + if(!$config['fixed']) continue; + if ($tag == $this->search) { $result.= "
  • ".image("images/checked.png")." "._($config['label'])."
  • "; } else { @@ -441,11 +451,14 @@ class filter { } else { $categories= array($this->category); } - foreach (userFilter::getFilter($categories) as $tag => $config) { + + foreach ($this->searches as $tag => $config) { + if($config['fixed']) continue; + if ($tag == $this->search) { - $result.= "".image("images/checked.png")." "._($config['description']).""; + $result.= "".image("images/checked.png")." "._($config['label']).""; } else { - $result.= "".image("images/empty.png")." "._($config['description']).""; + $result.= "".image("images/empty.png")." "._($config['label']).""; } $first= false; diff --git a/gosa-core/include/class_userFilter.inc b/gosa-core/include/class_userFilter.inc index 2bcf9ffd4..c7da3badb 100644 --- a/gosa-core/include/class_userFilter.inc +++ b/gosa-core/include/class_userFilter.inc @@ -206,6 +206,7 @@ class userFilter extends plugin static function getFilter($category=array()) { global $config; + $ldap=$config->get_ldap_link(); $ui = get_userinfo(); $ldap->cd($config->current['BASE']); @@ -219,8 +220,8 @@ class userFilter extends plugin // Remove line breaks from the filter, which may were added for better reading. foreach($tmp['queries'] as $key => $query){ $c = preg_split('/\n/',$query['filter']); - foreach($c as $key => $str) $c[$key] = trim($str); - $tmp['queries'][$key]['filter'] = implode($c); + foreach($c as $cKey => $str) $c[$cKey] = trim($str); + $tmp['queries'][$key]['filter'] = mb_convert_encoding(implode($c),'UTF-8'); } // The filter is visible if it is shared or if is one of our own creations. @@ -228,9 +229,6 @@ class userFilter extends plugin $visible = in_array('enable', $tmp['flags']) && ($attrs['dn'] == $ui->dn || in_array('share', $tmp['flags'])); - // Convert filter encoding - $tmp['filter'] = mb_convert_encoding($tmp['filter'], 'UTF-8'); - // Add filter if it matches the category list if($visible && (count($category) == 0 || array_intersect($category, $tmp['categories']))){ $filter[$tmp['name']] = $tmp; -- 2.30.2