source: subversion/trunk/roundcubemail/program/steps/addressbook/groups.inc @ 3614

Last change on this file since 3614 was 3614, checked in by alec, 3 years ago
  • Extend contact groups support (#1486682)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date Author Revision
File size: 4.2 KB
Line 
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
22if ($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
29if ($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'] && ($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($CONTACTS->count()->count + $num2add > $maxnum))
37      $OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum));
38    else if (!$plugin['abort'] && $CONTACTS->add_to_group($gid, $plugin['ids']))
39      $OUTPUT->show_message('contactaddedtogroup');
40    else if ($plugin['message'])
41      $OUTPUT->show_message($plugin['message'], 'warning');
42  }
43}
44
45else if ($RCMAIL->action == 'group-delmembers') {
46  if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST))) {
47    $plugin = $RCMAIL->plugins->exec_hook('group_delmembers', array('group_id' => $gid, 'ids' => $ids, 'source' => $source));
48   
49    if (!$plugin['abort'] && $CONTACTS->remove_from_group($gid, $plugin['ids']))
50      $OUTPUT->show_message('contactremovedfromgroup');
51    else if ($plugin['message'])
52      $OUTPUT->show_message($plugin['message'], 'warning');
53  }
54}
55
56else if ($RCMAIL->action == 'group-create') {
57  if ($name = trim(get_input_value('_name', RCUBE_INPUT_POST))) {
58    $plugin = $RCMAIL->plugins->exec_hook('group_create', array('name' => $name, 'source' => $source));
59    if (!$plugin['abort'])
60      $created = $CONTACTS->create_group($plugin['name']);
61  }
62 
63  if ($created && $OUTPUT->ajax_call) {
64    $created['source'] = $source;
65    $OUTPUT->command('insert_contact_group', $created);
66  }
67  else if (!$created) {
68    $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
69  }
70}
71
72else if ($RCMAIL->action == 'group-rename') {
73  if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($name = trim(get_input_value('_name', RCUBE_INPUT_POST)))) {
74    $plugin = $RCMAIL->plugins->exec_hook('group_rename', array('group_id' => $gid, 'name' => $name, 'source' => $source));
75    if (!$plugin['abort'])
76      $newname = $CONTACTS->rename_group($gid, $plugin['name']);
77  }
78
79  if ($newname && $OUTPUT->ajax_call)
80    $OUTPUT->command('update_contact_group', array('source' => $source, 'id' => $gid, 'name' => $newname));
81  else if (!$newname)
82    $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
83}
84
85else if ($RCMAIL->action == 'group-delete') {
86  if ($gid = get_input_value('_gid', RCUBE_INPUT_POST)) {
87    $plugin = $RCMAIL->plugins->exec_hook('group_delete', array('group_id' => $gid, 'source' => $source));
88    if (!$plugin['abort'])
89      $deleted = $CONTACTS->delete_group($gid);
90  }
91
92  if ($deleted)
93    $OUTPUT->command('remove_group_item', array('source' => $source, 'id' => $gid));
94  else
95    $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
96}
97
98// send response
99$OUTPUT->send();
100
101?>
Note: See TracBrowser for help on using the repository browser.