| 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 | | | |
|---|
| 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. | |
|---|
| 13 | | | |
|---|
| 14 | | PURPOSE: | |
|---|
| 15 | | Undelete contacts (CIDs) from last delete action | |
|---|
| 16 | | | |
|---|
| 17 | +-----------------------------------------------------------------------+ |
|---|
| 18 | | Author: Aleksander Machniak <machniak@kolabsys.com> | |
|---|
| 19 | +-----------------------------------------------------------------------+ |
|---|
| 20 | |
|---|
| 21 | $Id$ |
|---|
| 22 | |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | // process ajax requests only |
|---|
| 26 | if (!$OUTPUT->ajax_call) |
|---|
| 27 | return; |
|---|
| 28 | |
|---|
| 29 | $undo = $_SESSION['contact_undo']; |
|---|
| 30 | $delcnt = 0; |
|---|
| 31 | |
|---|
| 32 | foreach ((array)$undo['data'] as $source => $cid) |
|---|
| 33 | { |
|---|
| 34 | $CONTACTS = rcmail_contact_source($source); |
|---|
| 35 | |
|---|
| 36 | $plugin = $RCMAIL->plugins->exec_hook('contact_undelete', array( |
|---|
| 37 | 'id' => $cid, 'source' => $source)); |
|---|
| 38 | |
|---|
| 39 | $restored = !$plugin['abort'] ? $CONTACTS->undelete($cid) : $plugin['result']; |
|---|
| 40 | |
|---|
| 41 | if (!$restored) { |
|---|
| 42 | $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'contactrestoreerror', 'error'); |
|---|
| 43 | $OUTPUT->command('list_contacts'); |
|---|
| 44 | $OUTPUT->send(); |
|---|
| 45 | } |
|---|
| 46 | else { |
|---|
| 47 | $delcnt += $restored; |
|---|
| 48 | } |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | // update saved search after data changed |
|---|
| 52 | if ($delcnt && ($search_request = $_REQUEST['_search']) && isset($_SESSION['search'][$search_request])) { |
|---|
| 53 | $search = (array)$_SESSION['search'][$search_request]; |
|---|
| 54 | |
|---|
| 55 | foreach ($search as $s => $set) { |
|---|
| 56 | $source = $RCMAIL->get_address_book($s); |
|---|
| 57 | |
|---|
| 58 | // reset page |
|---|
| 59 | $source->set_page(1); |
|---|
| 60 | $source->set_pagesize(9999); |
|---|
| 61 | $source->set_search_set($set); |
|---|
| 62 | |
|---|
| 63 | // get records |
|---|
| 64 | $result = $source->list_records(array('name', 'email')); |
|---|
| 65 | |
|---|
| 66 | if (!$result->count) { |
|---|
| 67 | unset($search[$s]); |
|---|
| 68 | continue; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | $search[$s] = $source->get_search_set(); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | $_SESSION['search'][$search_request] = $search; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | $RCMAIL->session->remove('contact_undo'); |
|---|
| 78 | |
|---|
| 79 | $OUTPUT->show_message('contactrestored', 'confirmation'); |
|---|
| 80 | $OUTPUT->command('list_contacts'); |
|---|
| 81 | |
|---|
| 82 | // send response |
|---|
| 83 | $OUTPUT->send(); |
|---|