4 +-----------------------------------------------------------------------+
5 | program/steps/settings/edit_folder.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2009, The Roundcube Dev Team |
9 | Licensed under the GNU GPL |
12 | Provide functionality to create/edit a folder |
14 +-----------------------------------------------------------------------+
15 | Author: Aleksander Machniak <alec@alec.pl> |
16 +-----------------------------------------------------------------------+
18 $Id: edit_folder.inc 5022 2011-08-04 09:01:36Z alec $
22 // WARNING: folder names in UI are encoded with RCMAIL_CHARSET
24 // init IMAP connection
25 $RCMAIL->imap_connect();
27 function rcmail_folder_form($attrib)
31 // edited folder name (empty in create-folder mode)
32 $mbox = trim(get_input_value('_mbox', RCUBE_INPUT_GPC, true));
33 $mbox_imap = rcube_charset_convert($mbox, RCMAIL_CHARSET, 'UTF7-IMAP');
35 // predefined path for new folder
36 $parent = trim(get_input_value('_path', RCUBE_INPUT_GPC, true));
37 $parent_imap = rcube_charset_convert($parent, RCMAIL_CHARSET, 'UTF7-IMAP');
39 $threading_supported = $RCMAIL->imap->get_capability('THREAD');
40 $delimiter = $RCMAIL->imap->get_hierarchy_delimiter();
42 // Get mailbox parameters
44 $options = rcmail_folder_options($mbox_imap);
45 $namespace = $RCMAIL->imap->get_namespace();
47 $path = explode($delimiter, $mbox_imap);
48 $folder = array_pop($path);
49 $path = implode($delimiter, $path);
50 $folder = rcube_charset_convert($folder, 'UTF7-IMAP');
52 $hidden_fields = array('name' => '_mbox', 'value' => $mbox);
58 // allow creating subfolders of INBOX folder
59 if ($path == 'INBOX') {
60 $path = $RCMAIL->imap->mod_mailbox($path, 'in');
64 // remove personal namespace prefix
67 $path = $RCMAIL->imap->mod_mailbox($path.$delimiter);
68 if ($path[strlen($path)-1] == $delimiter) {
69 $path = substr($path, 0, -1);
76 $form['props'] = array(
77 'name' => rcube_label('properties'),
81 if ($options['protected']) {
82 $foldername = Q(str_replace($delimiter, ' » ', rcmail_localize_folderpath($mbox_imap)));
84 else if ($options['norename']) {
85 $foldername = Q($folder);
88 if (isset($_POST['_name']))
89 $folder = trim(get_input_value('_name', RCUBE_INPUT_POST, true));
91 $foldername = new html_inputfield(array('name' => '_name', 'id' => '_name', 'size' => 30));
92 $foldername = $foldername->show($folder);
94 if ($options['special']) {
95 $foldername .= ' (' . Q(rcmail_localize_foldername($mbox_imap)) .')';
99 $form['props']['fieldsets']['location'] = array(
100 'name' => rcube_label('location'),
103 'label' => rcube_label('foldername'),
104 'value' => $foldername,
109 if (!empty($options) && ($options['norename'] || $options['protected'])) {
110 // prevent user from moving folder
111 $hidden_path = new html_hiddenfield(array('name' => '_parent', 'value' => $path));
112 $form['props']['fieldsets']['location']['content']['name']['value'] .= $hidden_path->show();
115 $selected = isset($_POST['_parent']) ? $_POST['_parent'] : $path_id;
116 $select = rcmail_mailbox_select(array(
118 'noselection' => '---',
119 'realnames' => false,
121 'unsubscribed' => true,
122 'exceptions' => array($mbox_imap),
125 $form['props']['fieldsets']['location']['content']['path'] = array(
126 'label' => rcube_label('parentfolder'),
127 'value' => $select->show($selected),
132 $form['props']['fieldsets']['settings'] = array(
133 'name' => rcube_label('settings'),
136 // Settings: threading
137 if ($threading_supported && !$options['noselect'] && !$options['is_root']) {
138 $select = new html_select(array('name' => '_viewmode', 'id' => '_listmode'));
139 $select->add(rcube_label('list'), 0);
140 $select->add(rcube_label('threads'), 1);
142 if (isset($_POST['_viewmode'])) {
143 $value = (int) $_POST['_viewmode'];
145 else if (strlen($mbox_imap)) {
146 $a_threaded = $RCMAIL->config->get('message_threading', array());
147 $value = (int) isset($a_threaded[$mbox_imap]);
150 $form['props']['fieldsets']['settings']['content']['viewmode'] = array(
151 'label' => rcube_label('listmode'),
152 'value' => $select->show($value),
156 // Settings: sorting column
157 $select = new html_select(array('name' => '_sortcol', 'id' => '_sortcol'));
158 $select->add(rcube_label('nonesort'), '');
159 $select->add(rcube_label('arrival'), 'arrival');
160 $select->add(rcube_label('sentdate'), 'date');
161 $select->add(rcube_label('subject'), 'subject');
162 $select->add(rcube_label('fromto'), 'from');
163 $select->add(rcube_label('replyto'), 'replyto');
164 $select->add(rcube_label('cc'), 'cc');
165 $select->add(rcube_label('size'), 'size');
167 $value = isset($_POST['_sortcol']) ? $_POST['_sortcol'] : '';
169 $form['props']['fieldsets']['settings']['content']['sortcol'] = array(
170 'label' => rcube_label('listsorting'),
171 'value' => $select->show($value),
174 // Settings: sorting order
175 $select = new html_select(array('name' => '_sortord', 'id' => '_sortord'));
176 $select->add(rcube_label('asc'), 'ASC');
177 $select->add(rcube_label('desc'), 'DESC');
179 $value = isset($_POST['_sortord']) ? $_POST['_sortord'] : '';
181 $form['props']['fieldsets']['settings']['content']['sortord'] = array(
182 'label' => rcube_label('listorder'),
183 'value' => $select->show(),
186 // Information (count, size) - Edit mode
188 // Number of messages
189 $form['props']['fieldsets']['info'] = array(
190 'name' => rcube_label('info'),
194 if (!$options['noselect'] && !$options['is_root']) {
195 $msgcount = $RCMAIL->imap->messagecount($mbox_imap, 'ALL', true, false);
199 // create link with folder-size command
200 $onclick = sprintf("return %s.command('folder-size', '%s', this)",
201 JS_OBJECT_NAME, JQ($mbox_imap));
202 $size = html::a(array('href' => '#', 'onclick' => $onclick,
203 'id' => 'folder-size'), rcube_label('getfoldersize'));
206 // no messages -> zero size
210 $form['props']['fieldsets']['info']['content']['count'] = array(
211 'label' => rcube_label('messagecount'),
212 'value' => (int) $msgcount
214 $form['props']['fieldsets']['info']['content']['size'] = array(
215 'label' => rcube_label('size'),
220 // show folder type only if we have non-private namespaces
221 if (!empty($namespace['shared']) || !empty($namespace['others'])) {
222 $form['props']['fieldsets']['info']['content']['foldertype'] = array(
223 'label' => rcube_label('foldertype'),
224 'value' => rcube_label($options['namespace'] . 'folder'));
228 // Allow plugins to modify folder form content
229 $plugin = $RCMAIL->plugins->exec_hook('folder_form',
230 array('form' => $form, 'options' => $options,
231 'name' => $mbox_imap, 'parent_name' => $parent_imap));
233 $form = $plugin['form'];
235 // Set form tags and hidden fields
236 list($form_start, $form_end) = get_form_tags($attrib, 'save-folder', null, $hidden_fields);
238 unset($attrib['form']);
240 // return the complete edit form as table
241 $out = "$form_start\n";
243 // Create form output
244 foreach ($form as $tab) {
245 if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) {
247 foreach ($tab['fieldsets'] as $fieldset) {
248 $subcontent = rcmail_get_form_part($fieldset);
250 $content .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $subcontent) ."\n";
255 $content = rcmail_get_form_part($tab);
259 $out .= html::tag('fieldset', null, html::tag('legend', null, Q($tab['name'])) . $content) ."\n";
263 $out .= "\n$form_end";
265 $RCMAIL->output->set_env('messagecount', (int) $msgcount);
270 function rcmail_get_form_part($form)
274 if (is_array($form['content']) && !empty($form['content'])) {
275 $table = new html_table(array('cols' => 2));
276 foreach ($form['content'] as $col => $colprop) {
277 $colprop['id'] = '_'.$col;
278 $label = !empty($colprop['label']) ? $colprop['label'] : rcube_label($col);
280 $table->add('title', sprintf('<label for="%s">%s</label>', $colprop['id'], Q($label)));
281 $table->add(null, $colprop['value']);
283 $content = $table->show();
286 $content = $form['content'];
293 //$OUTPUT->set_pagetitle(rcube_label('folders'));
295 // register UI objects
296 $OUTPUT->add_handlers(array(
297 'folderdetails' => 'rcmail_folder_form',
300 $OUTPUT->add_label('nonamewarning');
302 $OUTPUT->send('folderedit');