You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

groups.inc 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/addressbook/groups.inc |
  5. | |
  6. | This file is part of the Roundcube Webmail client |
  7. | Copyright (C) 2010-2013, The Roundcube Dev Team |
  8. | |
  9. | Licensed under the GNU General Public License version 3 or |
  10. | any later version with exceptions for skins & plugins. |
  11. | See the README file for a full license statement. |
  12. | |
  13. | PURPOSE: |
  14. | Create/delete/rename contact groups and assign/remove contacts |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. $source = rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC);
  21. $CONTACTS = rcmail_contact_source($source);
  22. if ($CONTACTS->readonly || !$CONTACTS->groups) {
  23. $OUTPUT->show_message('sourceisreadonly', 'warning');
  24. $OUTPUT->send();
  25. }
  26. if ($RCMAIL->action == 'group-addmembers') {
  27. if (($gid = rcube_utils::get_input_value('_gid', rcube_utils::INPUT_POST)) && ($ids = rcmail_get_cids($source))) {
  28. $plugin = $RCMAIL->plugins->exec_hook('group_addmembers', array(
  29. 'group_id' => $gid,
  30. 'ids' => $ids,
  31. 'source' => $source,
  32. ));
  33. $CONTACTS->set_group($gid);
  34. $num2add = count($plugin['ids']);
  35. if (!$plugin['abort']) {
  36. if (($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($CONTACTS->count()->count + $num2add > $maxnum)) {
  37. $OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum));
  38. $OUTPUT->send();
  39. }
  40. $result = $CONTACTS->add_to_group($gid, $plugin['ids']);
  41. }
  42. else {
  43. $result = $plugin['result'];
  44. }
  45. if ($result)
  46. $OUTPUT->show_message('contactaddedtogroup');
  47. else if ($plugin['abort'] || $CONTACTS->get_error())
  48. $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error');
  49. else
  50. $OUTPUT->show_message($plugin['message'] ?: 'nogroupassignmentschanged');
  51. }
  52. }
  53. else if ($RCMAIL->action == 'group-delmembers') {
  54. if (($gid = rcube_utils::get_input_value('_gid', rcube_utils::INPUT_POST)) && ($ids = rcmail_get_cids($source))) {
  55. $plugin = $RCMAIL->plugins->exec_hook('group_delmembers', array(
  56. 'group_id' => $gid,
  57. 'ids' => $ids,
  58. 'source' => $source,
  59. ));
  60. if (!$plugin['abort'])
  61. $result = $CONTACTS->remove_from_group($gid, $plugin['ids']);
  62. else
  63. $result = $plugin['result'];
  64. if ($result) {
  65. $OUTPUT->show_message('contactremovedfromgroup');
  66. $OUTPUT->command('remove_group_contacts',array('source' => $source, 'gid' => $gid));
  67. }
  68. else {
  69. $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error');
  70. }
  71. }
  72. }
  73. else if ($RCMAIL->action == 'group-create') {
  74. if ($name = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST, true))) {
  75. $plugin = $RCMAIL->plugins->exec_hook('group_create', array(
  76. 'name' => $name,
  77. 'source' => $source,
  78. ));
  79. if (!$plugin['abort'])
  80. $created = $CONTACTS->create_group($plugin['name']);
  81. else
  82. $created = $plugin['result'];
  83. }
  84. if ($created && $OUTPUT->ajax_call) {
  85. $created['name'] = rcube::Q($created['name']);
  86. $OUTPUT->show_message('groupcreated', 'confirmation');
  87. $OUTPUT->command('insert_contact_group', array('source' => $source) + $created);
  88. }
  89. else if (!$created) {
  90. $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error');
  91. }
  92. }
  93. else if ($RCMAIL->action == 'group-rename') {
  94. if (($gid = rcube_utils::get_input_value('_gid', rcube_utils::INPUT_POST))
  95. && ($name = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST, true)))
  96. ) {
  97. $plugin = $RCMAIL->plugins->exec_hook('group_rename', array(
  98. 'group_id' => $gid,
  99. 'name' => $name,
  100. 'source' => $source,
  101. ));
  102. if (!$plugin['abort'])
  103. $newname = $CONTACTS->rename_group($gid, $plugin['name'], $newgid);
  104. else
  105. $newname = $plugin['result'];
  106. }
  107. if ($newname && $OUTPUT->ajax_call) {
  108. $OUTPUT->show_message('grouprenamed', 'confirmation');
  109. $OUTPUT->command('update_contact_group', array(
  110. 'source' => $source, 'id' => $gid, 'name' => rcube::Q($newname), 'newid' => $newgid));
  111. }
  112. else if (!$newname) {
  113. $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error');
  114. }
  115. }
  116. else if ($RCMAIL->action == 'group-delete') {
  117. if ($gid = rcube_utils::get_input_value('_gid', rcube_utils::INPUT_POST)) {
  118. $plugin = $RCMAIL->plugins->exec_hook('group_delete', array(
  119. 'group_id' => $gid,
  120. 'source' => $source,
  121. ));
  122. if (!$plugin['abort'])
  123. $deleted = $CONTACTS->delete_group($gid);
  124. else
  125. $deleted = $plugin['result'];
  126. }
  127. if ($deleted) {
  128. $OUTPUT->show_message('groupdeleted', 'confirmation');
  129. $OUTPUT->command('remove_group_item', array('source' => $source, 'id' => $gid));
  130. }
  131. else {
  132. $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error');
  133. }
  134. }
  135. // send response
  136. $OUTPUT->send();