1<?php
2/**
3 * Copyright 2002-2017 Horde LLC (http://www.horde.org/)
4 *
5 * See the enclosed file COPYING for license information (GPL). If you
6 * did not receive this file, see http://www.horde.org/licenses/gpl.
7 */
8
9require_once __DIR__ . '/../lib/Application.php';
10Horde_Registry::appInit('nag');
11
12// Exit if this isn't an authenticated user.
13if (!$GLOBALS['registry']->getAuth()) {
14    Horde::url('list.php', true)->redirect();
15}
16
17$vars = Horde_Variables::getDefaultVariables();
18try {
19    $tasklist = $nag_shares->getShare($vars->get('t'));
20} catch (Horde_Share_Exception $e) {
21    $notification->push($e);
22    Horde::url('list.php', true)->redirect();
23}
24$owner = $tasklist->get('owner') == $GLOBALS['registry']->getAuth() ||
25    (is_null($tasklist->get('owner')) && $GLOBALS['registry']->isAdmin());
26if (!$owner &&
27    !$tasklist->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
28    $notification->push(_("You are not allowed to see this task list."), 'horde.error');
29    Horde::url('list.php', true)->redirect();
30}
31$form = new Nag_Form_EditTaskList($vars, $tasklist);
32
33// Execute if the form is valid.
34if ($owner && $form->validate($vars)) {
35    $original_name = $tasklist->get('name');
36    try {
37        $form->execute();
38        if ($tasklist->get('name') != $original_name) {
39            $notification->push(sprintf(_("The task list \"%s\" has been renamed to \"%s\"."), $original_name, $tasklist->get('name')), 'horde.success');
40        } else {
41            $notification->push(sprintf(_("The task list \"%s\" has been saved."), $original_name), 'horde.success');
42        }
43        Horde::url('list.php', true)->redirect();
44    } catch (Exception $e) {
45        $notification->push($e);
46    }
47}
48
49$vars->set('name', $tasklist->get('name'));
50$vars->set('color', $tasklist->get('color'));
51$vars->set('system', is_null($tasklist->get('owner')));
52$vars->set('description', $tasklist->get('desc'));
53
54$page_output->header(array(
55    'title' => $form->getTitle()
56));
57Nag::status();
58if ($owner) {
59    echo $form->renderActive($form->getRenderer(), $vars,
60                             Horde::url('tasklists/edit.php'), 'post');
61} else {
62    echo $form->renderInactive($form->getRenderer(), $vars);
63}
64$page_output->footer();
65