]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/addressbook/undo.inc
Fix symlink mess
[roundcube.git] / program / steps / addressbook / undo.inc
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/addressbook/undo.inc                                    |
6  |                                                                       |
7  | This file is part of the Roundcube Webmail client                     |
8  | Copyright (C) 2011, Kolab Systems AG                                  |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Undelete contacts (CIDs) from last delete action                    |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Aleksander Machniak <machniak@kolabsys.com>                   |
16  +-----------------------------------------------------------------------+
17
18  $Id: undo.inc 5967 2012-03-05 19:59:07Z alec $
19
20 */
21
22 // process ajax requests only
23 if (!$OUTPUT->ajax_call)
24     return;
25
26 $undo   = $_SESSION['contact_undo'];
27 $delcnt = 0;
28
29 foreach ((array)$undo['data'] as $source => $cid)
30 {
31     $CONTACTS = rcmail_contact_source($source);
32
33     $plugin = $RCMAIL->plugins->exec_hook('contact_undelete', array(
34         'id' => $cid, 'source' => $source));
35
36     $restored = !$plugin['abort'] ? $CONTACTS->undelete($cid) : $plugin['result'];
37
38     if (!$restored) {
39         $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'contactrestoreerror', 'error');
40         $OUTPUT->command('list_contacts');
41         $OUTPUT->send();
42     }
43     else {
44         $delcnt += $restored;
45     }
46 }
47
48 // update saved search after data changed
49 if ($delcnt && ($search_request = $_REQUEST['_search']) && isset($_SESSION['search'][$search_request])) {
50     $search  = (array)$_SESSION['search'][$search_request];
51
52     foreach ($search as $s => $set) {
53         $source = $RCMAIL->get_address_book($s);
54
55         // reset page
56         $source->set_page(1);
57         $source->set_pagesize(9999);
58         $source->set_search_set($set);
59
60         // get records
61         $result = $source->list_records(array('name', 'email'));
62
63         if (!$result->count) {
64             unset($search[$s]);
65             continue;
66         }
67
68         $search[$s] = $source->get_search_set();
69     }
70
71     $_SESSION['search'][$search_request] = $search;
72 }
73
74 $RCMAIL->session->remove('contact_undo');
75
76 $OUTPUT->show_message('contactrestored', 'confirmation');
77 $OUTPUT->command('list_contacts');
78
79 // send response
80 $OUTPUT->send();