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