1<?php
2/**
3 * Turba addressbooks - delete.
4 *
5 * Copyright 2001-2017 Horde LLC (http://www.horde.org/)
6 *
7 * See the enclosed file LICENSE for license information (ASL). If you
8 * did not receive this file, see http://www.horde.org/licenses/apache.
9 */
10
11require_once __DIR__ . '/../lib/Application.php';
12Horde_Registry::appInit('turba');
13
14// Exit if this isn't an authenticated user, or if there's no source
15// configured for shares.
16if (!$GLOBALS['registry']->getAuth() || !$session->get('turba', 'has_share')) {
17    Horde::url('', true)->redirect();
18}
19
20$vars = Horde_Variables::getDefaultVariables();
21$addressbook_id = $vars->get('a');
22if ($addressbook_id == $GLOBALS['registry']->getAuth()) {
23    $notification->push(_("This address book cannot be deleted"), 'horde.warning');
24    Horde::url('', true)->redirect();
25}
26
27try {
28    $addressbook = $injector->getInstance('Turba_Shares')->getShare($addressbook_id);
29} catch (Horde_Share_Exception $e) {
30    $notification->push($e);
31    Horde::url('', true)->redirect();
32}
33if (!$GLOBALS['registry']->getAuth() ||
34    $addressbook->get('owner') != $GLOBALS['registry']->getAuth()) {
35    $notification->push(_("You are not allowed to delete this addressbook."), 'horde.error');
36    Horde::url('', true)->redirect();
37}
38
39$form = new Turba_Form_DeleteAddressBook($vars, $addressbook);
40
41// Execute if the form is valid (must pass with POST variables only).
42if ($form->validate(new Horde_Variables($_POST))) {
43    try {
44        $form->execute();
45        $notification->push(sprintf(_("The addressbook \"%s\" has been deleted."), $addressbook->get('name')), 'horde.success');
46    } catch (Turba_Exception $e) {
47        $notification->push($e);
48    }
49
50    Horde::url('', true)->redirect();
51}
52
53$page_output->header(array(
54    'title' => $form->getTitle()
55));
56$notification->notify(array('listeners' => 'status'));
57echo $form->renderActive($form->getRenderer(), $vars, Horde::url('addressbooks/delete.php'), 'post');
58$page_output->footer();
59