Code

Updated filter Editor
[gosa.git] / gosa-plugins / groupware / personal / groupware / class_filterEditor.inc
1 <?php
3 class filterEditor extends plugin
4 {
5     function __construct($config, $parent, $filter)
6     {
7         $this->config = &$config;
8         $this->parent = &$parent;
9         $this->filter = $filter;
10     }
12     function execute()
13     {
14         $smarty = get_smarty();
15         $smarty->assign('NAME',set_post($this->filter['NAME']));    
16         $smarty->assign('DESC',set_post($this->filter['DESC']));    
17         $smarty->assign('filterStr', $this->renderFilter());    
19         return($smarty->fetch(get_template_path('filterEditor.tpl',TRUE,dirname(__FILE__))));
20     }
22     function renderFilter()
23     {
24         $filter = $this->filter;
26         $actions = array(
27                 "MOVE" => _("move mail to"),
28                 "COPY" => _("copy mail to"),
29                 "FORWARD" => _("forward message to"),
30                 "MARK" => _("mark mail as "),
31                 "DROP" => _("remove mail"),
32                 "REPLY" => _("reply"));
34         $fields = array(
35                 'subject' => _("Subject"),
36                 'from'=> _("From"),
37                 'body'=> _("Body"),
38                 'date'=> _("Date"),
39                 'priority'=> _("Priority"),
40                 'status'=> _("Status"),
41                 'to'=> _("To"),
42                 'cc'=> _("CC"),
43                 'age'=> _("Age"),
44                 'size'=> _("Size"));
46         $comparators = array(
47                 "is" => _("is"),
48                 "is not" => _("is not"), 
49                 "equal" => _("is equal"),       
50                 "not equal" => _("is not equal"),   
51                 "is empty" => _("is empty"),
52                 "is not empty" => _("is not empty"),
53                 "contains" => _("contains"),
54                 "contains not" => _("does not contain"),
55                 "is in addressbook" => _("is in the addressbook"),
56                 "is not in addressbook" => _("is not in the addressbook"),
57                 "greater than" => _("is greater than"),
58                 "less than" => _("smaller than"));
60         
62         $cnt = count($filter['CONDITIONS']);
63         $str = "<h3>"._("Filter conditions")."</h3>";
64         $str.= "<ul>";
65         foreach($filter['CONDITIONS'] as $id => $cond){
66             $str .= "<li>";
67             $str .= _("Check field")."&nbsp;";
68             $str .= "\n<select name='cField_{$id}' onChange='document.mainform.submit();'>";
69             foreach($fields as $field => $desc){
70                 $checked = ($field == $cond['FIELD'])? ' selected ' : '';
71                 $str.= "\n<option {$checked} value=\"".set_post($field)."\">".set_post($desc)."</option>";
72             }
73             $str .= "\n</select>";
74             $str .= "&nbsp;"._("if it")."&nbsp;";
75             $str .= "\n<select name='cComparator_{$id}' onChange='document.mainform.submit();'>";
76             foreach($comparators as $comparator => $desc){
77                 $checked = ($comparator == $cond['COMPARATOR'])? ' selected ' : '';
78                 $str.= "\n<option {$checked} value=\"".set_post($comparator)."\">".set_post($desc)."</option>";
79             }
80             $str .= "\n</select>";
81             if(!in_array($cond['COMPARATOR'], array('is in addressbook','is not in addressbook','is empty','is not empty'))){
82                 $str .= "<input type='text' name='cMatch_{$id}' value=\"".set_post($cond['MATCH'])."\">";
83             }
84             $cnt --;
85             $str .= "</li>";
86             if($cnt) $str .= $filter['TYPE'];
87         } 
88         $str .= "</ul>";
89        
90         $str .= "<hr>";
91         $str .= "<h3>"._("Filter actions")."</h3>";
93         $str.= "<ul>";
94         foreach($filter['ACTION'] as $id => $action){
95             $str .= "<li>";
96             $str .= "\n<select name='cAction_{$id}' onChange='document.mainform.submit();'>";
97             foreach($actions as $act => $desc){
98                 $checked = ($act == $action['ACTION'])? ' selected ' : '';
99                 $str.= "\n<option {$checked} value=\"".set_post($act)."\">".set_post($desc)."</option>";
100             }
101             $str .= "</select>";
102             if(!in_array($action['ACTION'], array('remove'))){
103                 $str .= "<input type='text' name='cValue_{$id}' value=\"".set_post($action['VALUE'])."\">";
104             }
105             $str .= "</li>";
106         }
107         $str.= "</ul>";
108     
110         return($str);
111     }
114     function save_object()
115     {
116         foreach($this->filter['CONDITIONS'] as $id => $value){
117             if(isset($_POST['cField_'.$id])){
118                 $this->filter['CONDITIONS'][$id]['FIELD'] = get_post('cField_'.$id);
119             }
120             if(isset($_POST['cComparator_'.$id])){
121                 $this->filter['CONDITIONS'][$id]['COMPARATOR'] = get_post('cComparator_'.$id);
122             }
123             if(isset($_POST['cMatch_'.$id])){
124                 $this->filter['CONDITIONS'][$id]['MATCH'] = get_post('cMatch_'.$id);
125             }
126         }
127         foreach($this->filter['ACTION'] as $id => $value){
128             if(isset($_POST['cAction_'.$id])){
129                 $this->filter['ACTION'][$id]['ACTION'] = get_post('cAction_'.$id);
130             }
131             if(isset($_POST['cValue_'.$id])){
132                 $this->filter['ACTION'][$id]['VALUE'] = get_post('cValue_'.$id);
133             }
134         }
135     }
137 ?>