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