fixed warning
[squirrelmail.git] / src / folders.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * folders.php
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
35586184 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
86725763 16/* Path for SquirrelMail required files. */
17define('SM_PATH','../');
18
19/* SquirrelMail required files. */
08185f2a 20require_once(SM_PATH . 'include/validate.php');
86725763 21require_once(SM_PATH . 'functions/imap.php');
86725763 22require_once(SM_PATH . 'functions/plugin.php');
23require_once(SM_PATH . 'functions/html.php');
d3cdb279 24
e634431a 25displayPageHeader($color, 'None');
aa42fbfb 26
a32985a5 27/* get globals we may need */
28
f38b7cf0 29sqgetGlobalVar('username', $username, SQ_SESSION);
30sqgetGlobalVar('key', $key, SQ_COOKIE);
31sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
32sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
33
34sqgetGlobalVar('success', $success, SQ_GET);
a32985a5 35
36/* end of get globals */
37
2441907d 38echo '<br>' .
6206f6c4 39 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
2441907d 40 html_tag( 'tr' ) .
41 html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' .
42 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) .
43 html_tag( 'tr' ) .
44 html_tag( 'td', '', 'center', $color[4] );
aa42fbfb 45
b7f83b61 46if ( isset($success) && $success ) {
47
48 $td_str = '<b>';
49
50 switch ($success)
51 {
52 case 'subscribe':
53 $td_str .= _("Subscribed successfully!");
54 break;
55 case 'unsubscribe':
56 $td_str .= _("Unsubscribed successfully!");
57 break;
58 case 'delete':
59 $td_str .= _("Deleted folder successfully!");
60 break;
61 case 'create':
62 $td_str .= _("Created folder successfully!");
63 break;
64 case 'rename':
65 $td_str .= _("Renamed successfully!");
66 break;
67 case 'subscribe-doesnotexist':
68 $td_str .= _("Subscription Unsuccessful - Folder does not exist.");
69 break;
e634431a 70 }
71
b7f83b61 72 $td_str .= '</b><br>';
73
74
50ed645b 75 echo html_tag( 'table',
76 html_tag( 'tr',
77 html_tag( 'td', $td_str .
b7f83b61 78 '<a href="../src/left_main.php" target=left>' .
79 _("refresh folder list") . '</a>' ,
50ed645b 80 'center' )
81 ) ,
b7f83b61 82 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
e634431a 83}
b7f83b61 84
85echo "\n<br>";
86
e634431a 87$imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
88$boxes = sqimap_mailbox_list($imapConnection);
89
90/** CREATING FOLDERS **/
ac50138c 91echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
50ed645b 92 html_tag( 'tr',
93 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
94 ) .
95 html_tag( 'tr' ) .
96 html_tag( 'td', '', 'center', $color[0] ) .
97
1c52ba77 98 "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n".
6b4bd11f 99 "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n".
1c52ba77 100 _("as a subfolder of").
b7f83b61 101 '<BR>'.
1c52ba77 102 "<TT><SELECT NAME=subfolder>\n";
7f0a2c23 103
45f836eb 104$show_selected = array();
105$skip_folders = array();
7f0a2c23 106$server_type = strtolower($imap_server_type);
107if ( $server_type == 'courier' ) {
45f836eb 108 array_push($skip_folders, 'inbox.trash');
7c8b7b4f 109 if ( $default_folder_prefix == 'INBOX.' ) {
110 array_push($skip_folders, 'inbox');
111 }
7f0a2c23 112}
113
114if ( $default_sub_of_inbox == false ) {
e634431a 115 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
116} else {
117 echo '<OPTION VALUE="">[ '._("None")." ]\n";
be2d5495 118 $show_selected = array('inbox');
119}
be2d5495 120
6e2ae264 121// Call sqimap_mailbox_option_list, using existing connection to IMAP server,
122// the arrays of folders to include or skip (assembled above),
59a8e3e8 123// use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders.
124// use the long format to show subfolders in an intelligible way if parent is missing (special folder)
125echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true);
be2d5495 126
e634431a 127echo "</SELECT></TT>\n";
128if ($show_contain_subfolders_option) {
b7f83b61 129 echo '<br><input type=CHECKBOX NAME="contain_subs"> &nbsp;'
130 . _("Let this folder contain subfolders")
131 . '<BR>';
1c52ba77 132}
6b4bd11f 133echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n";
134echo "</FORM></td></tr>\n";
e634431a 135
50ed645b 136echo html_tag( 'tr',
137 html_tag( 'td', '&nbsp;', 'left', $color[4] )
138 ) ."\n";
0037f048 139
140/** count special folders **/
141$count_special_folders = 0;
142$num_max = 1;
143if (strtolower($imap_server_type) == "courier" || $move_to_trash) {
45f836eb 144 $num_max++;
0037f048 145}
146if ($move_to_sent) {
45f836eb 147 $num_max++;
0037f048 148}
149if ($save_as_draft) {
45f836eb 150 $num_max++;
0037f048 151}
336155db 152for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++) {
0037f048 153 if (strtolower($boxes[$p]['unformatted']) == 'inbox')
154 $count_special_folders++;
155 else if (strtolower($imap_server_type) == 'courier' &&
45f836eb 156 strtolower($boxes[$p]['unformatted']) == 'inbox.trash') {
0037f048 157 $count_special_folders++;
45f836eb 158 }
159 else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder) {
0037f048 160 $count_special_folders++;
45f836eb 161 array_push($skip_folders, strtolower($trash_folder));
162 }
163 else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder) {
0037f048 164 $count_special_folders++;
45f836eb 165 array_push($skip_folders, strtolower($sent_folder));
166 }
167 else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder) {
0037f048 168 $count_special_folders++;
45f836eb 169 array_push($skip_folders, strtolower($draft_folder));
170 }
0037f048 171}
172
173
e634431a 174/** RENAMING FOLDERS **/
50ed645b 175echo html_tag( 'tr',
176 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
177 ) .
178 html_tag( 'tr' ) .
179 html_tag( 'td', '', 'center', $color[0] );
180
0037f048 181if ($count_special_folders < count($boxes)) {
182 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
183 . "<TT><SELECT NAME=old>\n"
184 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
be2d5495 185
59a8e3e8 186 // use existing IMAP connection, we have no special values to show,
187 // but we do include values to skip. Use the pre-created $boxes to save an IMAP query.
188 // send NULL for the flag - ALL folders are eligible for rename!
189 // use long format to make sure folder names make sense when parents may be missing.
190 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
be2d5495 191
1c52ba77 192 echo "</SELECT></TT>\n".
6b4bd11f 193 "<input type=SUBMIT VALUE=\"".
1c52ba77 194 _("Rename").
195 "\">\n".
50ed645b 196 "</FORM></td></tr>\n";
e634431a 197} else {
b7f83b61 198 echo _("No folders found") . '<br><br></td></tr>';
e634431a 199}
200$boxes_sub = $boxes;
201
50ed645b 202echo html_tag( 'tr',
203 html_tag( 'td', '&nbsp;', 'left', $color[4] )
204 ) ."\n";
e634431a 205
206/** DELETING FOLDERS **/
50ed645b 207echo html_tag( 'tr',
208 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
209 ) .
210 html_tag( 'tr' ) .
211 html_tag( 'td', '', 'center', $color[0] );
e634431a 212
e634431a 213if ($count_special_folders < count($boxes)) {
0037f048 214 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
215 . "<TT><SELECT NAME=mailbox>\n"
216 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
be2d5495 217
59a8e3e8 218 // send NULL for the flag - ALL folders are eligible for delete (except what we've got in skiplist)
219 // use long format to make sure folder names make sense when parents may be missing.
220 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
be2d5495 221
b7f83b61 222 echo "</SELECT></TT>\n"
223 . '<input type=SUBMIT VALUE="'
224 . _("Delete")
225 . "\">\n"
226 . "</form></td></tr>\n";
e634431a 227} else {
6b4bd11f 228 echo _("No folders found") . "<br><br></td></tr>";
e634431a 229}
50ed645b 230
231echo html_tag( 'tr',
232 html_tag( 'td', '&nbsp;', 'left', $color[4] )
233 ) ."</table>\n";
234
e634431a 235
236/** UNSUBSCRIBE FOLDERS **/
12ff1cab 237echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
50ed645b 238 html_tag( 'tr',
239 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
240 ) .
241 html_tag( 'tr' ) .
242 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
243
e634431a 244if ($count_special_folders < count($boxes)) {
b7f83b61 245 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n"
246 . "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n";
e634431a 247 for ($i = 0; $i < count($boxes); $i++) {
248 $use_folder = true;
249 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
250 ($boxes[$i]["unformatted"] != $trash_folder) &&
251 ($boxes[$i]["unformatted"] != $sent_folder) &&
252 ($boxes[$i]["unformatted"] != $draft_folder)) {
253 $box = $boxes[$i]["unformatted-dm"];
46bc57c1 254 $box2 = str_replace(' ', '&nbsp;',
255 imap_utf7_decode_local($boxes[$i]["unformatted-disp"]));
e634431a 256 echo " <OPTION VALUE=\"$box\">$box2\n";
257 }
258 }
b7f83b61 259 echo "</SELECT></TT><br><br>\n"
260 . '<input type=SUBMIT VALUE="'
261 . _("Unsubscribe")
262 . "\">\n"
263 . "</FORM></td>\n";
e634431a 264} else {
b7f83b61 265 echo _("No folders were found to unsubscribe from!") . '</td>';
e634431a 266}
267$boxes_sub = $boxes;
268
269/** SUBSCRIBE TO FOLDERS **/
50ed645b 270echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
52ed2f88 271if(!$no_list_for_subscribe) {
336155db 272 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
52ed2f88 273
b7f83b61 274 $box = '';
275 $box2 = '';
52ed2f88 276 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
e634431a 277 $use_folder = true;
278 for ($p = 0; $p < count ($boxes); $p++) {
b7f83b61 279 if ($boxes_all[$i]['unformatted'] == $boxes[$p]['unformatted']) {
e634431a 280 $use_folder = false;
281 continue;
b7f83b61 282 } else if ($boxes_all[$i]['unformatted-dm'] == $folder_prefix) {
e634431a 283 $use_folder = false;
284 }
285 }
7e235a1a 286 if ($use_folder == true) {
b7f83b61 287 $box[$q] = $boxes_all[$i]['unformatted-dm'];
288 $box2[$q] = imap_utf7_decode_local($boxes_all[$i]['unformatted-disp']);
e634431a 289 $q++;
290 }
52ed2f88 291 }
52ed2f88 292 if ($box && $box2) {
b7f83b61 293 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
294 . '<tt><select name="mailbox[]" multiple size=8>';
e634431a 295
296 for ($q = 0; $q < count($box); $q++) {
297 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
298 }
b7f83b61 299 echo '</select></tt><br><br>'
300 . '<input type=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
301 . "</FORM></td></tr></table><BR>\n";
52ed2f88 302 } else {
b7f83b61 303 echo _("No folders were found to subscribe to!") . '</td></tr></table>';
52ed2f88 304 }
305} else {
306 /* don't perform the list action -- this is much faster */
b7f83b61 307 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
308 . _("Subscribe to:") . '<br>'
309 . '<tt><input type="text" name="mailbox[]" size=35>'
310 . '<INPUT TYPE=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
311 . "</FORM></TD></TR></TABLE><BR>\n";
e634431a 312}
e7db48af 313
b7f83b61 314do_hook('folders_bottom');
bd9bbfef 315?>
e7db48af 316
e7db48af 317 </td></tr>
318 </table>
319
320</td></tr>
321</table>
322
323<?php
1195c340 324 sqimap_logout($imapConnection);
aa42fbfb 325?>
e7db48af 326
0037f048 327</body></html>