templating for signout
[squirrelmail.git] / src / folders.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * folders.php
5 *
35586184 6 * Handles all interaction between the user and the other folder
7 * scripts which do most of the work. Also handles the Special
8 * Folders.
9 *
47ccfad4 10 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
4b4abf93 11 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 12 * @version $Id$
8f6f9ba5 13 * @package squirrelmail
35586184 14 */
15
30967a1e 16/**
202bcbcc 17 * Include the SquirrelMail initialization file.
30967a1e 18 */
202bcbcc 19require('../include/init.php');
86725763 20
21/* SquirrelMail required files. */
202bcbcc 22require_once(SM_PATH . 'functions/imap_general.php');
32aa0074 23require_once(SM_PATH . 'functions/folder_manip.php');
62366261 24require_once(SM_PATH . 'functions/forms.php');
d3cdb279 25
e634431a 26displayPageHeader($color, 'None');
aa42fbfb 27
a32985a5 28/* get globals we may need */
29
f38b7cf0 30sqgetGlobalVar('username', $username, SQ_SESSION);
31sqgetGlobalVar('key', $key, SQ_COOKIE);
32sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
33sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
34
32aa0074 35sqgetGlobalVar('smaction', $action, SQ_POST);
a32985a5 36
37/* end of get globals */
38
ff0969a0 39echo '<br />' .
6206f6c4 40 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) .
2441907d 41 html_tag( 'tr' ) .
42 html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' .
43 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) .
44 html_tag( 'tr' ) .
45 html_tag( 'td', '', 'center', $color[4] );
aa42fbfb 46
32aa0074 47$imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
b7f83b61 48
32aa0074 49/* switch to the right function based on what the user selected */
50if ( sqgetGlobalVar('smaction', $action, SQ_POST) ) {
b7f83b61 51
32aa0074 52 switch ($action)
b7f83b61 53 {
32aa0074 54 case 'create':
55 sqgetGlobalVar('folder_name', $folder_name, SQ_POST);
56 sqgetGlobalVar('subfolder', $subfolder, SQ_POST);
57 sqgetGlobalVar('contain_subs', $contain_subs, SQ_POST);
58 folders_create($imapConnection, $delimiter, $folder_name, $subfolder, $contain_subs);
59 $td_str = _("Created folder successfully.");
b7f83b61 60 break;
32aa0074 61 case 'rename':
62 if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST) ) {
63 break;
64 }
65 if ( ! sqgetGlobalVar('new_name', $new_name, SQ_POST) ) {
66 sqgetGlobalVar('old_name', $old_name, SQ_POST);
67 folders_rename_getname($imapConnection, $delimiter, $old_name);
68 } else {
69 sqgetGlobalVar('orig', $orig, SQ_POST);
70 sqgetGlobalVar('old_name', $old_name, SQ_POST);
71 folders_rename_do($imapConnection, $delimiter, $orig, $old_name, $new_name);
333daac7 72 $td_str = _("Renamed successfully.");
32aa0074 73 }
b7f83b61 74 break;
75 case 'delete':
32aa0074 76 if ( sqgetGlobalVar('cancelbutton', $dummy, SQ_POST) ) {
77 break;
78 }
79 sqgetGlobalVar('folder_name', $folder_name, SQ_POST);
80 if ( sqgetGlobalVar('confirmed', $dummy, SQ_POST) ) {
81 folders_delete_do($imapConnection, $delimiter, $folder_name);
82 $td_str = _("Deleted folder successfully.");
83 } else {
84 folders_delete_ask($imapConnection, $folder_name);
85 }
b7f83b61 86 break;
32aa0074 87 case 'subscribe':
88 sqgetGlobalVar('folder_names', $folder_names, SQ_POST);
89 folders_subscribe($imapConnection, $folder_names);
90 $td_str = _("Subscribed successfully.");
b7f83b61 91 break;
32aa0074 92 case 'unsubscribe':
93 sqgetGlobalVar('folder_names', $folder_names, SQ_POST);
94 folders_unsubscribe($imapConnection, $folder_names);
95 $td_str = _("Unsubscribed successfully.");
b7f83b61 96 break;
decb0c39 97 default:
98 // TODO: add hook for plugin action processing.
99 $td_str = '';
100 break;
f8a1ed5a 101 }
dcc1cc82 102
e0c5664a 103 // if there are any messages, output them.
104 if ( !empty($td_str) ) {
105 echo html_tag( 'table',
dcc1cc82 106 html_tag( 'tr',
32aa0074 107 html_tag( 'td', '<b>' . $td_str . "</b><br />\n" .
39bfea8f 108 '<a href="../src/left_main.php" target="left">' .
dcc1cc82 109 _("refresh folder list") . '</a>' ,
110 'center' )
111 ) ,
112 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' );
e0c5664a 113 }
e634431a 114}
b7f83b61 115
ff0969a0 116echo "\n<br />";
b7f83b61 117
cedd503c 118$boxes = sqimap_mailbox_list($imapConnection,true);
e634431a 119
120/** CREATING FOLDERS **/
ac50138c 121echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
50ed645b 122 html_tag( 'tr',
123 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] )
124 ) .
125 html_tag( 'tr' ) .
126 html_tag( 'td', '', 'center', $color[0] ) .
32aa0074 127 addForm('folders.php', 'post', 'cf').
128 addHidden('smaction','create').
62366261 129 addInput('folder_name', '', 25).
ff0969a0 130 "<br />\n". _("as a subfolder of"). '<br />'.
131 "<tt><select name=\"subfolder\">\n";
7f0a2c23 132
45f836eb 133$show_selected = array();
134$skip_folders = array();
7f0a2c23 135$server_type = strtolower($imap_server_type);
decb0c39 136
137// Special handling for courier
7f0a2c23 138if ( $server_type == 'courier' ) {
decb0c39 139 /**
140 * If we use courier, we should hide system trash folder
5c4ff7bf 141 * FIXME: (tokul) Who says that courier does not allow storing folders in
142 * INBOX.Trash or inbox.trash? Can't reproduce it 3.0.8. This entry is
143 * useless, because in_array() check is case sensitive and INBOX is in
decb0c39 144 * upper case.
145 */
146 array_push($skip_folders, 'inbox.trash');
147
148 if ( $default_folder_prefix == 'INBOX.' ) {
149 // We don't need INBOX, since it is top folder
150 array_push($skip_folders, 'INBOX');
151 }
e498ebbd 152} elseif ( $server_type == 'bincimap' ) {
153 if ( $default_folder_prefix == 'INBOX/' ) {
154 // We don't need INBOX, since it is top folder
155 array_push($skip_folders, 'INBOX');
156 }
7f0a2c23 157}
158
159if ( $default_sub_of_inbox == false ) {
ff0969a0 160 echo '<option selected="selected" value="">[ '._("None")." ]</option>\n";
e634431a 161} else {
ff0969a0 162 echo '<option value="">[ '._("None")." ]</option>\n";
be2d5495 163 $show_selected = array('inbox');
164}
be2d5495 165
6e2ae264 166// Call sqimap_mailbox_option_list, using existing connection to IMAP server,
91e0dccc 167// the arrays of folders to include or skip (assembled above),
59a8e3e8 168// use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders.
169// use the long format to show subfolders in an intelligible way if parent is missing (special folder)
170echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true);
be2d5495 171
ff0969a0 172echo "</select></tt>\n";
e634431a 173if ($show_contain_subfolders_option) {
ff0969a0 174 echo '<br />'.
62366261 175 addCheckBox('contain_subs', FALSE, '1') .' &nbsp;'
b7f83b61 176 . _("Let this folder contain subfolders")
ff0969a0 177 . '<br />';
1c52ba77 178}
ff0969a0 179echo "<input type=\"submit\" value=\""._("Create")."\" />\n";
180echo "</form></td></tr>\n";
e634431a 181
50ed645b 182echo html_tag( 'tr',
183 html_tag( 'td', '&nbsp;', 'left', $color[4] )
184 ) ."\n";
0037f048 185
186/** count special folders **/
decb0c39 187foreach ($boxes as $index => $aBoxData) {
188 if (isSpecialMailbox($aBoxData['unformatted']) &&
189 ! in_array($aBoxData['unformatted'],$skip_folders)) {
190 $skip_folders[] = $aBoxData['unformatted'];
5c4ff7bf 191 }
0037f048 192}
193
decb0c39 194/**
195 * Retrieve list of folders when special folders are excluded. Special folders
196 * should be unavailable in rename/delete/unsubscribe. Theoretically user can
5c4ff7bf 197 * modify form and perform these operations with special folders, but if user
198 * manages to delete/rename/unsubscribe special folder by hacking form...
decb0c39 199 *
200 * If script or program depends on special folder, they should not assume that
201 * folder is available.
202 *
203 * $filtered_folders contains empty string or html formated option list.
204 */
205$filtered_folders = sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
0037f048 206
e634431a 207/** RENAMING FOLDERS **/
50ed645b 208echo html_tag( 'tr',
209 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] )
210 ) .
211 html_tag( 'tr' ) .
212 html_tag( 'td', '', 'center', $color[0] );
213
32aa0074 214/* show only if we have folders to rename */
decb0c39 215if (! empty($filtered_folders)) {
32aa0074 216 echo addForm('folders.php')
217 . addHidden('smaction', 'rename')
218 . "<tt><select name=\"old_name\">\n"
ff0969a0 219 . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n";
be2d5495 220
91e0dccc 221 // use existing IMAP connection, we have no special values to show,
59a8e3e8 222 // but we do include values to skip. Use the pre-created $boxes to save an IMAP query.
223 // send NULL for the flag - ALL folders are eligible for rename!
224 // use long format to make sure folder names make sense when parents may be missing.
decb0c39 225 echo $filtered_folders;
be2d5495 226
ff0969a0 227 echo "</select></tt>\n".
228 '<input type="submit" value="'.
1c52ba77 229 _("Rename").
ff0969a0 230 "\" />\n".
231 "</form></td></tr>\n";
e634431a 232} else {
ff0969a0 233 echo _("No folders found") . '<br /><br /></td></tr>';
e634431a 234}
e634431a 235
50ed645b 236echo html_tag( 'tr',
237 html_tag( 'td', '&nbsp;', 'left', $color[4] )
238 ) ."\n";
e634431a 239
240/** DELETING FOLDERS **/
50ed645b 241echo html_tag( 'tr',
242 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] )
243 ) .
244 html_tag( 'tr' ) .
245 html_tag( 'td', '', 'center', $color[0] );
e634431a 246
32aa0074 247/* show only if we have folders to delete */
decb0c39 248if (!empty($filtered_folders)) {
32aa0074 249 echo addForm('folders.php')
250 . addHidden('smaction', 'delete')
251 . "<tt><select name=\"folder_name\">\n"
ff0969a0 252 . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n";
be2d5495 253
59a8e3e8 254 // send NULL for the flag - ALL folders are eligible for delete (except what we've got in skiplist)
255 // use long format to make sure folder names make sense when parents may be missing.
decb0c39 256 echo $filtered_folders;
be2d5495 257
ff0969a0 258 echo "</select></tt>\n"
259 . '<input type="submit" value="'
b7f83b61 260 . _("Delete")
ff0969a0 261 . "\" />\n"
b7f83b61 262 . "</form></td></tr>\n";
e634431a 263} else {
ff0969a0 264 echo _("No folders found") . "<br /><br /></td></tr>";
e634431a 265}
50ed645b 266
267echo html_tag( 'tr',
268 html_tag( 'td', '&nbsp;', 'left', $color[4] )
269 ) ."</table>\n";
270
e634431a 271
4d5f2b31 272if ($show_only_subscribed_folders) {
decb0c39 273 // FIXME: fix subscription options when top folder is not subscribed and sub folder is subscribed
274 // TODO: use checkboxes instead of select options.
50ed645b 275
4d5f2b31 276 /** UNSUBSCRIBE FOLDERS **/
277 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) .
278 html_tag( 'tr',
279 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' )
280 ) .
281 html_tag( 'tr' ) .
282 html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
283
decb0c39 284 if (!empty($filtered_folders)) {
32aa0074 285 echo addForm('folders.php')
286 . addHidden('smaction', 'unsubscribe')
decb0c39 287 . "<tt><select name=\"folder_names[]\" multiple=\"multiple\" size=\"8\">\n"
288 . $filtered_folders
289 . "</select></tt><br /><br />\n"
4d5f2b31 290 . '<input type="submit" value="'
291 . _("Unsubscribe")
292 . "\" />\n"
293 . "</form></td>\n";
294 } else {
333daac7 295 echo _("No folders were found to unsubscribe from.") . '</td>';
e634431a 296 }
4d5f2b31 297
298 /** SUBSCRIBE TO FOLDERS **/
299 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
300 if(!$no_list_for_subscribe) {
32aa0074 301 $boxes_all = sqimap_mailbox_list_all ($imapConnection);
302
303 $subboxes = array();
304 // here we filter out all boxes we're already subscribed to,
305 // so we keep only the unsubscribed ones.
306 foreach ($boxes_all as $box_a) {
f8a1ed5a 307
32aa0074 308 $use_folder = true;
309 foreach ( $boxes as $box ) {
310 if ($box_a['unformatted'] == $box['unformatted'] ||
311 $box_a['unformatted-dm'] == $folder_prefix ) {
312 $use_folder = false;
313 }
314 }
f8a1ed5a 315
32aa0074 316 if ($use_folder == true) {
f8a1ed5a 317 $box_enc = htmlspecialchars($box_a['unformatted-dm']);
32aa0074 318 $box_disp = htmlspecialchars(imap_utf7_decode_local($box_a['unformatted-disp']));
319 $subboxes[$box_enc] = $box_disp;
4d5f2b31 320 }
321 }
f8a1ed5a 322
32aa0074 323 if ( count($subboxes) > 0 ) {
324 echo addForm('folders.php')
325 . addHidden('smaction', 'subscribe')
326 . '<tt><select name="folder_names[]" multiple="multiple" size="8">';
327
328 foreach($subboxes as $subbox_enc => $subbox_disp) {
329 echo ' <option value="' . $subbox_enc . '">'.$subbox_disp."</option>\n";
330 }
e634431a 331
32aa0074 332 echo '</select></tt><br /><br />'
333 . '<input type="submit" value="'. _("Subscribe") . "\" />\n"
334 . "</form></td></tr></table><br />\n";
335 } else {
336 echo _("No folders were found to subscribe to.") . '</td></tr></table>';
4d5f2b31 337 }
4d5f2b31 338 } else {
32aa0074 339 /* don't perform the list action -- this is much faster */
340 echo addForm('folders.php')
341 . addHidden('smaction', 'subscribe')
4d5f2b31 342 . _("Subscribe to:") . '<br />'
32aa0074 343 . '<tt><input type="text" name="folder_names[]" size="35" />'
4d5f2b31 344 . '<input type="submit" value="'. _("Subscribe") . "\" />\n"
345 . "</form></td></tr></table><br />\n";
e634431a 346 }
e634431a 347}
e7db48af 348
b7f83b61 349do_hook('folders_bottom');
32aa0074 350sqimap_logout($imapConnection);
a2b193bc 351
bd9bbfef 352?>
e7db48af 353 </td></tr>
354 </table>
e7db48af 355</td></tr>
356</table>
5c4ff7bf 357<?php
358$oTemplate->display('footer.tpl');
359?>