0
|
1 <?php
|
|
2
|
|
3 /**
|
|
4 +-----------------------------------------------------------------------+
|
|
5 | program/steps/addressbook/groups.inc |
|
|
6 | |
|
|
7 | This file is part of the Roundcube Webmail client |
|
|
8 | Copyright (C) 2010-2013, The Roundcube Dev Team |
|
|
9 | |
|
|
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. |
|
|
13 | |
|
|
14 | PURPOSE: |
|
|
15 | Create/delete/rename contact groups and assign/remove contacts |
|
|
16 | |
|
|
17 +-----------------------------------------------------------------------+
|
|
18 | Author: Thomas Bruederli <roundcube@gmail.com> |
|
|
19 +-----------------------------------------------------------------------+
|
|
20 */
|
|
21
|
|
22 $source = rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC);
|
|
23 $CONTACTS = rcmail_contact_source($source);
|
|
24
|
|
25 if ($CONTACTS->readonly || !$CONTACTS->groups) {
|
|
26 $OUTPUT->show_message('sourceisreadonly', 'warning');
|
|
27 $OUTPUT->send();
|
|
28 }
|
|
29
|
|
30 if ($RCMAIL->action == 'group-addmembers') {
|
|
31 if (($gid = rcube_utils::get_input_value('_gid', rcube_utils::INPUT_POST)) && ($ids = rcmail_get_cids($source))) {
|
|
32 $plugin = $RCMAIL->plugins->exec_hook('group_addmembers', array(
|
|
33 'group_id' => $gid,
|
|
34 'ids' => $ids,
|
|
35 'source' => $source,
|
|
36 ));
|
|
37
|
|
38 $CONTACTS->set_group($gid);
|
|
39 $num2add = count($plugin['ids']);
|
|
40
|
|
41 if (!$plugin['abort']) {
|
|
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())
|
|
56 $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error');
|
|
57 else
|
|
58 $OUTPUT->show_message($plugin['message'] ?: 'nogroupassignmentschanged');
|
|
59 }
|
|
60 }
|
|
61 else if ($RCMAIL->action == 'group-delmembers') {
|
|
62 if (($gid = rcube_utils::get_input_value('_gid', rcube_utils::INPUT_POST)) && ($ids = rcmail_get_cids($source))) {
|
|
63 $plugin = $RCMAIL->plugins->exec_hook('group_delmembers', array(
|
|
64 'group_id' => $gid,
|
|
65 'ids' => $ids,
|
|
66 'source' => $source,
|
|
67 ));
|
|
68
|
|
69 if (!$plugin['abort'])
|
|
70 $result = $CONTACTS->remove_from_group($gid, $plugin['ids']);
|
|
71 else
|
|
72 $result = $plugin['result'];
|
|
73
|
|
74 if ($result) {
|
|
75 $OUTPUT->show_message('contactremovedfromgroup');
|
|
76 $OUTPUT->command('remove_group_contacts',array('source' => $source, 'gid' => $gid));
|
|
77 }
|
|
78 else {
|
|
79 $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error');
|
|
80 }
|
|
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) {
|
|
103 $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error');
|
|
104 }
|
|
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) {
|
|
128 $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error');
|
|
129 }
|
|
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));
|
|
147 }
|
|
148 else {
|
|
149 $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error');
|
|
150 }
|
|
151 }
|
|
152
|
|
153 // send response
|
|
154 $OUTPUT->send();
|