~ubuntu-branches/debian/sid/php-horde-turba/sid

« back to all changes in this revision

Viewing changes to turba-4.1.0/lib/Form/DeleteAddressBook.php

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2013-08-11 13:16:25 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130811131625-z91stjvq51jr9onv
Tags: 4.1.1-1
New upstream version 4.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
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(
34
 
            array('class' => 'horde-delete', 'value' => _("Delete")),
35
 
            array('class' => 'horde-cancel', 'value' => _("Cancel")),
36
 
        ));
37
 
    }
38
 
 
39
 
    /**
40
 
     * @throws Turba_Exception
41
 
     */
42
 
    public function execute()
43
 
    {
44
 
        // If cancel was clicked, return false.
45
 
        if ($this->_vars->get('submitbutton') == _("Cancel")) {
46
 
            Horde::url('', true)->redirect();
47
 
        }
48
 
 
49
 
        if (!$GLOBALS['registry']->getAuth() ||
50
 
            $this->_addressbook->get('owner') != $GLOBALS['registry']->getAuth()) {
51
 
            throw new Turba_Exception(_("You do not have permissions to delete this address book."));
52
 
        }
53
 
 
54
 
        $driver = $GLOBALS['injector']
55
 
            ->getInstance('Turba_Factory_Driver')
56
 
            ->create($this->_addressbook->getName());
57
 
        if ($driver->hasCapability('delete_all')) {
58
 
            try {
59
 
                $driver->deleteAll();
60
 
            } catch (Turba_Exception $e) {
61
 
                Horde::logMessage($e->getMessage(), 'ERR');
62
 
                throw $e;
63
 
            }
64
 
        }
65
 
 
66
 
        // Address book successfully deleted from backend, remove the share.
67
 
        try {
68
 
            $GLOBALS['injector']
69
 
                ->getInstance('Turba_Shares')
70
 
                ->removeShare($this->_addressbook);
71
 
        } catch (Horde_Share_Exception $e) {
72
 
            Horde::logMessage($e->getMessage(), 'ERR');
73
 
            throw new Turba_Exception($e);
74
 
        }
75
 
 
76
 
        if ($GLOBALS['session']->get('turba', 'source') == Horde_Util::getFormData('deleteshare')) {
77
 
            $GLOBALS['session']->remove('turba', 'source');
78
 
        }
79
 
    }
80
 
}