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