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

Last change on this file since 824 was 824, checked in by thomasb, 6 years ago

Set default IMAP folder delimiter; make sure is not empty

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