4 +-----------------------------------------------------------------------+
5 | program/steps/settings/edit_folder.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2009, Roundcube Dev. - Switzerland |
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 4389 2011-01-04 11:16:54Z alec $
22 // WARNING: folder names in UI are encoded with RCMAIL_CHARSET
24 // init IMAP connection
25 $RCMAIL->imap_connect();
27 function rcube_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 $delimiter = $RCMAIL->imap->get_hierarchy_delimiter();
40 $special = (strlen($mbox_imap) && in_array($mbox_imap, (array) $RCMAIL->config->get('default_imap_folders')));
41 $protected = ($special && $RCMAIL->config->get('protect_default_folders'));
42 $threading_supported = $RCMAIL->imap->get_capability('THREAD');
44 // Get mailbox stats (messages count, etc.), mailbox name and parent
46 $msgcount = $RCMAIL->imap->messagecount($mbox_imap, 'ALL', true, false);
48 $path = explode($delimiter, $mbox_imap);
49 $folder = array_pop($path);
50 $path = implode($delimiter, $path);
52 $folder = rcube_charset_convert($folder, 'UTF7-IMAP');
54 $hidden_fields = array('name' => '_mbox', 'value' => $mbox);
63 $form['props'] = array(
64 'name' => rcube_label('properties'),
69 $foldername = rcmail_localize_foldername($mbox_imap);
71 if (isset($_POST['_name']))
72 $folder = trim(get_input_value('_name', RCUBE_INPUT_POST, true));
74 $foldername = new html_inputfield(array('name' => '_name', 'id' => '_name', 'size' => 30));
75 $foldername = $foldername->show($folder);
78 $foldername .= ' (' . rcmail_localize_foldername($mbox_imap) .')';
81 $form['props']['fieldsets']['location'] = array(
82 'name' => rcube_label('location'),
85 'label' => rcube_label('foldername'),
86 'value' => $foldername,
92 $radio1 = new html_radiobutton(array('name' => '_parent', 'value' => ''));
93 $radio2 = new html_radiobutton(array('name' => '_parent', 'value' => $path));
94 $selected = isset($_POST['_parent']) ? $_POST['_parent'] : $path;
96 $html_path = str_replace($delimiter, ' » ', rcmail_localize_folderpath($path));
98 $folderpath = $radio1->show($selected) . Q(rcube_label('none')) . ' '
99 .$radio2->show($selected) . Q($html_path);
101 $form['props']['fieldsets']['location']['content']['path'] = array(
102 'label' => rcube_label('parentfolder'),
103 'value' => $folderpath,
108 $form['props']['fieldsets']['settings'] = array(
109 'name' => rcube_label('settings'),
112 // Settings: threading
113 if ($threading_supported) {
114 $select = new html_select(array('name' => '_viewmode', 'id' => '_listmode'));
115 $select->add(rcube_label('list'), 0);
116 $select->add(rcube_label('threads'), 1);
118 if (isset($_POST['_viewmode'])) {
119 $value = (int) $_POST['_viewmode'];
121 else if (strlen($mbox_imap)) {
122 $a_threaded = $RCMAIL->config->get('message_threading', array());
123 $value = (int) isset($a_threaded[$mbox_imap]);
126 $form['props']['fieldsets']['settings']['content']['viewmode'] = array(
127 'label' => rcube_label('listmode'),
128 'value' => $select->show($value),
132 // Settings: sorting column
133 $select = new html_select(array('name' => '_sortcol', 'id' => '_sortcol'));
134 $select->add(rcube_label('nonesort'), '');
135 $select->add(rcube_label('arrival'), 'arrival');
136 $select->add(rcube_label('sentdate'), 'date');
137 $select->add(rcube_label('subject'), 'subject');
138 $select->add(rcube_label('fromto'), 'from');
139 $select->add(rcube_label('replyto'), 'replyto');
140 $select->add(rcube_label('cc'), 'cc');
141 $select->add(rcube_label('size'), 'size');
143 $value = isset($_POST['_sortcol']) ? $_POST['_sortcol'] : '';
145 $form['props']['fieldsets']['settings']['content']['sortcol'] = array(
146 'label' => rcube_label('listsorting'),
147 'value' => $select->show($value),
150 // Settings: sorting order
151 $select = new html_select(array('name' => '_sortord', 'id' => '_sortord'));
152 $select->add(rcube_label('asc'), 'ASC');
153 $select->add(rcube_label('desc'), 'DESC');
155 $value = isset($_POST['_sortord']) ? $_POST['_sortord'] : '';
157 $form['props']['fieldsets']['settings']['content']['sortord'] = array(
158 'label' => rcube_label('listorder'),
159 'value' => $select->show(),
162 // Information (count, size) - Edit mode
164 // Number of messages
165 $form['props']['fieldsets']['info'] = array(
166 'name' => rcube_label('info'),
169 'label' => rcube_label('messagecount'),
170 'value' => (int) $msgcount,
177 // create link with folder-size command
178 $onclick = sprintf("return %s.command('folder-size', '%s', this)",
179 JS_OBJECT_NAME, JQ($mbox_imap));
180 $size = html::a(array('href' => '#', 'onclick' => $onclick, 'id' => 'folder-size'),
181 rcube_label('getfoldersize'));
184 // no messages -> zero size
187 $form['props']['fieldsets']['info']['content']['size'] = array(
188 'label' => rcube_label('size'),
193 // Allow plugins to modify folder form content
194 $plugin = $RCMAIL->plugins->exec_hook('folder_form', array('form' => $form));
196 $form = $plugin['form'];
198 // Set form tags and hidden fields
199 list($form_start, $form_end) = get_form_tags($attrib, 'save-folder', null, $hidden_fields);
201 unset($attrib['form']);
203 // return the complete edit form as table
204 $out = "$form_start\n";
206 // Create form output
207 foreach ($form as $tab) {
208 if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) {
210 foreach ($tab['fieldsets'] as $fieldset) {
211 $subcontent = rcmail_get_form_part($fieldset);
213 $content .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $subcontent) ."\n";
218 $content = rcmail_get_form_part($tab);
222 $out .= html::tag('fieldset', null, html::tag('legend', null, Q($tab['name'])) . $content) ."\n";
226 $out .= "\n$form_end";
228 $RCMAIL->output->set_env('messagecount', (int) $msgcount);
233 function rcmail_get_form_part($form)
237 if (is_array($form['content']) && !empty($form['content'])) {
238 $table = new html_table(array('cols' => 2));
239 foreach ($form['content'] as $col => $colprop) {
240 $colprop['id'] = '_'.$col;
241 $label = !empty($colprop['label']) ? $colprop['label'] : rcube_label($col);
243 $table->add('title', sprintf('<label for="%s">%s</label>', $colprop['id'], Q($label)));
244 $table->add(null, $colprop['value']);
246 $content = $table->show();
249 $content = $form['content'];
255 function rcmail_localize_folderpath($path)
259 $protect_folders = $RCMAIL->config->get('protect_default_folders');
260 $default_folders = (array) $RCMAIL->config->get('default_imap_folders');
261 $delimiter = $RCMAIL->imap->get_hierarchy_delimiter();
262 $path = explode($delimiter, $path);
265 foreach ($path as $idx => $dir) {
266 $directory = implode($delimiter, array_slice($path, 0, $idx+1));
267 if ($protect_folders && in_array($directory, $default_folders)) {
269 $result[] = rcmail_localize_foldername($directory);
271 else if ($protect_folders && in_array($dir, $default_folders)) {
272 $result[] = rcmail_localize_foldername($dir);
275 $result[] = rcube_charset_convert($dir, 'UTF7-IMAP');
279 return implode($delimiter, $result);
283 //$OUTPUT->set_pagetitle(rcube_label('folders'));
285 // register UI objects
286 $OUTPUT->add_handlers(array(
287 'folderdetails' => 'rcube_folder_form',
290 $OUTPUT->add_label('nonamewarning');
292 $OUTPUT->send('folderedit');