commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/addressbook/delete.inc | |
|
6 |
| | |
e019f2
|
7 |
| This file is part of the Roundcube Webmail client | |
f5e7b3
|
8 |
| Copyright (C) 2005-2009, The Roundcube Dev Team | |
7fe381
|
9 |
| | |
T |
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. | |
4e17e6
|
13 |
| | |
T |
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 |
$Id$ |
|
22 |
|
|
23 |
*/ |
|
24 |
|
ecf295
|
25 |
// process ajax requests only |
A |
26 |
if (!$OUTPUT->ajax_call) |
|
27 |
return; |
|
28 |
|
|
29 |
$cids = rcmail_get_cids(); |
|
30 |
$delcnt = 0; |
|
31 |
|
7f5a84
|
32 |
// remove previous deletes |
63fda8
|
33 |
$undo_time = $RCMAIL->config->get('undo_timeout', 0); |
7f5a84
|
34 |
$RCMAIL->session->remove('contact_undo'); |
A |
35 |
|
ecf295
|
36 |
foreach ($cids as $source => $cid) |
A |
37 |
{ |
|
38 |
$CONTACTS = rcmail_contact_source($source); |
|
39 |
|
|
40 |
if ($CONTACTS->readonly) { |
|
41 |
// more sources? do nothing, probably we have search results from |
|
42 |
// more than one source, some of these sources can be readonly |
|
43 |
if (count($cids) == 1) { |
|
44 |
$OUTPUT->show_message('contactdelerror', 'error'); |
|
45 |
$OUTPUT->command('list_contacts'); |
7f5a84
|
46 |
$OUTPUT->send(); |
ecf295
|
47 |
} |
A |
48 |
continue; |
|
49 |
} |
|
50 |
|
c50d88
|
51 |
$plugin = $RCMAIL->plugins->exec_hook('contact_delete', array( |
ecf295
|
52 |
'id' => $cid, 'source' => $source)); |
306f15
|
53 |
|
63fda8
|
54 |
$deleted = !$plugin['abort'] ? $CONTACTS->delete($cid, $undo_time < 1) : $plugin['result']; |
ce92ba
|
55 |
|
c50d88
|
56 |
if (!$deleted) { |
A |
57 |
$OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'contactdelerror', 'error'); |
|
58 |
$OUTPUT->command('list_contacts'); |
ecf295
|
59 |
$OUTPUT->send(); |
c50d88
|
60 |
} |
A |
61 |
else { |
ecf295
|
62 |
$delcnt += $deleted; |
7f5a84
|
63 |
|
63fda8
|
64 |
// store deleted contacts IDs in session for undo action |
A |
65 |
if ($undo_time > 0 && $CONTACTS->undelete) { |
7f5a84
|
66 |
$_SESSION['contact_undo']['data'][$source] = $cid; |
A |
67 |
} |
c50d88
|
68 |
} |
ce92ba
|
69 |
} |
b25dfd
|
70 |
|
ecf295
|
71 |
$page = isset($_SESSION['page']) ? $_SESSION['page'] : 1; |
A |
72 |
|
|
73 |
// update saved search after data changed |
|
74 |
if (($search_request = $_REQUEST['_search']) && isset($_SESSION['search'][$search_request])) { |
0203f1
|
75 |
$sort_col = $RCMAIL->config->get('addressbook_sort_col', 'name'); |
ecf295
|
76 |
$search = (array)$_SESSION['search'][$search_request]; |
A |
77 |
$records = array(); |
|
78 |
|
|
79 |
// Get records from all sources (refresh search) |
|
80 |
foreach ($search as $s => $set) { |
|
81 |
$source = $RCMAIL->get_address_book($s); |
|
82 |
|
|
83 |
// reset page |
|
84 |
$source->set_page(1); |
|
85 |
$source->set_pagesize(9999); |
|
86 |
$source->set_search_set($set); |
|
87 |
|
|
88 |
// get records |
|
89 |
$result = $source->list_records(array('name', 'email')); |
|
90 |
|
|
91 |
if (!$result->count) { |
|
92 |
unset($search[$s]); |
|
93 |
continue; |
|
94 |
} |
|
95 |
|
|
96 |
while ($row = $result->next()) { |
|
97 |
$row['sourceid'] = $s; |
0203f1
|
98 |
$key = rcmail_contact_key($row, $sort_col); |
ecf295
|
99 |
$records[$key] = $row; |
A |
100 |
} |
|
101 |
unset($result); |
|
102 |
|
|
103 |
$search[$s] = $source->get_search_set(); |
|
104 |
} |
|
105 |
|
|
106 |
$_SESSION['search'][$search_request] = $search; |
|
107 |
|
|
108 |
// create resultset object |
|
109 |
$count = count($records); |
08ffd9
|
110 |
$first = ($page-1) * $PAGE_SIZE; |
ecf295
|
111 |
$result = new rcube_result_set($count, $first); |
A |
112 |
|
|
113 |
// get records from the next page to add to the list |
08ffd9
|
114 |
$pages = ceil((count($records) + $delcnt) / $PAGE_SIZE); |
ecf295
|
115 |
if ($_GET['_from'] != 'show' && $pages > 1 && $page < $pages) { |
A |
116 |
// sort the records |
|
117 |
ksort($records, SORT_LOCALE_STRING); |
|
118 |
|
08ffd9
|
119 |
$first += $PAGE_SIZE; |
ecf295
|
120 |
// create resultset object |
A |
121 |
$res = new rcube_result_set($count, $first - $delcnt); |
|
122 |
|
08ffd9
|
123 |
if ($PAGE_SIZE < $count) { |
ecf295
|
124 |
$records = array_slice($records, $first - $delcnt, $delcnt); |
A |
125 |
} |
|
126 |
|
|
127 |
$res->records = array_values($records); |
|
128 |
$records = $res; |
|
129 |
} |
|
130 |
else { |
|
131 |
unset($records); |
|
132 |
} |
|
133 |
} |
|
134 |
else { |
|
135 |
// count contacts for this user |
|
136 |
$result = $CONTACTS->count(); |
|
137 |
|
|
138 |
// get records from the next page to add to the list |
08ffd9
|
139 |
$pages = ceil(($result->count + $delcnt) / $PAGE_SIZE); |
ecf295
|
140 |
if ($_GET['_from'] != 'show' && $pages > 1 && $page < $pages) { |
A |
141 |
$CONTACTS->set_page($page); |
|
142 |
$records = $CONTACTS->list_records(null, -$delcnt); |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
// update message count display |
08ffd9
|
147 |
$OUTPUT->set_env('pagecount', ceil($result->count / $PAGE_SIZE)); |
ecf295
|
148 |
$OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result)); |
A |
149 |
|
7f5a84
|
150 |
if (!empty($_SESSION['contact_undo'])) { |
A |
151 |
$_SESSION['contact_undo']['ts'] = time(); |
f52c4f
|
152 |
$msg = html::span(null, rcube_label('contactdeleted')) |
7f5a84
|
153 |
. ' ' . html::a(array('onclick' => JS_OBJECT_NAME.".command('undo', '', this)"), rcube_label('undo')); |
A |
154 |
|
63fda8
|
155 |
$OUTPUT->show_message($msg, 'confirmation', null, true, $undo_time); |
7f5a84
|
156 |
} |
A |
157 |
else { |
|
158 |
$OUTPUT->show_message('contactdeleted', 'confirmation'); |
|
159 |
} |
|
160 |
|
ecf295
|
161 |
// add new rows from next page (if any) |
A |
162 |
if (!empty($records)) { |
|
163 |
rcmail_js_contacts_list($records); |
|
164 |
} |
|
165 |
|
|
166 |
// send response |
|
167 |
$OUTPUT->send(); |