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