From: hickert Date: Fri, 12 Mar 2010 13:20:10 +0000 (+0000) Subject: Allow to set multiple queries for a user filter. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2239cac6b3bc84fbdf54eb0adc1dda0d0b6659e8;p=gosa.git Allow to set multiple queries for a user filter. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@16487 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/ihtml/themes/modern/userFilterEditor.tpl b/gosa-core/ihtml/themes/modern/userFilterEditor.tpl index f0a1ae8ce..99dd4f203 100644 --- a/gosa-core/ihtml/themes/modern/userFilterEditor.tpl +++ b/gosa-core/ihtml/themes/modern/userFilterEditor.tpl @@ -65,9 +65,14 @@
-Filter - - +{foreach from=$queries item=item key=key} + {t}Query{/t} #{$key} + + +
+{/foreach} +
diff --git a/gosa-core/include/class_userFilter.inc b/gosa-core/include/class_userFilter.inc index 4d3fbd61e..a96e1b877 100644 --- a/gosa-core/include/class_userFilter.inc +++ b/gosa-core/include/class_userFilter.inc @@ -4,7 +4,7 @@ class userFilter extends plugin { public $pathTitle= "Filter"; - protected $filters = array(); + public $filters = array(); protected $availableCategories = array(); public $objectclasses = array('gosaProperties'); @@ -67,9 +67,9 @@ class userFilter extends plugin /*! \brief Parses a filter string into an array. */ - static function explodeFilterString($filter) + static function explodeFilterString($filterStr) { - list($parent,$categories, $name, $description, $filter, $flags) = split(";", $filter); + list($parent,$categories, $name, $description, $filterList, $flags) = split(";", $filterStr); // Ensure that we no empty category in our category list. if(empty($categories)){ @@ -82,7 +82,14 @@ class userFilter extends plugin if(empty($flags)){ $flags = array(); }else{ - $flags = split(',', $flags); + $flags = preg_split('/,/', $flags); + } + + // Get filters and their backends + $queries = array(); + foreach(split(",", $filterList) as $data){ + list($filter, $backend) = preg_split('/:/', $data); + $queries[] = array('backend' => $backend, 'filter' => base64_decode($filter)); } // build up filter entry. @@ -91,7 +98,7 @@ class userFilter extends plugin 'name' => $name, 'categories' => $categories, 'description' => base64_decode($description), - 'filter' => base64_decode($filter), + 'queries' => $queries, 'flags' => $flags); return($tmp); @@ -124,7 +131,7 @@ class userFilter extends plugin function execute() { plugin::execute(); - + // Let the filter widget update itself $this->filterWidget->update(); @@ -251,7 +258,12 @@ class userFilter extends plugin $tmp.= implode(',', $filter['categories']).";"; $tmp.= $filter['name'].";"; $tmp.= base64_encode($filter['description']).";"; - $tmp.= base64_encode($filter['filter']).";"; + + // Add queries + foreach($filter['queries'] as $query){ + $tmp.= base64_encode($query['filter']).":".$query['backend'].","; + } + $tmp = trim($tmp,",").";"; $tmp.= implode(',', $filter['flags']); $attrs[] = $tmp; } diff --git a/gosa-core/include/class_userFilterEditor.inc b/gosa-core/include/class_userFilterEditor.inc index 31ea019a7..ea8bc2ead 100644 --- a/gosa-core/include/class_userFilterEditor.inc +++ b/gosa-core/include/class_userFilterEditor.inc @@ -14,7 +14,7 @@ class userFilterEditor extends plugin public $selectedCategories = array(); public $share = FALSE; public $enabled = TRUE; - public $filter = "(objectClass=*)"; + public $queries = array(); // The list of all categories mangaged by the current filter object. // Used in the grop-down box. @@ -35,7 +35,11 @@ class userFilterEditor extends plugin $this->parent = $entry['parent']; $this->name = $entry['name']; $this->description = $entry['description']; - $this->filter = userFilterEditor::_autoIndentFilter($entry['filter'], " "); + + foreach($entry['queries'] as $query){ + $query['filter'] = userFilterEditor::_autoIndentFilter($query['filter'], " "); + $this->queries[] = $query; + } $this->selectedCategories = $entry['categories']; $this->share = in_array("share",$entry['flags']); $this->enable = in_array("enable",$entry['flags']); @@ -112,10 +116,18 @@ class userFilterEditor extends plugin function execute() { plugin::execute(); + + // Build up HTML compliant html output + $queries = array(); + foreach($this->queries as $key => $query){ + $query['filter'] = htmlentities($query['filter'],ENT_COMPAT,'UTF-8'); + $queries[$key] = $query; + } + $smarty = get_smarty(); $smarty->assign('parent', $this->parent); $smarty->assign('name', htmlentities($this->name,ENT_COMPAT,'UTF-8')); - $smarty->assign('filter', htmlentities($this->filter,ENT_COMPAT,'UTF-8')); + $smarty->assign('queries', $queries); $smarty->assign('share', $this->share); $smarty->assign('enable', $this->enabled); $smarty->assign('description', htmlentities($this->description,ENT_COMPAT,'UTF-8')); @@ -141,12 +153,22 @@ class userFilterEditor extends plugin // Filter needs special handling, it may contain charactes like < and > // wich are stipped out by get_post() && validate() - if(isset($_POST['filter'])){ - $f = mb_convert_encoding($_POST['filter'], 'UTF-8'); - if(get_magic_quotes_gpc()){ - $f = stripcslashes($f); + foreach($this->queries as $key => $query){ + if(isset($_POST['filter_'.$key])){ + $f = mb_convert_encoding($_POST['filter_'.$key], 'UTF-8'); + if(get_magic_quotes_gpc()){ + $f = stripcslashes($f); + } + $this->queries[$key]['filter'] = $f; + $this->queries[$key]['backend'] = get_post('backend_'.$key); } - $this->filter = $f; + } + + foreach($this->queries as $key => $query){ + if(isset($_POST['removeQuery_'.$key])){ + unset($this->queries[$key]); + $this->queries = array_values($this->queries); + } } // Get posted flags @@ -168,6 +190,11 @@ class userFilterEditor extends plugin if(isset($this->selectedCategories[$cat])) unset($this->selectedCategories[$cat]); } } + + // Add new query + if(isset($_POST['addQuery'])){ + $this->queries[] = array('backend'=>'filterLDAP', 'filter' => '(objectClass=*)'); + } } } @@ -194,11 +221,13 @@ class userFilterEditor extends plugin } // Count the number of opening and closing brackets - exclude escaped ones. - $f = preg_replace('/\\\\[\(\)]/',"",$this->filter); - $o = substr_count($f, '('); - $c = substr_count($f, ')'); - if($o != $c){ - $msgs[] = sprintf(_("Please check your filter. You have '%s' opening and '%s' closing brackets!"), $o, $c); + foreach($this->queries as $key => $query){ + $f = preg_replace('/\\\\[\(\)]/',"",$query['filter']); + $o = substr_count($f, '('); + $c = substr_count($f, ')'); + if($o != $c){ + $msgs[] = sprintf(_("Please check your filter #%s. You have '%s' opening and '%s' closing brackets!"), ($key+1),$o, $c); + } } return($msgs); @@ -216,7 +245,7 @@ class userFilterEditor extends plugin $ret['name'] = $this->name; $ret['description'] = $this->description; $ret['categories'] = $this->selectedCategories; - $ret['filter'] = $this->filter; + $ret['queries'] = $this->queries; $ret['flags'] = array(); if($this->share){ $ret['flags'][] = "share";