950276efb45695f380a8db4f295cf727c965796c
[squirrelmail.git] / src / folders.php
1 <?php
2
3 /**
4 * folders.php
5 *
6 * Copyright (c) 1999-2001 The Squirrelmail Development Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Handles all interaction between the user and the other folder
10 * scripts which do most of the work. Also handles the Special
11 * Folders.
12 *
13 * $Id$
14 */
15
16 /*****************************************************************/
17 /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
18 /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
19 /*** + Base level indent should begin at left margin, as ***/
20 /*** the require_once below looks. ***/
21 /*** + All identation should consist of four space blocks ***/
22 /*** + Tab characters are evil. ***/
23 /*** + all comments should use "slash-star ... star-slash" ***/
24 /*** style -- no pound characters, no slash-slash style ***/
25 /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
26 /*** ALWAYS USE { AND } CHARACTERS!!! ***/
27 /*** + Please use ' instead of ", when possible. Note " ***/
28 /*** should always be used in _( ) function calls. ***/
29 /*** Thank you for your help making the SM code more readable. ***/
30 /*****************************************************************/
31
32 require_once('../src/validate.php');
33 require_once('../functions/imap.php');
34 require_once('../functions/array.php');
35 require_once('../functions/plugin.php');
36
37 displayPageHeader($color, 'None');
38
39 ?>
40
41 <br>
42 <table bgcolor="<?php echo $color[0] ?>" width="95%" align="center" cellpadding="2" cellspacing="0" border="0">
43 <tr><td align="center">
44
45 <b><?php echo _("Folders"); ?></b>
46
47 <table width="100%" border="0" cellpadding="5" cellspacing="0">
48 <tr><td bgcolor="<?php echo $color[4] ?>" align="center">
49
50 <?php
51
52 if ((isset($success) && $success) ||
53 (isset($sent_create) && $sent_create == "true") ||
54 (isset($trash_create) && $trash_create == "true")) {
55 echo "<table width=100% align=center cellpadding=2 cellspacing=0 border=0>\n";
56 echo " <tr><td align=center>\n";
57 if ($success == "subscribe") {
58 echo "<b>" . _("Subscribed successfully!") . "</b><br>";
59 } else if ($success == "unsubscribe") {
60 echo "<b>" . _("Unsubscribed successfully!") . "</b><br>";
61 } else if ($success == "delete") {
62 echo "<b>" . _("Deleted folder successfully!") . "</b><br>";
63 } else if ($success == "create") {
64 echo "<b>" . _("Created folder successfully!") . "</b><br>";
65 } else if ($success == "rename") {
66 echo "<b>" . _("Renamed successfully!") . "</b><br>";
67 }
68
69 echo " <a href=\"../src/left_main.php\" target=left>" . _("refresh folder list") . "</a>";
70 echo " </td></tr>\n";
71 echo "</table><br>\n";
72 }
73 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
74 $boxes = sqimap_mailbox_list($imapConnection);
75
76 /** DELETING FOLDERS **/
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 _("Delete Folder");
80 echo "</B></TD></TR>";
81 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
82
83 $count_special_folders = 0;
84 $num_max = 1;
85 if (strtolower($imap_server_type) == "courier" || $move_to_trash)
86 $num_max++;
87 if ($move_to_sent)
88 $num_max++;
89
90 for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++) {
91 if (strtolower($boxes[$p]["unformatted"]) == "inbox")
92 $count_special_folders++;
93 else if (strtolower($imap_server_type) == "courier" &&
94 strtolower($boxes[$p]["unformatted"]) == "inbox.trash")
95 $count_special_folders++;
96 else if ($boxes[$p]["unformatted"] == $trash_folder && $trash_folder)
97 $count_special_folders++;
98 else if ($boxes[$p]["unformatted"] == $sent_folder && $sent_folder)
99 $count_special_folders++;
100 }
101
102 if ($count_special_folders < count($boxes)) {
103 echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n";
104 echo "<TT><SELECT NAME=mailbox>\n";
105 for ($i = 0; $i < count($boxes); $i++) {
106 $use_folder = true;
107 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
108 ($boxes[$i]["unformatted"] != $trash_folder) &&
109 ($boxes[$i]["unformatted"] != $sent_folder) &&
110 (strtolower($imap_server_type) != "courier" ||
111 strtolower($boxes[$i]["unformatted"]) != "inbox.trash"))
112 {
113 $box = $boxes[$i]["unformatted-dm"];
114 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
115 echo " <OPTION VALUE=\"$box\">$box2\n";
116 }
117 }
118 echo "</SELECT></TT>\n";
119 echo "<INPUT TYPE=SUBMIT VALUE=\"";
120 echo _("Delete");
121 echo "\">\n";
122 echo "</FORM></TD></TR>\n";
123 } else {
124 echo _("No folders found") . "<br><br></td><tr>";
125 }
126
127 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
128
129 /** CREATING FOLDERS **/
130 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
131 echo _("Create Folder");
132 echo "</B></TD></TR>";
133 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
134 echo "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n";
135 echo "<INPUT TYPE=TEXT SIZE=25 NAME=folder_name><BR>\n";
136 echo _("as a subfolder of");
137 echo "<BR>";
138 echo "<TT><SELECT NAME=subfolder>\n";
139 if (strtolower($imap_server_type) != "courier"){
140 if ($default_sub_of_inbox == false)
141 echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n";
142 else
143 echo '<OPTION VALUE="">[ '._("None")." ]\n";
144 }
145
146 for ($i = 0; $i < count($boxes); $i++) {
147 if (!in_array('noinferiors', $boxes[$i]['flags'])) {
148 if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
149 $box = $boxes[$i]["unformatted"];
150 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
151 echo "<OPTION SELECTED VALUE=\"$box\">$box2\n";
152 } else {
153 $box = $boxes[$i]["unformatted"];
154 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
155 if (strtolower($imap_server_type) != "courier" ||
156 strtolower($box) != "inbox.trash")
157 echo "<OPTION VALUE=\"$box\">$box2\n";
158 }
159 }
160 }
161 echo "</SELECT></TT>\n";
162 if ($show_contain_subfolders_option) {
163 echo "<br><INPUT TYPE=CHECKBOX NAME=\"contain_subs\"> &nbsp;";
164 echo _("Let this folder contain subfolders");
165 echo "<BR>";
166 }
167 echo "<INPUT TYPE=SUBMIT VALUE=\""._("Create")."\">\n";
168 echo "</FORM></TD></TR>\n";
169
170 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr>\n";
171
172 /** RENAMING FOLDERS **/
173 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>";
174 echo _("Rename a Folder");
175 echo "</B></TD></TR>";
176 echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
177 if ($count_special_folders < count($boxes)) {
178 echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n";
179 echo "<TT><SELECT NAME=old>\n";
180 for ($i = 0; $i < count($boxes); $i++) {
181 $use_folder = true;
182
183 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
184 ($boxes[$i]["unformatted"] != $trash_folder) &&
185 ($boxes[$i]["unformatted"] != $sent_folder))
186 {
187 $box = $boxes[$i]["unformatted-dm"];
188 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
189 if (strtolower($imap_server_type) != "courier" || strtolower($box) != "inbox.trash")
190 echo "<OPTION VALUE=\"$box\">$box2\n";
191 }
192 }
193 echo "</SELECT></TT>\n";
194 echo "<INPUT TYPE=SUBMIT VALUE=\"";
195 echo _("Rename");
196 echo "\">\n";
197 echo "</FORM></TD></TR>\n";
198 } else {
199 echo _("No folders found") . "<br><br></td></tr>";
200 }
201 $boxes_sub = $boxes;
202
203 echo "<tr><td bgcolor=\"$color[4]\">&nbsp;</td></tr></table>\n";
204
205 /** UNSUBSCRIBE FOLDERS **/
206 echo "<TABLE WIDTH=70% COLS=2 ALIGN=CENTER cellpadding=2 cellspacing=1 border=0>\n";
207 echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER colspan=2><B>";
208 echo _("Unsubscribe") . "/" . _("Subscribe");
209 echo "</B></TD></TR>\n";
210 echo "<TR><TD BGCOLOR=\"$color[0]\" width=50% ALIGN=CENTER>\n";
211 if ($count_special_folders < count($boxes)) {
212 echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n";
213 echo "<TT><SELECT NAME=mailbox[] multiple size=8>\n";
214 for ($i = 0; $i < count($boxes); $i++) {
215 $use_folder = true;
216 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
217 ($boxes[$i]["unformatted"] != $trash_folder) &&
218 ($boxes[$i]["unformatted"] != $sent_folder))
219 {
220 $box = $boxes[$i]["unformatted-dm"];
221 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
222 echo " <OPTION VALUE=\"$box\">$box2\n";
223 }
224 }
225 echo "</SELECT></TT><br>\n";
226 echo "<INPUT TYPE=SUBMIT VALUE=\"";
227 echo _("Unsubscribe");
228 echo "\">\n";
229 echo "</FORM></TD>\n";
230 } else {
231 echo _("No folders were found to unsubscribe from!") . "</td>";
232 }
233 $boxes_sub = $boxes;
234
235 /** SUBSCRIBE TO FOLDERS **/
236 echo "<TD BGCOLOR=\"$color[0]\" width=50% ALIGN=CENTER>";
237 $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1);
238 $boxes_all = sqimap_mailbox_list_all ($imap_stream);
239
240 $box = "";
241 $box2 = "";
242 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
243 $use_folder = true;
244 for ($p = 0; $p < count ($boxes); $p++) {
245 if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
246 $use_folder = false;
247 continue;
248 } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) {
249 $use_folder = false;
250 }
251 }
252 if ($use_folder == true) {
253 $box[$q] = $boxes_all[$i]["unformatted-dm"];
254 $box2[$q] = $boxes_all[$i]["unformatted-disp"];
255 $q++;
256 }
257 }
258 sqimap_logout($imap_stream);
259
260 if ($box && $box2) {
261 echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
262 echo "<tt><select name=mailbox[] multiple size=8>";
263
264 for ($q = 0; $q < count($box); $q++) {
265 echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n";
266 }
267 echo "</select></tt><br>";
268 echo "<INPUT TYPE=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
269 echo "</FORM></TD></TR></TABLE><BR>\n";
270 } else {
271 echo _("No folders were found to subscribe to!") . "</td></tr></table>";
272 }
273 ?>
274
275
276 <?php do_hook("folders_bottom"); ?>
277
278
279 </td></tr>
280 </table>
281
282 </td></tr>
283 </table>
284
285 <?php
286 sqimap_logout($imapConnection);
287 ?>
288
289 </body></html>