Code

Updated filter Edtor
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 6 Sep 2010 14:16:06 +0000 (14:16 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 6 Sep 2010 14:16:06 +0000 (14:16 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19533 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/groupware/personal/groupware/class_filterEditor.inc

index 832f3e9a5f996ee4cb025c8174f313f7119fd7c2..5522daa50600ec6f8e6f28ce68514cc4b26f7ff7 100644 (file)
@@ -7,23 +7,9 @@ class filterEditor extends plugin
         $this->config = &$config;
         $this->parent = &$parent;
         $this->filter = $filter;
-    }
-
-    function execute()
-    {
-        $smarty = get_smarty();
-        $smarty->assign('NAME',set_post($this->filter['NAME']));    
-        $smarty->assign('DESC',set_post($this->filter['DESC']));    
-        $smarty->assign('filterStr', $this->renderFilter());    
-
-        return($smarty->fetch(get_template_path('filterEditor.tpl',TRUE,dirname(__FILE__))));
-    }
-
-    function renderFilter()
-    {
-        $filter = $this->filter;
 
-        $actions = array(
+        $this->types = array('OR' => _("or"), 'AND' => _("and"));
+        $this->actions = array(
                 "MOVE" => _("move mail to"),
                 "COPY" => _("copy mail to"),
                 "FORWARD" => _("forward message to"),
@@ -31,7 +17,7 @@ class filterEditor extends plugin
                 "DROP" => _("remove mail"),
                 "REPLY" => _("reply"));
 
-        $fields = array(
+        $this->fields = array(
                 'subject' => _("Subject"),
                 'from'=> _("From"),
                 'body'=> _("Body"),
@@ -43,7 +29,7 @@ class filterEditor extends plugin
                 'age'=> _("Age"),
                 'size'=> _("Size"));
 
-        $comparators = array(
+        $this->comparators = array(
                 "is" => _("is"),
                 "is not" => _("is not"), 
                 "equal" => _("is equal"),       
@@ -56,8 +42,21 @@ class filterEditor extends plugin
                 "is not in addressbook" => _("is not in the addressbook"),
                 "greater than" => _("is greater than"),
                 "less than" => _("smaller than"));
+    }
 
-        
+    function execute()
+    {
+        $smarty = get_smarty();
+        $smarty->assign('NAME',set_post($this->filter['NAME']));    
+        $smarty->assign('DESC',set_post($this->filter['DESC']));    
+        $smarty->assign('filterStr', $this->renderFilter());    
+
+        return($smarty->fetch(get_template_path('filterEditor.tpl',TRUE,dirname(__FILE__))));
+    }
+
+    function renderFilter()
+    {
+        $filter = $this->filter;
 
         $cnt = count($filter['CONDITIONS']);
         $str = "<h3>"._("Filter conditions")."</h3>";
@@ -66,14 +65,14 @@ class filterEditor extends plugin
             $str .= "<li>";
             $str .= _("Check field")."&nbsp;";
             $str .= "\n<select name='cField_{$id}' onChange='document.mainform.submit();'>";
-            foreach($fields as $field => $desc){
+            foreach($this->fields as $field => $desc){
                 $checked = ($field == $cond['FIELD'])? ' selected ' : '';
                 $str.= "\n<option {$checked} value=\"".set_post($field)."\">".set_post($desc)."</option>";
             }
             $str .= "\n</select>";
             $str .= "&nbsp;"._("if it")."&nbsp;";
             $str .= "\n<select name='cComparator_{$id}' onChange='document.mainform.submit();'>";
-            foreach($comparators as $comparator => $desc){
+            foreach($this->comparators as $comparator => $desc){
                 $checked = ($comparator == $cond['COMPARATOR'])? ' selected ' : '';
                 $str.= "\n<option {$checked} value=\"".set_post($comparator)."\">".set_post($desc)."</option>";
             }
@@ -83,9 +82,13 @@ class filterEditor extends plugin
             }
             $cnt --;
             $str .= "</li>";
-            if($cnt) $str .= $filter['TYPE'];
+            if($cnt) $str .= $this->types[$filter['TYPE']];
         } 
         $str .= "</ul>";
+        $str .= "<button name='addCondition'>".msgPool::addButton()."</button> ";
+        if(count($filter['CONDITIONS']) >= 2){
+            $str .= "<button name='removeCondition'>".msgPool::delButton()."</button> ";
+        }
        
         $str .= "<hr>";
         $str .= "<h3>"._("Filter actions")."</h3>";
@@ -94,7 +97,7 @@ class filterEditor extends plugin
         foreach($filter['ACTION'] as $id => $action){
             $str .= "<li>";
             $str .= "\n<select name='cAction_{$id}' onChange='document.mainform.submit();'>";
-            foreach($actions as $act => $desc){
+            foreach($this->actions as $act => $desc){
                 $checked = ($act == $action['ACTION'])? ' selected ' : '';
                 $str.= "\n<option {$checked} value=\"".set_post($act)."\">".set_post($desc)."</option>";
             }
@@ -106,6 +109,10 @@ class filterEditor extends plugin
         }
         $str.= "</ul>";
     
+        $str .= "<button name='addAction'>".msgPool::addButton()."</button> ";
+        if(count($filter['ACTION']) >= 2){
+            $str .= "<button name='removeAction'>".msgPool::delButton()."</button> ";
+        }
 
         return($str);
     }
@@ -132,6 +139,22 @@ class filterEditor extends plugin
                 $this->filter['ACTION'][$id]['VALUE'] = get_post('cValue_'.$id);
             }
         }
+
+        if(isset($_POST['removeCondition']) && count($this->filter['CONDITIONS']) >= 2){
+            array_pop($this->filter['CONDITIONS']);
+        }
+
+        if(isset($_POST['addCondition'])){
+            $this->filter['CONDITIONS'][] = array('FIELD' => key($this->fields),'COMPARATOR' => key($this->comparators), 'MATCH' => '');
+        }
+    
+        if(isset($_POST['removeAction']) && count($this->filter['ACTION']) >= 2){
+            array_pop($this->filter['ACTION']);
+        }
+
+        if(isset($_POST['addAction'])){
+            $this->filter['ACTION'][] = array('ACTION' => 'MOVE', 'VALUE' => '');
+        }
     }
 }
 ?>