source: subversion/trunk/roundcubemail/program/steps/settings/manage_folders.inc @ 866

Last change on this file since 866 was 866, checked in by robin, 6 years ago

When a parent folder is deleted, delete the children immediately, instead of one-by-one as r833 did.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.4 KB
Line 
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$
19
20*/
21
22// init IMAP connection
23rcmail_imap_init(TRUE);
24
25$OUTPUT->include_script('list.js');
26
27
28// subscribe to one or more mailboxes
29if ($_action=='subscribe')
30  {
31  if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_POST))
32    $IMAP->subscribe($mboxes);
33
34  if ($OUTPUT->ajax_call)
35    $OUTPUT->remote_response('// subscribed');
36  }
37
38// unsubscribe one or more mailboxes
39else if ($_action=='unsubscribe')
40  {
41  if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_POST))
42    $IMAP->unsubscribe($mboxes);
43
44  if ($OUTPUT->ajax_call)
45    $OUTPUT->remote_response('// unsubscribed');
46  }
47
48// create a new mailbox
49else if ($_action=='create-folder')
50  {
51  if (!empty($_POST['_name']))
52    $create = $IMAP->create_mailbox(trim(get_input_value('_name', RCUBE_INPUT_POST, FALSE, 'UTF-7')), TRUE);
53
54  if ($create && $OUTPUT->ajax_call)
55    {
56    $delimiter = $IMAP->get_hierarchy_delimiter();
57    $foldersplit = explode($delimiter, $create);
58    $display_create = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', substr_count($create, $delimiter)) . rcube_charset_convert($foldersplit[count($foldersplit)-1], 'UTF-7');
59    $OUTPUT->command('add_folder_row', $create, $display_create);
60    $OUTPUT->send();
61    }
62  else if (!$create && $OUTPUT->ajax_call)
63    {
64    $OUTPUT->show_message('errorsaving', 'error');
65    $OUTPUT->remote_response();
66    }
67  else if (!$create)
68    $OUTPUT->show_message('errorsaving', 'error');
69  }
70
71// rename a mailbox
72else if ($_action=='rename-folder')
73  {
74  if (!empty($_POST['_folder_oldname']) && !empty($_POST['_folder_newname']))
75    $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')));
76   
77  if ($rename && $OUTPUT->ajax_call)
78    {
79    $delimiter = $IMAP->get_hierarchy_delimiter();
80    $foldersplit = explode($delimiter, $rename);
81    $level = count($foldersplit) - 1;
82    $display_rename = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level) . rcube_charset_convert($foldersplit[$level], 'UTF-7');
83    $OUTPUT->command('replace_folder_row', $oldname, $rename, $display_rename);
84    $OUTPUT->command('reset_folder_rename');
85    $OUTPUT->send();
86    }
87  else if (!$rename && $OUTPUT->ajax_call)
88    {
89    $OUTPUT->command('reset_folder_rename');
90    $OUTPUT->show_message('errorsaving', 'error');
91    $OUTPUT->send();
92    }
93  else if (!$rename)
94    $OUTPUT->show_message('errorsaving', 'error');
95  }
96
97// delete an existing IMAP mailbox
98else if ($_action=='delete-folder')
99  {
100  $a_mboxes = array_merge($IMAP->list_mailboxes(), $IMAP->list_unsubscribed());
101  $delimiter = $IMAP->get_hierarchy_delimiter();
102
103  if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_POST))
104    $deleted = $IMAP->delete_mailbox(array($mboxes));
105
106  if ($OUTPUT->ajax_call && $deleted)
107    {
108    $OUTPUT->command('remove_folder_row', get_input_value('_mboxes', RCUBE_INPUT_POST));
109    foreach ($a_mboxes as $mbox)
110      if (preg_match('/^'.preg_quote(get_input_value('_mboxes', RCUBE_INPUT_POST).$delimiter).'/', $mbox))
111        $OUTPUT->command('remove_folder_row', $mbox);
112    $OUTPUT->show_message('folderdeleted', 'confirmation');
113    $OUTPUT->send();
114    }
115  else if ($OUTPUT->ajax_call)
116    {
117    $OUTPUT->show_message('errorsaving', 'error');
118    $OUTPUT->send();
119    }
120  }
121
122
123
124// build table with all folders listed by server
125function rcube_subscription_form($attrib)
126  {
127  global $IMAP, $CONFIG, $OUTPUT;
128
129  list($form_start, $form_end) = get_form_tags($attrib, 'folders');
130  unset($attrib['form']);
131 
132 
133  if (!$attrib['id'])
134    $attrib['id'] = 'rcmSubscriptionlist';
135
136  // allow the following attributes to be added to the <table> tag
137  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary'));
138
139  $out = "$form_start\n<table" . $attrib_str . ">\n";
140
141
142  // add table header
143  $out .= "<thead><tr>\n";
144  $out .= sprintf('<td class="name">%s</td><td class="subscribed">%s</td>'.
145                  '<td class="rename">&nbsp;</td><td class="delete">&nbsp;</td>',
146                  rcube_label('foldername'), rcube_label('subscribed'));
147                 
148  $out .= "\n</tr></thead>\n<tbody>\n";
149
150
151  // get folders from server
152  $IMAP->clear_cache('mailboxes');
153
154  $a_unsubscribed = $IMAP->list_unsubscribed();
155  $a_subscribed = $IMAP->list_mailboxes();
156  $delimiter = $IMAP->get_hierarchy_delimiter();
157  $a_js_folders = array();
158 
159  $checkbox_subscribe = new checkbox(array('name' => '_subscribed[]', 'onclick' => JS_OBJECT_NAME.".command(this.checked?'subscribe':'unsubscribe',this.value)"));
160 
161  if (!empty($attrib['deleteicon']))
162    $del_button = sprintf('<img src="%s%s" alt="%s" border="0" />', $CONFIG['skin_path'], $attrib['deleteicon'], rcube_label('delete'));
163  else
164    $del_button = rcube_label('delete');
165
166  if (!empty($attrib['renameicon']))
167    $edit_button = sprintf('<img src="%s%s" alt="%s" border="0" />', $CONFIG['skin_path'], $attrib['renameicon'], rcube_label('rename'));
168  else
169    $del_button = rcube_label('rename');
170
171  // create list of available folders
172  foreach ($a_unsubscribed as $i => $folder)
173    {
174    $subscribed = in_array($folder, $a_subscribed);
175    $protected = ($CONFIG['protect_default_folders'] == TRUE && in_array($folder,$CONFIG['default_imap_folders']));
176    $zebra_class = $i%2 ? 'even' : 'odd';
177    $folder_js = JQ($folder);
178    $foldersplit = explode($delimiter, $folder);
179    $level = count($foldersplit) - 1;
180    $display_folder = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level) . rcube_charset_convert($foldersplit[$level], 'UTF-7');
181    $folder_html = $CONFIG['protect_default_folders'] && in_array($folder, $CONFIG['default_imap_folders']) ? rcube_label(strtolower($folder)) : $display_folder;
182   
183    if (!$protected)
184      $a_js_folders['rcmrow'.($i+1)] = array($folder, rcube_charset_convert($folder, 'UTF-7'));
185
186    $out .= sprintf('<tr id="rcmrow%d" class="%s"' .
187                    ' onmouseover="return %s.focus_subscription(\'%s\')"' .
188                    ' onmouseout="return %s.unfocus_subscription(\'%s\')"><td>%s</td>',
189                    $i+1,
190                    $zebra_class,
191                    JS_OBJECT_NAME,
192                    $folder_js,
193                    JS_OBJECT_NAME,
194                    $folder_js,
195                    Q($folder_html));
196                   
197    if ($protected)
198      $out .= '<td>&nbsp;'.($subscribed ? '&#x2022;' : '-').'</td>';
199    else
200      $out .= '<td>'.$checkbox_subscribe->show($subscribed?$folder:'', array('value' => $folder)).'</td>';
201
202    // add rename and delete buttons
203    if (!$protected)
204      $out .= sprintf('<td><a href="#rename" onclick="%s.command(\'rename-folder\',\'%s\')" title="%s">%s</a>'.
205                      '<td><a href="#delete" onclick="%s.command(\'delete-folder\',\'%s\')" title="%s">%s</a></td>',
206                      JS_OBJECT_NAME,
207                      $folder_js,
208                      rcube_label('renamefolder'),
209                      $edit_button,
210                      JS_OBJECT_NAME,
211                      $folder_js,
212                      rcube_label('deletefolder'),
213                      $del_button);
214    else
215      $out .= '<td></td><td></td>';
216   
217    $out .= "</tr>\n";
218    }
219
220  $out .= "</tbody>\n</table>";
221  $out .= "\n$form_end";
222
223  $OUTPUT->add_gui_object('subscriptionlist', $attrib['id']);
224  $OUTPUT->set_env('subscriptionrows', $a_js_folders);
225  $OUTPUT->set_env('defaultfolders', $CONFIG['default_imap_folders']);
226  $OUTPUT->set_env('delimiter', $delimiter);
227
228  return $out; 
229  }
230
231
232function rcube_create_folder_form($attrib)
233  {
234  list($form_start, $form_end) = get_form_tags($attrib, 'create-folder');
235  unset($attrib['form']);
236
237
238  // return the complete edit form as table
239  $out = "$form_start\n";
240
241  $input = new textfield(array('name' => '_folder_name'));
242  $out .= $input->show();
243 
244  if (get_boolean($attrib['button']))
245    {
246    $button = new input_field(array('type' => 'button',
247                                    'value' => rcube_label('create'),
248                                    'onclick' => JS_OBJECT_NAME.".command('create-folder',this.form)"));
249    $out .= $button->show();
250    }
251
252  $out .= "\n$form_end";
253
254  return $out;
255  }
256
257function rcube_rename_folder_form($attrib)
258  {
259  global $CONFIG, $IMAP;
260
261  list($form_start, $form_end) = get_form_tags($attrib, 'rename-folder');
262  unset($attrib['form']);
263
264  // return the complete edit form as table
265  $out = "$form_start\n";
266
267  $a_unsubscribed = $IMAP->list_unsubscribed();
268  $select_folder = new select(array('name' => '_folder_oldname', 'id' => 'rcmfd_oldfolder'));
269
270  foreach ($a_unsubscribed as $i => $folder)
271    {
272    if ($CONFIG['protect_default_folders'] == TRUE && in_array($folder,$CONFIG['default_imap_folders']))
273      continue;
274
275    $select_folder->add($folder);
276    }
277
278  $out .= $select_folder->show();
279
280  $out .= " to ";
281  $inputtwo = new textfield(array('name' => '_folder_newname'));
282  $out .= $inputtwo->show();
283
284  if (get_boolean($attrib['button']))
285    {
286    $button = new input_field(array('type' => 'button',
287                                    'value' => rcube_label('rename'),
288                                    'onclick' => JS_OBJECT_NAME.".command('rename-folder',this.form)"));
289    $out .= $button->show();
290    }
291
292  $out .= "\n$form_end";
293
294  return $out;
295  }
296
297
298// register UI objects
299$OUTPUT->add_handlers(array(
300  'foldersubscription' => 'rcube_subscription_form',
301  'createfolder' => 'rcube_create_folder_form',
302  'renamefolder' => 'rcube_rename_folder_form'
303));
304
305// add some labels to client
306rcube_add_label('deletefolderconfirm');
307
308$OUTPUT->send('managefolders');
309?>
Note: See TracBrowser for help on using the repository browser.