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