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