spelling mistake
[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 = replace_spaces($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 (count($boxes[$i]["flags"]) > 0) {
169 $noinf = false;
170 for ($j = 0; $j < count($boxes[$i]["flags"]); $j++) {
171 if ($boxes[$i]["flags"][$j] == "noinferiors") {
172 $noinf = true;
173 continue;
174 }
175 }
176 if ($noinf == false) {
177 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
178 $box = $boxes[$i]["unformatted"];
179 $box2 = replace_spaces($boxes[$i]["unformatted-disp"]);
180 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
181 } else {
182 $box = $boxes[$i]["unformatted"];
183 $box2 = replace_spaces($boxes[$i]["unformatted-disp"]);
184 if (strtolower($imap_server_type) != "courier" ||
185 strtolower($box) != "inbox.trash")
186 echo "<OPTION VALUE=\"$box\">$box2\n";
187 }
188 }
189 } else {
190 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
191 $box = $boxes[$i]["unformatted"];
192 $box2 = replace_spaces($boxes[$i]["unformatted-disp"]);
193 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
194 } else {
195 $box = $boxes[$i]["unformatted"];
196 $box2 = replace_spaces($boxes[$i]["unformatted-disp"]);
197 if (strtolower($imap_server_type) != "courier" ||
198 strtolower($box) != "inbox.trash")
199 echo "<OPTION VALUE=\"$box\">$box2\n";
200 }
201 }
202 }
203 echo "</SELECT></TT><BR>\n";
204 if ($show_contain_subfolders_option) {
205 echo "<INPUT TYPE=CHECKBOX NAME=\"contain_subs\"> &nbsp;";
206 echo _("Let this folder contain subfolders");
207 echo "<BR>";
208 }
209 echo "<INPUT TYPE=SUBMIT VALUE=\""._("Create")."\">\n";
210 echo "</FORM></TD></TR>\n";
211
212 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
213
214 /** RENAMING FOLDERS **/
215 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
216 echo _("Rename a Folder");
217 echo "</B></TD></TR>";
218 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
219 if ($count_special_folders < count($boxes)) {
220 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n";
221 echo "<TT><SELECT NAME=old>\n";
222 for ($i = 0; $i < count($boxes); $i++) {
223 $use_folder = true;
224
225 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
226 ($boxes[$i]["unformatted"] != $trash_folder) &&
227 ($boxes[$i]["unformatted"] != $sent_folder))
228 {
229 $box = $boxes[$i]["unformatted-dm"];
230 $box2 = replace_spaces($boxes[$i]["unformatted-disp"]);
231 if (strtolower($imap_server_type) != "courier" || strtolower($box) != "inbox.trash")
232 echo "<OPTION VALUE=\"$box\">$box2\n";
233 }
234 }
235 echo "</SELECT></TT>\n";
236 echo "<INPUT TYPE=SUBMIT VALUE=\"";
237 echo _("Rename");
238 echo "\">\n";
239 echo "</FORM></TD></TR>\n";
240 } else {
241 echo _("No folders found") . "<br><br></td></tr>";
242 }
243 $boxes_sub = $boxes;
244
245 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr></table>\n";
246
247 /** UNSUBSCRIBE FOLDERS **/
248 echo "<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=2 cellspacing=0 border=0>\n";
249 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER colspan=3><B>";
250 echo _("Unsubscribe") . "/" . _("Subscribe");
251 echo "</B></TD></TR>";
252 echo "<TR><TD BGCOLOR=\"$color[0]\" width=49% ALIGN=CENTER>";
253 if ($count_special_folders < count($boxes)) {
254 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
255 echo "<TT><SELECT NAME=mailbox[] multiple size=8>\n";
256 for ($i = 0; $i < count($boxes); $i++) {
257 $use_folder = true;
258 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
259 ($boxes[$i]["unformatted"] != $trash_folder) &&
260 ($boxes[$i]["unformatted"] != $sent_folder))
261 {
262 $box = $boxes[$i]["unformatted-dm"];
263 $box2 = replace_spaces($boxes[$i]["unformatted-disp"]);
264 echo " <OPTION VALUE=\"$box\">$box2\n";
265 }
266 }
267 echo "</SELECT></TT><br>\n";
268 echo "<INPUT TYPE=SUBMIT VALUE=\"";
269 echo _("Unsubscribe");
270 echo "\">\n";
271 echo "</FORM></TD>\n";
272 } else {
273 echo _("No folders were found to unsubscribe from!") . "</td>";
274 }
275 $boxes_sub = $boxes;
276
277 echo "<td bgcolor=\"$color[9]\" width=2%>&nbsp;</td>";
278
279 /** SUBSCRIBE TO FOLDERS **/
280 echo "<TD BGCOLOR=\"$color[0]\" widtn=49% ALIGN=CENTER>";
281 $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1);
282 $boxes_all = sqimap_mailbox_list_all ($imap_stream);
283
284 $box = "";
285 $box2 = "";
286 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
287 $use_folder = true;
288 for ($p = 0; $p < count ($boxes); $p++) {
289 if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
290 $use_folder = false;
291 continue;
292 } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) {
293 $use_folder = false;
294 }
295 }
296 if ($use_folder == true) {
297 $box[$q] = $boxes_all[$i]["unformatted-dm"];
298 $box2[$q] = $boxes_all[$i]["unformatted-disp"];
299 $q++;
300 }
301 }
302 sqimap_logout($imap_stream);
303
304 if ($box && $box2) {
305 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
306 echo "<tt><select name=mailbox[] multiple size=8>";
307
308 for ($q = 0; $q < count($box); $q++) {
309 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
310 }
311 echo "</select></tt><br>";
312 echo "<INPUT TYPE=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
313 echo "</FORM></TD></TR></TABLE><BR>\n";
314 } else {
315 echo _("No folders were found to subscribe to!") . "</td></tr></table>";
316 }
317
318 do_hook("folders_bottom");
319 sqimap_logout($imapConnection);
320 ?>
321 </BODY></HTML>