]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/settings/edit_folder.inc
Imported Upstream version 0.7
[roundcube.git] / program / steps / settings / edit_folder.inc
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-2009, The Roundcube Dev Team                       |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Provide functionality to create/edit a folder                       |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Aleksander Machniak <alec@alec.pl>                            |
16  +-----------------------------------------------------------------------+
17
18  $Id: edit_folder.inc 5402 2011-11-09 10:03:54Z alec $
19
20 */
21
22 // WARNING: folder names in UI are encoded with RCMAIL_CHARSET
23
24 // init IMAP connection
25 $RCMAIL->imap_connect();
26
27 function rcmail_folder_form($attrib)
28 {
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
39     $threading_supported = $RCMAIL->imap->get_capability('THREAD');
40     $delimiter = $RCMAIL->imap->get_hierarchy_delimiter();
41
42     // Get mailbox parameters
43     if (strlen($mbox)) {
44         $options   = rcmail_folder_options($mbox_imap);
45         $namespace = $RCMAIL->imap->get_namespace();
46
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 {
55         $options = array();
56         $path    = $parent_imap;
57
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         }
71     }
72
73     $form = array();
74
75     // General tab
76     $form['props'] = array(
77         'name' => rcube_label('properties'),
78     );
79
80     // Location (name)
81     if ($options['protected']) {
82         $foldername = Q(str_replace($delimiter, ' &raquo; ', rcmail_localize_folderpath($mbox_imap)));
83     }
84     else if ($options['norename']) {
85         $foldername = Q($folder);
86     }
87     else {
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
94         if ($options['special']) {
95             $foldername .= '&nbsp;(' . Q(rcmail_localize_foldername($mbox_imap)) .')';
96         }
97     }
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
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();
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             'skip_noinferiors' => true,
123             'exceptions'  => array($mbox_imap),
124         ));
125
126         $form['props']['fieldsets']['location']['content']['path'] = array(
127             'label' => rcube_label('parentfolder'),
128             'value' => $select->show($selected),
129         );
130     }
131
132     // Settings
133     $form['props']['fieldsets']['settings'] = array(
134         'name'  => rcube_label('settings'),
135     );
136
137     // Settings: threading
138     if ($threading_supported && ($mbox_imap == 'INBOX' || (!$options['noselect'] && !$options['is_root']))) {
139         $select = new html_select(array('name' => '_viewmode', 'id' => '_listmode'));
140         $select->add(rcube_label('list'), 0);
141         $select->add(rcube_label('threads'), 1);
142
143         if (isset($_POST['_viewmode'])) {
144             $value = (int) $_POST['_viewmode'];
145         }
146         else if (strlen($mbox_imap)) {
147             $a_threaded = $RCMAIL->config->get('message_threading', array());
148             $value = (int) isset($a_threaded[$mbox_imap]);
149         }
150
151         $form['props']['fieldsets']['settings']['content']['viewmode'] = array(
152             'label' => rcube_label('listmode'),
153             'value' => $select->show($value),
154         );
155     }
156 /*
157     // Settings: sorting column
158     $select = new html_select(array('name' => '_sortcol', 'id' => '_sortcol'));
159     $select->add(rcube_label('nonesort'), '');
160     $select->add(rcube_label('arrival'), 'arrival');
161     $select->add(rcube_label('sentdate'), 'date');
162     $select->add(rcube_label('subject'), 'subject');
163     $select->add(rcube_label('fromto'), 'from');
164     $select->add(rcube_label('replyto'), 'replyto');
165     $select->add(rcube_label('cc'), 'cc');
166     $select->add(rcube_label('size'), 'size');
167
168     $value = isset($_POST['_sortcol']) ? $_POST['_sortcol'] : '';
169
170     $form['props']['fieldsets']['settings']['content']['sortcol'] = array(
171         'label' => rcube_label('listsorting'),
172         'value' => $select->show($value),
173     );
174
175     // Settings: sorting order
176     $select = new html_select(array('name' => '_sortord', 'id' => '_sortord'));
177     $select->add(rcube_label('asc'), 'ASC');
178     $select->add(rcube_label('desc'), 'DESC');
179
180     $value = isset($_POST['_sortord']) ? $_POST['_sortord'] : '';
181
182     $form['props']['fieldsets']['settings']['content']['sortord'] = array(
183         'label' => rcube_label('listorder'),
184         'value' => $select->show(),
185     );
186 */
187     // Information (count, size) - Edit mode
188     if (strlen($mbox)) {
189         // Number of messages
190         $form['props']['fieldsets']['info'] = array(
191             'name'  => rcube_label('info'),
192             'content' => array()
193         );
194
195         if ((!$options['noselect'] && !$options['is_root']) || $mbox_imap == 'INBOX') {
196             $msgcount = $RCMAIL->imap->messagecount($mbox_imap, 'ALL', true, false);
197
198             // Size
199             if ($msgcount) {
200                 // create link with folder-size command
201                 $onclick = sprintf("return %s.command('folder-size', '%s', this)",
202                     JS_OBJECT_NAME, JQ($mbox_imap));
203                 $size = html::a(array('href' => '#', 'onclick' => $onclick,
204                     'id' => 'folder-size'), rcube_label('getfoldersize'));
205             }
206             else {
207                 // no messages -> zero size
208                 $size = 0;
209             }
210
211             $form['props']['fieldsets']['info']['content']['count'] = array(
212                 'label' => rcube_label('messagecount'),
213                 'value' => (int) $msgcount
214             );
215             $form['props']['fieldsets']['info']['content']['size'] = array(
216                 'label' => rcube_label('size'),
217                 'value' => $size,
218             );
219         }
220
221         // show folder type only if we have non-private namespaces
222         if (!empty($namespace['shared']) || !empty($namespace['others'])) {
223             $form['props']['fieldsets']['info']['content']['foldertype'] = array(
224                 'label' => rcube_label('foldertype'),
225                 'value' => rcube_label($options['namespace'] . 'folder'));
226         }
227     }
228
229     // Allow plugins to modify folder form content
230     $plugin = $RCMAIL->plugins->exec_hook('folder_form',
231         array('form' => $form, 'options' => $options,
232             'name' => $mbox_imap, 'parent_name' => $parent_imap));
233
234     $form = $plugin['form'];
235
236     // Set form tags and hidden fields
237     list($form_start, $form_end) = get_form_tags($attrib, 'save-folder', null, $hidden_fields);
238
239     unset($attrib['form']);
240
241     // return the complete edit form as table
242     $out = "$form_start\n";
243
244     // Create form output
245     foreach ($form as $tab) {
246         if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) {
247             $content = '';
248             foreach ($tab['fieldsets'] as $fieldset) {
249                 $subcontent = rcmail_get_form_part($fieldset);
250                 if ($subcontent) {
251                     $content .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $subcontent) ."\n";
252                 }
253             }
254         }
255         else {
256             $content = rcmail_get_form_part($tab);
257         }
258
259         if ($content) {
260             $out .= html::tag('fieldset', null, html::tag('legend', null, Q($tab['name'])) . $content) ."\n";
261         }
262     }
263
264     $out .= "\n$form_end";
265
266     $RCMAIL->output->set_env('messagecount', (int) $msgcount);
267
268     return $out;
269 }
270
271 function rcmail_get_form_part($form)
272 {
273     $content = '';
274
275     if (is_array($form['content']) && !empty($form['content'])) {
276         $table = new html_table(array('cols' => 2));
277         foreach ($form['content'] as $col => $colprop) {
278             $colprop['id'] = '_'.$col;
279             $label = !empty($colprop['label']) ? $colprop['label'] : rcube_label($col);
280
281             $table->add('title', sprintf('<label for="%s">%s</label>', $colprop['id'], Q($label)));
282             $table->add(null, $colprop['value']);
283         }
284         $content = $table->show();
285     }
286     else {
287         $content = $form['content'];
288     }
289
290     return $content;
291 }
292
293
294 //$OUTPUT->set_pagetitle(rcube_label('folders'));
295
296 // register UI objects
297 $OUTPUT->add_handlers(array(
298     'folderdetails' => 'rcmail_folder_form',
299 ));
300
301 $OUTPUT->add_label('nonamewarning');
302
303 $OUTPUT->send('folderedit');