0
|
1 <?php
|
|
2
|
|
3 /**
|
|
4 +-----------------------------------------------------------------------+
|
|
5 | program/steps/settings/edit_folder.inc |
|
|
6 | |
|
|
7 | This file is part of the Roundcube Webmail client |
|
|
8 | Copyright (C) 2005-2013, The Roundcube Dev Team |
|
|
9 | |
|
|
10 | Licensed under the GNU General Public License version 3 or |
|
|
11 | any later version with exceptions for skins & plugins. |
|
|
12 | See the README file for a full license statement. |
|
|
13 | |
|
|
14 | PURPOSE: |
|
|
15 | Provide functionality to create/edit a folder |
|
|
16 | |
|
|
17 +-----------------------------------------------------------------------+
|
|
18 | Author: Aleksander Machniak <alec@alec.pl> |
|
|
19 +-----------------------------------------------------------------------+
|
|
20 */
|
|
21
|
|
22 // register UI objects
|
|
23 $OUTPUT->add_handlers(array(
|
|
24 'folderdetails' => 'rcmail_folder_form',
|
|
25 ));
|
|
26
|
|
27 $OUTPUT->add_label('nonamewarning');
|
|
28
|
|
29 $OUTPUT->send('folderedit');
|
|
30
|
|
31
|
|
32 // WARNING: folder names in UI are encoded with RCUBE_CHARSET
|
|
33
|
|
34 function rcmail_folder_form($attrib)
|
|
35 {
|
|
36 global $RCMAIL;
|
|
37
|
|
38 $storage = $RCMAIL->get_storage();
|
|
39
|
|
40 // edited folder name (empty in create-folder mode)
|
|
41 $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GPC, true);
|
|
42
|
|
43 // predefined path for new folder
|
|
44 $parent = rcube_utils::get_input_value('_path', rcube_utils::INPUT_GPC, true);
|
|
45
|
|
46 $threading_supported = $storage->get_capability('THREAD');
|
|
47 $delimiter = $storage->get_hierarchy_delimiter();
|
|
48
|
|
49 // Get mailbox parameters
|
|
50 if (strlen($mbox)) {
|
|
51 $options = rcmail_folder_options($mbox);
|
|
52 $namespace = $storage->get_namespace();
|
|
53
|
|
54 $path = explode($delimiter, $mbox);
|
|
55 $folder = array_pop($path);
|
|
56 $path = implode($delimiter, $path);
|
|
57 $folder = rcube_charset::convert($folder, 'UTF7-IMAP');
|
|
58
|
|
59 $hidden_fields = array('name' => '_mbox', 'value' => $mbox);
|
|
60 }
|
|
61 else {
|
|
62 $options = array();
|
|
63 $path = $parent;
|
|
64
|
|
65 // allow creating subfolders of INBOX folder
|
|
66 if ($path == 'INBOX') {
|
|
67 $path = $storage->mod_folder($path, 'in');
|
|
68 }
|
|
69 }
|
|
70
|
|
71 // remove personal namespace prefix
|
|
72 if (strlen($path)) {
|
|
73 $path_id = $path;
|
|
74 $path = $storage->mod_folder($path.$delimiter);
|
|
75 if ($path[strlen($path)-1] == $delimiter) {
|
|
76 $path = substr($path, 0, -1);
|
|
77 }
|
|
78 }
|
|
79
|
|
80 $form = array();
|
|
81
|
|
82 // General tab
|
|
83 $form['props'] = array(
|
|
84 'name' => $RCMAIL->gettext('properties'),
|
|
85 );
|
|
86
|
|
87 // Location (name)
|
|
88 if ($options['protected']) {
|
|
89 $foldername = str_replace($delimiter, ' » ', rcube::Q($RCMAIL->localize_foldername($mbox, false, true)));
|
|
90 }
|
|
91 else if ($options['norename']) {
|
|
92 $foldername = rcube::Q($folder);
|
|
93 }
|
|
94 else {
|
|
95 if (isset($_POST['_name'])) {
|
|
96 $folder = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST, true));
|
|
97 }
|
|
98
|
|
99 $foldername = new html_inputfield(array('name' => '_name', 'id' => '_name', 'size' => 30));
|
|
100 $foldername = $foldername->show($folder);
|
|
101
|
|
102 if ($options['special'] && ($sname = $RCMAIL->localize_foldername($mbox, false, true)) != $folder) {
|
|
103 $foldername .= ' (' . rcube::Q($sname) .')';
|
|
104 }
|
|
105 }
|
|
106
|
|
107 $form['props']['fieldsets']['location'] = array(
|
|
108 'name' => $RCMAIL->gettext('location'),
|
|
109 'content' => array(
|
|
110 'name' => array(
|
|
111 'label' => $RCMAIL->gettext('foldername'),
|
|
112 'value' => $foldername,
|
|
113 ),
|
|
114 ),
|
|
115 );
|
|
116
|
|
117 if (!empty($options) && ($options['norename'] || $options['protected'])) {
|
|
118 // prevent user from moving folder
|
|
119 $hidden_path = new html_hiddenfield(array('name' => '_parent', 'value' => $path));
|
|
120 $form['props']['fieldsets']['location']['content']['name']['value'] .= $hidden_path->show();
|
|
121 }
|
|
122 else {
|
|
123 $selected = isset($_POST['_parent']) ? $_POST['_parent'] : $path_id;
|
|
124 $exceptions = array($mbox);
|
|
125
|
|
126 // Exclude 'prefix' namespace from parent folders list (#1488349)
|
|
127 // If INBOX. namespace exists, folders created as INBOX subfolders
|
|
128 // will be listed at the same level - selecting INBOX as a parent does nothing
|
|
129 if ($prefix = $storage->get_namespace('prefix')) {
|
|
130 $exceptions[] = substr($prefix, 0, -1);
|
|
131 }
|
|
132
|
|
133 $select = $RCMAIL->folder_selector(array(
|
|
134 'id' => '_parent',
|
|
135 'name' => '_parent',
|
|
136 'noselection' => '---',
|
|
137 'maxlength' => 150,
|
|
138 'unsubscribed' => true,
|
|
139 'skip_noinferiors' => true,
|
|
140 'exceptions' => $exceptions,
|
|
141 'additional' => strlen($selected) ? array($selected) : null,
|
|
142 ));
|
|
143
|
|
144 $form['props']['fieldsets']['location']['content']['path'] = array(
|
|
145 'label' => $RCMAIL->gettext('parentfolder'),
|
|
146 'value' => $select->show($selected),
|
|
147 );
|
|
148 }
|
|
149
|
|
150 // Settings
|
|
151 $form['props']['fieldsets']['settings'] = array(
|
|
152 'name' => $RCMAIL->gettext('settings'),
|
|
153 );
|
|
154
|
|
155 // Settings: threading
|
|
156 if ($threading_supported && ($mbox == 'INBOX' || (!$options['noselect'] && !$options['is_root']))) {
|
|
157 $select = new html_select(array('name' => '_viewmode', 'id' => '_viewmode'));
|
|
158 $select->add($RCMAIL->gettext('list'), 0);
|
|
159 $select->add($RCMAIL->gettext('threads'), 1);
|
|
160
|
|
161 if (isset($_POST['_viewmode'])) {
|
|
162 $value = (int) $_POST['_viewmode'];
|
|
163 }
|
|
164 else if (strlen($mbox)) {
|
|
165 $a_threaded = $RCMAIL->config->get('message_threading', array());
|
|
166 $default_mode = $RCMAIL->config->get('default_list_mode', 'list');
|
|
167
|
|
168 $value = (int) (isset($a_threaded[$mbox]) ? $a_threaded[$mbox] : $default_mode == 'threads');
|
|
169 }
|
|
170
|
|
171 $form['props']['fieldsets']['settings']['content']['viewmode'] = array(
|
|
172 'label' => $RCMAIL->gettext('listmode'),
|
|
173 'value' => $select->show($value),
|
|
174 );
|
|
175 }
|
|
176 /*
|
|
177 // Settings: sorting column
|
|
178 $select = new html_select(array('name' => '_sortcol', 'id' => '_sortcol'));
|
|
179 $select->add($RCMAIL->gettext('nonesort'), '');
|
|
180 $select->add($RCMAIL->gettext('arrival'), 'arrival');
|
|
181 $select->add($RCMAIL->gettext('sentdate'), 'date');
|
|
182 $select->add($RCMAIL->gettext('subject'), 'subject');
|
|
183 $select->add($RCMAIL->gettext('fromto'), 'from');
|
|
184 $select->add($RCMAIL->gettext('replyto'), 'replyto');
|
|
185 $select->add($RCMAIL->gettext('cc'), 'cc');
|
|
186 $select->add($RCMAIL->gettext('size'), 'size');
|
|
187
|
|
188 $value = isset($_POST['_sortcol']) ? $_POST['_sortcol'] : '';
|
|
189
|
|
190 $form['props']['fieldsets']['settings']['content']['sortcol'] = array(
|
|
191 'label' => $RCMAIL->gettext('listsorting'),
|
|
192 'value' => $select->show($value),
|
|
193 );
|
|
194
|
|
195 // Settings: sorting order
|
|
196 $select = new html_select(array('name' => '_sortord', 'id' => '_sortord'));
|
|
197 $select->add($RCMAIL->gettext('asc'), 'ASC');
|
|
198 $select->add($RCMAIL->gettext('desc'), 'DESC');
|
|
199
|
|
200 $value = isset($_POST['_sortord']) ? $_POST['_sortord'] : '';
|
|
201
|
|
202 $form['props']['fieldsets']['settings']['content']['sortord'] = array(
|
|
203 'label' => $RCMAIL->gettext('listorder'),
|
|
204 'value' => $select->show(),
|
|
205 );
|
|
206 */
|
|
207 // Information (count, size) - Edit mode
|
|
208 if (strlen($mbox)) {
|
|
209 // Number of messages
|
|
210 $form['props']['fieldsets']['info'] = array(
|
|
211 'name' => $RCMAIL->gettext('info'),
|
|
212 'content' => array()
|
|
213 );
|
|
214
|
|
215 if ((!$options['noselect'] && !$options['is_root']) || $mbox == 'INBOX') {
|
|
216 $msgcount = $storage->count($mbox, 'ALL', true, false);
|
|
217
|
|
218 // Size
|
|
219 if ($msgcount) {
|
|
220 // create link with folder-size command
|
|
221 $onclick = sprintf("return %s.command('folder-size', '%s', this)",
|
|
222 rcmail_output::JS_OBJECT_NAME, rcube::JQ($mbox));
|
|
223 $size = html::a(array('href' => '#', 'onclick' => $onclick,
|
|
224 'id' => 'folder-size'), $RCMAIL->gettext('getfoldersize'));
|
|
225 }
|
|
226 else {
|
|
227 // no messages -> zero size
|
|
228 $size = 0;
|
|
229 }
|
|
230
|
|
231 $form['props']['fieldsets']['info']['content']['count'] = array(
|
|
232 'label' => $RCMAIL->gettext('messagecount'),
|
|
233 'value' => (int) $msgcount
|
|
234 );
|
|
235 $form['props']['fieldsets']['info']['content']['size'] = array(
|
|
236 'label' => $RCMAIL->gettext('size'),
|
|
237 'value' => $size,
|
|
238 );
|
|
239 }
|
|
240
|
|
241 // show folder type only if we have non-private namespaces
|
|
242 if (!empty($namespace['shared']) || !empty($namespace['others'])) {
|
|
243 $form['props']['fieldsets']['info']['content']['foldertype'] = array(
|
|
244 'label' => $RCMAIL->gettext('foldertype'),
|
|
245 'value' => $RCMAIL->gettext($options['namespace'] . 'folder'));
|
|
246 }
|
|
247 }
|
|
248
|
|
249 // Allow plugins to modify folder form content
|
|
250 $plugin = $RCMAIL->plugins->exec_hook('folder_form',
|
|
251 array('form' => $form, 'options' => $options,
|
|
252 'name' => $mbox, 'parent_name' => $parent));
|
|
253
|
|
254 $form = $plugin['form'];
|
|
255
|
|
256 // Set form tags and hidden fields
|
|
257 list($form_start, $form_end) = get_form_tags($attrib, 'save-folder', null, $hidden_fields);
|
|
258
|
|
259 unset($attrib['form'], $attrib['id']);
|
|
260
|
|
261 // return the complete edit form as table
|
|
262 $out = "$form_start\n";
|
|
263
|
|
264 // Create form output
|
|
265 foreach ($form as $idx => $tab) {
|
|
266 if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) {
|
|
267 $content = '';
|
|
268 foreach ($tab['fieldsets'] as $fieldset) {
|
|
269 $subcontent = rcmail_get_form_part($fieldset, $attrib);
|
|
270 if ($subcontent) {
|
|
271 $subcontent = html::tag('legend', null, rcube::Q($fieldset['name'])) . $subcontent;
|
|
272 $content .= html::tag('fieldset', null, $subcontent) ."\n";
|
|
273 }
|
|
274 }
|
|
275 }
|
|
276 else {
|
|
277 $content = rcmail_get_form_part($tab, $attrib);
|
|
278 }
|
|
279
|
|
280 if ($idx != 'props') {
|
|
281 $out .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($tab['name'])) . $content) ."\n";
|
|
282 }
|
|
283 else {
|
|
284 $out .= $content ."\n";
|
|
285 }
|
|
286 }
|
|
287
|
|
288 $out .= "\n$form_end";
|
|
289
|
|
290 $RCMAIL->output->set_env('messagecount', (int) $msgcount);
|
|
291 $RCMAIL->output->set_env('folder', $mbox);
|
|
292
|
|
293 if ($mbox !== null && empty($_POST)) {
|
|
294 $RCMAIL->output->command('parent.set_quota', $RCMAIL->quota_content(null, $mbox));
|
|
295 }
|
|
296
|
|
297 return $out;
|
|
298 }
|
|
299
|
|
300 function rcmail_get_form_part($form, $attrib = array())
|
|
301 {
|
|
302 global $RCMAIL;
|
|
303
|
|
304 $content = '';
|
|
305
|
|
306 if (is_array($form['content']) && !empty($form['content'])) {
|
|
307 $table = new html_table(array('cols' => 2));
|
|
308 foreach ($form['content'] as $col => $colprop) {
|
|
309 $colprop['id'] = '_'.$col;
|
|
310 $label = $colprop['label'] ?: $RCMAIL->gettext($col);
|
|
311
|
|
312 $table->add('title', html::label($colprop['id'], rcube::Q($label)));
|
|
313 $table->add(null, $colprop['value']);
|
|
314 }
|
|
315 $content = $table->show($attrib);
|
|
316 }
|
|
317 else {
|
|
318 $content = $form['content'];
|
|
319 }
|
|
320
|
|
321 return $content;
|
|
322 }
|