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