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