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