您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

delete.inc 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/addressbook/delete.inc |
  5. | |
  6. | This file is part of the Roundcube Webmail client |
  7. | Copyright (C) 2005-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. | Delete the submitted contacts (CIDs) from the users address book |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. // process ajax requests only
  21. if (!$OUTPUT->ajax_call) {
  22. return;
  23. }
  24. $cids = rcmail_get_cids(null, rcube_utils::INPUT_POST);
  25. $delcnt = 0;
  26. // remove previous deletes
  27. $undo_time = $RCMAIL->config->get('undo_timeout', 0);
  28. $RCMAIL->session->remove('contact_undo');
  29. foreach ($cids as $source => $cid) {
  30. $CONTACTS = rcmail_contact_source($source);
  31. if ($CONTACTS->readonly) {
  32. // more sources? do nothing, probably we have search results from
  33. // more than one source, some of these sources can be readonly
  34. if (count($cids) == 1) {
  35. $OUTPUT->show_message('contactdelerror', 'error');
  36. $OUTPUT->command('list_contacts');
  37. $OUTPUT->send();
  38. }
  39. continue;
  40. }
  41. $plugin = $RCMAIL->plugins->exec_hook('contact_delete', array(
  42. 'id' => $cid, 'source' => $source));
  43. $deleted = !$plugin['abort'] ? $CONTACTS->delete($cid, $undo_time < 1) : $plugin['result'];
  44. if (!$deleted) {
  45. if ($plugin['message']) {
  46. $error = $plugin['message'];
  47. }
  48. else if (($error = $CONTACTS->get_error()) && $error['message']) {
  49. $error = $error['message'];
  50. }
  51. else {
  52. $error = 'contactdelerror';
  53. }
  54. $source = rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC);
  55. $group = rcube_utils::get_input_value('_gid', rcube_utils::INPUT_GPC);
  56. $OUTPUT->show_message($error, 'error');
  57. $OUTPUT->command('list_contacts', $source, $group);
  58. $OUTPUT->send();
  59. }
  60. else {
  61. $delcnt += $deleted;
  62. // store deleted contacts IDs in session for undo action
  63. if ($undo_time > 0 && $CONTACTS->undelete) {
  64. $_SESSION['contact_undo']['data'][$source] = $cid;
  65. }
  66. }
  67. }
  68. if (!empty($_SESSION['contact_undo'])) {
  69. $_SESSION['contact_undo']['ts'] = time();
  70. $msg = html::span(null, $RCMAIL->gettext('contactdeleted'))
  71. . ' ' . html::a(array('onclick' => rcmail_output::JS_OBJECT_NAME.".command('undo', '', this)"), $RCMAIL->gettext('undo'));
  72. $OUTPUT->show_message($msg, 'confirmation', null, true, $undo_time);
  73. }
  74. else {
  75. $OUTPUT->show_message('contactdeleted', 'confirmation');
  76. }
  77. $page = isset($_SESSION['page']) ? $_SESSION['page'] : 1;
  78. // update saved search after data changed
  79. if (($records = rcmail_search_update(true)) !== false) {
  80. // create resultset object
  81. $count = count($records);
  82. $first = ($page-1) * $PAGE_SIZE;
  83. $result = new rcube_result_set($count, $first);
  84. $pages = ceil((count($records) + $delcnt) / $PAGE_SIZE);
  85. // last page and it's empty, display previous one
  86. if ($result->count && $result->count <= ($PAGE_SIZE * ($page - 1))) {
  87. $OUTPUT->command('list_page', 'prev');
  88. $rowcount = $RCMAIL->gettext('loading');
  89. }
  90. // get records from the next page to add to the list
  91. else if ($pages > 1 && $page < $pages) {
  92. // sort the records
  93. ksort($records, SORT_LOCALE_STRING);
  94. $first += $PAGE_SIZE;
  95. // create resultset object
  96. $res = new rcube_result_set($count, $first - $delcnt);
  97. if ($PAGE_SIZE < $count) {
  98. $records = array_slice($records, $first - $delcnt, $delcnt);
  99. }
  100. $res->records = array_values($records);
  101. $records = $res;
  102. }
  103. else {
  104. unset($records);
  105. }
  106. }
  107. else {
  108. // count contacts for this user
  109. $result = $CONTACTS->count();
  110. $pages = ceil(($result->count + $delcnt) / $PAGE_SIZE);
  111. // last page and it's empty, display previous one
  112. if ($result->count && $result->count <= ($PAGE_SIZE * ($page - 1))) {
  113. $OUTPUT->command('list_page', 'prev');
  114. $rowcount = $RCMAIL->gettext('loading');
  115. }
  116. // get records from the next page to add to the list
  117. else if ($pages > 1 && $page < $pages) {
  118. $CONTACTS->set_page($page);
  119. $records = $CONTACTS->list_records(null, -$delcnt);
  120. }
  121. }
  122. // update message count display
  123. $OUTPUT->set_env('pagecount', ceil($result->count / $PAGE_SIZE));
  124. $OUTPUT->command('set_rowcount', $rowcount ?: rcmail_get_rowcount_text($result));
  125. // add new rows from next page (if any)
  126. if (!empty($records)) {
  127. rcmail_js_contacts_list($records);
  128. }
  129. // send response
  130. $OUTPUT->send();