commit | author | age
|
a61bbb
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/addressbook/groups.inc | |
|
6 |
| | |
e019f2
|
7 |
| This file is part of the Roundcube Webmail client | |
f5e7b3
|
8 |
| Copyright (C) 2010, The Roundcube Dev Team | |
a61bbb
|
9 |
| Licensed under the GNU GPL | |
T |
10 |
| | |
|
11 |
| PURPOSE: | |
|
12 |
| Create/delete/rename contact groups and assign/remove contacts | |
|
13 |
| | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
|
|
18 |
$Id$ |
|
19 |
|
|
20 |
*/ |
|
21 |
|
ecf295
|
22 |
$source = get_input_value('_source', RCUBE_INPUT_GPC); |
A |
23 |
$CONTACTS = rcmail_contact_source($source, true); |
|
24 |
|
a61bbb
|
25 |
if ($CONTACTS->readonly || !$CONTACTS->groups) { |
T |
26 |
$OUTPUT->show_message('sourceisreadonly', 'warning'); |
|
27 |
$OUTPUT->send(); |
|
28 |
} |
aa12df
|
29 |
|
T |
30 |
if ($RCMAIL->action == 'group-addmembers') { |
|
31 |
if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST))) { |
1d773d
|
32 |
$plugin = $RCMAIL->plugins->exec_hook('group_addmembers', array('group_id' => $gid, 'ids' => $ids, 'source' => $source)); |
c50d88
|
33 |
|
d1851b
|
34 |
$CONTACTS->set_group($gid); |
T |
35 |
$num2add = count(explode(',', $plugin['ids'])); |
c50d88
|
36 |
|
ce92ba
|
37 |
if (!$plugin['abort']) { |
A |
38 |
if (($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($CONTACTS->count()->count + $num2add > $maxnum)) { |
|
39 |
$OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum)); |
|
40 |
$OUTPUT->send(); |
|
41 |
} |
|
42 |
$result = $CONTACTS->add_to_group($gid, $plugin['ids']); |
|
43 |
} |
|
44 |
else { |
|
45 |
$result = $plugin['result']; |
|
46 |
} |
|
47 |
|
c50d88
|
48 |
if ($result) |
aa12df
|
49 |
$OUTPUT->show_message('contactaddedtogroup'); |
c50d88
|
50 |
else |
A |
51 |
$OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error'); |
aa12df
|
52 |
} |
3baa72
|
53 |
} |
T |
54 |
|
aa12df
|
55 |
else if ($RCMAIL->action == 'group-delmembers') { |
T |
56 |
if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST))) { |
|
57 |
$plugin = $RCMAIL->plugins->exec_hook('group_delmembers', array('group_id' => $gid, 'ids' => $ids, 'source' => $source)); |
c50d88
|
58 |
|
ce92ba
|
59 |
if (!$plugin['abort']) |
A |
60 |
$result = $CONTACTS->remove_from_group($gid, $plugin['ids']); |
|
61 |
else |
|
62 |
$result = $plugin['result']; |
|
63 |
|
c50d88
|
64 |
if ($result) |
aa12df
|
65 |
$OUTPUT->show_message('contactremovedfromgroup'); |
c50d88
|
66 |
else |
A |
67 |
$OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error'); |
aa12df
|
68 |
} |
3baa72
|
69 |
} |
T |
70 |
|
|
71 |
else if ($RCMAIL->action == 'group-create') { |
55150f
|
72 |
if ($name = trim(get_input_value('_name', RCUBE_INPUT_POST, true))) { |
aa12df
|
73 |
$plugin = $RCMAIL->plugins->exec_hook('group_create', array('name' => $name, 'source' => $source)); |
ce92ba
|
74 |
|
aa12df
|
75 |
if (!$plugin['abort']) |
T |
76 |
$created = $CONTACTS->create_group($plugin['name']); |
ce92ba
|
77 |
else |
A |
78 |
$created = $plugin['result']; |
a61bbb
|
79 |
} |
c50d88
|
80 |
|
a61bbb
|
81 |
if ($created && $OUTPUT->ajax_call) { |
55150f
|
82 |
$created['name'] = Q($created['name']); |
c50d88
|
83 |
$OUTPUT->show_message('groupcreated', 'confirmation'); |
0501b6
|
84 |
$OUTPUT->command('insert_contact_group', array('source' => $source) + $created); |
a61bbb
|
85 |
} |
aa12df
|
86 |
else if (!$created) { |
T |
87 |
$OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error'); |
a61bbb
|
88 |
} |
T |
89 |
} |
|
90 |
|
3baa72
|
91 |
else if ($RCMAIL->action == 'group-rename') { |
55150f
|
92 |
if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($name = trim(get_input_value('_name', RCUBE_INPUT_POST, true)))) { |
aa12df
|
93 |
$plugin = $RCMAIL->plugins->exec_hook('group_rename', array('group_id' => $gid, 'name' => $name, 'source' => $source)); |
ce92ba
|
94 |
|
aa12df
|
95 |
if (!$plugin['abort']) |
360bd3
|
96 |
$newname = $CONTACTS->rename_group($gid, $plugin['name'], $newgid); |
ce92ba
|
97 |
else |
A |
98 |
$newname = $plugin['result']; |
aa12df
|
99 |
} |
3baa72
|
100 |
|
c50d88
|
101 |
if ($newname && $OUTPUT->ajax_call) { |
A |
102 |
$OUTPUT->show_message('grouprenamed', 'confirmation'); |
1f052f
|
103 |
$OUTPUT->command('update_contact_group', array( |
55150f
|
104 |
'source' => $source, 'id' => $gid, 'name' => Q($newname), 'newid' => $newgid)); |
c50d88
|
105 |
} |
3baa72
|
106 |
else if (!$newname) |
aa12df
|
107 |
$OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error'); |
a61bbb
|
108 |
} |
T |
109 |
|
3baa72
|
110 |
else if ($RCMAIL->action == 'group-delete') { |
aa12df
|
111 |
if ($gid = get_input_value('_gid', RCUBE_INPUT_POST)) { |
T |
112 |
$plugin = $RCMAIL->plugins->exec_hook('group_delete', array('group_id' => $gid, 'source' => $source)); |
ce92ba
|
113 |
|
aa12df
|
114 |
if (!$plugin['abort']) |
T |
115 |
$deleted = $CONTACTS->delete_group($gid); |
ce92ba
|
116 |
else |
A |
117 |
$deleted = $plugin['result']; |
aa12df
|
118 |
} |
3baa72
|
119 |
|
c50d88
|
120 |
if ($deleted) { |
A |
121 |
$OUTPUT->show_message('groupdeleted', 'confirmation'); |
bb8012
|
122 |
$OUTPUT->command('remove_group_item', array('source' => $source, 'id' => $gid)); |
c50d88
|
123 |
} |
3baa72
|
124 |
else |
aa12df
|
125 |
$OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error'); |
a61bbb
|
126 |
} |
T |
127 |
|
|
128 |
// send response |
|
129 |
$OUTPUT->send(); |
|
130 |
|