Some language fixes.
[squirrelmail.git] / plugins / filters / options.php
1 <?php
2 /**
3 * Message and Spam Filter Plugin - Filtering Options
4 *
5 * @version $Id$
6 * @copyright (c) 1999-2005 The SquirrelMail Project Team
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
8 * @package plugins
9 * @subpackage filters
10 */
11
12 /**
13 * Path for SquirrelMail required files.
14 * @ignore
15 */
16 define('SM_PATH','../../');
17
18 /* SquirrelMail required files. */
19 require_once(SM_PATH . 'include/validate.php');
20 require_once(SM_PATH . 'functions/imap.php');
21 require_once(SM_PATH . 'plugins/filters/filters.php');
22
23 if (!file_exists(SM_PATH . 'plugins/filters/config.php')) return;
24 include_once (SM_PATH . 'plugins/filters/config.php');
25
26 global $AllowSpamFilters;
27
28 displayPageHeader($color, 'None');
29
30 /* get globals */
31 sqgetGlobalVar('username', $username, SQ_SESSION);
32 sqgetGlobalVar('key', $key, SQ_COOKIE);
33 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
34 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
35
36 sqgetGlobalVar('theid', $theid);
37 sqgetGlobalVar('action', $action, SQ_GET);
38
39 if (sqgetGlobalVar('filter_submit',$filter_submit,SQ_POST)) {
40
41 if(! isset($theid) ) $theid = 0;
42
43 $complete_post=true;
44
45 // FIXME: write human readable error messages
46 sqgetGlobalVar('filter_what', $filter_what, SQ_POST);
47 if (!sqgetGlobalVar('filter_what', $filter_what, SQ_POST)) {
48 do_error("Post error");
49 $complete_post=false;
50 }
51
52 sqgetGlobalVar('filter_where', $filter_where, SQ_POST);
53 if (!sqgetGlobalVar('filter_where', $filter_where, SQ_POST)) {
54 do_error("Post error");
55 $complete_post=false;
56 }
57
58 sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST);
59 if (!sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST)) {
60 do_error("Post error");
61 $complete_post=false;
62 }
63
64 if ($complete_post) {
65 $filter_what = str_replace(',', ' ', $filter_what);
66 $filter_what = str_replace("\\\\", "\\", $filter_what);
67 $filter_what = str_replace("\\\"", '"', $filter_what);
68 $filter_what = str_replace('"', '&quot;', $filter_what);
69
70 if (empty($filter_what)) {
71 do_error(_("WARNING! You must enter something to search for."));
72 $action = 'edit';
73 }
74
75 if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) {
76 do_error(_("WARNING! Header filters should be of the format &quot;Header: value&quot;"));
77 $action = 'edit';
78 }
79 if ($action != 'edit') {
80 setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder);
81 }
82 $filters[$theid]['where'] = $filter_where;
83 $filters[$theid]['what'] = $filter_what;
84 $filters[$theid]['folder'] = $filter_folder;
85 }
86 } elseif (isset($action) && $action == 'delete') {
87 remove_filter($theid);
88 } elseif (isset($action) && $action == 'move_up') {
89 filter_swap($theid, $theid - 1);
90 } elseif (isset($action) && $action == 'move_down') {
91 filter_swap($theid, $theid + 1);
92 } elseif (sqgetGlobalVar('user_submit',$user_submit,SQ_POST)) {
93 sqgetGlobalVar('filters_user_scan_set',$filters_user_scan_set,SQ_POST);
94 setPref($data_dir, $username, 'filters_user_scan', $filters_user_scan_set);
95 echo '<br /><center><b>'._("Saved Scan type")."</b></center>\n";
96 }
97
98 $filters = load_filters();
99 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
100
101 echo html_tag( 'table',
102 html_tag( 'tr',
103 html_tag( 'td',
104 '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>' ,
105 'left', $color[0]
106 )
107 ),
108 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"'
109 ) .
110 '<br /><form method="post" action="options.php">'.
111 '<center>'.
112 html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
113 html_tag( 'tr' ) .
114 html_tag( 'th', _("What to Scan:"), 'right', '', 'style="white-space: nowrap;"' ) .
115 html_tag( 'td', '', 'left' ) .
116 '<select name="filters_user_scan_set">'.
117 '<option value=""';
118 if ($filters_user_scan == '') {
119 echo ' selected="selected"';
120 }
121 echo '>' . _("All messages") . '</option>'.
122 '<option value="new"';
123 if ($filters_user_scan == 'new') {
124 echo ' selected="selected"';
125 }
126 echo '>' . _("Only unread messages") . '</option>' .
127 '</select>'.
128 '</td>'.
129 html_tag( 'td', '<input type="submit" name="user_submit" value="' . _("Save") . '" />', 'left' ) .
130 '</table>'.
131 '</center>'.
132 '</form>'.
133
134 html_tag( 'div', '[<a href="options.php?action=add">' . _("New") .
135 '</a>] - [<a href="'.SM_PATH.'src/options.php">' . _("Done") . '</a>]' ,
136 'center' ) . '<br />';
137
138 if (isset($action) && ($action == 'add' || $action == 'edit')) {
139
140 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
141 $boxes = sqimap_mailbox_list($imapConnection);
142
143 for ($a = 0, $cnt = count($boxes); $a < $cnt; $a++) {
144 if (strtolower($boxes[$a]['formatted']) == 'inbox') {
145 unset($boxes[$a]);
146 }
147 }
148
149 sqimap_logout($imapConnection);
150 if ( !isset($theid) ) {
151 $theid = count($filters);
152 }
153 echo html_tag( 'div', '', 'center' ) .
154 '<form action="options.php" method="post">'.
155 html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
156 html_tag( 'tr' ) .
157 html_tag( 'td', _("Match:"), 'left' ) .
158 html_tag( 'td', '', 'left' ) .
159 '<select name="filter_where">';
160
161 $L = isset($filters[$theid]['where']);
162
163 $sel = (($L && $filters[$theid]['where'] == 'From')?' selected="selected"':'');
164 echo "<option value=\"From\"$sel>" . _("From") . '</option>';
165
166 $sel = (($L && $filters[$theid]['where'] == 'To')?' selected="selected"':'');
167 echo "<option value=\"To\"$sel>" . _("To") . '</option>';
168
169 $sel = (($L && $filters[$theid]['where'] == 'Cc')?' selected="selected"':'');
170 echo "<option value=\"Cc\"$sel>" . _("Cc") . '</option>';
171
172 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?' selected="selected"':'');
173 echo "<option value=\"To or Cc\"$sel>" . _("To or Cc") . '</option>';
174
175 $sel = (($L && $filters[$theid]['where'] == 'Subject')?' selected="selected"':'');
176 echo "<option value=\"Subject\"$sel>" . _("Subject") . '</option>';
177
178 $sel = (($L && $filters[$theid]['where'] == 'Message Body')?' selected="selected"':'');
179 echo "<option value=\"Message Body\"$sel>" . _("Message Body") . '</option>';
180
181 $sel = (($L && $filters[$theid]['where'] == 'Header and Body')?' selected="selected"':'');
182 echo "<option value=\"Header and Body\"$sel>" . _("Header and Body") . '</option>';
183
184 $sel = (($L && $filters[$theid]['where'] == 'Header')?' selected="selected"':'');
185 echo "<option value=\"Header\"$sel>" . _("Header") . '</option>';
186
187 echo '</select>'.
188 '</td>'.
189 '</tr>'.
190 html_tag( 'tr' ) .
191 html_tag( 'td', _("Contains:"), 'right' ) .
192 html_tag( 'td', '', 'left' ) .
193 '<input type="text" size="32" name="filter_what" value="';
194 if (isset($filters[$theid]['what'])) {
195 echo $filters[$theid]['what'];
196 }
197 echo '" />'.
198 '</td>'.
199 '</tr>'.
200 html_tag( 'tr' ) .
201 html_tag( 'td', _("Move to:"), 'left' ) .
202 html_tag( 'td', '', 'left' ) .
203 '<tt>'.
204 '<select name="filter_folder">';
205 $selected = 0;
206 if ( isset($filters[$theid]['folder']) )
207 $selected = array(strtolower($filters[$theid]['folder']));
208 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
209 echo '</tt>'.
210 '</select>'.
211 '</td>'.
212 '</tr>'.
213 '</table>'.
214 '<input type="submit" name="filter_submit" value="' . _("Submit") . "\" />\n".
215 addHidden('theid', $theid).
216 '</form>'.
217 '</div>';
218
219 }
220
221 echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' );
222
223 for ($i=0, $num = count($filters); $i < $num; $i++) {
224
225 $clr = (($i % 2)?$color[0]:$color[9]);
226 $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
227 echo html_tag( 'tr', '', '', $clr ) .
228 html_tag( 'td',
229 '<small>' .
230 "[<a href=\"options.php?theid=$i&amp;action=edit\">" . _("Edit") . '</a>]'.
231 '</small>' ,
232 'left' ) .
233 html_tag( 'td',
234 '<small>' .
235 "[<a href=\"options.php?theid=$i&amp;action=delete\">" . _("Delete") . '</a>]'.
236 '</small>' ,
237 'left' );
238
239 if ($num > 1) {
240 echo html_tag( 'td', '', 'center' ) . '<small>[';
241 if (isset($filters[$i + 1])) {
242 echo "<a href=\"options.php?theid=$i&amp;action=move_down\">" . _("Down") . '</a>';
243 if ($i > 0) {
244 echo '&nbsp;|&nbsp;';
245 }
246 }
247 if ($i > 0) {
248 echo "<a href=\"options.php?theid=$i&amp;action=move_up\">" . _("Up") . '</a>';
249 }
250 echo ']</small></td>';
251 }
252 echo html_tag( 'td', '-', 'left' ) .
253 html_tag( 'td', '', 'left' );
254 printf( _("If %s contains %s then move to %s"),
255 '<b>'.$filters[$i]['where'].'</b>',
256 '<b>'.$filters[$i]['what'].'</b>',
257 '<b>'.imap_utf7_decode_local($fdr).'</b>');
258 echo '</td></tr>';
259
260 }
261 echo '</table>'.
262 html_tag( 'table',
263 html_tag( 'tr',
264 html_tag( 'td', '&nbsp;', 'left' )
265 ) ,
266 'center', '', 'width="80%" border="0" cellpadding="2" cellspacing="0"' );
267 echo '</body></html>';
268 ?>