4 +-----------------------------------------------------------------------+
5 | program/steps/settings/manage_folders.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005, RoundCube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Provide functionality to create/delete/rename folders |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: manage_folders.inc 285 2006-07-30 19:38:06Z thomasb $
22 // init IMAP connection
23 rcmail_imap_init(TRUE);
26 // subscribe to one or more mailboxes
27 if ($_action=='subscribe')
29 if (strlen($_GET['_mboxes']))
30 $IMAP->subscribe(array($_GET['_mboxes']));
33 rcube_remote_response('// subscribed');
36 // unsubscribe one or more mailboxes
37 else if ($_action=='unsubscribe')
39 if (strlen($_GET['_mboxes']))
40 $IMAP->unsubscribe(array($_GET['_mboxes']));
43 rcube_remote_response('// unsubscribed');
46 // create a new mailbox
47 else if ($_action=='create-folder')
49 if (!empty($_GET['_name']))
50 $create = $IMAP->create_mailbox(trim(get_input_value('_name', RCUBE_INPUT_GET)), TRUE);
52 if ($create && $REMOTE_REQUEST)
54 $commands = sprintf("this.add_folder_row('%s')", rep_specialchars_output($create, 'js'));
55 rcube_remote_response($commands);
57 else if (!$create && $REMOTE_REQUEST)
59 $commands = show_message('errorsaving', 'error');
60 rcube_remote_response($commands);
63 show_message('errorsaving', 'error');
67 else if ($_action=='rename-folder')
69 if (!empty($_GET['_folder_oldname']) && !empty($_GET['_folder_newname']))
70 $rename = $IMAP->rename_mailbox(get_input_value('_folder_oldname', RCUBE_INPUT_GET), trim(get_input_value('_folder_newname', RCUBE_INPUT_GET)));
72 if ($rename && $REMOTE_REQUEST)
74 $commands = sprintf("this.replace_folder_row('%s','%s');",
75 addslashes(rep_specialchars_output($rename, 'js')),
76 rep_specialchars_output($_GET['_folder_oldname'], 'js'));
77 rcube_remote_response($commands);
79 else if (!$rename && $REMOTE_REQUEST)
81 $commands = "this.reset_folder_rename();\n";
82 $commands .= show_message('errorsaving', 'error');
83 rcube_remote_response($commands);
86 show_message('errorsaving', 'error');
89 // delete an existing IMAP mailbox
90 else if ($_action=='delete-folder')
92 if (!empty($_GET['_mboxes']))
93 $deleted = $IMAP->delete_mailbox(array(get_input_value('_mboxes', RCUBE_INPUT_GET)));
95 if ($REMOTE_REQUEST && $deleted)
97 $commands = sprintf("this.remove_folder_row('%s');\n", rep_specialchars_output(get_input_value('_mboxes', RCUBE_INPUT_GET), 'js'));
98 $commands .= show_message('folderdeleted', 'confirmation');
99 rcube_remote_response($commands);
101 else if ($REMOTE_REQUEST)
103 $commands = show_message('errorsaving', 'error');
104 rcube_remote_response($commands);
110 // build table with all folders listed by server
111 function rcube_subscription_form($attrib)
113 global $IMAP, $CONFIG, $OUTPUT, $JS_OBJECT_NAME;
115 list($form_start, $form_end) = get_form_tags($attrib, 'folders');
116 unset($attrib['form']);
120 $attrib['id'] = 'rcmSubscriptionlist';
122 // allow the following attributes to be added to the <table> tag
123 $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary'));
125 $out = "$form_start\n<table" . $attrib_str . ">\n";
129 $out .= "<thead><tr>\n";
130 $out .= sprintf('<td class="name">%s</td><td class="subscribed">%s</td>'.
131 '<td class="rename"> </td><td class="delete"> </td>',
132 rcube_label('foldername'), rcube_label('subscribed'));
134 $out .= "\n</tr></thead>\n<tbody>\n";
137 // get folders from server
138 $a_unsubscribed = $IMAP->list_unsubscribed();
139 $a_subscribed = $IMAP->list_mailboxes();
140 $a_js_folders = array();
142 $checkbox_subscribe = new checkbox(array('name' => '_subscribed[]', 'onclick' => "$JS_OBJECT_NAME.command(this.checked?'subscribe':'unsubscribe',this.value)"));
144 if (!empty($attrib['deleteicon']))
145 $del_button = sprintf('<img src="%s%s" alt="%s" border="0" />', $CONFIG['skin_path'], $attrib['deleteicon'], rcube_label('delete'));
147 $del_button = rcube_label('delete');
149 if (!empty($attrib['renameicon']))
150 $edit_button = sprintf('<img src="%s%s" alt="%s" border="0" />', $CONFIG['skin_path'], $attrib['renameicon'], rcube_label('rename'));
152 $del_button = rcube_label('rename');
154 // create list of available folders
155 foreach ($a_unsubscribed as $i => $folder)
157 $protected = ($CONFIG['protect_default_folders'] == TRUE && in_array($folder,$CONFIG['default_imap_folders']));
158 $zebra_class = $i%2 ? 'even' : 'odd';
159 $folder_js = rep_specialchars_output($folder, 'js');
162 $a_js_folders['rcmrow'.($i+1)] = $folder_js;
164 $out .= sprintf('<tr id="rcmrow%d" class="%s"><td>%s</td><td>%s</td>',
167 rep_specialchars_output(rcube_charset_convert($folder, 'UTF-7', 'UTF-8'), 'html', 'all'),
168 $checkbox_subscribe->show(in_array($folder, $a_subscribed)?$folder:'', array('value' => $folder, 'disabled' => $protected)));
170 // add rename and delete buttons
172 $out .= sprintf('<td><a href="#rename" onclick="%s.command(\'rename-folder\',\'%s\')" title="%s">%s</a>'.
173 '<td><a href="#delete" onclick="%s.command(\'delete-folder\',\'%s\')" title="%s">%s</a></td>',
176 rcube_label('renamefolder'),
180 rcube_label('deletefolder'),
183 $out .= '<td></td><td></td>';
188 $out .= "</tbody>\n</table>";
189 $out .= "\n$form_end";
192 $javascript = sprintf("%s.gui_object('subscriptionlist', '%s');\n", $JS_OBJECT_NAME, $attrib['id']);
193 $javascript .= sprintf("%s.set_env('subscriptionrows', %s);", $JS_OBJECT_NAME, array2js($a_js_folders));
194 $OUTPUT->add_script($javascript);
200 function rcube_create_folder_form($attrib)
202 global $JS_OBJECT_NAME;
204 list($form_start, $form_end) = get_form_tags($attrib, 'create-folder');
205 unset($attrib['form']);
208 // return the complete edit form as table
209 $out = "$form_start\n";
211 $input = new textfield(array('name' => '_folder_name'));
212 $out .= $input->show();
214 if (get_boolean($attrib['button']))
216 $button = new input_field(array('type' => 'button',
217 'value' => rcube_label('create'),
218 'onclick' => "$JS_OBJECT_NAME.command('create-folder',this.form)"));
219 $out .= $button->show();
222 $out .= "\n$form_end";
227 function rcube_rename_folder_form($attrib)
229 global $CONFIG, $IMAP, $JS_OBJECT_NAME;
231 list($form_start, $form_end) = get_form_tags($attrib, 'rename-folder');
232 unset($attrib['form']);
234 // return the complete edit form as table
235 $out = "$form_start\n";
237 $a_unsubscribed = $IMAP->list_unsubscribed();
238 $select_folder = new select(array('name' => '_folder_oldname', 'id' => 'rcmfd_oldfolder'));
240 foreach ($a_unsubscribed as $i => $folder)
242 if ($CONFIG['protect_default_folders'] == TRUE && in_array($folder,$CONFIG['default_imap_folders']))
245 $select_folder->add($folder);
248 $out .= $select_folder->show();
251 $inputtwo = new textfield(array('name' => '_folder_newname'));
252 $out .= $inputtwo->show();
254 if (get_boolean($attrib['button']))
256 $button = new input_field(array('type' => 'button',
257 'value' => rcube_label('rename'),
258 'onclick' => "$JS_OBJECT_NAME.command('rename-folder',this.form)"));
259 $out .= $button->show();
262 $out .= "\n$form_end";
268 // add some labels to client
269 rcube_add_label('deletefolderconfirm');
272 parse_template('managefolders');