commit | author | age
|
af3c04
|
1 |
<?php |
A |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/settings/edit_folder.inc | |
|
6 |
| | |
|
7 |
| This file is part of the Roundcube Webmail client | |
f5e7b3
|
8 |
| Copyright (C) 2005-2009, The Roundcube Dev Team | |
af3c04
|
9 |
| Licensed under the GNU GPL | |
A |
10 |
| | |
|
11 |
| PURPOSE: | |
|
12 |
| Provide functionality to create/edit a folder | |
|
13 |
| | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
| Author: Aleksander Machniak <alec@alec.pl> | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
|
|
18 |
$Id$ |
|
19 |
|
|
20 |
*/ |
|
21 |
|
|
22 |
// WARNING: folder names in UI are encoded with RCMAIL_CHARSET |
|
23 |
|
|
24 |
// init IMAP connection |
|
25 |
$RCMAIL->imap_connect(); |
|
26 |
|
254d5e
|
27 |
function rcmail_folder_form($attrib) |
af3c04
|
28 |
{ |
A |
29 |
global $RCMAIL; |
|
30 |
|
|
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'); |
|
34 |
|
|
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'); |
|
38 |
|
600bb1
|
39 |
$threading_supported = $RCMAIL->imap->get_capability('THREAD'); |
bbce3e
|
40 |
$delimiter = $RCMAIL->imap->get_hierarchy_delimiter(); |
af3c04
|
41 |
|
bbce3e
|
42 |
// Get mailbox parameters |
af3c04
|
43 |
if (strlen($mbox)) { |
254d5e
|
44 |
$options = rcmail_folder_options($mbox_imap); |
bbce3e
|
45 |
$namespace = $RCMAIL->imap->get_namespace(); |
af3c04
|
46 |
|
A |
47 |
$path = explode($delimiter, $mbox_imap); |
|
48 |
$folder = array_pop($path); |
|
49 |
$path = implode($delimiter, $path); |
|
50 |
$folder = rcube_charset_convert($folder, 'UTF7-IMAP'); |
|
51 |
|
|
52 |
$hidden_fields = array('name' => '_mbox', 'value' => $mbox); |
|
53 |
} |
|
54 |
else { |
bbce3e
|
55 |
$options = array(); |
A |
56 |
$path = $parent_imap; |
d08333
|
57 |
|
A |
58 |
// allow creating subfolders of INBOX folder |
|
59 |
if ($path == 'INBOX') { |
|
60 |
$path = $RCMAIL->imap->mod_mailbox($path, 'in'); |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
// remove personal namespace prefix |
|
65 |
if (strlen($path)) { |
|
66 |
$path_id = $path; |
|
67 |
$path = $RCMAIL->imap->mod_mailbox($path.$delimiter); |
|
68 |
if ($path[strlen($path)-1] == $delimiter) { |
|
69 |
$path = substr($path, 0, -1); |
|
70 |
} |
af3c04
|
71 |
} |
A |
72 |
|
|
73 |
$form = array(); |
|
74 |
|
|
75 |
// General tab |
|
76 |
$form['props'] = array( |
|
77 |
'name' => rcube_label('properties'), |
|
78 |
); |
|
79 |
|
|
80 |
// Location (name) |
bbce3e
|
81 |
if ($options['protected']) { |
922016
|
82 |
$foldername = Q(str_replace($delimiter, ' » ', rcmail_localize_folderpath($mbox_imap))); |
bbce3e
|
83 |
} |
A |
84 |
else if ($options['norename']) { |
|
85 |
$foldername = Q($folder); |
|
86 |
} |
af3c04
|
87 |
else { |
A |
88 |
if (isset($_POST['_name'])) |
|
89 |
$folder = trim(get_input_value('_name', RCUBE_INPUT_POST, true)); |
|
90 |
|
|
91 |
$foldername = new html_inputfield(array('name' => '_name', 'id' => '_name', 'size' => 30)); |
|
92 |
$foldername = $foldername->show($folder); |
|
93 |
|
bbce3e
|
94 |
if ($options['special']) { |
A |
95 |
$foldername .= ' (' . Q(rcmail_localize_foldername($mbox_imap)) .')'; |
|
96 |
} |
af3c04
|
97 |
} |
A |
98 |
|
|
99 |
$form['props']['fieldsets']['location'] = array( |
|
100 |
'name' => rcube_label('location'), |
|
101 |
'content' => array( |
|
102 |
'name' => array( |
|
103 |
'label' => rcube_label('foldername'), |
|
104 |
'value' => $foldername, |
|
105 |
), |
|
106 |
), |
|
107 |
); |
|
108 |
|
1cd362
|
109 |
if (!empty($options) && ($options['norename'] || $options['protected'])) { |
A |
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(); |
|
113 |
} |
|
114 |
else { |
|
115 |
$selected = isset($_POST['_parent']) ? $_POST['_parent'] : $path_id; |
|
116 |
$select = rcmail_mailbox_select(array( |
|
117 |
'name' => '_parent', |
|
118 |
'noselection' => '---', |
|
119 |
'realnames' => false, |
|
120 |
'maxlength' => 150, |
|
121 |
'unsubscribed' => true, |
|
122 |
'exceptions' => array($mbox_imap), |
|
123 |
)); |
af3c04
|
124 |
|
1cd362
|
125 |
$form['props']['fieldsets']['location']['content']['path'] = array( |
A |
126 |
'label' => rcube_label('parentfolder'), |
|
127 |
'value' => $select->show($selected), |
|
128 |
); |
af3c04
|
129 |
} |
A |
130 |
|
|
131 |
// Settings |
|
132 |
$form['props']['fieldsets']['settings'] = array( |
|
133 |
'name' => rcube_label('settings'), |
|
134 |
); |
|
135 |
|
|
136 |
// Settings: threading |
67975b
|
137 |
if ($threading_supported && !$options['noselect'] && !$options['is_root']) { |
af3c04
|
138 |
$select = new html_select(array('name' => '_viewmode', 'id' => '_listmode')); |
A |
139 |
$select->add(rcube_label('list'), 0); |
|
140 |
$select->add(rcube_label('threads'), 1); |
|
141 |
|
|
142 |
if (isset($_POST['_viewmode'])) { |
|
143 |
$value = (int) $_POST['_viewmode']; |
|
144 |
} |
|
145 |
else if (strlen($mbox_imap)) { |
|
146 |
$a_threaded = $RCMAIL->config->get('message_threading', array()); |
|
147 |
$value = (int) isset($a_threaded[$mbox_imap]); |
|
148 |
} |
|
149 |
|
|
150 |
$form['props']['fieldsets']['settings']['content']['viewmode'] = array( |
|
151 |
'label' => rcube_label('listmode'), |
|
152 |
'value' => $select->show($value), |
|
153 |
); |
|
154 |
} |
|
155 |
/* |
|
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'); |
|
166 |
|
|
167 |
$value = isset($_POST['_sortcol']) ? $_POST['_sortcol'] : ''; |
|
168 |
|
|
169 |
$form['props']['fieldsets']['settings']['content']['sortcol'] = array( |
|
170 |
'label' => rcube_label('listsorting'), |
|
171 |
'value' => $select->show($value), |
|
172 |
); |
|
173 |
|
|
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'); |
|
178 |
|
|
179 |
$value = isset($_POST['_sortord']) ? $_POST['_sortord'] : ''; |
|
180 |
|
|
181 |
$form['props']['fieldsets']['settings']['content']['sortord'] = array( |
|
182 |
'label' => rcube_label('listorder'), |
|
183 |
'value' => $select->show(), |
|
184 |
); |
|
185 |
*/ |
|
186 |
// Information (count, size) - Edit mode |
|
187 |
if (strlen($mbox)) { |
|
188 |
// Number of messages |
|
189 |
$form['props']['fieldsets']['info'] = array( |
|
190 |
'name' => rcube_label('info'), |
bbce3e
|
191 |
'content' => array() |
af3c04
|
192 |
); |
A |
193 |
|
67975b
|
194 |
if (!$options['noselect'] && !$options['is_root']) { |
bbce3e
|
195 |
$msgcount = $RCMAIL->imap->messagecount($mbox_imap, 'ALL', true, false); |
A |
196 |
|
|
197 |
// Size |
|
198 |
if ($msgcount) { |
|
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')); |
|
204 |
} |
|
205 |
else { |
|
206 |
// no messages -> zero size |
|
207 |
$size = 0; |
|
208 |
} |
|
209 |
|
|
210 |
$form['props']['fieldsets']['info']['content']['count'] = array( |
|
211 |
'label' => rcube_label('messagecount'), |
|
212 |
'value' => (int) $msgcount |
|
213 |
); |
|
214 |
$form['props']['fieldsets']['info']['content']['size'] = array( |
|
215 |
'label' => rcube_label('size'), |
|
216 |
'value' => $size, |
|
217 |
); |
af3c04
|
218 |
} |
bbce3e
|
219 |
|
A |
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')); |
af3c04
|
225 |
} |
A |
226 |
} |
|
227 |
|
|
228 |
// Allow plugins to modify folder form content |
bbce3e
|
229 |
$plugin = $RCMAIL->plugins->exec_hook('folder_form', |
0d277e
|
230 |
array('form' => $form, 'options' => $options, |
A |
231 |
'name' => $mbox_imap, 'parent_name' => $parent_imap)); |
af3c04
|
232 |
|
A |
233 |
$form = $plugin['form']; |
|
234 |
|
|
235 |
// Set form tags and hidden fields |
|
236 |
list($form_start, $form_end) = get_form_tags($attrib, 'save-folder', null, $hidden_fields); |
|
237 |
|
|
238 |
unset($attrib['form']); |
|
239 |
|
|
240 |
// return the complete edit form as table |
|
241 |
$out = "$form_start\n"; |
|
242 |
|
|
243 |
// Create form output |
|
244 |
foreach ($form as $tab) { |
|
245 |
if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) { |
|
246 |
$content = ''; |
|
247 |
foreach ($tab['fieldsets'] as $fieldset) { |
|
248 |
$subcontent = rcmail_get_form_part($fieldset); |
|
249 |
if ($subcontent) { |
|
250 |
$content .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $subcontent) ."\n"; |
|
251 |
} |
|
252 |
} |
|
253 |
} |
|
254 |
else { |
|
255 |
$content = rcmail_get_form_part($tab); |
|
256 |
} |
|
257 |
|
|
258 |
if ($content) { |
|
259 |
$out .= html::tag('fieldset', null, html::tag('legend', null, Q($tab['name'])) . $content) ."\n"; |
|
260 |
} |
|
261 |
} |
|
262 |
|
|
263 |
$out .= "\n$form_end"; |
|
264 |
|
|
265 |
$RCMAIL->output->set_env('messagecount', (int) $msgcount); |
|
266 |
|
|
267 |
return $out; |
|
268 |
} |
|
269 |
|
|
270 |
function rcmail_get_form_part($form) |
|
271 |
{ |
|
272 |
$content = ''; |
|
273 |
|
|
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); |
|
279 |
|
|
280 |
$table->add('title', sprintf('<label for="%s">%s</label>', $colprop['id'], Q($label))); |
|
281 |
$table->add(null, $colprop['value']); |
|
282 |
} |
|
283 |
$content = $table->show(); |
|
284 |
} |
|
285 |
else { |
77437e
|
286 |
$content = $form['content']; |
af3c04
|
287 |
} |
A |
288 |
|
|
289 |
return $content; |
|
290 |
} |
|
291 |
|
|
292 |
|
|
293 |
//$OUTPUT->set_pagetitle(rcube_label('folders')); |
|
294 |
|
|
295 |
// register UI objects |
|
296 |
$OUTPUT->add_handlers(array( |
254d5e
|
297 |
'folderdetails' => 'rcmail_folder_form', |
af3c04
|
298 |
)); |
A |
299 |
|
|
300 |
$OUTPUT->add_label('nonamewarning'); |
|
301 |
|
|
302 |
$OUTPUT->send('folderedit'); |