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