thomascube
2007-02-16 b3ce7915610a6d272cc38ecd2a8b61e04ee4aeae
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   {
b3ce79 29   if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_GET))
T 30     $IMAP->subscribe(array($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   {
b3ce79 39   if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_GET))
T 40     $IMAP->unsubscribe(array($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')",
2bca6e 55                         JQ($create),
T 56                         JQ(rcube_charset_convert($create, 'UTF-7')));
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     {
e170b4 76     $commands = sprintf("this.replace_folder_row('%s','%s','%s');\n",
2bca6e 77                         JQ(get_input_value('_folder_oldname', RCUBE_INPUT_GET)),
T 78                         JQ($rename),
79                         JQ(rcube_charset_convert($rename, 'UTF-7')));
e170b4 80
T 81     $commands .= "this.reset_folder_rename();\n";
4d4264 82                         
c8c1e0 83     rcube_remote_response($commands);
S 84     }
85   else if (!$rename && $REMOTE_REQUEST)
86     {
24053e 87     $commands = "this.reset_folder_rename();\n";
T 88     $commands .= show_message('errorsaving', 'error');
c8c1e0 89     rcube_remote_response($commands);
S 90     }
91   else if (!$rename)
4e17e6 92     show_message('errorsaving', 'error');
T 93   }
94
95 // delete an existing IMAP mailbox
96 else if ($_action=='delete-folder')
97   {
b3ce79 98   if (get_input_value('_mboxes', RCUBE_INPUT_GET))
T 99     $deleted = $IMAP->delete_mailbox(array($mboxes));
4e17e6 100
ea7c46 101   if ($REMOTE_REQUEST && $deleted)
f9c107 102     {
2bca6e 103     $commands = sprintf("this.remove_folder_row('%s');\n", JQ(get_input_value('_mboxes', RCUBE_INPUT_GET)));
f9c107 104     $commands .= show_message('folderdeleted', 'confirmation');
T 105     rcube_remote_response($commands);
106     }
ea7c46 107   else if ($REMOTE_REQUEST)
1cded8 108     {
T 109     $commands = show_message('errorsaving', 'error');
110     rcube_remote_response($commands);
111     }
4e17e6 112   }
T 113
114
115
116 // build table with all folders listed by server
117 function rcube_subscription_form($attrib)
118   {
119   global $IMAP, $CONFIG, $OUTPUT, $JS_OBJECT_NAME;
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";
24053e 136   $out .= sprintf('<td class="name">%s</td><td class="subscribed">%s</td>'.
T 137                   '<td class="rename">&nbsp;</td><td class="delete">&nbsp;</td>',
138                   rcube_label('foldername'), rcube_label('subscribed'));
139                   
4e17e6 140   $out .= "\n</tr></thead>\n<tbody>\n";
T 141
142
143   // get folders from server
4d4264 144   $IMAP->clear_cache('mailboxes');
T 145
4e17e6 146   $a_unsubscribed = $IMAP->list_unsubscribed();
T 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   
24053e 152   if (!empty($attrib['deleteicon']))
T 153     $del_button = sprintf('<img src="%s%s" alt="%s" border="0" />', $CONFIG['skin_path'], $attrib['deleteicon'], rcube_label('delete'));
4e17e6 154   else
24053e 155     $del_button = rcube_label('delete');
4e17e6 156
24053e 157   if (!empty($attrib['renameicon']))
T 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');
4e17e6 161
T 162   // create list of available folders
163   foreach ($a_unsubscribed as $i => $folder)
164     {
4d4264 165     $subscribed = in_array($folder, $a_subscribed);
24053e 166     $protected = ($CONFIG['protect_default_folders'] == TRUE && in_array($folder,$CONFIG['default_imap_folders']));
4e17e6 167     $zebra_class = $i%2 ? 'even' : 'odd';
2bca6e 168     $folder_js = JQ($folder);
T 169     $folder_js_enc = JQ(rcube_charset_convert($folder, 'UTF-7'));
7e0ec7 170     $folder_html = $CONFIG['protect_default_folders'] && in_array($folder, $CONFIG['default_imap_folders']) ? rcube_label(strtolower($folder)) : rcube_charset_convert($folder, 'UTF-7');
24053e 171     
T 172     if (!$protected)
4d4264 173       $a_js_folders['rcmrow'.($i+1)] = array($folder_js, $folder_js_enc);
4e17e6 174
4d4264 175     $out .= sprintf('<tr id="rcmrow%d" class="%s"><td>%s</td>',
4e17e6 176                     $i+1,
T 177                     $zebra_class,
2bca6e 178                     Q($folder_html));
4d4264 179                     
T 180     if ($protected)
181       $out .= '<td>&nbsp;'.($subscribed ? '&#x2022;' : '-').'</td>';
182     else
183       $out .= '<td>'.$checkbox_subscribe->show($subscribed?$folder:'', array('value' => $folder)).'</td>';
24053e 184
T 185     // add rename and delete buttons
186     if (!$protected)
187       $out .= sprintf('<td><a href="#rename" onclick="%s.command(\'rename-folder\',\'%s\')" title="%s">%s</a>'.
188                       '<td><a href="#delete" onclick="%s.command(\'delete-folder\',\'%s\')" title="%s">%s</a></td>',
189                       $JS_OBJECT_NAME,
190                       $folder_js,
191                       rcube_label('renamefolder'),
192                       $edit_button,
193                       $JS_OBJECT_NAME,
194                       $folder_js,
195                       rcube_label('deletefolder'),
196                       $del_button);
197     else
198       $out .= '<td></td><td></td>';
4e17e6 199     
T 200     $out .= "</tr>\n";
201     }
202
203   $out .= "</tbody>\n</table>";
204   $out .= "\n$form_end";
205
206
207   $javascript = sprintf("%s.gui_object('subscriptionlist', '%s');\n", $JS_OBJECT_NAME, $attrib['id']);
208   $javascript .= sprintf("%s.set_env('subscriptionrows', %s);", $JS_OBJECT_NAME, array2js($a_js_folders));
209   $OUTPUT->add_script($javascript);
210
211   return $out;  
212   }
213
214
215 function rcube_create_folder_form($attrib)
216   {
217   global $JS_OBJECT_NAME;
218
219   list($form_start, $form_end) = get_form_tags($attrib, 'create-folder');
220   unset($attrib['form']);
221
222
223   // return the complete edit form as table
224   $out = "$form_start\n";
225
226   $input = new textfield(array('name' => '_folder_name'));
227   $out .= $input->show();
228   
229   if (get_boolean($attrib['button']))
230     {
231     $button = new input_field(array('type' => 'button',
232                                     'value' => rcube_label('create'),
233                                     'onclick' => "$JS_OBJECT_NAME.command('create-folder',this.form)"));
234     $out .= $button->show();
235     }
236
237   $out .= "\n$form_end";
238
239   return $out;
240   }
241
c8c1e0 242 function rcube_rename_folder_form($attrib)
S 243   {
244   global $CONFIG, $IMAP, $JS_OBJECT_NAME;
245
246   list($form_start, $form_end) = get_form_tags($attrib, 'rename-folder');
247   unset($attrib['form']);
248
249   // return the complete edit form as table
250   $out = "$form_start\n";
251
252   $a_unsubscribed = $IMAP->list_unsubscribed();
253   $select_folder = new select(array('name' => '_folder_oldname', 'id' => 'rcmfd_oldfolder'));
254
255   foreach ($a_unsubscribed as $i => $folder)
256     {
257     if ($CONFIG['protect_default_folders'] == TRUE && in_array($folder,$CONFIG['default_imap_folders'])) 
258       continue;
259
260     $select_folder->add($folder);
261     }
262
263   $out .= $select_folder->show();
264
265   $out .= " to ";
266   $inputtwo = new textfield(array('name' => '_folder_newname'));
267   $out .= $inputtwo->show();
268
269   if (get_boolean($attrib['button']))
270     {
271     $button = new input_field(array('type' => 'button',
272                                     'value' => rcube_label('rename'),
273                                     'onclick' => "$JS_OBJECT_NAME.command('rename-folder',this.form)"));
274     $out .= $button->show();
275     }
276
277   $out .= "\n$form_end";
278
279   return $out;
280   }
281
4e17e6 282
1cded8 283 // add some labels to client
T 284 rcube_add_label('deletefolderconfirm');
285
286
4e17e6 287 parse_template('managefolders');
c8c1e0 288 ?>