Updating strings
[squirrelmail.git] / src / folders.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * folders.php
5 *
6c84ba1e 6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
35586184 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 *
30967a1e 13 * @version $Id$
8f6f9ba5 14 * @package squirrelmail
35586184 15 */
16
30967a1e 17/**
18 * Path for SquirrelMail required files.
19 * @ignore
20 */
86725763 21define('SM_PATH','../');
22
23/* SquirrelMail required files. */
08185f2a 24require_once(SM_PATH . 'include/validate.php');
86725763 25require_once(SM_PATH . 'functions/imap.php');
86725763 26require_once(SM_PATH . 'functions/plugin.php');
27require_once(SM_PATH . 'functions/html.php');
62366261 28require_once(SM_PATH . 'functions/forms.php');
d3cdb279 29
e634431a 30displayPageHeader($color, 'None');
aa42fbfb 31
a32985a5 32/* get globals we may need */
33
f38b7cf0 34sqgetGlobalVar('username', $username, SQ_SESSION);
35sqgetGlobalVar('key', $key, SQ_COOKIE);
36sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
37sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
38
39sqgetGlobalVar('success', $success, SQ_GET);
a32985a5 40
41/* end of get globals */
42
ff0969a0 43echo '<br />' .
6206f6c4 44 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
2441907d 45 html_tag( 'tr' ) .
46 html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' .
47 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) .
48 html_tag( 'tr' ) .
49 html_tag( 'td', '', 'center', $color[4] );
aa42fbfb 50
b7f83b61 51if ( isset($success) && $success ) {
52
53 $td_str = '<b>';
54
55 switch ($success)
56 {
57 case 'subscribe':
58 $td_str .= _("Subscribed successfully!");
59 break;
60 case 'unsubscribe':
61 $td_str .= _("Unsubscribed successfully!");
62 break;
63 case 'delete':
64 $td_str .= _("Deleted folder successfully!");
65 break;
66 case 'create':
67 $td_str .= _("Created folder successfully!");
68 break;
69 case 'rename':
70 $td_str .= _("Renamed successfully!");
71 break;
72 case 'subscribe-doesnotexist':
73 $td_str .= _("Subscription Unsuccessful - Folder does not exist.");
74 break;
e634431a 75 }
76
ff0969a0 77 $td_str .= '</b><br />';
b7f83b61 78
dcc1cc82 79
80 echo html_tag( 'table',
81 html_tag( 'tr',
82 html_tag( 'td', $td_str .
39bfea8f 83 '<a href="../src/left_main.php" target="left">' .
dcc1cc82 84 _("refresh folder list") . '</a>' ,
85 'center' )
86 ) ,
87 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
e634431a 88}
b7f83b61 89
ff0969a0 90echo "\n<br />";
b7f83b61 91
e634431a 92$imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
cedd503c 93$boxes = sqimap_mailbox_list($imapConnection,true);
e634431a 94
95/** CREATING FOLDERS **/
ac50138c 96echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
50ed645b 97 html_tag( 'tr',
98 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
99 ) .
100 html_tag( 'tr' ) .
101 html_tag( 'td', '', 'center', $color[0] ) .
c435f076 102 addForm('folders_create.php', 'post', 'cf').
62366261 103 addInput('folder_name', '', 25).
ff0969a0 104 "<br />\n". _("as a subfolder of"). '<br />'.
105 "<tt><select name=\"subfolder\">\n";
7f0a2c23 106
45f836eb 107$show_selected = array();
108$skip_folders = array();
7f0a2c23 109$server_type = strtolower($imap_server_type);
110if ( $server_type == 'courier' ) {
45f836eb 111 array_push($skip_folders, 'inbox.trash');
7c8b7b4f 112 if ( $default_folder_prefix == 'INBOX.' ) {
99e400a4 113 array_push($skip_folders, 'INBOX');
7c8b7b4f 114 }
7f0a2c23 115}
116
117if ( $default_sub_of_inbox == false ) {
ff0969a0 118 echo '<option selected="selected" value="">[ '._("None")." ]</option>\n";
e634431a 119} else {
ff0969a0 120 echo '<option value="">[ '._("None")." ]</option>\n";
be2d5495 121 $show_selected = array('inbox');
122}
be2d5495 123
6e2ae264 124// Call sqimap_mailbox_option_list, using existing connection to IMAP server,
91e0dccc 125// the arrays of folders to include or skip (assembled above),
59a8e3e8 126// use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders.
127// use the long format to show subfolders in an intelligible way if parent is missing (special folder)
128echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true);
be2d5495 129
ff0969a0 130echo "</select></tt>\n";
e634431a 131if ($show_contain_subfolders_option) {
ff0969a0 132 echo '<br />'.
62366261 133 addCheckBox('contain_subs', FALSE, '1') .' &nbsp;'
b7f83b61 134 . _("Let this folder contain subfolders")
ff0969a0 135 . '<br />';
1c52ba77 136}
ff0969a0 137echo "<input type=\"submit\" value=\""._("Create")."\" />\n";
138echo "</form></td></tr>\n";
e634431a 139
50ed645b 140echo html_tag( 'tr',
141 html_tag( 'td', '&nbsp;', 'left', $color[4] )
142 ) ."\n";
0037f048 143
144/** count special folders **/
74fff934 145
146// FIX ME, why not check if the folders are defined IMHO move_to_sent, move_to_trash has nothing todo with it
0037f048 147$count_special_folders = 0;
148$num_max = 1;
149if (strtolower($imap_server_type) == "courier" || $move_to_trash) {
45f836eb 150 $num_max++;
0037f048 151}
152if ($move_to_sent) {
45f836eb 153 $num_max++;
0037f048 154}
155if ($save_as_draft) {
45f836eb 156 $num_max++;
0037f048 157}
74fff934 158
159// What if move_to_sent = false and $sent_folder is set? Should it still be skipped?
160
336155db 161for ($p = 0, $cnt = count($boxes); $p < $cnt && $count_special_folders < $num_max; $p++) {
134e4174 162 switch ($boxes[$p]['unformatted']) {
163 case (strtoupper($boxes[$p]['unformatted']) == 'INBOX'):
164 ++$count_special_folders;
165 $skip_folders[] = $boxes[$p]['unformatted'];
166 break;
167 // FIX ME inbox.trash should be set in conf.pl
168 case 'inbox.trash':
169 if (strtolower($imap_server_type) == 'courier') {
170 ++$count_special_folders;
171 }
172 break;
173 case $trash_folder:
174 ++$count_special_folders;
175 $skip_folders[] = $trash_folder;
176 break;
177 case $sent_folder:
178 ++$count_special_folders;
179 $skip_folders[] = $sent_folder;
180 break;
181 case $draft_folder:
182 ++$count_special_folders;
183 $skip_folders[] = $draft_folder;
184 break;
185 default: break;
186 }
0037f048 187}
188
189
e634431a 190/** RENAMING FOLDERS **/
50ed645b 191echo html_tag( 'tr',
192 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
193 ) .
194 html_tag( 'tr' ) .
195 html_tag( 'td', '', 'center', $color[0] );
196
0037f048 197if ($count_special_folders < count($boxes)) {
62366261 198 echo addForm('folders_rename_getname.php')
ff0969a0 199 . "<tt><select name=\"old\">\n"
200 . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n";
be2d5495 201
91e0dccc 202 // use existing IMAP connection, we have no special values to show,
59a8e3e8 203 // but we do include values to skip. Use the pre-created $boxes to save an IMAP query.
204 // send NULL for the flag - ALL folders are eligible for rename!
205 // use long format to make sure folder names make sense when parents may be missing.
206 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
be2d5495 207
ff0969a0 208 echo "</select></tt>\n".
209 '<input type="submit" value="'.
1c52ba77 210 _("Rename").
ff0969a0 211 "\" />\n".
212 "</form></td></tr>\n";
e634431a 213} else {
ff0969a0 214 echo _("No folders found") . '<br /><br /></td></tr>';
e634431a 215}
216$boxes_sub = $boxes;
217
50ed645b 218echo html_tag( 'tr',
219 html_tag( 'td', '&nbsp;', 'left', $color[4] )
220 ) ."\n";
e634431a 221
222/** DELETING FOLDERS **/
50ed645b 223echo html_tag( 'tr',
224 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
225 ) .
226 html_tag( 'tr' ) .
227 html_tag( 'td', '', 'center', $color[0] );
e634431a 228
e634431a 229if ($count_special_folders < count($boxes)) {
62366261 230 echo addForm('folders_delete.php')
ff0969a0 231 . "<tt><select name=\"mailbox\">\n"
232 . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n";
be2d5495 233
59a8e3e8 234 // send NULL for the flag - ALL folders are eligible for delete (except what we've got in skiplist)
235 // use long format to make sure folder names make sense when parents may be missing.
236 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
be2d5495 237
ff0969a0 238 echo "</select></tt>\n"
239 . '<input type="submit" value="'
b7f83b61 240 . _("Delete")
ff0969a0 241 . "\" />\n"
b7f83b61 242 . "</form></td></tr>\n";
e634431a 243} else {
ff0969a0 244 echo _("No folders found") . "<br /><br /></td></tr>";
e634431a 245}
50ed645b 246
247echo html_tag( 'tr',
248 html_tag( 'td', '&nbsp;', 'left', $color[4] )
249 ) ."</table>\n";
250
e634431a 251
4d5f2b31 252if ($show_only_subscribed_folders) {
50ed645b 253
4d5f2b31 254 /** UNSUBSCRIBE FOLDERS **/
255 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
256 html_tag( 'tr',
257 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
258 ) .
259 html_tag( 'tr' ) .
260 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
261
262 if ($count_special_folders < count($boxes)) {
263 echo addForm('folders_subscribe.php?method=unsub')
264 . "<tt><select name=\"mailbox[]\" multiple=\"multiple\" size=\"8\">\n";
265 for ($i = 0; $i < count($boxes); $i++) {
266 $use_folder = true;
267 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
268 ($boxes[$i]["unformatted"] != $trash_folder) &&
269 ($boxes[$i]["unformatted"] != $sent_folder) &&
270 ($boxes[$i]["unformatted"] != $draft_folder)) {
271 $box = htmlspecialchars($boxes[$i]["unformatted-dm"]);
272 $box2 = str_replace(' ', '&nbsp;',
273 htmlspecialchars(imap_utf7_decode_local($boxes[$i]["unformatted-disp"])));
274 echo " <option value=\"$box\">$box2</option>\n";
275 }
276 }
277 echo "</select></tt><br /><br />\n"
278 . '<input type="submit" value="'
279 . _("Unsubscribe")
280 . "\" />\n"
281 . "</form></td>\n";
282 } else {
283 echo _("No folders were found to unsubscribe from!") . '</td>';
e634431a 284 }
4d5f2b31 285 $boxes_sub = $boxes;
286
287 /** SUBSCRIBE TO FOLDERS **/
288 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
289 if(!$no_list_for_subscribe) {
290 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
291
292 $box = '';
293 $box2 = '';
294 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
295 $use_folder = true;
296 for ($p = 0; $p < count ($boxes); $p++) {
297 if ($boxes_all[$i]['unformatted'] == $boxes[$p]['unformatted']) {
298 $use_folder = false;
299 continue;
300 } else if ($boxes_all[$i]['unformatted-dm'] == $folder_prefix) {
301 $use_folder = false;
302 }
303 }
304 if ($use_folder == true) {
305 $box[$q] = htmlspecialchars($boxes_all[$i]['unformatted-dm']);
306 $box2[$q] = htmlspecialchars(imap_utf7_decode_local($boxes_all[$i]['unformatted-disp']));
307 $q++;
308 }
309 }
310 if ($box && $box2) {
311 echo addForm('folders_subscribe.php?method=sub')
312 . '<tt><select name="mailbox[]" multiple="multiple" size="8">';
e634431a 313
4d5f2b31 314 for ($q = 0; $q < count($box); $q++) {
315 echo ' <option value="' . $box[$q] . '">'.$box2[$q]."</option>\n";
316 }
317 echo '</select></tt><br /><br />'
318 . '<input type="submit" value="'. _("Subscribe") . "\" />\n"
319 . "</form></td></tr></table><br />\n";
320 } else {
321 echo _("No folders were found to subscribe to!") . '</td></tr></table>';
322 }
323 } else {
324 /* don't perform the list action -- this is much faster */
325 echo addForm('folders_subscribe.php?method=sub')
326 . _("Subscribe to:") . '<br />'
327 . '<tt><input type="text" name="mailbox[]" size="35" />'
328 . '<input type="submit" value="'. _("Subscribe") . "\" />\n"
329 . "</form></td></tr></table><br />\n";
e634431a 330 }
e634431a 331}
e7db48af 332
b7f83b61 333do_hook('folders_bottom');
bd9bbfef 334?>
e7db48af 335 </td></tr>
336 </table>
e7db48af 337</td></tr>
338</table>
e7db48af 339<?php
1195c340 340 sqimap_logout($imapConnection);
dcc1cc82 341?>
4d5f2b31 342</body></html>