Code

Fixed multi query editor
[gosa.git] / gosa-core / include / class_userFilter.inc
index c188e981257e630c1755e7904e6806e544a993e0..c7da3badbe3eb6ad75544067c77ad6da94b52c6d 100644 (file)
@@ -2,15 +2,14 @@
 
 class userFilter extends plugin 
 {
-  protected $filters = array();
-  protected $availableCategories = array();
+  public $pathTitle= "Filter";
+
+  public $filters = array();
   
   public $objectclasses = array('gosaProperties');
   public $attributes = array('gosaUserDefinedFilter');
   public $gosaUserDefinedFilter = array();
-
   private $listing = NULL;
-  private $fixedFilter = NULL;
 
   /*! \brief    Returns true if we are able to read and write userFilters 
    *            (schema has to be present, gosaProperties)
@@ -36,10 +35,6 @@ class userFilter extends plugin
     plugin::plugin($config, $ui->dn);
     $this->listing = &$listing;
     $filter= $this->listing->getFilter();
-    $this->fixedFilter = $filter->getFixedFilters();
-
-    // Keep list of currently managed categories.
-    $this->availableCategories = array_unique($this->listing->categories);
 
     // Load list of filters
     if(isset($this->attrs['gosaUserDefinedFilter'])){
@@ -52,7 +47,7 @@ class userFilter extends plugin
     }
 
     // Create the filter list
-    $this->filterWidget= new sortableListing();
+    $this->filterWidget= new sortableListing($this->filters, $this->convertFilterList());
     $this->filterWidget->setDeleteable(true);
     $this->filterWidget->setEditable(true);
     $this->filterWidget->setWidth("100%");
@@ -60,15 +55,14 @@ class userFilter extends plugin
     $this->filterWidget->setHeader(array(_("Parent filter"),_("Name"),_("Description"),_("Category"),_("Options"),""));
     $this->filterWidget->setColspecs(array('80px', '100px', '200px', '120px','150px'));
     $this->filterWidget->setAcl($ui->get_permissions($ui->dn,'users/user','gosaUserDefinedFilter'));
-    $this->filterWidget->setListData($this->filters, $this->convertFilterList());
   }
 
   
   /*! \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)){
@@ -81,7 +75,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.
@@ -90,7 +91,7 @@ class userFilter extends plugin
         'name' => $name, 
         'categories' => $categories,
         'description' => base64_decode($description),
-        'filter' => base64_decode($filter),
+        'queries' => $queries,
         'flags' => $flags);
 
     return($tmp);
@@ -123,6 +124,9 @@ class userFilter extends plugin
   function execute()
   {
     plugin::execute();
+    
+    // Let the filter widget update itself
+    $this->filterWidget->update();
 
     // Cancel filter modifications (edit dialog)
     if(isset($_POST['cancelFilterSettings'])){
@@ -165,13 +169,13 @@ class userFilter extends plugin
     if($action['action'] == 'edit' && count($action['targets']) == 1){
       $key= $this->filterWidget->getKey($action['targets'][0]);
       if(isset($this->filters[$key])){
-        $this->dialog=new userFilterEditor($this->filters[$key], $this->availableCategories, $this->fixedFilter);
+        $this->dialog=new userFilterEditor($this->filters[$key], $this->listing);
       }
     }
 
     // Act on new requests
     if(isset($_POST['addFilter'])){
-      $this->dialog=new userFilterEditor(array(), $this->availableCategories, $this->fixedFilter);
+      $this->dialog=new userFilterEditor(array(), $this->listing);
     }
 
     // Act on remove requests 
@@ -202,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']);
@@ -213,19 +218,17 @@ class userFilter extends plugin
         if(!isset($tmp['name'])) continue;
           
         // Remove line breaks from the filter, which may were added for better reading. 
-        $c = preg_split('/\n/',$tmp['filter']);
-
-        foreach($c as $key => $str) $c[$key] = trim($str);
-        $tmp['filter'] = implode($c);
+        foreach($tmp['queries'] as $key => $query){
+          $c = preg_split('/\n/',$query['filter']);
+          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.
         //  ... and enabled.
         $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;
@@ -247,7 +250,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;
     }