-added patch 101376 => makes some things in folders.php bold, like in the rest of...
[squirrelmail.git] / src / folders.php
1 <?php
2 /**
3 ** folders.php
4 **
5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** Handles all interaction between the user and the other folder
9 ** scripts which do most of the work. Also handles the Special
10 ** Folders.
11 **/
12
13 session_start();
14
15 if (!isset($config_php))
16 include("../config/config.php");
17 if (!isset($strings_php))
18 include("../functions/strings.php");
19 if (!isset($page_header_php))
20 include("../functions/page_header.php");
21 if (!isset($imap_php))
22 include("../functions/imap.php");
23 if (!isset($array_php))
24 include("../functions/array.php");
25 if (!isset($plugin_php))
26 include("../functions/plugin.php");
27
28 include("../src/load_prefs.php");
29
30 displayPageHeader($color, "None");
31
32 echo "<br>";
33 echo "<TABLE WIDTH=95% COLS=1 ALIGN=CENTER>\n";
34 echo " <TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>\n";
35 echo _("Folders");
36 echo " </b></TD></TR>\n";
37 echo "</TABLE>\n";
38
39 if ($success) {
40 echo "<table width=100% align=center cellpadding=3 cellspacing=0 border=0>\n";
41 echo " <tr><td><center>\n";
42 if ($success == "subscribe") {
43 echo "<b>" . _("Subscribed successfully!") . "</b><br>";
44 } else if ($success == "unsubscribe") {
45 echo "<b>" . _("Unsubscribed successfully!") . "</b><br>";
46 } else if ($success == "delete") {
47 echo "<b>" . _("Deleted folder successfully!") . "</b><br>";
48 } else if ($success == "create") {
49 echo "<b>" . _("Created folder successfully!") . "</b><br>";
50 } else if ($success == "rename") {
51 echo "<b>" . _("Renamed successfully!") . "</b><br>";
52 } else if (($sent_create == "true") || ($trash_create == "true")) {
53 if ($sent_create == "true") {
54 sqimap_mailbox_create ($imapConnection, $sent_folder, "");
55 }
56 if ($trash_create == "true") {
57 sqimap_mailbox_create ($imapConnection, $trash_folder, "");
58 }
59 echo _("Folders created successfully!");
60 }
61
62 echo " <a href=\"../src/left_main.php\" target=left>" . _("refresh folder list") . "</a>";
63 echo " </center></td></tr>\n";
64 echo "</table><br>\n";
65 }
66 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
67 $boxes = sqimap_mailbox_list($imapConnection);
68
69 //display form option for creating Sent and Trash folder
70 if ($imap_server_type == "cyrus" && ($sent_folder != "none" || $trash_folder != "none")) {
71 if ((!sqimap_mailbox_exists ($imapConnection, $sent_folder)) || (!sqimap_mailbox_exists ($imapConnection, $trash_folder))) {
72 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=2 cellspacing=0 border=0>\n";
73 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
74 echo _("Special Folder Options");
75 echo "</B></TD></TR>";
76 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
77 echo _("In order for SquirrelMail to provide the full set of options you need to create the special folders listed below. Just click the check box and hit the create button.");
78 echo "<FORM ACTION=\"folders.php\" METHOD=\"POST\">\n";
79 if (!sqimap_mailbox_exists ($imapConnection, $sent_folder) && $sent_folder != "none") {
80 echo _("Create Sent") . "<INPUT TYPE=checkbox NAME=sent_create value=true><br>\n";
81 }
82 if (!sqimap_mailbox_exists ($imapConnection, $trash_folder) && $trash_folder != "none"){
83 echo _("Create Trash") . "<INPUT TYPE=checkbox NAME=trash_create value=true><br>\n";
84 }
85 echo "<INPUT TYPE=submit VALUE="._("Create").">";
86 echo "</FORM></TD></TR></TABLE><br>";
87 }
88 }
89
90 /** DELETING FOLDERS **/
91 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=2 cellspacing=0 border=0>\n";
92 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
93 echo _("Delete Folder");
94 echo "</B></TD></TR>";
95 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
96
97 $count_special_folders = 0;
98 $num_max = 1;
99 if (strtolower($imap_server_type) == "courier" || $move_to_trash)
100 $num_max++;
101 if ($move_to_sent)
102 $num_max++;
103
104 for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++) {
105 if (strtolower($boxes[$p]["unformatted"]) == "inbox")
106 $count_special_folders++;
107 else if (strtolower($imap_server_type) == "courier" &&
108 strtolower($boxes[$p]["unformatted"]) == "inbox.trash")
109 $count_special_folders++;
110 else if ($boxes[$p]["unformatted"] == $trash_folder && $trash_folder)
111 $count_special_folders++;
112 else if ($boxes[$p]["unformatted"] == $sent_folder && $sent_folder)
113 $count_special_folders++;
114 }
115
116 if ($count_special_folders < count($boxes)) {
117 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n";
118 echo "<TT><SELECT NAME=mailbox>\n";
119 for ($i = 0; $i < count($boxes); $i++) {
120 $use_folder = true;
121 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
122 ($boxes[$i]["unformatted"] != $trash_folder) &&
123 ($boxes[$i]["unformatted"] != $sent_folder) &&
124 (strtolower($imap_server_type) != "courier" ||
125 strtolower($boxes[$i]["unformatted"]) != "inbox.trash"))
126 {
127 $box = $boxes[$i]["unformatted-dm"];
128 $box2 = replace_spaces($boxes[$i]["formatted"]);
129 echo " <OPTION VALUE=\"$box\">$box2\n";
130 }
131 }
132 echo "</SELECT></TT>\n";
133 echo "<INPUT TYPE=SUBMIT VALUE=\"";
134 echo _("Delete");
135 echo "\">\n";
136 echo "</FORM></TD></TR>\n";
137 } else {
138 echo _("No folders found") . "<br><br></td><tr>";
139 }
140
141 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
142
143 /** CREATING FOLDERS **/
144 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
145 echo _("Create Folder");
146 echo "</B></TD></TR>";
147 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
148 echo "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n";
149 echo "<INPUT TYPE=TEXT SIZE=25 NAME=folder_name><BR>\n";
150 echo _("as a subfolder of");
151 echo "<BR>";
152 echo "<TT><SELECT NAME=subfolder>\n";
153 if (strtolower($imap_server_type) != "courier"){
154 if ($default_sub_of_inbox == false)
155 echo "<OPTION SELECTED>[ None ]\n";
156 else
157 echo "<OPTION>[ None ]\n";
158 }
159
160 for ($i = 0; $i < count($boxes); $i++) {
161 if (count($boxes[$i]["flags"]) > 0) {
162 $noinf = false;
163 for ($j = 0; $j < count($boxes[$i]["flags"]); $j++) {
164 if ($boxes[$i]["flags"][$j] == "noinferiors") {
165 $noinf = true;
166 continue;
167 }
168 }
169 if ($noinf == false) {
170 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
171 $box = $boxes[$i]["unformatted"];
172 $box2 = replace_spaces($boxes[$i]["formatted"]);
173 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
174 } else {
175 $box = $boxes[$i]["unformatted"];
176 $box2 = replace_spaces($boxes[$i]["formatted"]);
177 if (strtolower($imap_server_type) != "courier" ||
178 strtolower($box) != "inbox.trash")
179 echo "<OPTION VALUE=\"$box\">$box2\n";
180 }
181 }
182 } else {
183 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
184 $box = $boxes[$i]["unformatted"];
185 $box2 = replace_spaces($boxes[$i]["formatted"]);
186 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
187 } else {
188 $box = $boxes[$i]["unformatted"];
189 $box2 = replace_spaces($boxes[$i]["formatted"]);
190 if (strtolower($imap_server_type) != "courier" ||
191 strtolower($box) != "inbox.trash")
192 echo "<OPTION VALUE=\"$box\">$box2\n";
193 }
194 }
195 }
196 echo "</SELECT></TT><BR>\n";
197 if ($show_contain_subfolders_option) {
198 echo "<INPUT TYPE=CHECKBOX NAME=\"contain_subs\"> &nbsp;";
199 echo _("Let this folder contain subfolders");
200 echo "<BR>";
201 }
202 echo "<INPUT TYPE=SUBMIT VALUE=\""._("Create")."\">\n";
203 echo "</FORM></TD></TR>\n";
204
205 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
206
207 /** RENAMING FOLDERS **/
208 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
209 echo _("Rename a Folder");
210 echo "</B></TD></TR>";
211 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
212 if ($count_special_folders < count($boxes)) {
213 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n";
214 echo "<TT><SELECT NAME=old>\n";
215 for ($i = 0; $i < count($boxes); $i++) {
216 $use_folder = true;
217
218 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
219 ($boxes[$i]["unformatted"] != $trash_folder) &&
220 ($boxes[$i]["unformatted"] != $sent_folder))
221 {
222 $box = $boxes[$i]["unformatted-dm"];
223 $box2 = replace_spaces($boxes[$i]["formatted"]);
224 if (strtolower($imap_server_type) != "courier" || strtolower($box) != "inbox.trash")
225 echo "<OPTION VALUE=\"$box\">$box2\n";
226 }
227 }
228 echo "</SELECT></TT>\n";
229 echo "<INPUT TYPE=SUBMIT VALUE=\"";
230 echo _("Rename");
231 echo "\">\n";
232 echo "</FORM></TD></TR>\n";
233 } else {
234 echo _("No folders found") . "<br><br></td></tr>";
235 }
236 $boxes_sub = $boxes;
237
238 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr></table>\n";
239
240 /** UNSUBSCRIBE FOLDERS **/
241 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=2 cellspacing=0 border=0>\n";
242 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER colspan=3><B>";
243 echo _("Unsubscribe") . "/" . _("Subscribe");
244 echo "</B></TD></TR>";
245 echo "<TR><TD BGCOLOR=\"$color[0]\" width=49% ALIGN=CENTER>";
246 if ($count_special_folders < count($boxes)) {
247 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
248 echo "<TT><SELECT NAME=mailbox[] multiple size=8>\n";
249 for ($i = 0; $i < count($boxes); $i++) {
250 $use_folder = true;
251 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
252 ($boxes[$i]["unformatted"] != $trash_folder) &&
253 ($boxes[$i]["unformatted"] != $sent_folder))
254 {
255 $box = $boxes[$i]["unformatted-dm"];
256 $box2 = replace_spaces($boxes[$i]["formatted"]);
257 echo " <OPTION VALUE=\"$box\">$box2\n";
258 }
259 }
260 echo "</SELECT></TT><br>\n";
261 echo "<INPUT TYPE=SUBMIT VALUE=\"";
262 echo _("Unsubscribe");
263 echo "\">\n";
264 echo "</FORM></TD>\n";
265 } else {
266 echo _("No folders were found to unsubscribe from!") . "</td>";
267 }
268 $boxes_sub = $boxes;
269
270 echo "<td bgcolor=\"$color[9]\" width=2%>&nbsp;</td>";
271
272 /** SUBSCRIBE TO FOLDERS **/
273 echo "<TD BGCOLOR=\"$color[0]\" widtn=49% ALIGN=CENTER>";
274 $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1);
275 $boxes_all = sqimap_mailbox_list_all ($imap_stream);
276
277 $box = "";
278 $box2 = "";
279 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
280 $use_folder = true;
281 for ($p = 0; $p < count ($boxes); $p++) {
282 if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
283 $use_folder = false;
284 continue;
285 } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) {
286 $use_folder = false;
287 }
288 }
289 if ($use_folder == true) {
290 $box[$q] = $boxes_all[$i]["unformatted-dm"];
291 $box2[$q] = $boxes_all[$i]["formatted"];
292 $q++;
293 }
294 }
295 sqimap_logout($imap_stream);
296
297 if ($box && $box2) {
298 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
299 echo "<tt><select name=mailbox[] multiple size=8>";
300
301 for ($q = 0; $q < count($box); $q++) {
302 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
303 }
304 echo "</select></tt><br>";
305 echo "<INPUT TYPE=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
306 echo "</FORM></TD></TR></TABLE><BR>\n";
307 } else {
308 echo _("No folders were found to subscribe to!") . "</td></tr></table>";
309 }
310
311 do_hook("folders_bottom");
312 sqimap_logout($imapConnection);
313 ?>
314 </BODY></HTML>