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