Fixed bug with courier not showing "none" option for subfolders.
[squirrelmail.git] / src / folders.php
1 <?php
2
3 /**
4 * folders.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
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
16 /*****************************************************************/
17 /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
18 /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
19 /*** + Base level indent should begin at left margin, as ***/
20 /*** the require_once below looks. ***/
21 /*** + All identation should consist of four space blocks ***/
22 /*** + Tab characters are evil. ***/
23 /*** + all comments should use "slash-star ... star-slash" ***/
24 /*** style -- no pound characters, no slash-slash style ***/
25 /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
26 /*** ALWAYS USE { AND } CHARACTERS!!! ***/
27 /*** + Please use ' instead of ", when possible. Note " ***/
28 /*** should always be used in _( ) function calls. ***/
29 /*** Thank you for your help making the SM code more readable. ***/
30 /*****************************************************************/
31
32 require_once('../src/validate.php');
33 require_once('../functions/imap.php');
34 require_once('../functions/array.php');
35 require_once('../functions/plugin.php');
36
37 displayPageHeader($color, 'None');
38
39 ?>
40
41 <br>
42 <table bgcolor="<?php echo $color[0] ?>" width="95%" align="center" cellpadding="2" cellspacing="0" border="0">
43 <tr><td align="center">
44
45 <b><?php echo _("Folders"); ?></b>
46
47 <table width="100%" border="0" cellpadding="5" cellspacing="0">
48 <tr><td bgcolor="<?php echo $color[4] ?>" align="center">
49
50 <?php
51
52 if ((isset($success) && $success) ||
53 (isset($sent_create) && $sent_create == "true") ||
54 (isset($trash_create) && $trash_create == "true")) {
55 echo "<table width=100% align=center cellpadding=2 cellspacing=0 border=0>\n";
56 echo " <tr><td align=center>\n";
57 if ($success == "subscribe") {
58 echo "<b>" . _("Subscribed successfully!") . "</b><br>";
59 } else if ($success == "unsubscribe") {
60 echo "<b>" . _("Unsubscribed successfully!") . "</b><br>";
61 } else if ($success == "delete") {
62 echo "<b>" . _("Deleted folder successfully!") . "</b><br>";
63 } else if ($success == "create") {
64 echo "<b>" . _("Created folder successfully!") . "</b><br>";
65 } else if ($success == "rename") {
66 echo "<b>" . _("Renamed successfully!") . "</b><br>";
67 }
68
69 echo " <a href=\"../src/left_main.php\" target=left>" . _("refresh folder list") . "</a>";
70 echo " </td></tr>\n";
71 echo "</table><br>\n";
72 }
73 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
74 $boxes = sqimap_mailbox_list($imapConnection);
75
76 /** DELETING FOLDERS **/
77 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=2 cellspacing=0 border=0>\n";
78 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
79 echo _("Delete Folder");
80 echo "</B></TD></TR>";
81 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
82
83 $count_special_folders = 0;
84 $num_max = 1;
85 if (strtolower($imap_server_type) == "courier" || $move_to_trash)
86 $num_max++;
87 if ($move_to_sent)
88 $num_max++;
89 if ($save_as_draft)
90 $num_max++;
91
92 for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++) {
93 if (strtolower($boxes[$p]["unformatted"]) == "inbox")
94 $count_special_folders++;
95 else if (strtolower($imap_server_type) == "courier" &&
96 strtolower($boxes[$p]["unformatted"]) == "inbox.trash")
97 $count_special_folders++;
98 else if ($boxes[$p]["unformatted"] == $trash_folder && $trash_folder)
99 $count_special_folders++;
100 else if ($boxes[$p]["unformatted"] == $sent_folder && $sent_folder)
101 $count_special_folders++;
102 else if ($boxes[$p]["unformatted"] == $draft_folder && $draft_folder)
103 $count_special_folders++;
104 }
105
106 if ($count_special_folders < count($boxes)) {
107 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n";
108 echo "<TT><SELECT NAME=mailbox>\n";
109 for ($i = 0; $i < count($boxes); $i++) {
110 $use_folder = true;
111 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
112 ($boxes[$i]["unformatted"] != $trash_folder) &&
113 ($boxes[$i]["unformatted"] != $sent_folder) &&
114 ($boxes[$i]["unformatted"] != $draft_folder) &&
115 (strtolower($imap_server_type) != "courier" ||
116 strtolower($boxes[$i]["unformatted"]) != "inbox.trash"))
117 {
118 $box = $boxes[$i]["unformatted-dm"];
119 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
120 echo " <OPTION VALUE=\"$box\">$box2\n";
121 }
122 }
123 echo "</SELECT></TT>\n";
124 echo "<INPUT TYPE=SUBMIT VALUE=\"";
125 echo _("Delete");
126 echo "\">\n";
127 echo "</FORM></TD></TR>\n";
128 } else {
129 echo _("No folders found") . "<br><br></td><tr>";
130 }
131
132 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
133
134 /** CREATING FOLDERS **/
135 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
136 echo _("Create Folder");
137 echo "</B></TD></TR>";
138 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
139 echo "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n";
140 echo "<INPUT TYPE=TEXT SIZE=25 NAME=folder_name><BR>\n";
141 echo _("as a subfolder of");
142 echo "<BR>";
143 echo "<TT><SELECT NAME=subfolder>\n";
144 if ($default_sub_of_inbox == false) {
145 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
146 } else {
147 echo '<OPTION VALUE="">[ '._("None")." ]\n";
148 }
149
150 for ($i = 0; $i < count($boxes); $i++) {
151 if (!in_array('noinferiors', $boxes[$i]['flags'])) {
152 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
153 $box = $boxes[$i]["unformatted"];
154 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
155 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
156 } else {
157 $box = $boxes[$i]["unformatted"];
158 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
159 if (strtolower($imap_server_type) != "courier" ||
160 strtolower($box) != "inbox.trash")
161 echo "<OPTION VALUE=\"$box\">$box2\n";
162 }
163 }
164 }
165 echo "</SELECT></TT>\n";
166 if ($show_contain_subfolders_option) {
167 echo "<br><INPUT TYPE=CHECKBOX NAME=\"contain_subs\"> &nbsp;";
168 echo _("Let this folder contain subfolders");
169 echo "<BR>";
170 }
171 echo "<INPUT TYPE=SUBMIT VALUE=\""._("Create")."\">\n";
172 echo "</FORM></TD></TR>\n";
173
174 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
175
176 /** RENAMING FOLDERS **/
177 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
178 echo _("Rename a Folder");
179 echo "</B></TD></TR>";
180 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
181 if ($count_special_folders < count($boxes)) {
182 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n";
183 echo "<TT><SELECT NAME=old>\n";
184 for ($i = 0; $i < count($boxes); $i++) {
185 $use_folder = true;
186
187 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
188 ($boxes[$i]["unformatted"] != $trash_folder) &&
189 ($boxes[$i]["unformatted"] != $sent_folder) &&
190 ($boxes[$i]["unformatted"] != $draft_folder))
191 {
192 $box = $boxes[$i]["unformatted-dm"];
193 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
194 if (strtolower($imap_server_type) != "courier" || strtolower($box) != "inbox.trash")
195 echo "<OPTION VALUE=\"$box\">$box2\n";
196 }
197 }
198 echo "</SELECT></TT>\n";
199 echo "<INPUT TYPE=SUBMIT VALUE=\"";
200 echo _("Rename");
201 echo "\">\n";
202 echo "</FORM></TD></TR>\n";
203 } else {
204 echo _("No folders found") . "<br><br></td></tr>";
205 }
206 $boxes_sub = $boxes;
207
208 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr></table>\n";
209
210 /** UNSUBSCRIBE FOLDERS **/
211 echo "<TABLE WIDTH=70% COLS=2 ALIGN=CENTER cellpadding=2 cellspacing=1 border=0>\n";
212 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER colspan=2><B>";
213 echo _("Unsubscribe") . "/" . _("Subscribe");
214 echo "</B></TD></TR>\n";
215 echo "<TR><TD BGCOLOR=\"$color[0]\" width=50% ALIGN=CENTER>\n";
216 if ($count_special_folders < count($boxes)) {
217 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
218 echo "<TT><SELECT NAME=mailbox[] multiple size=8>\n";
219 for ($i = 0; $i < count($boxes); $i++) {
220 $use_folder = true;
221 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
222 ($boxes[$i]["unformatted"] != $trash_folder) &&
223 ($boxes[$i]["unformatted"] != $sent_folder) &&
224 ($boxes[$i]["unformatted"] != $draft_folder))
225 {
226 $box = $boxes[$i]["unformatted-dm"];
227 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
228 echo " <OPTION VALUE=\"$box\">$box2\n";
229 }
230 }
231 echo "</SELECT></TT><br>\n";
232 echo "<INPUT TYPE=SUBMIT VALUE=\"";
233 echo _("Unsubscribe");
234 echo "\">\n";
235 echo "</FORM></TD>\n";
236 } else {
237 echo _("No folders were found to unsubscribe from!") . "</td>";
238 }
239 $boxes_sub = $boxes;
240
241 /** SUBSCRIBE TO FOLDERS **/
242 echo "<TD BGCOLOR=\"$color[0]\" width=50% ALIGN=CENTER>";
243 $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1);
244 $boxes_all = sqimap_mailbox_list_all ($imap_stream);
245
246 $box = "";
247 $box2 = "";
248 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
249 $use_folder = true;
250 for ($p = 0; $p < count ($boxes); $p++) {
251 if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
252 $use_folder = false;
253 continue;
254 } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) {
255 $use_folder = false;
256 }
257 }
258 if ($use_folder == true) {
259 $box[$q] = $boxes_all[$i]["unformatted-dm"];
260 $box2[$q] = $boxes_all[$i]["unformatted-disp"];
261 $q++;
262 }
263 }
264 sqimap_logout($imap_stream);
265
266 if ($box && $box2) {
267 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
268 echo "<tt><select name=mailbox[] multiple size=8>";
269
270 for ($q = 0; $q < count($box); $q++) {
271 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
272 }
273 echo "</select></tt><br>";
274 echo "<INPUT TYPE=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
275 echo "</FORM></TD></TR></TABLE><BR>\n";
276 } else {
277 echo _("No folders were found to subscribe to!") . "</td></tr></table>";
278 }
279 ?>
280
281
282 <?php do_hook("folders_bottom"); ?>
283
284
285 </td></tr>
286 </table>
287
288 </td></tr>
289 </table>
290
291 <?php
292 sqimap_logout($imapConnection);
293 ?>
294
295 </body></html>