thomascube
2010-04-01 1d773d71414316e0b9836a15c35576593427ee21
commit | author | age
a61bbb 1 <?php
T 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$
19
20 */
21
22
23 if ($CONTACTS->readonly || !$CONTACTS->groups) {
24   $OUTPUT->show_message('sourceisreadonly', 'warning');
25   $OUTPUT->send();
26 }
27
aa12df 28 $source = get_input_value('_source', RCUBE_INPUT_GPC);
T 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))) {
1d773d 32     $plugin = $RCMAIL->plugins->exec_hook('group_addmembers', array('group_id' => $gid, 'ids' => $ids, 'source' => $source));
aa12df 33     
T 34     if (!$plugin['abort'] && $CONTACTS->add_to_group($gid, $plugin['ids']))
35       $OUTPUT->show_message('contactaddedtogroup');
36     else if ($plugin['message'])
37       $OUTPUT->show_message($plugin['message'], 'warning');
38   }
3baa72 39 }
T 40
aa12df 41 else if ($RCMAIL->action == 'group-delmembers') {
T 42   if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST))) {
43     $plugin = $RCMAIL->plugins->exec_hook('group_delmembers', array('group_id' => $gid, 'ids' => $ids, 'source' => $source));
44     $ids = $plugin['ids'];
45     
46     if (!$plugin['abort'] && $CONTACTS->remove_from_group($gid, $ids))
47       $OUTPUT->show_message('contactremovedfromgroup');
48     else if ($plugin['message'])
49       $OUTPUT->show_message($plugin['message'], 'warning');
50   }
3baa72 51 }
T 52
53 else if ($RCMAIL->action == 'group-create') {
aa12df 54   if ($name = trim(get_input_value('_name', RCUBE_INPUT_POST))) {
T 55     $plugin = $RCMAIL->plugins->exec_hook('group_create', array('name' => $name, 'source' => $source));
56     if (!$plugin['abort'])
57       $created = $CONTACTS->create_group($plugin['name']);
a61bbb 58   }
T 59   
60   if ($created && $OUTPUT->ajax_call) {
61     $OUTPUT->command('insert_contact_group', $created);
62   }
aa12df 63   else if (!$created) {
T 64     $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
a61bbb 65   }
T 66 }
67
3baa72 68 else if ($RCMAIL->action == 'group-rename') {
aa12df 69   if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($name = trim(get_input_value('_name', RCUBE_INPUT_POST)))) {
T 70     $plugin = $RCMAIL->plugins->exec_hook('group_rename', array('group_id' => $gid, 'name' => $name, 'source' => $source));
71     if (!$plugin['abort'])
72       $newname = $CONTACTS->rename_group($gid, $plugin['name']);
73   }
3baa72 74
T 75   if ($newname && $OUTPUT->ajax_call)
76     $OUTPUT->command('update_contact_group', $gid, $newname);
77   else if (!$newname)
aa12df 78     $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
a61bbb 79 }
T 80
3baa72 81 else if ($RCMAIL->action == 'group-delete') {
aa12df 82   if ($gid = get_input_value('_gid', RCUBE_INPUT_POST)) {
T 83     $plugin = $RCMAIL->plugins->exec_hook('group_delete', array('group_id' => $gid, 'source' => $source));
84     if (!$plugin['abort'])
85       $deleted = $CONTACTS->delete_group($gid);
86   }
3baa72 87
T 88   if ($deleted)
89     $OUTPUT->command('remove_group_item', $gid);
90   else
aa12df 91     $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
a61bbb 92 }
T 93
94 // send response
95 $OUTPUT->send();
96
97 ?>