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