1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
<?php
/**
* Horde_Form for deleting address books.
*
* $Horde: turba/lib/Forms/DeleteAddressBook.php,v 1.1.2.1 2007/12/24 05:18:00 chuck Exp $
*
* See the enclosed file LICENSE for license information (ASL). If you
* did not receive this file, see http://www.horde.org/licenses/asl.php.
*
* @package Turba
*/
/** Variables */
require_once 'Horde/Variables.php';
/** Horde_Form */
require_once 'Horde/Form.php';
/** Horde_Form_Renderer */
require_once 'Horde/Form/Renderer.php';
/**
* The Turba_DeleteAddressbookForm class provides the form for
* deleting an address book.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @since Turba 2.2
* @package Turba
*/
class Turba_DeleteAddressBookForm extends Horde_Form {
/**
* Address book being deleted
*/
var $_addressbook;
function Turba_DeleteAddressBookForm(&$vars, &$addressbook)
{
$this->_addressbook = &$addressbook;
parent::Horde_Form($vars, sprintf(_("Delete %s"), $addressbook->get('name')));
$this->addHidden('', 'a', 'text', true);
$this->addVariable(sprintf(_("Really delete the address book \"%s\"? This cannot be undone and all contacts in this address book will be permanently removed."), $this->_addressbook->get('name')), 'desc', 'description', false);
$this->setButtons(array(_("Delete"), _("Cancel")));
}
/**
* @TODO Remove share from 'addressbooks' pref
*/
function execute()
{
// If cancel was clicked, return false.
if ($this->_vars->get('submitbutton') == _("Cancel")) {
return false;
}
if ($this->_addressbook->get('owner') != Auth::getAuth()) {
return PEAR::raiseError(_("You do not have permissions to delete this address book."));
}
$driver = &Turba_Driver::singleton($this->_addressbook->getName());
if (is_a($driver, 'PEAR_Error')) {
return $driver;
}
// We have a Turba_Driver, try to delete the address book.
$result = $driver->deleteAll();
if (is_a($result, 'PEAR_Error')) {
return $result;
}
// Address book successfully deleted from backend, remove the
// share.
$result = $GLOBALS['turba_shares']->removeShare($this->_addressbook);
if (is_a($result, 'PEAR_Error')) {
return $result;
}
if (isset($_SESSION['turba']['source']) && $_SESSION['turba']['source'] == Util::getFormData('deleteshare')) {
unset($_SESSION['turba']['source']);
}
return true;
}
}
|