]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/settings/edit_folder.inc
Imported Upstream version 0.5
[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, Roundcube Dev. - Switzerland                 |
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 4389 2011-01-04 11:16: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 rcube_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     $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');
43
44     // Get mailbox stats (messages count, etc.), mailbox name and parent
45     if (strlen($mbox)) {
46         $msgcount = $RCMAIL->imap->messagecount($mbox_imap, 'ALL', true, false);
47
48         $path   = explode($delimiter, $mbox_imap);
49         $folder = array_pop($path);
50         $path   = implode($delimiter, $path);
51
52         $folder = rcube_charset_convert($folder, 'UTF7-IMAP');
53
54         $hidden_fields = array('name' => '_mbox', 'value' => $mbox);
55     }
56     else {
57         $path = $parent_imap;
58     }
59
60     $form = array();
61
62     // General tab
63     $form['props'] = array(
64         'name' => rcube_label('properties'),
65     );
66
67     // Location (name)
68     if ($protected)
69         $foldername = rcmail_localize_foldername($mbox_imap);
70     else {
71         if (isset($_POST['_name']))
72             $folder = trim(get_input_value('_name', RCUBE_INPUT_POST, true));
73
74         $foldername = new html_inputfield(array('name' => '_name', 'id' => '_name', 'size' => 30));
75         $foldername = $foldername->show($folder);
76
77         if ($special)
78             $foldername .= '&nbsp;(' . rcmail_localize_foldername($mbox_imap) .')';
79     }
80
81     $form['props']['fieldsets']['location'] = array(
82         'name'  => rcube_label('location'),
83         'content' => array(
84             'name' => array(
85                 'label' => rcube_label('foldername'),
86                 'value' => $foldername,
87             ),
88         ),
89     );
90
91     if (strlen($path)) {
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;
95
96         $html_path = str_replace($delimiter, ' &raquo; ', rcmail_localize_folderpath($path));
97
98         $folderpath = $radio1->show($selected) . Q(rcube_label('none')) . '&nbsp;'
99             .$radio2->show($selected) . Q($html_path);
100
101         $form['props']['fieldsets']['location']['content']['path'] = array(
102             'label' => rcube_label('parentfolder'),
103             'value' => $folderpath,
104         );
105     }
106
107     // Settings
108     $form['props']['fieldsets']['settings'] = array(
109         'name'  => rcube_label('settings'),
110     );
111
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);
117
118         if (isset($_POST['_viewmode'])) {
119             $value = (int) $_POST['_viewmode'];
120         }
121         else if (strlen($mbox_imap)) {
122             $a_threaded = $RCMAIL->config->get('message_threading', array());
123             $value = (int) isset($a_threaded[$mbox_imap]);
124         }
125
126         $form['props']['fieldsets']['settings']['content']['viewmode'] = array(
127             'label' => rcube_label('listmode'),
128             'value' => $select->show($value),
129         );
130     }
131 /*
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');
142
143     $value = isset($_POST['_sortcol']) ? $_POST['_sortcol'] : '';
144
145     $form['props']['fieldsets']['settings']['content']['sortcol'] = array(
146         'label' => rcube_label('listsorting'),
147         'value' => $select->show($value),
148     );
149
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');
154
155     $value = isset($_POST['_sortord']) ? $_POST['_sortord'] : '';
156
157     $form['props']['fieldsets']['settings']['content']['sortord'] = array(
158         'label' => rcube_label('listorder'),
159         'value' => $select->show(),
160     );
161 */
162     // Information (count, size) - Edit mode
163     if (strlen($mbox)) {
164         // Number of messages
165         $form['props']['fieldsets']['info'] = array(
166             'name'  => rcube_label('info'),
167             'content' => array(
168                 'count' => array(
169                     'label' => rcube_label('messagecount'),
170                     'value' => (int) $msgcount,
171                 ),
172             ),
173         );
174
175         // Size
176         if ($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'));
182         }
183         else {
184             // no messages -> zero size
185             $size = 0;
186         }
187         $form['props']['fieldsets']['info']['content']['size'] = array(
188             'label' => rcube_label('size'),
189             'value' => $size,
190         );
191     }
192
193     // Allow plugins to modify folder form content
194     $plugin = $RCMAIL->plugins->exec_hook('folder_form', array('form' => $form));
195
196     $form = $plugin['form'];
197
198     // Set form tags and hidden fields
199     list($form_start, $form_end) = get_form_tags($attrib, 'save-folder', null, $hidden_fields);
200
201     unset($attrib['form']);
202
203     // return the complete edit form as table
204     $out = "$form_start\n";
205
206     // Create form output
207     foreach ($form as $tab) {
208         if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) {
209             $content = '';
210             foreach ($tab['fieldsets'] as $fieldset) {
211                 $subcontent = rcmail_get_form_part($fieldset);
212                 if ($subcontent) {
213                     $content .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $subcontent) ."\n";
214                 }
215             }
216         }
217         else {
218             $content = rcmail_get_form_part($tab);
219         }
220
221         if ($content) {        
222             $out .= html::tag('fieldset', null, html::tag('legend', null, Q($tab['name'])) . $content) ."\n";
223         }
224     }
225
226     $out .= "\n$form_end";
227
228     $RCMAIL->output->set_env('messagecount', (int) $msgcount);
229
230     return $out;
231 }
232
233 function rcmail_get_form_part($form)
234 {
235     $content = '';
236
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);
242
243             $table->add('title', sprintf('<label for="%s">%s</label>', $colprop['id'], Q($label)));
244             $table->add(null, $colprop['value']);
245         }
246         $content = $table->show();
247     }
248     else {
249         $content = $form['content'];
250     }
251
252     return $content;
253 }
254
255 function rcmail_localize_folderpath($path)
256 {
257     global $RCMAIL;
258
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);
263     $result          = array();
264
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)) {
268             unset($result);
269             $result[] = rcmail_localize_foldername($directory);
270         }
271         else if ($protect_folders && in_array($dir, $default_folders)) {
272             $result[] = rcmail_localize_foldername($dir);
273         }
274         else {
275             $result[] = rcube_charset_convert($dir, 'UTF7-IMAP');
276         }
277     }
278
279     return implode($delimiter, $result);
280 }
281
282
283 //$OUTPUT->set_pagetitle(rcube_label('folders'));
284
285 // register UI objects
286 $OUTPUT->add_handlers(array(
287     'folderdetails' => 'rcube_folder_form',
288 ));
289
290 $OUTPUT->add_label('nonamewarning');
291
292 $OUTPUT->send('folderedit');