]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/addressbook/groups.inc
f54c59cddf37934388bcab2b0f75fe304d043c1e
[roundcube.git] / program / steps / addressbook / groups.inc
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, Roundcube Dev. - Switzerland                      |
9  | Licensed under the GNU GPL                                            |
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: groups.inc 4252 2010-11-23 08:18:39Z alec $
19
20 */
21
22 if ($CONTACTS->readonly || !$CONTACTS->groups) {
23   $OUTPUT->show_message('sourceisreadonly', 'warning');
24   $OUTPUT->send();
25 }
26
27 $source = get_input_value('_source', RCUBE_INPUT_GPC);
28
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));
32
33     $CONTACTS->set_group($gid);
34     $num2add = count(explode(',', $plugin['ids']));
35
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));
39         $OUTPUT->send();
40       }
41       $result = $CONTACTS->add_to_group($gid, $plugin['ids']);
42     }
43     else {
44       $result = $plugin['result'];
45     }
46
47     if ($result)
48       $OUTPUT->show_message('contactaddedtogroup');
49     else
50       $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
51   }
52 }
53
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));
57
58     if (!$plugin['abort'])
59       $result = $CONTACTS->remove_from_group($gid, $plugin['ids']);
60     else
61       $result = $plugin['result'];
62
63     if ($result)
64       $OUTPUT->show_message('contactremovedfromgroup');
65     else
66       $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
67   }
68 }
69
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));
73
74     if (!$plugin['abort'])
75       $created = $CONTACTS->create_group($plugin['name']);
76     else
77       $created = $plugin['result'];
78   }
79
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']));
84   }
85   else if (!$created) {
86     $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
87   }
88 }
89
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));
93
94     if (!$plugin['abort'])
95       $newname = $CONTACTS->rename_group($gid, $plugin['name']);
96     else
97       $newname = $plugin['result'];
98   }
99
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));
104   }
105   else if (!$newname)
106     $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
107 }
108
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));
112
113     if (!$plugin['abort'])
114       $deleted = $CONTACTS->delete_group($gid);
115     else
116       $deleted = $plugin['result'];
117   }
118
119   if ($deleted) {
120     $OUTPUT->show_message('groupdeleted', 'confirmation');
121     $OUTPUT->command('remove_group_item', array('source' => $source, 'id' => $gid));
122   }
123   else
124     $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
125 }
126
127 // send response
128 $OUTPUT->send();
129