commit | author | age
|
a61bbb
|
1 |
<?php |
T |
2 |
|
a95874
|
3 |
/** |
a61bbb
|
4 |
+-----------------------------------------------------------------------+ |
T |
5 |
| program/steps/addressbook/groups.inc | |
|
6 |
| | |
e019f2
|
7 |
| This file is part of the Roundcube Webmail client | |
c97625
|
8 |
| Copyright (C) 2010-2013, The Roundcube Dev Team | |
7fe381
|
9 |
| | |
T |
10 |
| Licensed under the GNU General Public License version 3 or | |
|
11 |
| any later version with exceptions for skins & plugins. | |
|
12 |
| See the README file for a full license statement. | |
a61bbb
|
13 |
| | |
T |
14 |
| PURPOSE: | |
|
15 |
| Create/delete/rename contact groups and assign/remove contacts | |
|
16 |
| | |
|
17 |
+-----------------------------------------------------------------------+ |
|
18 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
19 |
+-----------------------------------------------------------------------+ |
|
20 |
*/ |
|
21 |
|
c97625
|
22 |
$source = rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC); |
ff4a92
|
23 |
$CONTACTS = rcmail_contact_source($source); |
ecf295
|
24 |
|
a61bbb
|
25 |
if ($CONTACTS->readonly || !$CONTACTS->groups) { |
c97625
|
26 |
$OUTPUT->show_message('sourceisreadonly', 'warning'); |
AM |
27 |
$OUTPUT->send(); |
a61bbb
|
28 |
} |
aa12df
|
29 |
|
T |
30 |
if ($RCMAIL->action == 'group-addmembers') { |
c97625
|
31 |
if (($gid = rcube_utils::get_input_value('_gid', rcube_utils::INPUT_POST)) && ($ids = rcmail_get_cids($source))) { |
AM |
32 |
$plugin = $RCMAIL->plugins->exec_hook('group_addmembers', array( |
|
33 |
'group_id' => $gid, |
|
34 |
'ids' => $ids, |
|
35 |
'source' => $source, |
|
36 |
)); |
c50d88
|
37 |
|
c97625
|
38 |
$CONTACTS->set_group($gid); |
AM |
39 |
$num2add = count($plugin['ids']); |
c50d88
|
40 |
|
c97625
|
41 |
if (!$plugin['abort']) { |
AM |
42 |
if (($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($CONTACTS->count()->count + $num2add > $maxnum)) { |
|
43 |
$OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum)); |
|
44 |
$OUTPUT->send(); |
|
45 |
} |
|
46 |
|
|
47 |
$result = $CONTACTS->add_to_group($gid, $plugin['ids']); |
|
48 |
} |
|
49 |
else { |
|
50 |
$result = $plugin['result']; |
|
51 |
} |
|
52 |
|
|
53 |
if ($result) |
|
54 |
$OUTPUT->show_message('contactaddedtogroup'); |
|
55 |
else if ($plugin['abort'] || $CONTACTS->get_error()) |
827159
|
56 |
$OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error'); |
c97625
|
57 |
else |
827159
|
58 |
$OUTPUT->show_message($plugin['message'] ?: 'nogroupassignmentschanged'); |
ce92ba
|
59 |
} |
3baa72
|
60 |
} |
aa12df
|
61 |
else if ($RCMAIL->action == 'group-delmembers') { |
c97625
|
62 |
if (($gid = rcube_utils::get_input_value('_gid', rcube_utils::INPUT_POST)) && ($ids = rcmail_get_cids($source))) { |
AM |
63 |
$plugin = $RCMAIL->plugins->exec_hook('group_delmembers', array( |
|
64 |
'group_id' => $gid, |
|
65 |
'ids' => $ids, |
|
66 |
'source' => $source, |
|
67 |
)); |
c50d88
|
68 |
|
c97625
|
69 |
if (!$plugin['abort']) |
AM |
70 |
$result = $CONTACTS->remove_from_group($gid, $plugin['ids']); |
|
71 |
else |
|
72 |
$result = $plugin['result']; |
ce92ba
|
73 |
|
c97625
|
74 |
if ($result) { |
AM |
75 |
$OUTPUT->show_message('contactremovedfromgroup'); |
|
76 |
$OUTPUT->command('remove_group_contacts',array('source' => $source, 'gid' => $gid)); |
|
77 |
} |
|
78 |
else { |
827159
|
79 |
$OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error'); |
c97625
|
80 |
} |
AM |
81 |
} |
|
82 |
} |
|
83 |
else if ($RCMAIL->action == 'group-create') { |
|
84 |
if ($name = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST, true))) { |
|
85 |
$plugin = $RCMAIL->plugins->exec_hook('group_create', array( |
|
86 |
'name' => $name, |
|
87 |
'source' => $source, |
|
88 |
)); |
|
89 |
|
|
90 |
if (!$plugin['abort']) |
|
91 |
$created = $CONTACTS->create_group($plugin['name']); |
|
92 |
else |
|
93 |
$created = $plugin['result']; |
|
94 |
} |
|
95 |
|
|
96 |
if ($created && $OUTPUT->ajax_call) { |
|
97 |
$created['name'] = rcube::Q($created['name']); |
|
98 |
|
|
99 |
$OUTPUT->show_message('groupcreated', 'confirmation'); |
|
100 |
$OUTPUT->command('insert_contact_group', array('source' => $source) + $created); |
|
101 |
} |
|
102 |
else if (!$created) { |
827159
|
103 |
$OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error'); |
c97625
|
104 |
} |
AM |
105 |
} |
|
106 |
else if ($RCMAIL->action == 'group-rename') { |
|
107 |
if (($gid = rcube_utils::get_input_value('_gid', rcube_utils::INPUT_POST)) |
|
108 |
&& ($name = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST, true))) |
|
109 |
) { |
|
110 |
$plugin = $RCMAIL->plugins->exec_hook('group_rename', array( |
|
111 |
'group_id' => $gid, |
|
112 |
'name' => $name, |
|
113 |
'source' => $source, |
|
114 |
)); |
|
115 |
|
|
116 |
if (!$plugin['abort']) |
|
117 |
$newname = $CONTACTS->rename_group($gid, $plugin['name'], $newgid); |
|
118 |
else |
|
119 |
$newname = $plugin['result']; |
|
120 |
} |
|
121 |
|
|
122 |
if ($newname && $OUTPUT->ajax_call) { |
|
123 |
$OUTPUT->show_message('grouprenamed', 'confirmation'); |
|
124 |
$OUTPUT->command('update_contact_group', array( |
|
125 |
'source' => $source, 'id' => $gid, 'name' => rcube::Q($newname), 'newid' => $newgid)); |
|
126 |
} |
|
127 |
else if (!$newname) { |
827159
|
128 |
$OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error'); |
c97625
|
129 |
} |
AM |
130 |
} |
|
131 |
else if ($RCMAIL->action == 'group-delete') { |
|
132 |
if ($gid = rcube_utils::get_input_value('_gid', rcube_utils::INPUT_POST)) { |
|
133 |
$plugin = $RCMAIL->plugins->exec_hook('group_delete', array( |
|
134 |
'group_id' => $gid, |
|
135 |
'source' => $source, |
|
136 |
)); |
|
137 |
|
|
138 |
if (!$plugin['abort']) |
|
139 |
$deleted = $CONTACTS->delete_group($gid); |
|
140 |
else |
|
141 |
$deleted = $plugin['result']; |
|
142 |
} |
|
143 |
|
|
144 |
if ($deleted) { |
|
145 |
$OUTPUT->show_message('groupdeleted', 'confirmation'); |
|
146 |
$OUTPUT->command('remove_group_item', array('source' => $source, 'id' => $gid)); |
ff4a92
|
147 |
} |
AM |
148 |
else { |
827159
|
149 |
$OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error'); |
1ba07f
|
150 |
} |
a61bbb
|
151 |
} |
T |
152 |
|
|
153 |
// send response |
|
154 |
$OUTPUT->send(); |