Overview

Packages

  • Horde
    • Data
  • None
  • Turba

Classes

  • Turba
  • Turba_Api
  • Turba_Driver
  • Turba_Driver_Facebook
  • Turba_Driver_Favourites
  • Turba_Driver_Group
  • Turba_Driver_Imsp
  • Turba_Driver_Kolab
  • Turba_Driver_Ldap
  • Turba_Driver_Prefs
  • Turba_Driver_Share
  • Turba_Driver_Sql
  • Turba_Driver_Vbook
  • Turba_Exception
  • Turba_Factory_Driver
  • Turba_Form_AddContact
  • Turba_Form_Contact
  • Turba_Form_ContactBase
  • Turba_Form_CreateAddressBook
  • Turba_Form_DeleteAddressBook
  • Turba_Form_EditAddressBook
  • Turba_Form_EditContact
  • Turba_Form_EditContactGroup
  • Turba_List
  • Turba_LoginTasks_SystemTask_Upgrade
  • Turba_Object
  • Turba_Object_Group
  • Turba_Test
  • Turba_View_Browse
  • Turba_View_Contact
  • Turba_View_DeleteContact
  • Turba_View_Duplicates
  • Turba_View_EditContact
  • Turba_View_List
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Horde_Form for deleting address books.
 4:  *
 5:  * See the enclosed file LICENSE for license information (ASL). If you
 6:  * did not receive this file, see http://www.horde.org/licenses/apache.
 7:  *
 8:  * @package Turba
 9:  */
10: 
11: /**
12:  * The Turba_Form_DeleteAddressbook class provides the form for
13:  * deleting an address book.
14:  *
15:  * @author  Chuck Hagenbuch <chuck@horde.org>
16:  * @package Turba
17:  */
18: class Turba_Form_DeleteAddressBook extends Horde_Form
19: {
20:     /**
21:      * Address book being deleted
22:      */
23:     protected $_addressbook;
24: 
25:     public function __construct($vars, $addressbook)
26:     {
27:         $this->_addressbook = $addressbook;
28:         parent::__construct($vars, sprintf(_("Delete %s"), $addressbook->get('name')));
29: 
30:         $this->addHidden('', 'a', 'text', true);
31:         $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);
32: 
33:         $this->setButtons(array(_("Delete"), _("Cancel")));
34:     }
35: 
36:     /**
37:      * @TODO Remove share from 'addressbooks' pref
38:      *
39:      * @throws Turba_Exception
40:      */
41:     public function execute()
42:     {
43:         // If cancel was clicked, return false.
44:         if ($this->_vars->get('submitbutton') == _("Cancel")) {
45:             return false;
46:         }
47: 
48:         if (!$GLOBALS['registry']->getAuth() ||
49:             $this->_addressbook->get('owner') != $GLOBALS['registry']->getAuth()) {
50:             throw new Turba_Exception(_("You do not have permissions to delete this address book."));
51:         }
52: 
53:         $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($this->_addressbook->getName());
54:         if ($driver->hasCapability('delete_all')) {
55:             try {
56:                 $driver->deleteAll();
57:             } catch (Turba_Exception $e) {
58:                 Horde::logMessage($e->getMessage(), 'ERR');
59:                 throw $e;
60:             }
61:         }
62: 
63:         // Address book successfully deleted from backend, remove the share.
64:         try {
65:             $GLOBALS['turba_shares']->removeShare($this->_addressbook);
66:         } catch (Horde_Share_Exception $e) {
67:             Horde::logMessage($e->getMessage(), 'ERR');
68:             throw new Turba_Exception($e);
69:         }
70: 
71:         if ($GLOBALS['session']->get('turba', 'source') == Horde_Util::getFormData('deleteshare')) {
72:             $GLOBALS['session']->remove('turba', 'source');
73:         }
74: 
75:         $abooks = json_decode($GLOBALS['prefs']->getValue('addressbooks'), true);
76:         if (($pos = array_search($this->_addressbook->getName(), $abooks)) !== false) {
77:             unset($abooks[$pos]);
78:             $GLOBALS['prefs']->setValue('addressbooks', json_encode($abooks));
79:         }
80: 
81:         return true;
82:     }
83: 
84: }
85: 
API documentation generated by ApiGen