| 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$ |
|---|
| 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('source' => $source) + $created); |
|---|
| 83 | } |
|---|
| 84 | else if (!$created) { |
|---|
| 85 | $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error'); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | else if ($RCMAIL->action == 'group-rename') { |
|---|
| 90 | if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($name = trim(get_input_value('_name', RCUBE_INPUT_POST)))) { |
|---|
| 91 | $plugin = $RCMAIL->plugins->exec_hook('group_rename', array('group_id' => $gid, 'name' => $name, 'source' => $source)); |
|---|
| 92 | |
|---|
| 93 | if (!$plugin['abort']) |
|---|
| 94 | $newname = $CONTACTS->rename_group($gid, $plugin['name']); |
|---|
| 95 | else |
|---|
| 96 | $newname = $plugin['result']; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | if ($newname && $OUTPUT->ajax_call) { |
|---|
| 100 | $OUTPUT->show_message('grouprenamed', 'confirmation'); |
|---|
| 101 | $OUTPUT->command('update_contact_group', array('source' => $source, 'id' => $gid, 'name' => $newname)); |
|---|
| 102 | } |
|---|
| 103 | else if (!$newname) |
|---|
| 104 | $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error'); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | else if ($RCMAIL->action == 'group-delete') { |
|---|
| 108 | if ($gid = get_input_value('_gid', RCUBE_INPUT_POST)) { |
|---|
| 109 | $plugin = $RCMAIL->plugins->exec_hook('group_delete', array('group_id' => $gid, 'source' => $source)); |
|---|
| 110 | |
|---|
| 111 | if (!$plugin['abort']) |
|---|
| 112 | $deleted = $CONTACTS->delete_group($gid); |
|---|
| 113 | else |
|---|
| 114 | $deleted = $plugin['result']; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | if ($deleted) { |
|---|
| 118 | $OUTPUT->show_message('groupdeleted', 'confirmation'); |
|---|
| 119 | $OUTPUT->command('remove_group_item', array('source' => $source, 'id' => $gid)); |
|---|
| 120 | } |
|---|
| 121 | else |
|---|
| 122 | $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error'); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | // send response |
|---|
| 126 | $OUTPUT->send(); |
|---|
| 127 | |
|---|