]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/addressbook/groups.inc
Fix symlink mess
[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, The Roundcube Dev Team                            |
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 4850 2011-06-14 13:45:26Z alec $
19
20 */
21
22 $source = get_input_value('_source', RCUBE_INPUT_GPC);
23 $CONTACTS = rcmail_contact_source($source, true);
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 = 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));
33
34     $CONTACTS->set_group($gid);
35     $num2add = count(explode(',', $plugin['ids']));
36
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));
40         $OUTPUT->send();
41       }
42       $result = $CONTACTS->add_to_group($gid, $plugin['ids']);
43     }
44     else {
45       $result = $plugin['result'];
46     }
47
48     if ($result)
49       $OUTPUT->show_message('contactaddedtogroup');
50     else
51       $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
52   }
53 }
54
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));
58
59     if (!$plugin['abort'])
60       $result = $CONTACTS->remove_from_group($gid, $plugin['ids']);
61     else
62       $result = $plugin['result'];
63
64     if ($result)
65       $OUTPUT->show_message('contactremovedfromgroup');
66     else
67       $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
68   }
69 }
70
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));
74
75     if (!$plugin['abort'])
76       $created = $CONTACTS->create_group($plugin['name']);
77     else
78       $created = $plugin['result'];
79   }
80
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);
85   }
86   else if (!$created) {
87     $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
88   }
89 }
90
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));
94
95     if (!$plugin['abort'])
96       $newname = $CONTACTS->rename_group($gid, $plugin['name'], $newgid);
97     else
98       $newname = $plugin['result'];
99   }
100
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));
105   }
106   else if (!$newname)
107     $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
108 }
109
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));
113
114     if (!$plugin['abort'])
115       $deleted = $CONTACTS->delete_group($gid);
116     else
117       $deleted = $plugin['result'];
118   }
119
120   if ($deleted) {
121     $OUTPUT->show_message('groupdeleted', 'confirmation');
122     $OUTPUT->command('remove_group_item', array('source' => $source, 'id' => $gid));
123   }
124   else
125     $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
126 }
127
128 // send response
129 $OUTPUT->send();
130