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