source: github/program/steps/settings/manage_folders.inc @ f0db3d4

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since f0db3d4 was f0db3d4, checked in by svncommit <devs@…>, 6 years ago

Create new folder as child of selected folder.

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