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