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