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 |
|
|
22 |
// init IAMP connection |
|
23 |
rcmail_imap_init(TRUE); |
|
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 |
|
T |
32 |
if ($_GET['_remote']) |
|
33 |
rcube_remote_response('// subscribed'); |
|
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 |
|
T |
42 |
if ($_GET['_remote']) |
|
43 |
rcube_remote_response('// unsubscribed'); |
|
44 |
} |
|
45 |
|
|
46 |
// create a new mailbox |
|
47 |
else if ($_action=='create-folder') |
|
48 |
{ |
|
49 |
if (strlen($_GET['_name'])) |
a95e0e
|
50 |
$create = $IMAP->create_mailbox(strip_tags(trim($_GET['_name'])), TRUE); |
4e17e6
|
51 |
|
T |
52 |
if ($create && $_GET['_remote']) |
|
53 |
{ |
3f9edb
|
54 |
$commands = sprintf("this.add_folder_row('%s')", rep_specialchars_output($create, 'js')); |
4e17e6
|
55 |
rcube_remote_response($commands); |
T |
56 |
} |
|
57 |
else if (!$create && $_GET['_remote']) |
|
58 |
{ |
|
59 |
$commands = show_message('errorsaving', 'error'); |
|
60 |
rcube_remote_response($commands); |
|
61 |
} |
|
62 |
else if (!$create) |
|
63 |
show_message('errorsaving', 'error'); |
|
64 |
} |
|
65 |
|
|
66 |
// delete an existing IMAP mailbox |
|
67 |
else if ($_action=='delete-folder') |
|
68 |
{ |
|
69 |
if (strlen($_GET['_mboxes'])) |
c03095
|
70 |
$deleted = $IMAP->delete_mailbox(array($_GET['_mboxes'])); |
4e17e6
|
71 |
|
1cded8
|
72 |
if ($_GET['_remote'] && $deleted) |
T |
73 |
rcube_remote_response(sprintf("this.remove_folder_row('%s')", rep_specialchars_output($_GET['_mboxes'], 'js'))); |
|
74 |
else if ($_GET['_remote']) |
|
75 |
{ |
|
76 |
$commands = show_message('errorsaving', 'error'); |
|
77 |
rcube_remote_response($commands); |
|
78 |
} |
4e17e6
|
79 |
} |
T |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
// build table with all folders listed by server |
|
84 |
function rcube_subscription_form($attrib) |
|
85 |
{ |
|
86 |
global $IMAP, $CONFIG, $OUTPUT, $JS_OBJECT_NAME; |
|
87 |
|
|
88 |
list($form_start, $form_end) = get_form_tags($attrib, 'folders'); |
|
89 |
unset($attrib['form']); |
|
90 |
|
|
91 |
|
|
92 |
if (!$attrib['id']) |
|
93 |
$attrib['id'] = 'rcmSubscriptionlist'; |
|
94 |
|
|
95 |
// allow the following attributes to be added to the <table> tag |
|
96 |
$attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary')); |
|
97 |
|
|
98 |
$out = "$form_start\n<table" . $attrib_str . ">\n"; |
|
99 |
|
|
100 |
|
|
101 |
// add table header |
|
102 |
$out .= "<thead><tr>\n"; |
|
103 |
$out .= sprintf('<td>%s</td><td>%s</td><td></td>', rcube_label('foldername'), rcube_label('subscribed')); |
|
104 |
$out .= "\n</tr></thead>\n<tbody>\n"; |
|
105 |
|
|
106 |
|
|
107 |
// get folders from server |
|
108 |
$a_unsubscribed = $IMAP->list_unsubscribed(); |
|
109 |
$a_subscribed = $IMAP->list_mailboxes(); |
|
110 |
$a_js_folders = array(); |
|
111 |
|
|
112 |
$checkbox_subscribe = new checkbox(array('name' => '_subscribed[]', 'onclick' => "$JS_OBJECT_NAME.command(this.checked?'subscribe':'unsubscribe',this.value)")); |
|
113 |
|
|
114 |
if ($attrib['deleteicon']) |
|
115 |
$button = sprintf('<img src="%s%s" alt="%s" border="0" />', $CONFIG['skin_path'], $attrib['deleteicon'], rcube_label('delete')); |
|
116 |
else |
|
117 |
$button = rcube_label('delete'); |
|
118 |
|
|
119 |
|
|
120 |
// create list of available folders |
|
121 |
foreach ($a_unsubscribed as $i => $folder) |
|
122 |
{ |
|
123 |
$zebra_class = $i%2 ? 'even' : 'odd'; |
|
124 |
$folder_js = rep_specialchars_output($folder, 'js'); |
|
125 |
$a_js_folders['rcmrow'.($i+1)] = $folder_js; |
|
126 |
|
|
127 |
$out .= sprintf('<tr id="rcmrow%d" class="%s"><td>%s</td><td>%s</td><td><a href="#delete" onclick="%s.command(\'delete-folder\',\'%s\')" title="%s">%s</a></td>', |
|
128 |
$i+1, |
|
129 |
$zebra_class, |
3f9edb
|
130 |
rep_specialchars_output(rcube_charset_convert($folder, 'UTF-7', 'UTF-8'), 'html', 'all'), |
4e17e6
|
131 |
$checkbox_subscribe->show(in_array($folder, $a_subscribed)?$folder:'', array('value' => $folder)), |
T |
132 |
$JS_OBJECT_NAME, |
|
133 |
$folder_js, |
|
134 |
rcube_label('deletefolder'), |
|
135 |
$button); |
|
136 |
|
|
137 |
$out .= "</tr>\n"; |
|
138 |
} |
|
139 |
|
|
140 |
$out .= "</tbody>\n</table>"; |
|
141 |
$out .= "\n$form_end"; |
|
142 |
|
|
143 |
|
|
144 |
$javascript = sprintf("%s.gui_object('subscriptionlist', '%s');\n", $JS_OBJECT_NAME, $attrib['id']); |
|
145 |
$javascript .= sprintf("%s.set_env('subscriptionrows', %s);", $JS_OBJECT_NAME, array2js($a_js_folders)); |
|
146 |
$OUTPUT->add_script($javascript); |
|
147 |
|
|
148 |
return $out; |
|
149 |
} |
|
150 |
|
|
151 |
|
|
152 |
function rcube_create_folder_form($attrib) |
|
153 |
{ |
|
154 |
global $JS_OBJECT_NAME; |
|
155 |
|
|
156 |
list($form_start, $form_end) = get_form_tags($attrib, 'create-folder'); |
|
157 |
unset($attrib['form']); |
|
158 |
|
|
159 |
|
|
160 |
// return the complete edit form as table |
|
161 |
$out = "$form_start\n"; |
|
162 |
|
|
163 |
$input = new textfield(array('name' => '_folder_name')); |
|
164 |
$out .= $input->show(); |
|
165 |
|
|
166 |
if (get_boolean($attrib['button'])) |
|
167 |
{ |
|
168 |
$button = new input_field(array('type' => 'button', |
|
169 |
'value' => rcube_label('create'), |
|
170 |
'onclick' => "$JS_OBJECT_NAME.command('create-folder',this.form)")); |
|
171 |
$out .= $button->show(); |
|
172 |
} |
|
173 |
|
|
174 |
$out .= "\n$form_end"; |
|
175 |
|
|
176 |
return $out; |
|
177 |
} |
|
178 |
|
|
179 |
|
1cded8
|
180 |
// add some labels to client |
T |
181 |
rcube_add_label('deletefolderconfirm'); |
|
182 |
|
|
183 |
|
4e17e6
|
184 |
parse_template('managefolders'); |
T |
185 |
?> |