4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/delete.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2009, The Roundcube Dev Team |
9 | Licensed under the GNU GPL |
12 | Delete the submitted contacts (CIDs) from the users address book |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: delete.inc 4951 2011-07-21 11:15:18Z alec $
22 // process ajax requests only
23 if (!$OUTPUT->ajax_call)
26 $cids = rcmail_get_cids();
29 // remove previous deletes
30 $undo_time = $RCMAIL->config->get('undo_timeout', 0);
31 $RCMAIL->session->remove('contact_undo');
33 foreach ($cids as $source => $cid)
35 $CONTACTS = rcmail_contact_source($source);
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');
48 $plugin = $RCMAIL->plugins->exec_hook('contact_delete', array(
49 'id' => $cid, 'source' => $source));
51 $deleted = !$plugin['abort'] ? $CONTACTS->delete($cid, $undo_time < 1) : $plugin['result'];
54 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'contactdelerror', 'error');
55 $OUTPUT->command('list_contacts');
61 // store deleted contacts IDs in session for undo action
62 if ($undo_time > 0 && $CONTACTS->undelete) {
63 $_SESSION['contact_undo']['data'][$source] = $cid;
68 $page = isset($_SESSION['page']) ? $_SESSION['page'] : 1;
70 // update saved search after data changed
71 if (($search_request = $_REQUEST['_search']) && isset($_SESSION['search'][$search_request])) {
72 $search = (array)$_SESSION['search'][$search_request];
75 // Get records from all sources (refresh search)
76 foreach ($search as $s => $set) {
77 $source = $RCMAIL->get_address_book($s);
81 $source->set_pagesize(9999);
82 $source->set_search_set($set);
85 $result = $source->list_records(array('name', 'email'));
87 if (!$result->count) {
92 while ($row = $result->next()) {
93 $row['sourceid'] = $s;
94 $key = $row['name'] . ':' . $row['sourceid'];
95 $records[$key] = $row;
99 $search[$s] = $source->get_search_set();
102 $_SESSION['search'][$search_request] = $search;
104 // create resultset object
105 $count = count($records);
106 $first = ($page-1) * $CONFIG['pagesize'];
107 $result = new rcube_result_set($count, $first);
109 // get records from the next page to add to the list
110 $pages = ceil((count($records) + $delcnt) / $CONFIG['pagesize']);
111 if ($_GET['_from'] != 'show' && $pages > 1 && $page < $pages) {
113 ksort($records, SORT_LOCALE_STRING);
115 $first += $CONFIG['pagesize'];
116 // create resultset object
117 $res = new rcube_result_set($count, $first - $delcnt);
119 if ($CONFIG['pagesize'] < $count) {
120 $records = array_slice($records, $first - $delcnt, $delcnt);
123 $res->records = array_values($records);
131 // count contacts for this user
132 $result = $CONTACTS->count();
134 // get records from the next page to add to the list
135 $pages = ceil(($result->count + $delcnt) / $CONFIG['pagesize']);
136 if ($_GET['_from'] != 'show' && $pages > 1 && $page < $pages) {
137 $CONTACTS->set_page($page);
138 $records = $CONTACTS->list_records(null, -$delcnt);
142 // update message count display
143 $OUTPUT->set_env('pagecount', ceil($result->count / $CONFIG['pagesize']));
144 $OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result));
146 if (!empty($_SESSION['contact_undo'])) {
147 $_SESSION['contact_undo']['ts'] = time();
148 $msg = html::span(null, rcube_label('contactdeleted'))
149 . ' ' . html::a(array('onclick' => JS_OBJECT_NAME.".command('undo', '', this)"), rcube_label('undo'));
151 $OUTPUT->show_message($msg, 'confirmation', null, true, $undo_time);
154 $OUTPUT->show_message('contactdeleted', 'confirmation');
157 // add new rows from next page (if any)
158 if (!empty($records)) {
159 rcmail_js_contacts_list($records);