Code

Added is_harmless
[gosa.git] / gosa-core / include / class_userFilterEditor.inc
index ea8bc2ead3a6d4d25d6b3e71929417c5e143fbee..a14215d7d768b1a1ac7e1be1102c3788e7dc28f0 100644 (file)
@@ -16,27 +16,27 @@ class userFilterEditor extends plugin
   public $enabled = TRUE;
   public $queries = array();
 
+  public $listing = NULL;
+
   // The list of all categories mangaged by the current filter object.
   // Used in the grop-down box.
-  public $availableCategories = array();
-  public $fixedFilters = array();
   public $orig_name = "";
+  public $backends = array('LDAP', 'SYSTEMS', 'FAI', 'GroupLDAP','ACL', 'OPSIPackages','APPLICATIONS','MIMETYPES');  
 
 
   /*! \brief    Instantiate the filter editing dialog. 
    *            Parses the filter info into editable data.
    */
-  function __construct($entry, $categories, $fixedFilters)
+  function __construct($entry, $listing)
   {
-    $this->availableCategories = $categories;
-    $this->fixedFilters = $fixedFilters;
+    $this->listing = &$listing;
     if($entry){
       $this->entry = $entry;
       $this->parent = $entry['parent'];
-      $this->name = $entry['name'];
+      $this->name = $entry['tag'];
       $this->description = $entry['description'];
       
-      foreach($entry['queries'] as $query){
+      foreach($entry['query'] as $query){
         $query['filter'] = userFilterEditor::_autoIndentFilter($query['filter'], "  ");
         $this->queries[] = $query;
       }
@@ -117,6 +117,8 @@ class userFilterEditor extends plugin
   {
     plugin::execute();
 
+    $smarty = get_smarty();
+
     // Build up HTML compliant html output
     $queries = array();
     foreach($this->queries as $key => $query){
@@ -124,16 +126,19 @@ class userFilterEditor extends plugin
       $queries[$key] = $query; 
     }  
 
-    $smarty = get_smarty();
+    // Build up list of hard coded filters 
+    $filter= $this->listing->getFilter();
+
+    $smarty->assign("fixedFilters", array_keys($filter->searches));
     $smarty->assign('parent', $this->parent);
+    $smarty->assign('backends', $this->backends);
     $smarty->assign('name', htmlentities($this->name,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'));
     $smarty->assign('selectedCategories', $this->selectedCategories);
-    $smarty->assign('availableCategories', $this->availableCategories);
-    $smarty->assign('fixedFilters', $this->fixedFilters);
+    $smarty->assign('availableCategories', array_unique($this->listing->categories));
     return($smarty->fetch(get_template_path('userFilterEditor.tpl', FALSE)));
   }
 
@@ -182,6 +187,7 @@ class userFilterEditor extends plugin
         }elseif(isset($_POST['availableCategory']) && !empty($_POST['availableCategory'])){
           $this->selectedCategories[] = get_post('availableCategory');
         }
+        $this->selectedCategories = array_unique($this->selectedCategories);
       }
 
       // Remove categories
@@ -193,7 +199,23 @@ class userFilterEditor extends plugin
 
       // Add new query 
       if(isset($_POST['addQuery'])){
-        $this->queries[] = array('backend'=>'filterLDAP', 'filter' => '(objectClass=*)');
+
+        $filter= $this->listing->getFilter();
+        $backend = 'LDAP';
+        $query = "(objectClass=*)";
+        if(isset($filter->searches[$this->parent])){
+      
+          $tmp = $filter->searches[$this->parent];  
+          if(isset($tmp['query'][count($this->queries)])){
+            $query = $tmp['query'][count($this->queries)]['filter'];
+            $backend = $tmp['query'][count($this->queries)]['backend'];
+          }elseif(isset($tmp['query']['filter'])){
+            $query = $tmp['query']['filter'];
+            $backend = $tmp['query']['backend'];
+          }
+        }
+
+        $this->queries[] = array('backend'=> $backend, 'filter' => userFilterEditor::_autoIndentFilter($query,"  "));
       }
     }
   }
@@ -226,7 +248,7 @@ class userFilterEditor extends plugin
       $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);
+        $msgs[] = sprintf(_("Error in filter #%s: %s opening and %s closing brackets detected!"), bold($key+1), bold($o), bold($c));
       }
     }
 
@@ -242,10 +264,10 @@ class userFilterEditor extends plugin
   {
     $ret= array();
     $ret['parent'] = $this->parent;
-    $ret['name'] = $this->name;
+    $ret['tag'] = $this->name;
     $ret['description'] = $this->description;
     $ret['categories'] = $this->selectedCategories;
-    $ret['queries'] = $this->queries;
+    $ret['query'] = $this->queries;
     $ret['flags'] = array();
     if($this->share){
       $ret['flags'][] = "share";