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