]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/addressbook/delete.inc
4c686da5ba470ec5296eada03fabe15da25f2fad
[roundcube.git] / program / steps / addressbook / delete.inc
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-2009, Roundcube Dev. - Switzerland                 |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Delete the submitted contacts (CIDs) from the users address book    |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id: delete.inc 4172 2010-11-03 14:19:48Z alec $
19
20 */
21
22 if ($OUTPUT->ajax_call &&
23     ($cid = get_input_value('_cid', RCUBE_INPUT_POST)) &&
24     preg_match('/^[a-zA-Z0-9\+\/=_-]+(,[a-zA-Z0-9\+\/=_-]+)*$/', $cid)
25 ) {
26     $plugin = $RCMAIL->plugins->exec_hook('contact_delete', array(
27         'id' => $cid, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
28
29     $deleted = !$plugin['abort'] ? $CONTACTS->delete($cid) : $plugin['result'];
30
31     if (!$deleted) {
32         $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'contactdelerror', 'error');
33         $OUTPUT->command('list_contacts');
34     }
35     else {
36         $OUTPUT->show_message('contactdeleted', 'confirmation');
37
38         // count contacts for this user
39         $result = $CONTACTS->count();
40
41         // update message count display
42         $OUTPUT->set_env('pagecount', ceil($result->count / $CONTACTS->page_size));
43         $OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result->count));
44
45         // add new rows from next page (if any)
46         $pages = ceil(($result->count + $deleted) / $CONTACTS->page_size);
47         if ($_GET['_from'] != 'show' && $pages > 1 && $CONTACTS->list_page < $pages)
48             rcmail_js_contacts_list($CONTACTS->list_records(null, -$deleted));
49     }
50
51     // send response
52     $OUTPUT->send();
53 }
54
55 exit;
56