charsetDecode / htmlspecialchar usage is a mess :-(
[squirrelmail.git] / src / folders.php
... / ...
CommitLineData
1<?php
2
3/**
4 * folders.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Handles all interaction between the user and the other folder
10 * scripts which do most of the work. Also handles the Special
11 * Folders.
12 *
13 * $Id$
14 */
15
16/* Path for SquirrelMail required files. */
17define('SM_PATH','../');
18
19/* SquirrelMail required files. */
20require_once(SM_PATH . 'include/validate.php');
21require_once(SM_PATH . 'functions/imap.php');
22require_once(SM_PATH . 'functions/plugin.php');
23require_once(SM_PATH . 'functions/html.php');
24
25displayPageHeader($color, 'None');
26
27/* get globals we may need */
28
29$username = $_SESSION['username'];
30$key = $_COOKIE['key'];
31$delimiter = $_SESSION['delimiter'];
32$onetimepad = $_SESSION['onetimepad'];
33if (isset($_GET['success'])) {
34 $success = $_GET['success'];
35}
36
37/* end of get globals */
38
39echo '<br>' .
40 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
41 html_tag( 'tr' ) .
42 html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' .
43 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) .
44 html_tag( 'tr' ) .
45 html_tag( 'td', '', 'center', $color[4] );
46
47if ( isset($success) && $success ) {
48
49 $td_str = '<b>';
50
51 switch ($success)
52 {
53 case 'subscribe':
54 $td_str .= _("Subscribed successfully!");
55 break;
56 case 'unsubscribe':
57 $td_str .= _("Unsubscribed successfully!");
58 break;
59 case 'delete':
60 $td_str .= _("Deleted folder successfully!");
61 break;
62 case 'create':
63 $td_str .= _("Created folder successfully!");
64 break;
65 case 'rename':
66 $td_str .= _("Renamed successfully!");
67 break;
68 case 'subscribe-doesnotexist':
69 $td_str .= _("Subscription Unsuccessful - Folder does not exist.");
70 break;
71 }
72
73 $td_str .= '</b><br>';
74
75
76 echo html_tag( 'table',
77 html_tag( 'tr',
78 html_tag( 'td', $td_str .
79 '<a href="../src/left_main.php" target=left>' .
80 _("refresh folder list") . '</a>' ,
81 'center' )
82 ) ,
83 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
84}
85
86echo "\n<br>";
87
88$imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
89$boxes = sqimap_mailbox_list($imapConnection);
90
91/** CREATING FOLDERS **/
92echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
93 html_tag( 'tr',
94 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
95 ) .
96 html_tag( 'tr' ) .
97 html_tag( 'td', '', 'center', $color[0] ) .
98
99 "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n".
100 "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n".
101 _("as a subfolder of").
102 '<BR>'.
103 "<TT><SELECT NAME=subfolder>\n";
104if ($default_sub_of_inbox == false) {
105 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
106} else {
107 echo '<OPTION VALUE="">[ '._("None")." ]\n";
108}
109
110$show_selected = 0;
111if ( $default_sub_of_inbox ) {
112 $show_selected = array('inbox');
113}
114$skip_folders = 0;
115if ( strtolower($imap_server_type) == 'courier' ) {
116 $skip_folders = array('inbox.trash');
117}
118
119echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors');
120
121echo "</SELECT></TT>\n";
122if ($show_contain_subfolders_option) {
123 echo '<br><input type=CHECKBOX NAME="contain_subs"> &nbsp;'
124 . _("Let this folder contain subfolders")
125 . '<BR>';
126}
127echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n";
128echo "</FORM></td></tr>\n";
129
130echo html_tag( 'tr',
131 html_tag( 'td', '&nbsp;', 'left', $color[4] )
132 ) ."\n";
133
134/** count special folders **/
135$count_special_folders = 0;
136$num_max = 1;
137if (strtolower($imap_server_type) == "courier" || $move_to_trash) {
138 $num_max++;
139}
140if ($move_to_sent) {
141 $num_max++;
142}
143if ($save_as_draft) {
144 $num_max++;
145}
146for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++) {
147 if (strtolower($boxes[$p]['unformatted']) == 'inbox')
148 $count_special_folders++;
149 else if (strtolower($imap_server_type) == 'courier' &&
150 strtolower($boxes[$p]['unformatted']) == 'inbox.trash')
151 $count_special_folders++;
152 else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder)
153 $count_special_folders++;
154 else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder)
155 $count_special_folders++;
156 else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder)
157 $count_special_folders++;
158}
159
160
161/** RENAMING FOLDERS **/
162echo html_tag( 'tr',
163 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
164 ) .
165 html_tag( 'tr' ) .
166 html_tag( 'td', '', 'center', $color[0] );
167
168if ($count_special_folders < count($boxes)) {
169 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
170 . "<TT><SELECT NAME=old>\n"
171 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
172
173 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes);
174
175 echo "</SELECT></TT>\n".
176 "<input type=SUBMIT VALUE=\"".
177 _("Rename").
178 "\">\n".
179 "</FORM></td></tr>\n";
180} else {
181 echo _("No folders found") . '<br><br></td></tr>';
182}
183$boxes_sub = $boxes;
184
185echo html_tag( 'tr',
186 html_tag( 'td', '&nbsp;', 'left', $color[4] )
187 ) ."\n";
188
189/** DELETING FOLDERS **/
190echo html_tag( 'tr',
191 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
192 ) .
193 html_tag( 'tr' ) .
194 html_tag( 'td', '', 'center', $color[0] );
195
196if ($count_special_folders < count($boxes)) {
197 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
198 . "<TT><SELECT NAME=mailbox>\n"
199 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
200
201 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes);
202
203 echo "</SELECT></TT>\n"
204 . '<input type=SUBMIT VALUE="'
205 . _("Delete")
206 . "\">\n"
207 . "</form></td></tr>\n";
208} else {
209 echo _("No folders found") . "<br><br></td></tr>";
210}
211
212echo html_tag( 'tr',
213 html_tag( 'td', '&nbsp;', 'left', $color[4] )
214 ) ."</table>\n";
215
216
217/** UNSUBSCRIBE FOLDERS **/
218echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
219 html_tag( 'tr',
220 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
221 ) .
222 html_tag( 'tr' ) .
223 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
224
225if ($count_special_folders < count($boxes)) {
226 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n"
227 . "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n";
228 for ($i = 0; $i < count($boxes); $i++) {
229 $use_folder = true;
230 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
231 ($boxes[$i]["unformatted"] != $trash_folder) &&
232 ($boxes[$i]["unformatted"] != $sent_folder) &&
233 ($boxes[$i]["unformatted"] != $draft_folder)) {
234 $box = $boxes[$i]["unformatted-dm"];
235 $box2 = str_replace(' ', '&nbsp;',
236 imap_utf7_decode_local($boxes[$i]["unformatted-disp"]));
237 echo " <OPTION VALUE=\"$box\">$box2\n";
238 }
239 }
240 echo "</SELECT></TT><br><br>\n"
241 . '<input type=SUBMIT VALUE="'
242 . _("Unsubscribe")
243 . "\">\n"
244 . "</FORM></td>\n";
245} else {
246 echo _("No folders were found to unsubscribe from!") . '</td>';
247}
248$boxes_sub = $boxes;
249
250/** SUBSCRIBE TO FOLDERS **/
251echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
252if(!$no_list_for_subscribe) {
253 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
254
255 $box = '';
256 $box2 = '';
257 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
258 $use_folder = true;
259 for ($p = 0; $p < count ($boxes); $p++) {
260 if ($boxes_all[$i]['unformatted'] == $boxes[$p]['unformatted']) {
261 $use_folder = false;
262 continue;
263 } else if ($boxes_all[$i]['unformatted-dm'] == $folder_prefix) {
264 $use_folder = false;
265 }
266 }
267 if ($use_folder == true) {
268 $box[$q] = $boxes_all[$i]['unformatted-dm'];
269 $box2[$q] = imap_utf7_decode_local($boxes_all[$i]['unformatted-disp']);
270 $q++;
271 }
272 }
273 if ($box && $box2) {
274 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
275 . '<tt><select name="mailbox[]" multiple size=8>';
276
277 for ($q = 0; $q < count($box); $q++) {
278 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
279 }
280 echo '</select></tt><br><br>'
281 . '<input type=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
282 . "</FORM></td></tr></table><BR>\n";
283 } else {
284 echo _("No folders were found to subscribe to!") . '</td></tr></table>';
285 }
286} else {
287 /* don't perform the list action -- this is much faster */
288 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
289 . _("Subscribe to:") . '<br>'
290 . '<tt><input type="text" name="mailbox[]" size=35>'
291 . '<INPUT TYPE=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
292 . "</FORM></TD></TR></TABLE><BR>\n";
293}
294
295do_hook('folders_bottom');
296?>
297
298 </td></tr>
299 </table>
300
301</td></tr>
302</table>
303
304<?php
305 sqimap_logout($imapConnection);
306?>
307
308</body></html>