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