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