Slight cleanup to filter option page display.
[squirrelmail.git] / plugins / filters / options.php
1 <?php
2
3 /**
4 * Message and Spam Filter Plugin
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This plugin filters your inbox into different folders based upon given
10 * criteria. It is most useful for people who are subscibed to mailing lists
11 * to help organize their messages. The argument stands that filtering is
12 * not the place of the client, which is why this has been made a plugin for
13 * SquirrelMail. You may be better off using products such as Sieve or
14 * Procmail to do your filtering so it happens even when SquirrelMail isn't
15 * running.
16 *
17 * If you need help with this, or see improvements that can be made, please
18 * email me directly at the address above. I definately welcome suggestions
19 * and comments. This plugin, as is the case with all SquirrelMail plugins,
20 * is not directly supported by the developers. Please come to me off the
21 * mailing list if you have trouble with it.
22 *
23 * Also view plugins/README.plugins for more information.
24 *
25 * $Id$
26 */
27
28 chdir ('..');
29 require_once('../src/validate.php');
30 require_once('../functions/page_header.php');
31 require_once('../functions/imap.php');
32 require_once('../src/load_prefs.php');
33
34 global $AllowSpamFilters;
35
36 displayPageHeader($color, 'None');
37
38 if (isset($filter_submit)) {
39 if (!isset($theid)) $theid = 0;
40 $filter_what = ereg_replace(",", " ", $filter_what);
41 $filter_what = str_replace("\\\\", "\\", $filter_what);
42 $filter_what = str_replace("\\\"", "\"", $filter_what);
43 $filter_what = str_replace("\"", "&quot;", $filter_what);
44
45 setPref($data_dir, $username, "filter".$theid, $filter_where.",".$filter_what.",".$filter_folder);
46 $filters[$theid]["where"] = $filter_where;
47 $filters[$theid]["what"] = $filter_what;
48 $filters[$theid]["folder"] = $filter_folder;
49 } elseif (isset($action) && $action == 'delete') {
50 remove_filter($theid);
51 } elseif (isset($action) && $action == 'move_up') {
52 filter_swap($theid, $theid - 1);
53 } elseif (isset($action) && $action == 'move_down') {
54 filter_swap($theid, $theid + 1);
55 }
56
57 $filters = load_filters();
58
59 echo '<br>' .
60 '<table width=95% align=center border=0 cellpadding=2 cellspacing=0>'.
61 "<tr><td bgcolor=\"$color[0]\">".
62 '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>'.
63 '</td></tr></table>'.
64 '<br><center>[<a href="options.php?action=add">' . _("New") .
65 '</a>] - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br>';
66
67 if (isset($action) && ($action == 'add' || $action == 'edit')) {
68 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
69 $boxes = sqimap_mailbox_list($imapConnection);
70 sqimap_logout($imapConnection);
71 if ( !isset($theid) ) {
72 $theid = count($filters);
73 }
74 echo '<center>'.
75 '<form action="options.php" method=post>'.
76 '<table cellpadding=2 cellspacing=0 border=0>'.
77 '<tr>'.
78 '<td>' . _("Match:") . '</td>'.
79 '<td>'.
80 '<select name=filter_where>';
81
82 $L = isset($filters[$theid]['where']);
83
84 $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':'');
85 echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
86
87 $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':'');
88 echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
89
90 $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':'');
91 echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
92
93 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':'');
94 echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
95
96 $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':'');
97 echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
98
99 echo '</select>'.
100 '</td>'.
101 '</tr>'.
102 '<tr>'.
103 '<td align=right>'.
104 _("Contains:").
105 '</td>'.
106 '<td>'.
107 '<input type=text size=32 name=filter_what value="';
108 if (isset($filters[$theid]['what'])) {
109 echo $filters[$theid]["what"];
110 }
111 echo '">'.
112 '</td>'.
113 '</tr>'.
114 '<tr>'.
115 '<td>'.
116 _("Move to:").
117 '</td>'.
118 '<td>'.
119 '<tt>'.
120 '<select name=filter_folder>';
121
122 for ($i = 0; $i < count($boxes); $i++) {
123 if (! in_array('noselect', $boxes[$i]['flags'])) {
124 $box = $boxes[$i]['unformatted'];
125 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
126 if (isset($filters[$theid]['folder']) &&
127 $filters[$theid]['folder'] == $box)
128 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</option>";
129 else
130 echo "<OPTION VALUE=\"$box\">$box2</option>";
131 }
132 }
133 echo '</tt>'.
134 '</select>'.
135 '</td>'.
136 '</tr>'.
137 '</table>'.
138 '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
139 "<input type=hidden name=theid value=$theid>".
140 '</form>'.
141 '</center>';
142
143 }
144
145 echo '<table border=0 cellpadding=3 cellspacing=0 align=center>';
146
147 for ($i=0; $i < count($filters); $i++) {
148
149 $clr = (($i % 2)?$color[0]:$color[9]);
150 $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
151 echo "<tr bgcolor=\"$clr\"><td><small>".
152 "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
153 '</small></td><td><small>'.
154 "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
155 '</small></td><td align=center><small>[';
156
157 if (isset($filters[$i + 1])) {
158 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
159 if ($i > 0) {
160 echo '&nbsp;|&nbsp;';
161 }
162 }
163 if ($i > 0) {
164 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
165 }
166 echo ']</small></td><td>-</td><td>';
167 printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), _($filters[$i]['where']), $filters[$i]['what'], $fdr );
168 echo '</td></tr>';
169
170 }
171 echo '</table>'.
172 '<table width=80% align=center border=0 cellpadding=2 cellspacing=0">'.
173 '<tr><td>&nbsp</td></tr>'.
174 '</table>';
175
176 ?>