Alternating reply colours... makes things easier to read on mass-replies.
[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
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
2441907d 39echo '<br>' .
6206f6c4 40 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
2441907d 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] );
aa42fbfb 46
b7f83b61 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;
e634431a 71 }
72
b7f83b61 73 $td_str .= '</b><br>';
74
75
50ed645b 76 echo html_tag( 'table',
77 html_tag( 'tr',
78 html_tag( 'td', $td_str .
b7f83b61 79 '<a href="../src/left_main.php" target=left>' .
80 _("refresh folder list") . '</a>' ,
50ed645b 81 'center' )
82 ) ,
b7f83b61 83 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
e634431a 84}
b7f83b61 85
86echo "\n<br>";
87
e634431a 88$imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
89$boxes = sqimap_mailbox_list($imapConnection);
90
91/** CREATING FOLDERS **/
ac50138c 92echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
50ed645b 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
1c52ba77 99 "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n".
6b4bd11f 100 "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n".
1c52ba77 101 _("as a subfolder of").
b7f83b61 102 '<BR>'.
1c52ba77 103 "<TT><SELECT NAME=subfolder>\n";
7f0a2c23 104
105$show_selected=0;
106$skip_folders=0;
107$server_type = strtolower($imap_server_type);
108if ( $server_type == 'courier' ) {
109 $show_selected = array('inbox');
110 $skip_folders = array('inbox','inbox.trash');
111}
112
113if ( $default_sub_of_inbox == false ) {
e634431a 114 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
115} else {
116 echo '<OPTION VALUE="">[ '._("None")." ]\n";
be2d5495 117 $show_selected = array('inbox');
118}
be2d5495 119
120echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors');
121
e634431a 122echo "</SELECT></TT>\n";
123if ($show_contain_subfolders_option) {
b7f83b61 124 echo '<br><input type=CHECKBOX NAME="contain_subs"> &nbsp;'
125 . _("Let this folder contain subfolders")
126 . '<BR>';
1c52ba77 127}
6b4bd11f 128echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n";
129echo "</FORM></td></tr>\n";
e634431a 130
50ed645b 131echo html_tag( 'tr',
132 html_tag( 'td', '&nbsp;', 'left', $color[4] )
133 ) ."\n";
0037f048 134
135/** count special folders **/
136$count_special_folders = 0;
137$num_max = 1;
138if (strtolower($imap_server_type) == "courier" || $move_to_trash) {
139 $num_max++;
140}
141if ($move_to_sent) {
142 $num_max++;
143}
144if ($save_as_draft) {
145 $num_max++;
146}
336155db 147for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++) {
0037f048 148 if (strtolower($boxes[$p]['unformatted']) == 'inbox')
149 $count_special_folders++;
150 else if (strtolower($imap_server_type) == 'courier' &&
151 strtolower($boxes[$p]['unformatted']) == 'inbox.trash')
152 $count_special_folders++;
153 else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder)
154 $count_special_folders++;
155 else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder)
156 $count_special_folders++;
157 else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder)
158 $count_special_folders++;
159}
160
161
e634431a 162/** RENAMING FOLDERS **/
50ed645b 163echo html_tag( 'tr',
164 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
165 ) .
166 html_tag( 'tr' ) .
167 html_tag( 'td', '', 'center', $color[0] );
168
0037f048 169if ($count_special_folders < count($boxes)) {
170 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
171 . "<TT><SELECT NAME=old>\n"
172 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
be2d5495 173
174 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes);
175
1c52ba77 176 echo "</SELECT></TT>\n".
6b4bd11f 177 "<input type=SUBMIT VALUE=\"".
1c52ba77 178 _("Rename").
179 "\">\n".
50ed645b 180 "</FORM></td></tr>\n";
e634431a 181} else {
b7f83b61 182 echo _("No folders found") . '<br><br></td></tr>';
e634431a 183}
184$boxes_sub = $boxes;
185
50ed645b 186echo html_tag( 'tr',
187 html_tag( 'td', '&nbsp;', 'left', $color[4] )
188 ) ."\n";
e634431a 189
190/** DELETING FOLDERS **/
50ed645b 191echo html_tag( 'tr',
192 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
193 ) .
194 html_tag( 'tr' ) .
195 html_tag( 'td', '', 'center', $color[0] );
e634431a 196
e634431a 197if ($count_special_folders < count($boxes)) {
0037f048 198 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
199 . "<TT><SELECT NAME=mailbox>\n"
200 . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
be2d5495 201
202 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes);
203
b7f83b61 204 echo "</SELECT></TT>\n"
205 . '<input type=SUBMIT VALUE="'
206 . _("Delete")
207 . "\">\n"
208 . "</form></td></tr>\n";
e634431a 209} else {
6b4bd11f 210 echo _("No folders found") . "<br><br></td></tr>";
e634431a 211}
50ed645b 212
213echo html_tag( 'tr',
214 html_tag( 'td', '&nbsp;', 'left', $color[4] )
215 ) ."</table>\n";
216
e634431a 217
218/** UNSUBSCRIBE FOLDERS **/
12ff1cab 219echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
50ed645b 220 html_tag( 'tr',
221 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
222 ) .
223 html_tag( 'tr' ) .
224 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
225
e634431a 226if ($count_special_folders < count($boxes)) {
b7f83b61 227 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n"
228 . "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n";
e634431a 229 for ($i = 0; $i < count($boxes); $i++) {
230 $use_folder = true;
231 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
232 ($boxes[$i]["unformatted"] != $trash_folder) &&
233 ($boxes[$i]["unformatted"] != $sent_folder) &&
234 ($boxes[$i]["unformatted"] != $draft_folder)) {
235 $box = $boxes[$i]["unformatted-dm"];
46bc57c1 236 $box2 = str_replace(' ', '&nbsp;',
237 imap_utf7_decode_local($boxes[$i]["unformatted-disp"]));
e634431a 238 echo " <OPTION VALUE=\"$box\">$box2\n";
239 }
240 }
b7f83b61 241 echo "</SELECT></TT><br><br>\n"
242 . '<input type=SUBMIT VALUE="'
243 . _("Unsubscribe")
244 . "\">\n"
245 . "</FORM></td>\n";
e634431a 246} else {
b7f83b61 247 echo _("No folders were found to unsubscribe from!") . '</td>';
e634431a 248}
249$boxes_sub = $boxes;
250
251/** SUBSCRIBE TO FOLDERS **/
50ed645b 252echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
52ed2f88 253if(!$no_list_for_subscribe) {
336155db 254 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
52ed2f88 255
b7f83b61 256 $box = '';
257 $box2 = '';
52ed2f88 258 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
e634431a 259 $use_folder = true;
260 for ($p = 0; $p < count ($boxes); $p++) {
b7f83b61 261 if ($boxes_all[$i]['unformatted'] == $boxes[$p]['unformatted']) {
e634431a 262 $use_folder = false;
263 continue;
b7f83b61 264 } else if ($boxes_all[$i]['unformatted-dm'] == $folder_prefix) {
e634431a 265 $use_folder = false;
266 }
267 }
7e235a1a 268 if ($use_folder == true) {
b7f83b61 269 $box[$q] = $boxes_all[$i]['unformatted-dm'];
270 $box2[$q] = imap_utf7_decode_local($boxes_all[$i]['unformatted-disp']);
e634431a 271 $q++;
272 }
52ed2f88 273 }
52ed2f88 274 if ($box && $box2) {
b7f83b61 275 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
276 . '<tt><select name="mailbox[]" multiple size=8>';
e634431a 277
278 for ($q = 0; $q < count($box); $q++) {
279 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
280 }
b7f83b61 281 echo '</select></tt><br><br>'
282 . '<input type=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
283 . "</FORM></td></tr></table><BR>\n";
52ed2f88 284 } else {
b7f83b61 285 echo _("No folders were found to subscribe to!") . '</td></tr></table>';
52ed2f88 286 }
287} else {
288 /* don't perform the list action -- this is much faster */
b7f83b61 289 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"
290 . _("Subscribe to:") . '<br>'
291 . '<tt><input type="text" name="mailbox[]" size=35>'
292 . '<INPUT TYPE=SUBMIT VALUE="'. _("Subscribe") . "\">\n"
293 . "</FORM></TD></TR></TABLE><BR>\n";
e634431a 294}
e7db48af 295
b7f83b61 296do_hook('folders_bottom');
bd9bbfef 297?>
e7db48af 298
e7db48af 299 </td></tr>
300 </table>
301
302</td></tr>
303</table>
304
305<?php
1195c340 306 sqimap_logout($imapConnection);
aa42fbfb 307?>
e7db48af 308
0037f048 309</body></html>