comparison program/steps/addressbook/delete.inc @ 0:4681f974d28b

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:52:31 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4681f974d28b
1 <?php
2
3 /**
4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/delete.inc |
6 | |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2013, The Roundcube Dev Team |
9 | |
10 | Licensed under the GNU General Public License version 3 or |
11 | any later version with exceptions for skins & plugins. |
12 | See the README file for a full license statement. |
13 | |
14 | PURPOSE: |
15 | Delete the submitted contacts (CIDs) from the users address book |
16 | |
17 +-----------------------------------------------------------------------+
18 | Author: Thomas Bruederli <roundcube@gmail.com> |
19 +-----------------------------------------------------------------------+
20 */
21
22 // process ajax requests only
23 if (!$OUTPUT->ajax_call) {
24 return;
25 }
26
27 $cids = rcmail_get_cids(null, rcube_utils::INPUT_POST);
28 $delcnt = 0;
29
30 // remove previous deletes
31 $undo_time = $RCMAIL->config->get('undo_timeout', 0);
32 $RCMAIL->session->remove('contact_undo');
33
34 foreach ($cids as $source => $cid) {
35 $CONTACTS = rcmail_contact_source($source);
36
37 if ($CONTACTS->readonly) {
38 // more sources? do nothing, probably we have search results from
39 // more than one source, some of these sources can be readonly
40 if (count($cids) == 1) {
41 $OUTPUT->show_message('contactdelerror', 'error');
42 $OUTPUT->command('list_contacts');
43 $OUTPUT->send();
44 }
45 continue;
46 }
47
48 $plugin = $RCMAIL->plugins->exec_hook('contact_delete', array(
49 'id' => $cid, 'source' => $source));
50
51 $deleted = !$plugin['abort'] ? $CONTACTS->delete($cid, $undo_time < 1) : $plugin['result'];
52
53 if (!$deleted) {
54 if ($plugin['message']) {
55 $error = $plugin['message'];
56 }
57 else if (($error = $CONTACTS->get_error()) && $error['message']) {
58 $error = $error['message'];
59 }
60 else {
61 $error = 'contactdelerror';
62 }
63
64 $source = rcube_utils::get_input_value('_source', rcube_utils::INPUT_GP);
65 $group = rcube_utils::get_input_value('_gid', rcube_utils::INPUT_GP);
66
67 $OUTPUT->show_message($error, 'error');
68 $OUTPUT->command('list_contacts', $source, $group);
69 $OUTPUT->send();
70 }
71 else {
72 $delcnt += $deleted;
73
74 // store deleted contacts IDs in session for undo action
75 if ($undo_time > 0 && $CONTACTS->undelete) {
76 $_SESSION['contact_undo']['data'][$source] = $cid;
77 }
78 }
79 }
80
81 if (!empty($_SESSION['contact_undo'])) {
82 $_SESSION['contact_undo']['ts'] = time();
83 $msg = html::span(null, $RCMAIL->gettext('contactdeleted'))
84 . ' ' . html::a(array('onclick' => rcmail_output::JS_OBJECT_NAME.".command('undo', '', this)"), $RCMAIL->gettext('undo'));
85
86 $OUTPUT->show_message($msg, 'confirmation', null, true, $undo_time);
87 }
88 else {
89 $OUTPUT->show_message('contactdeleted', 'confirmation');
90 }
91
92 $page = isset($_SESSION['page']) ? $_SESSION['page'] : 1;
93
94 // update saved search after data changed
95 if (($records = rcmail_search_update(true)) !== false) {
96 // create resultset object
97 $count = count($records);
98 $first = ($page-1) * $PAGE_SIZE;
99 $result = new rcube_result_set($count, $first);
100 $pages = ceil((count($records) + $delcnt) / $PAGE_SIZE);
101
102 // last page and it's empty, display previous one
103 if ($result->count && $result->count <= ($PAGE_SIZE * ($page - 1))) {
104 $OUTPUT->command('list_page', 'prev');
105 $rowcount = $RCMAIL->gettext('loading');
106 }
107 // get records from the next page to add to the list
108 else if ($pages > 1 && $page < $pages) {
109 // sort the records
110 ksort($records, SORT_LOCALE_STRING);
111
112 $first += $PAGE_SIZE;
113 // create resultset object
114 $res = new rcube_result_set($count, $first - $delcnt);
115
116 if ($PAGE_SIZE < $count) {
117 $records = array_slice($records, $first - $delcnt, $delcnt);
118 }
119
120 $res->records = array_values($records);
121 $records = $res;
122 }
123 else {
124 unset($records);
125 }
126 }
127 else {
128 // count contacts for this user
129 $result = $CONTACTS->count();
130 $pages = ceil(($result->count + $delcnt) / $PAGE_SIZE);
131
132 // last page and it's empty, display previous one
133 if ($result->count && $result->count <= ($PAGE_SIZE * ($page - 1))) {
134 $OUTPUT->command('list_page', 'prev');
135 $rowcount = $RCMAIL->gettext('loading');
136 }
137 // get records from the next page to add to the list
138 else if ($pages > 1 && $page < $pages) {
139 $CONTACTS->set_page($page);
140 $records = $CONTACTS->list_records(null, -$delcnt);
141 }
142 }
143
144 // update message count display
145 $OUTPUT->set_env('pagecount', ceil($result->count / $PAGE_SIZE));
146 $OUTPUT->command('set_rowcount', $rowcount ?: rcmail_get_rowcount_text($result));
147
148 // add new rows from next page (if any)
149 if (!empty($records)) {
150 rcmail_js_contacts_list($records);
151 }
152
153 // send response
154 $OUTPUT->send();