4 +-----------------------------------------------------------------------+
5 | program/steps/settings/manage_folders.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Provide functionality to create/delete/rename folders |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: manage_folders.inc 573 2007-05-18 11:29:25Z thomasb $
22 // init IMAP connection
23 rcmail_imap_init(TRUE);
26 // subscribe to one or more mailboxes
27 if ($_action=='subscribe')
29 if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_POST))
30 $IMAP->subscribe(array($mboxes));
32 if ($OUTPUT->ajax_call)
33 $OUTPUT->remote_response('// subscribed');
36 // unsubscribe one or more mailboxes
37 else if ($_action=='unsubscribe')
39 if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_POST))
40 $IMAP->unsubscribe(array($mboxes));
42 if ($OUTPUT->ajax_call)
43 $OUTPUT->remote_response('// unsubscribed');
46 // create a new mailbox
47 else if ($_action=='create-folder')
49 if (!empty($_POST['_name']))
50 $create = $IMAP->create_mailbox(trim(get_input_value('_name', RCUBE_INPUT_POST, FALSE, 'UTF-7')), TRUE);
52 if ($create && $OUTPUT->ajax_call)
54 $OUTPUT->command('add_folder_row', $create, rcube_charset_convert($create, 'UTF-7'));
57 else if (!$create && $OUTPUT->ajax_call)
59 $OUTPUT->show_message('errorsaving', 'error');
60 $OUTPUT->remote_response();
63 $OUTPUT->show_message('errorsaving', 'error');
67 else if ($_action=='rename-folder')
69 if (!empty($_POST['_folder_oldname']) && !empty($_POST['_folder_newname']))
70 $rename = $IMAP->rename_mailbox(($oldname = get_input_value('_folder_oldname', RCUBE_INPUT_POST)), trim(get_input_value('_folder_newname', RCUBE_INPUT_POST, FALSE, 'UTF-7')));
72 if ($rename && $OUTPUT->ajax_call)
74 $OUTPUT->command('replace_folder_row', $oldname, $rename, rcube_charset_convert($rename, 'UTF-7'));
75 $OUTPUT->command('reset_folder_rename');
78 else if (!$rename && $OUTPUT->ajax_call)
80 $OUTPUT->command('reset_folder_rename');
81 $OUTPUT->show_message('errorsaving', 'error');
85 $OUTPUT->show_message('errorsaving', 'error');
88 // delete an existing IMAP mailbox
89 else if ($_action=='delete-folder')
91 if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_POST))
92 $deleted = $IMAP->delete_mailbox(array($mboxes));
94 if ($OUTPUT->ajax_call && $deleted)
96 $OUTPUT->command('remove_folder_row', get_input_value('_mboxes', RCUBE_INPUT_POST));
97 $OUTPUT->show_message('folderdeleted', 'confirmation');
100 else if ($OUTPUT->ajax_call)
102 $OUTPUT->show_message('errorsaving', 'error');
109 // build table with all folders listed by server
110 function rcube_subscription_form($attrib)
112 global $IMAP, $CONFIG, $OUTPUT;
114 list($form_start, $form_end) = get_form_tags($attrib, 'folders');
115 unset($attrib['form']);
119 $attrib['id'] = 'rcmSubscriptionlist';
121 // allow the following attributes to be added to the <table> tag
122 $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary'));
124 $out = "$form_start\n<table" . $attrib_str . ">\n";
128 $out .= "<thead><tr>\n";
129 $out .= sprintf('<td class="name">%s</td><td class="subscribed">%s</td>'.
130 '<td class="rename"> </td><td class="delete"> </td>',
131 rcube_label('foldername'), rcube_label('subscribed'));
133 $out .= "\n</tr></thead>\n<tbody>\n";
136 // get folders from server
137 $IMAP->clear_cache('mailboxes');
139 $a_unsubscribed = $IMAP->list_unsubscribed();
140 $a_subscribed = $IMAP->list_mailboxes();
141 $a_js_folders = array();
143 $checkbox_subscribe = new checkbox(array('name' => '_subscribed[]', 'onclick' => JS_OBJECT_NAME.".command(this.checked?'subscribe':'unsubscribe',this.value)"));
145 if (!empty($attrib['deleteicon']))
146 $del_button = sprintf('<img src="%s%s" alt="%s" border="0" />', $CONFIG['skin_path'], $attrib['deleteicon'], rcube_label('delete'));
148 $del_button = rcube_label('delete');
150 if (!empty($attrib['renameicon']))
151 $edit_button = sprintf('<img src="%s%s" alt="%s" border="0" />', $CONFIG['skin_path'], $attrib['renameicon'], rcube_label('rename'));
153 $del_button = rcube_label('rename');
155 // create list of available folders
156 foreach ($a_unsubscribed as $i => $folder)
158 $subscribed = in_array($folder, $a_subscribed);
159 $protected = ($CONFIG['protect_default_folders'] == TRUE && in_array($folder,$CONFIG['default_imap_folders']));
160 $zebra_class = $i%2 ? 'even' : 'odd';
161 $folder_js = JQ($folder);
162 $folder_html = $CONFIG['protect_default_folders'] && in_array($folder, $CONFIG['default_imap_folders']) ? rcube_label(strtolower($folder)) : rcube_charset_convert($folder, 'UTF-7');
165 $a_js_folders['rcmrow'.($i+1)] = array($folder, rcube_charset_convert($folder, 'UTF-7'));
167 $out .= sprintf('<tr id="rcmrow%d" class="%s"><td>%s</td>',
173 $out .= '<td> '.($subscribed ? '•' : '-').'</td>';
175 $out .= '<td>'.$checkbox_subscribe->show($subscribed?$folder:'', array('value' => $folder)).'</td>';
177 // add rename and delete buttons
179 $out .= sprintf('<td><a href="#rename" onclick="%s.command(\'rename-folder\',\'%s\')" title="%s">%s</a>'.
180 '<td><a href="#delete" onclick="%s.command(\'delete-folder\',\'%s\')" title="%s">%s</a></td>',
183 rcube_label('renamefolder'),
187 rcube_label('deletefolder'),
190 $out .= '<td></td><td></td>';
195 $out .= "</tbody>\n</table>";
196 $out .= "\n$form_end";
198 $OUTPUT->add_gui_object('subscriptionlist', $attrib['id']);
199 $OUTPUT->set_env('subscriptionrows', $a_js_folders);
205 function rcube_create_folder_form($attrib)
207 list($form_start, $form_end) = get_form_tags($attrib, 'create-folder');
208 unset($attrib['form']);
211 // return the complete edit form as table
212 $out = "$form_start\n";
214 $input = new textfield(array('name' => '_folder_name'));
215 $out .= $input->show();
217 if (get_boolean($attrib['button']))
219 $button = new input_field(array('type' => 'button',
220 'value' => rcube_label('create'),
221 'onclick' => JS_OBJECT_NAME.".command('create-folder',this.form)"));
222 $out .= $button->show();
225 $out .= "\n$form_end";
230 function rcube_rename_folder_form($attrib)
232 global $CONFIG, $IMAP;
234 list($form_start, $form_end) = get_form_tags($attrib, 'rename-folder');
235 unset($attrib['form']);
237 // return the complete edit form as table
238 $out = "$form_start\n";
240 $a_unsubscribed = $IMAP->list_unsubscribed();
241 $select_folder = new select(array('name' => '_folder_oldname', 'id' => 'rcmfd_oldfolder'));
243 foreach ($a_unsubscribed as $i => $folder)
245 if ($CONFIG['protect_default_folders'] == TRUE && in_array($folder,$CONFIG['default_imap_folders']))
248 $select_folder->add($folder);
251 $out .= $select_folder->show();
254 $inputtwo = new textfield(array('name' => '_folder_newname'));
255 $out .= $inputtwo->show();
257 if (get_boolean($attrib['button']))
259 $button = new input_field(array('type' => 'button',
260 'value' => rcube_label('rename'),
261 'onclick' => JS_OBJECT_NAME.".command('rename-folder',this.form)"));
262 $out .= $button->show();
265 $out .= "\n$form_end";
271 // register UI objects
272 $OUTPUT->add_handlers(array(
273 'foldersubscription' => 'rcube_subscription_form',
274 'createfolder' => 'rcube_create_folder_form',
275 'renamefolder' => 'rcube_rename_folder_form'
278 // add some labels to client
279 rcube_add_label('deletefolderconfirm');
281 $OUTPUT->send('managefolders');