X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Finclude%2Fclass_filter.inc;h=04de2dae2c5cb13fce48ef21f3638fe6ce823937;hb=c9bd6c4d92532063a9dd8df3cfd20740d43e5841;hp=f28f400c209e2b2f78dae8ea5ed98a05143eaff8;hpb=a196e57e04729d27474f019cc90a913c4cef9538;p=gosa.git diff --git a/gosa-core/include/class_filter.inc b/gosa-core/include/class_filter.inc index f28f400c2..04de2dae2 100644 --- a/gosa-core/include/class_filter.inc +++ b/gosa-core/include/class_filter.inc @@ -22,9 +22,11 @@ class filter { - var $xmlData; var $searches= array(); + var $xmlSearches= array(); + var $attributes= array(); var $search; + var $defaultSearch; var $category= ""; var $objectStorage= array(); var $base= ""; @@ -53,111 +55,95 @@ 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"]; - - // Transfer category - if (isset($this->xmlData['definition']['category'])){ - $this->category= $this->xmlData['definition']['category']; - } + $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']; - } - - // Fix problem with only one defined query. - if(isset($this->xmlData['search']['query'])){ - $this->xmlData['search'] = array($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 */ - $search['fixed'] = TRUE; - $this->searches[$search['tag']]= $search; - } - - $this->reloadUserFilter(); + $this->xmlSearches[$search['tag']]= $search; + } } else { return false; } // 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; } - // Set default search mode - $this->setSearch($this->xmlData['definition']['default']); + // Transfer category + if (isset($xmlData['definition']['category'])){ + $this->category= $xmlData['definition']['category']; + } + if (!is_array($this->category)) { + $this->category= array($this->category); + } + + // Initialize searches and default search mode + $this->defaultSearch= $xmlData['definition']['default']; + $this->reloadFilters(); + $this->setSearch($this->defaultSearch); return true; } - function reloadUserFilter() + + function reloadFilters() { - // 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; - } + $this->searches= array_merge($this->xmlSearches, userFilter::getFilter($this->category)); + $this->setSearch($this->search); } - function setSearch($method) + function setSearch($method= null) { $patch= null; - // Move information + // 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!"); @@ -169,7 +155,7 @@ class filter { { $size= 30; $maxlength= 30; - $result= ""; + $result= ""; if ($element && isset($element['autocomplete'])) { $frequency= "0.5"; $characters= "1"; @@ -237,10 +223,7 @@ class filter { function render() { - - $this->reloadUserFilter(); - - $content= "
".$this->renderFilterMenu()." | ";
+ $content= "
|