4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/groups.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2010, The Roundcube Dev Team |
9 | Licensed under the GNU GPL |
12 | Create/delete/rename contact groups and assign/remove contacts |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: groups.inc 4850 2011-06-14 13:45:26Z alec $
22 $source = get_input_value('_source', RCUBE_INPUT_GPC);
23 $CONTACTS = rcmail_contact_source($source, true);
25 if ($CONTACTS->readonly || !$CONTACTS->groups) {
26 $OUTPUT->show_message('sourceisreadonly', 'warning');
30 if ($RCMAIL->action == 'group-addmembers') {
31 if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST))) {
32 $plugin = $RCMAIL->plugins->exec_hook('group_addmembers', array('group_id' => $gid, 'ids' => $ids, 'source' => $source));
34 $CONTACTS->set_group($gid);
35 $num2add = count(explode(',', $plugin['ids']));
37 if (!$plugin['abort']) {
38 if (($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($CONTACTS->count()->count + $num2add > $maxnum)) {
39 $OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum));
42 $result = $CONTACTS->add_to_group($gid, $plugin['ids']);
45 $result = $plugin['result'];
49 $OUTPUT->show_message('contactaddedtogroup');
51 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
55 else if ($RCMAIL->action == 'group-delmembers') {
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));
59 if (!$plugin['abort'])
60 $result = $CONTACTS->remove_from_group($gid, $plugin['ids']);
62 $result = $plugin['result'];
65 $OUTPUT->show_message('contactremovedfromgroup');
67 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
71 else if ($RCMAIL->action == 'group-create') {
72 if ($name = trim(get_input_value('_name', RCUBE_INPUT_POST, true))) {
73 $plugin = $RCMAIL->plugins->exec_hook('group_create', array('name' => $name, 'source' => $source));
75 if (!$plugin['abort'])
76 $created = $CONTACTS->create_group($plugin['name']);
78 $created = $plugin['result'];
81 if ($created && $OUTPUT->ajax_call) {
82 $created['name'] = Q($created['name']);
83 $OUTPUT->show_message('groupcreated', 'confirmation');
84 $OUTPUT->command('insert_contact_group', array('source' => $source) + $created);
87 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
91 else if ($RCMAIL->action == 'group-rename') {
92 if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($name = trim(get_input_value('_name', RCUBE_INPUT_POST, true)))) {
93 $plugin = $RCMAIL->plugins->exec_hook('group_rename', array('group_id' => $gid, 'name' => $name, 'source' => $source));
95 if (!$plugin['abort'])
96 $newname = $CONTACTS->rename_group($gid, $plugin['name'], $newgid);
98 $newname = $plugin['result'];
101 if ($newname && $OUTPUT->ajax_call) {
102 $OUTPUT->show_message('grouprenamed', 'confirmation');
103 $OUTPUT->command('update_contact_group', array(
104 'source' => $source, 'id' => $gid, 'name' => Q($newname), 'newid' => $newgid));
107 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
110 else if ($RCMAIL->action == 'group-delete') {
111 if ($gid = get_input_value('_gid', RCUBE_INPUT_POST)) {
112 $plugin = $RCMAIL->plugins->exec_hook('group_delete', array('group_id' => $gid, 'source' => $source));
114 if (!$plugin['abort'])
115 $deleted = $CONTACTS->delete_group($gid);
117 $deleted = $plugin['result'];
121 $OUTPUT->show_message('groupdeleted', 'confirmation');
122 $OUTPUT->command('remove_group_item', array('source' => $source, 'id' => $gid));
125 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');