4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/groups.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2010, Roundcube Dev. - Switzerland |
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 4252 2010-11-23 08:18:39Z alec $
22 if ($CONTACTS->readonly || !$CONTACTS->groups) {
23 $OUTPUT->show_message('sourceisreadonly', 'warning');
27 $source = get_input_value('_source', RCUBE_INPUT_GPC);
29 if ($RCMAIL->action == 'group-addmembers') {
30 if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST))) {
31 $plugin = $RCMAIL->plugins->exec_hook('group_addmembers', array('group_id' => $gid, 'ids' => $ids, 'source' => $source));
33 $CONTACTS->set_group($gid);
34 $num2add = count(explode(',', $plugin['ids']));
36 if (!$plugin['abort']) {
37 if (($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($CONTACTS->count()->count + $num2add > $maxnum)) {
38 $OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum));
41 $result = $CONTACTS->add_to_group($gid, $plugin['ids']);
44 $result = $plugin['result'];
48 $OUTPUT->show_message('contactaddedtogroup');
50 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
54 else if ($RCMAIL->action == 'group-delmembers') {
55 if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST))) {
56 $plugin = $RCMAIL->plugins->exec_hook('group_delmembers', array('group_id' => $gid, 'ids' => $ids, 'source' => $source));
58 if (!$plugin['abort'])
59 $result = $CONTACTS->remove_from_group($gid, $plugin['ids']);
61 $result = $plugin['result'];
64 $OUTPUT->show_message('contactremovedfromgroup');
66 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
70 else if ($RCMAIL->action == 'group-create') {
71 if ($name = trim(get_input_value('_name', RCUBE_INPUT_POST))) {
72 $plugin = $RCMAIL->plugins->exec_hook('group_create', array('name' => $name, 'source' => $source));
74 if (!$plugin['abort'])
75 $created = $CONTACTS->create_group($plugin['name']);
77 $created = $plugin['result'];
80 if ($created && $OUTPUT->ajax_call) {
81 $OUTPUT->show_message('groupcreated', 'confirmation');
82 $OUTPUT->command('insert_contact_group', array(
83 'source' => $source, 'id' => $created['id'], 'name' => $created['name']));
86 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
90 else if ($RCMAIL->action == 'group-rename') {
91 if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($name = trim(get_input_value('_name', RCUBE_INPUT_POST)))) {
92 $plugin = $RCMAIL->plugins->exec_hook('group_rename', array('group_id' => $gid, 'name' => $name, 'source' => $source));
94 if (!$plugin['abort'])
95 $newname = $CONTACTS->rename_group($gid, $plugin['name']);
97 $newname = $plugin['result'];
100 if ($newname && $OUTPUT->ajax_call) {
101 $OUTPUT->show_message('grouprenamed', 'confirmation');
102 $OUTPUT->command('update_contact_group', array(
103 'source' => $source, 'id' => $gid, 'name' => $newname));
106 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
109 else if ($RCMAIL->action == 'group-delete') {
110 if ($gid = get_input_value('_gid', RCUBE_INPUT_POST)) {
111 $plugin = $RCMAIL->plugins->exec_hook('group_delete', array('group_id' => $gid, 'source' => $source));
113 if (!$plugin['abort'])
114 $deleted = $CONTACTS->delete_group($gid);
116 $deleted = $plugin['result'];
120 $OUTPUT->show_message('groupdeleted', 'confirmation');
121 $OUTPUT->command('remove_group_item', array('source' => $source, 'id' => $gid));
124 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');