| 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, 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 |
|---|
| 23 | rcmail_imap_init(TRUE); |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | // subscribe to one or more mailboxes |
|---|
| 27 | if ($_action=='subscribe') |
|---|
| 28 | { |
|---|
| 29 | if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_GET)) |
|---|
| 30 | $IMAP->subscribe(array($mboxes)); |
|---|
| 31 | |
|---|
| 32 | if ($REMOTE_REQUEST) |
|---|
| 33 | rcube_remote_response('// subscribed'); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | // unsubscribe one or more mailboxes |
|---|
| 37 | else if ($_action=='unsubscribe') |
|---|
| 38 | { |
|---|
| 39 | if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_GET)) |
|---|
| 40 | $IMAP->unsubscribe(array($mboxes)); |
|---|
| 41 | |
|---|
| 42 | if ($REMOTE_REQUEST) |
|---|
| 43 | rcube_remote_response('// unsubscribed'); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | // create a new mailbox |
|---|
| 47 | else if ($_action=='create-folder') |
|---|
| 48 | { |
|---|
| 49 | if (!empty($_GET['_name'])) |
|---|
| 50 | $create = $IMAP->create_mailbox(trim(get_input_value('_name', RCUBE_INPUT_GET, FALSE, 'UTF-7')), TRUE); |
|---|
| 51 | |
|---|
| 52 | if ($create && $REMOTE_REQUEST) |
|---|
| 53 | { |
|---|
| 54 | $commands = sprintf("this.add_folder_row('%s','%s')", |
|---|
| 55 | JQ($create), |
|---|
| 56 | JQ(rcube_charset_convert($create, 'UTF-7'))); |
|---|
| 57 | rcube_remote_response($commands); |
|---|
| 58 | } |
|---|
| 59 | else if (!$create && $REMOTE_REQUEST) |
|---|
| 60 | { |
|---|
| 61 | $commands = show_message('errorsaving', 'error'); |
|---|
| 62 | rcube_remote_response($commands); |
|---|
| 63 | } |
|---|
| 64 | else if (!$create) |
|---|
| 65 | show_message('errorsaving', 'error'); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | // rename a mailbox |
|---|
| 69 | else if ($_action=='rename-folder') |
|---|
| 70 | { |
|---|
| 71 | if (!empty($_GET['_folder_oldname']) && !empty($_GET['_folder_newname'])) |
|---|
| 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'))); |
|---|
| 73 | |
|---|
| 74 | if ($rename && $REMOTE_REQUEST) |
|---|
| 75 | { |
|---|
| 76 | $commands = sprintf("this.replace_folder_row('%s','%s','%s');\n", |
|---|
| 77 | JQ(get_input_value('_folder_oldname', RCUBE_INPUT_GET)), |
|---|
| 78 | JQ($rename), |
|---|
| 79 | JQ(rcube_charset_convert($rename, 'UTF-7'))); |
|---|
| 80 | |
|---|
| 81 | $commands .= "this.reset_folder_rename();\n"; |
|---|
| 82 | |
|---|
| 83 | rcube_remote_response($commands); |
|---|
| 84 | } |
|---|
| 85 | else if (!$rename && $REMOTE_REQUEST) |
|---|
| 86 | { |
|---|
| 87 | $commands = "this.reset_folder_rename();\n"; |
|---|
| 88 | $commands .= show_message('errorsaving', 'error'); |
|---|
| 89 | rcube_remote_response($commands); |
|---|
| 90 | } |
|---|
| 91 | else if (!$rename) |
|---|
| 92 | show_message('errorsaving', 'error'); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | // delete an existing IMAP mailbox |
|---|
| 96 | else if ($_action=='delete-folder') |
|---|
| 97 | { |
|---|
| 98 | if (get_input_value('_mboxes', RCUBE_INPUT_GET)) |
|---|
| 99 | $deleted = $IMAP->delete_mailbox(array($mboxes)); |
|---|
| 100 | |
|---|
| 101 | if ($REMOTE_REQUEST && $deleted) |
|---|
| 102 | { |
|---|
| 103 | $commands = sprintf("this.remove_folder_row('%s');\n", JQ(get_input_value('_mboxes', RCUBE_INPUT_GET))); |
|---|
| 104 | $commands .= show_message('folderdeleted', 'confirmation'); |
|---|
| 105 | rcube_remote_response($commands); |
|---|
| 106 | } |
|---|
| 107 | else if ($REMOTE_REQUEST) |
|---|
| 108 | { |
|---|
| 109 | $commands = show_message('errorsaving', 'error'); |
|---|
| 110 | rcube_remote_response($commands); |
|---|
| 111 | } |
|---|
| 112 | } |
|---|
| 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"; |
|---|
| 136 | $out .= sprintf('<td class="name">%s</td><td class="subscribed">%s</td>'. |
|---|
| 137 | '<td class="rename"> </td><td class="delete"> </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 | $folder_js_enc = JQ(rcube_charset_convert($folder, 'UTF-7')); |
|---|
| 170 | $folder_html = $CONFIG['protect_default_folders'] && in_array($folder, $CONFIG['default_imap_folders']) ? rcube_label(strtolower($folder)) : rcube_charset_convert($folder, 'UTF-7'); |
|---|
| 171 | |
|---|
| 172 | if (!$protected) |
|---|
| 173 | $a_js_folders['rcmrow'.($i+1)] = array($folder_js, $folder_js_enc); |
|---|
| 174 | |
|---|
| 175 | $out .= sprintf('<tr id="rcmrow%d" class="%s"><td>%s</td>', |
|---|
| 176 | $i+1, |
|---|
| 177 | $zebra_class, |
|---|
| 178 | Q($folder_html)); |
|---|
| 179 | |
|---|
| 180 | if ($protected) |
|---|
| 181 | $out .= '<td> '.($subscribed ? '•' : '-').'</td>'; |
|---|
| 182 | else |
|---|
| 183 | $out .= '<td>'.$checkbox_subscribe->show($subscribed?$folder:'', array('value' => $folder)).'</td>'; |
|---|
| 184 | |
|---|
| 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>'; |
|---|
| 199 | |
|---|
| 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 | |
|---|
| 242 | function rcube_rename_folder_form($attrib) |
|---|
| 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 | |
|---|
| 282 | |
|---|
| 283 | // add some labels to client |
|---|
| 284 | rcube_add_label('deletefolderconfirm'); |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | parse_template('managefolders'); |
|---|
| 288 | ?> |
|---|