]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/settings/manage_folders.inc
Imported Upstream version 0.1~rc1~dfsg
[roundcube.git] / program / steps / settings / manage_folders.inc
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/settings/manage_folders.inc                             |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
8  | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland                 |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Provide functionality to create/delete/rename folders               |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id: manage_folders.inc 573 2007-05-18 11:29:25Z thomasb $
19
20 */
21
22 // init IMAP connection
23 rcmail_imap_init(TRUE);
24
25
26 // subscribe to one or more mailboxes
27 if ($_action=='subscribe')
28   {
29   if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_POST))
30     $IMAP->subscribe(array($mboxes));
31
32   if ($OUTPUT->ajax_call)
33     $OUTPUT->remote_response('// subscribed');
34   }
35
36 // unsubscribe one or more mailboxes
37 else if ($_action=='unsubscribe')
38   {
39   if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_POST))
40     $IMAP->unsubscribe(array($mboxes));
41
42   if ($OUTPUT->ajax_call)
43     $OUTPUT->remote_response('// unsubscribed');
44   }
45
46 // create a new mailbox
47 else if ($_action=='create-folder')
48   {
49   if (!empty($_POST['_name']))
50     $create = $IMAP->create_mailbox(trim(get_input_value('_name', RCUBE_INPUT_POST, FALSE, 'UTF-7')), TRUE);
51
52   if ($create && $OUTPUT->ajax_call)
53     {
54     $OUTPUT->command('add_folder_row', $create, rcube_charset_convert($create, 'UTF-7'));
55     $OUTPUT->send();
56     }
57   else if (!$create && $OUTPUT->ajax_call)
58     {
59     $OUTPUT->show_message('errorsaving', 'error');
60     $OUTPUT->remote_response();
61     }
62   else if (!$create)
63     $OUTPUT->show_message('errorsaving', 'error');
64   }
65
66 // rename a mailbox
67 else if ($_action=='rename-folder')
68   {
69   if (!empty($_POST['_folder_oldname']) && !empty($_POST['_folder_newname']))
70     $rename = $IMAP->rename_mailbox(($oldname = get_input_value('_folder_oldname', RCUBE_INPUT_POST)), trim(get_input_value('_folder_newname', RCUBE_INPUT_POST, FALSE, 'UTF-7')));
71     
72   if ($rename && $OUTPUT->ajax_call)
73     {
74     $OUTPUT->command('replace_folder_row', $oldname, $rename, rcube_charset_convert($rename, 'UTF-7'));
75     $OUTPUT->command('reset_folder_rename');
76     $OUTPUT->send();
77     }
78   else if (!$rename && $OUTPUT->ajax_call)
79     {
80     $OUTPUT->command('reset_folder_rename');
81     $OUTPUT->show_message('errorsaving', 'error');
82     $OUTPUT->send();
83     }
84   else if (!$rename)
85     $OUTPUT->show_message('errorsaving', 'error');
86   }
87
88 // delete an existing IMAP mailbox
89 else if ($_action=='delete-folder')
90   {
91   if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_POST))
92     $deleted = $IMAP->delete_mailbox(array($mboxes));
93
94   if ($OUTPUT->ajax_call && $deleted)
95     {
96     $OUTPUT->command('remove_folder_row', get_input_value('_mboxes', RCUBE_INPUT_POST));
97     $OUTPUT->show_message('folderdeleted', 'confirmation');
98     $OUTPUT->send();
99     }
100   else if ($OUTPUT->ajax_call)
101     {
102     $OUTPUT->show_message('errorsaving', 'error');
103     $OUTPUT->send();
104     }
105   }
106
107
108
109 // build table with all folders listed by server
110 function rcube_subscription_form($attrib)
111   {
112   global $IMAP, $CONFIG, $OUTPUT;
113
114   list($form_start, $form_end) = get_form_tags($attrib, 'folders');
115   unset($attrib['form']);
116   
117   
118   if (!$attrib['id'])
119     $attrib['id'] = 'rcmSubscriptionlist';
120
121   // allow the following attributes to be added to the <table> tag
122   $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary'));
123
124   $out = "$form_start\n<table" . $attrib_str . ">\n";
125
126
127   // add table header
128   $out .= "<thead><tr>\n";
129   $out .= sprintf('<td class="name">%s</td><td class="subscribed">%s</td>'.
130                   '<td class="rename">&nbsp;</td><td class="delete">&nbsp;</td>',
131                   rcube_label('foldername'), rcube_label('subscribed'));
132                   
133   $out .= "\n</tr></thead>\n<tbody>\n";
134
135
136   // get folders from server
137   $IMAP->clear_cache('mailboxes');
138
139   $a_unsubscribed = $IMAP->list_unsubscribed();
140   $a_subscribed = $IMAP->list_mailboxes();
141   $a_js_folders = array();
142  
143   $checkbox_subscribe = new checkbox(array('name' => '_subscribed[]', 'onclick' => JS_OBJECT_NAME.".command(this.checked?'subscribe':'unsubscribe',this.value)"));
144   
145   if (!empty($attrib['deleteicon']))
146     $del_button = sprintf('<img src="%s%s" alt="%s" border="0" />', $CONFIG['skin_path'], $attrib['deleteicon'], rcube_label('delete'));
147   else
148     $del_button = rcube_label('delete');
149
150   if (!empty($attrib['renameicon']))
151     $edit_button = sprintf('<img src="%s%s" alt="%s" border="0" />', $CONFIG['skin_path'], $attrib['renameicon'], rcube_label('rename'));
152   else
153     $del_button = rcube_label('rename');
154
155   // create list of available folders
156   foreach ($a_unsubscribed as $i => $folder)
157     {
158     $subscribed = in_array($folder, $a_subscribed);
159     $protected = ($CONFIG['protect_default_folders'] == TRUE && in_array($folder,$CONFIG['default_imap_folders']));
160     $zebra_class = $i%2 ? 'even' : 'odd';
161     $folder_js = JQ($folder);
162     $folder_html = $CONFIG['protect_default_folders'] && in_array($folder, $CONFIG['default_imap_folders']) ? rcube_label(strtolower($folder)) : rcube_charset_convert($folder, 'UTF-7');
163     
164     if (!$protected)
165       $a_js_folders['rcmrow'.($i+1)] = array($folder, rcube_charset_convert($folder, 'UTF-7'));
166
167     $out .= sprintf('<tr id="rcmrow%d" class="%s"><td>%s</td>',
168                     $i+1,
169                     $zebra_class,
170                     Q($folder_html));
171                     
172     if ($protected)
173       $out .= '<td>&nbsp;'.($subscribed ? '&#x2022;' : '-').'</td>';
174     else
175       $out .= '<td>'.$checkbox_subscribe->show($subscribed?$folder:'', array('value' => $folder)).'</td>';
176
177     // add rename and delete buttons
178     if (!$protected)
179       $out .= sprintf('<td><a href="#rename" onclick="%s.command(\'rename-folder\',\'%s\')" title="%s">%s</a>'.
180                       '<td><a href="#delete" onclick="%s.command(\'delete-folder\',\'%s\')" title="%s">%s</a></td>',
181                       JS_OBJECT_NAME,
182                       $folder_js,
183                       rcube_label('renamefolder'),
184                       $edit_button,
185                       JS_OBJECT_NAME,
186                       $folder_js,
187                       rcube_label('deletefolder'),
188                       $del_button);
189     else
190       $out .= '<td></td><td></td>';
191     
192     $out .= "</tr>\n";
193     }
194
195   $out .= "</tbody>\n</table>";
196   $out .= "\n$form_end";
197
198   $OUTPUT->add_gui_object('subscriptionlist', $attrib['id']);
199   $OUTPUT->set_env('subscriptionrows', $a_js_folders);
200
201   return $out;  
202   }
203
204
205 function rcube_create_folder_form($attrib)
206   {
207   list($form_start, $form_end) = get_form_tags($attrib, 'create-folder');
208   unset($attrib['form']);
209
210
211   // return the complete edit form as table
212   $out = "$form_start\n";
213
214   $input = new textfield(array('name' => '_folder_name'));
215   $out .= $input->show();
216   
217   if (get_boolean($attrib['button']))
218     {
219     $button = new input_field(array('type' => 'button',
220                                     'value' => rcube_label('create'),
221                                     'onclick' => JS_OBJECT_NAME.".command('create-folder',this.form)"));
222     $out .= $button->show();
223     }
224
225   $out .= "\n$form_end";
226
227   return $out;
228   }
229
230 function rcube_rename_folder_form($attrib)
231   {
232   global $CONFIG, $IMAP;
233
234   list($form_start, $form_end) = get_form_tags($attrib, 'rename-folder');
235   unset($attrib['form']);
236
237   // return the complete edit form as table
238   $out = "$form_start\n";
239
240   $a_unsubscribed = $IMAP->list_unsubscribed();
241   $select_folder = new select(array('name' => '_folder_oldname', 'id' => 'rcmfd_oldfolder'));
242
243   foreach ($a_unsubscribed as $i => $folder)
244     {
245     if ($CONFIG['protect_default_folders'] == TRUE && in_array($folder,$CONFIG['default_imap_folders'])) 
246       continue;
247
248     $select_folder->add($folder);
249     }
250
251   $out .= $select_folder->show();
252
253   $out .= " to ";
254   $inputtwo = new textfield(array('name' => '_folder_newname'));
255   $out .= $inputtwo->show();
256
257   if (get_boolean($attrib['button']))
258     {
259     $button = new input_field(array('type' => 'button',
260                                     'value' => rcube_label('rename'),
261                                     'onclick' => JS_OBJECT_NAME.".command('rename-folder',this.form)"));
262     $out .= $button->show();
263     }
264
265   $out .= "\n$form_end";
266
267   return $out;
268   }
269
270
271 // register UI objects
272 $OUTPUT->add_handlers(array(
273   'foldersubscription' => 'rcube_subscription_form',
274   'createfolder' => 'rcube_create_folder_form',
275   'renamefolder' => 'rcube_rename_folder_form'
276 ));
277
278 // add some labels to client
279 rcube_add_label('deletefolderconfirm');
280
281 $OUTPUT->send('managefolders');
282 ?>