Code

Allow to set multiple queries for a user filter.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 12 Mar 2010 13:20:10 +0000 (13:20 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 12 Mar 2010 13:20:10 +0000 (13:20 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@16487 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/ihtml/themes/modern/userFilterEditor.tpl
gosa-core/include/class_userFilter.inc
gosa-core/include/class_userFilterEditor.inc

index f0a1ae8ce1c1c9327a27fe80a12a20496f34a024..99dd4f20309a0259724b9f26d1e3c72ef6ffa4fc 100644 (file)
 
 <hr>
 
-<b>Filter</b>
-<textarea name='filter' id='filter' cols="0" style='width:100%; height: 250px;'>{$filter}</textarea>
-
+{foreach from=$queries item=item key=key}
+  <b>{t}Query{/t} #{$key}</b><input type='text' name='backend_{$key}' value='{$item.backend}'>
+  <button type='submit' name='removeQuery_{$key}'>{msgPool type='delButton'}</button> 
+  <textarea name='filter_{$key}' id='filter_{$key}' cols="0" 
+      style='width:100%; height: 120px;'>{$item.filter}</textarea>
+  <hr>
+{/foreach}
+  <button type='submit' name='addQuery'>{msgPool type='addButton'}</button> 
 <hr>
 
 <input type='hidden' value='1' name='userFilterEditor'>
index 4d3fbd61e32d237e932da82309a844ef7198707b..a96e1b877347184d76cb14eb71f2d1cb4cc16fb0 100644 (file)
@@ -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;
     }
index 31ea019a7724bdf6ef1e4b166b04e0d9d673ebf0..ea8bc2ead3a6d4d25d6b3e71929417c5e143fbee 100644 (file)
@@ -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";