Replacing deprecated HTML "center" element.
[squirrelmail.git] / plugins / filters / spamoptions.php
1 <?php
2
3 /**
4 * Message and Spam Filter Plugin - Spam 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 /* get globals */
25 sqgetGlobalVar('username', $username, SQ_SESSION);
26 sqgetGlobalVar('key', $key, SQ_COOKIE);
27 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
28 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
29
30 sqgetGlobalVar('action', $action, SQ_GET);
31 /* end globals */
32
33 displayPageHeader($color, 'None');
34
35 if (sqgetGlobalVar('spam_submit',$spam_submit,SQ_POST)) {
36 $spam_filters = load_spam_filters();
37
38 // setting spam folder
39 sqgetGlobalVar('filters_spam_folder_set',$filters_spam_folder_set,SQ_POST);
40 if (isset($filters_spam_folder_set)) {
41 setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
42 } else {
43 echo _("You must select a spam folder.");
44 }
45
46 // setting scan type
47 sqgetGlobalVar('filters_spam_scan_set',$filters_spam_scan_set,SQ_POST);
48 if (isset($filters_spam_scan_set)) {
49 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
50 } else {
51 echo _("You must select a scan type.");
52 }
53
54 foreach ($spam_filters as $Key => $Value) {
55 $input = $spam_filters[$Key]['prefname'] . '_set';
56 if ( sqgetGlobalVar($input,$input_key,SQ_POST) ) {
57 setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],$input_key);
58 } else {
59 removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
60 }
61 }
62 }
63
64 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
65 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
66 $filters = load_filters();
67
68 echo html_tag( 'table',
69 html_tag( 'tr',
70 html_tag( 'th', _("Spam Filtering"), 'center' )
71 ) ,
72 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
73
74 if ($SpamFilters_YourHop == ' ') {
75 echo '<br />' .
76 html_tag( 'div', '<b>' .
77 sprintf(_("WARNING! Tell the administrator to set the %s variable."), '&quot;SpamFilters_YourHop&quot;') .
78 '</b>' ,
79 'center' ) .
80 '<br />';
81 }
82
83
84 if (isset($action) && $action == 'spam') {
85 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
86 $boxes = sqimap_mailbox_list($imapConnection);
87 sqimap_logout($imapConnection);
88 $numboxes = count($boxes);
89
90 for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++) {
91 if ((isset($boxes[$i]['flags'][0]) && $boxes[$i]['flags'][0] != 'noselect') &&
92 (isset($boxes[$i]['flags'][1]) && $boxes[$i]['flags'][1] != 'noselect') &&
93 (isset($boxes[$i]['flags'][2]) && $boxes[$i]['flags'][2] != 'noselect')) {
94 $filters_spam_folder = $boxes[$i]['unformatted'];
95 }
96 }
97
98 echo '<form method="post" action="spamoptions.php">'.
99 '<div style="text-align: center;">'.
100 html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
101 html_tag( 'tr' ) .
102 html_tag( 'th', _("Move spam to:"), 'right', '', 'style="white-space: nowrap;"' ) .
103 html_tag( 'td', '', 'left' ) .
104 '<select name="filters_spam_folder_set">';
105
106 $selected = 0;
107 if ( isset($filters_spam_folder) )
108 $selected = array(strtolower($filters_spam_folder));
109 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
110 echo '</select>'.
111 '</td>'.
112 '</tr>'.
113 html_tag( 'tr',
114 html_tag( 'td', '&nbsp;' ) .
115 html_tag( 'td',
116 _("Moving spam directly to the trash may not be a good idea at first, since messages from friends and mailing lists might accidentally be marked as spam. Whatever folder you set this to, make sure that it gets cleaned out periodically, so that you don't have an excessively large mailbox hanging around.") ,
117 'left' )
118 ) .
119 html_tag( 'tr' ) .
120 html_tag( 'th', _("What to Scan:"), 'right', '', 'style="white-space: nowrap;"' ) .
121 html_tag( 'td' ) .
122 '<select name="filters_spam_scan_set">'.
123 '<option value=""';
124 if ($filters_spam_scan == '') {
125 echo ' selected="selected"';
126 }
127 echo '>' . _("All messages") . '</option>'.
128 '<option value="new"';
129 if ($filters_spam_scan == 'new') {
130 echo ' selected="selected"';
131 }
132 echo '>' . _("Unread messages only") . '</option>' .
133 '</select>'.
134 '</td>'.
135 '</tr>'.
136 html_tag( 'tr',
137 html_tag( 'td', '&nbsp;' ) .
138 html_tag( 'td',
139 _("The more messages scanned, the longer it takes. It's recommended to scan unread messages only. If a change to the filters is made, it's recommended to set it to scan all messages, then go view the INBOX, then come back and set it to scan unread messages only. That way, the new spam filters will be applied and even the spam you didn't catch with the old filters will be scanned.") ,
140 'left' )
141 );
142
143 $spam_filters = load_spam_filters();
144
145 foreach ($spam_filters as $Key => $Value) {
146 echo html_tag( 'tr' ) .
147 html_tag( 'th', $Key, 'right', '', 'style="white-space: nowrap;"' ) ."\n" .
148 html_tag( 'td' ) .
149 '<input type="checkbox" name="' .
150 $spam_filters[$Key]['prefname'] .
151 '_set"';
152 if ($spam_filters[$Key]['enabled']) {
153 echo ' checked="checked"';
154 }
155 echo ' /> - ';
156 if ($spam_filters[$Key]['link']) {
157 echo '<a href="' .
158 $spam_filters[$Key]['link'] .
159 '" target="_blank">';
160 }
161 echo $spam_filters[$Key]['name'];
162 if ($spam_filters[$Key]['link']) {
163 echo '</a>';
164 }
165 echo '</td></tr>' .
166 html_tag( 'tr',
167 html_tag( 'td', '&nbsp;' ) .
168 html_tag( 'td', $spam_filters[$Key]['comment'], 'left' )
169 ) . "\n";
170
171 }
172 echo html_tag( 'tr',
173 html_tag( 'td', '<input type="submit" name="spam_submit" value="' . _("Save") . '" />', 'center', '', 'colspan="2"' )
174 ) . "\n" .
175 '</table>'.
176 '</div>'.
177 '</form>';
178 } else {
179 // action is not set or action is not spam
180 echo html_tag( 'p', '', 'center' ) .
181 '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
182 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</div><br /><br />';
183 printf( _("Spam is sent to %s."), ($filters_spam_folder?'<b>'.htmlspecialchars(imap_utf7_decode_local($filters_spam_folder)).'</b>':'[<i>'._("not set yet").'</i>]' ) );
184 echo '<br />';
185 printf( _("Spam scan is limited to %s."), '<b>' . ( ($filters_spam_scan == 'new')?_("Unread messages only"):_("All messages") ) . '</b>' );
186 echo '</p>'.
187 '<table border="0" cellpadding="3" cellspacing="0" align="center" bgcolor="' . $color[0] . "\">\n";
188
189 $spam_filters = load_spam_filters();
190
191 foreach ($spam_filters as $Key => $Value) {
192 echo html_tag( 'tr' ) .
193 html_tag( 'th', '', 'center' );
194
195 if ($spam_filters[$Key]['enabled']) {
196 echo _("ON");
197 } else {
198 echo _("OFF");
199 }
200
201 echo '</th>' .
202 html_tag( 'td', '&nbsp;-&nbsp;', 'left' ) .
203 html_tag( 'td', '', 'left' );
204
205 if ($spam_filters[$Key]['link']) {
206 echo '<a href="' .
207 $spam_filters[$Key]['link'] .
208 '" target="_blank">';
209 }
210
211 echo $spam_filters[$Key]['name'];
212 if ($spam_filters[$Key]['link']) {
213 echo '</a>';
214 }
215 echo "</td></tr>\n";
216 }
217 echo '</table>';
218 }
219 ?>
220 </body></html>