]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/addressbook/undo.inc
Imported Upstream version 0.6+dfsg
[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 4916 2011-07-07 11:44:26Z 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         while ($row = $result->next()) {
69             $row['sourceid'] = $s;
70             $key = $row['name'] . ':' . $row['sourceid'];
71             $records[$key] = $row;
72         }
73         unset($result);
74
75         $search[$s] = $source->get_search_set();
76     }
77
78     $_SESSION['search'][$search_request] = $search;
79 }
80
81 $RCMAIL->session->remove('contact_undo');
82
83 $OUTPUT->show_message('contactrestored', 'confirmation');
84 $OUTPUT->command('list_contacts');
85
86 // send response
87 $OUTPUT->send();