From 2b9bd293a17ec16d3c432143900e3e16061431f9 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 18 Dec 2009 15:11:44 +0100 Subject: [PATCH] Add management interfaces for system calendars (Request #2059). --- kronolith/calendars/delete.php | 3 ++- kronolith/calendars/edit.php | 4 +++- kronolith/calendars/index.php | 7 +++++++ kronolith/docs/CHANGES | 3 ++- kronolith/lib/Forms/CreateCalendar.php | 5 ++++- kronolith/lib/Forms/EditCalendar.php | 6 +++++- kronolith/lib/Kronolith.php | 18 ++++++++++++------ kronolith/templates/calendar_list.php | 2 +- nag/docs/CHANGES | 1 + nag/lib/Forms/CreateTaskList.php | 5 ++++- nag/lib/Forms/EditTaskList.php | 5 ++++- nag/lib/Nag.php | 10 ++++++++-- nag/tasklists/delete.php | 14 +++++++++++++- nag/tasklists/edit.php | 6 ++++++ nag/tasklists/index.php | 7 +++++++ nag/templates/tasklist_list.php | 2 ++ 16 files changed, 81 insertions(+), 17 deletions(-) diff --git a/kronolith/calendars/delete.php b/kronolith/calendars/delete.php index 5310e4109..5569c5f0d 100644 --- a/kronolith/calendars/delete.php +++ b/kronolith/calendars/delete.php @@ -29,7 +29,8 @@ if (is_a($calendar, 'PEAR_Error')) { $notification->push($calendar, 'horde.error'); header('Location: ' . Horde::applicationUrl('calendars/', true)); exit; -} elseif ($calendar->get('owner') != Horde_Auth::getAuth()) { +} elseif ($calendar->get('owner') != Horde_Auth::getAuth() && + (!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin())) { $notification->push(_("You are not allowed to delete this calendar."), 'horde.error'); header('Location: ' . Horde::applicationUrl('calendars/', true)); exit; diff --git a/kronolith/calendars/edit.php b/kronolith/calendars/edit.php index 1cad577b9..79dea1472 100644 --- a/kronolith/calendars/edit.php +++ b/kronolith/calendars/edit.php @@ -23,7 +23,8 @@ if (is_a($calendar, 'PEAR_Error')) { $notification->push($calendar, 'horde.error'); header('Location: ' . Horde::applicationUrl('calendars/', true)); exit; -} elseif ($calendar->get('owner') != Horde_Auth::getAuth()) { +} elseif ($calendar->get('owner') != Horde_Auth::getAuth() && + (!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin())) { $notification->push(_("You are not allowed to change this calendar."), 'horde.error'); header('Location: ' . Horde::applicationUrl('calendars/', true)); exit; @@ -53,6 +54,7 @@ $vars->set('color', $calendar->get('color')); $vars->set('description', $calendar->get('desc')); $tagger = Kronolith::getTagger(); $vars->set('tags', implode(',', array_values($tagger->getTags($calendar->getName(), 'calendar')))); +$vars->set('system', is_null($calendar->get('owner'))); $title = $form->getTitle(); require KRONOLITH_TEMPLATES . '/common-header.inc'; require KRONOLITH_TEMPLATES . '/menu.inc'; diff --git a/kronolith/calendars/index.php b/kronolith/calendars/index.php index 2c14417e5..b7d7f9a51 100644 --- a/kronolith/calendars/index.php +++ b/kronolith/calendars/index.php @@ -50,6 +50,13 @@ foreach ($my_calendars as $calendar) { $calendars[$calendar->getName()] = $calendar; $sorted_calendars[$calendar->getName()] = $calendar->get('name'); } +if (Horde_Auth::isAdmin()) { + $system_calendars = $kronolith_shares->listSystemShares(); + foreach ($system_calendars as $calendar) { + $calendars[$calendar->getName()] = $calendar; + $sorted_calendars[$calendar->getName()] = $calendar->get('name'); + } +} $remote_calendars = unserialize($prefs->getValue('remote_cals')); foreach ($remote_calendars as $calendar) { $calendars[$calendar['url']] = $calendar; diff --git a/kronolith/docs/CHANGES b/kronolith/docs/CHANGES index 56846344a..ccb4c3592 100644 --- a/kronolith/docs/CHANGES +++ b/kronolith/docs/CHANGES @@ -2,10 +2,11 @@ v3.0-git -------- +[jan] Add system calendars (Request #2059). [jan] Add URL field to events. [jan] Add task management capabilities to the Ajax interface. [jan] Manage holidays like any other calendar driver. -[mjr] Add support for resource scheduling. +[mjr] Add resource scheduling. [jan] Integrate tasks into Ajax interface (Gonçalo Queirós ). [mjr] Extend listTimeObjects API to include optional links and icons. diff --git a/kronolith/lib/Forms/CreateCalendar.php b/kronolith/lib/Forms/CreateCalendar.php index 7a71c5220..5bf4f352b 100755 --- a/kronolith/lib/Forms/CreateCalendar.php +++ b/kronolith/lib/Forms/CreateCalendar.php @@ -31,6 +31,9 @@ class Kronolith_CreateCalendarForm extends Horde_Form { $this->addVariable(_("Color"), 'color', 'colorpicker', false); $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60)); $this->addVariable(_("Tags"), 'tags', 'text', false); + if (Horde_Auth::isAdmin()) { + $this->addVariable(_("System Calendar"), 'system', 'boolean', false, false, _("System calendars don't have an owner. Only administrators can change the calendar settings and permissions.")); + } $this->setButtons(array(_("Create"))); } @@ -38,7 +41,7 @@ class Kronolith_CreateCalendarForm extends Horde_Form { function execute() { $info = array(); - foreach (array('name', 'color', 'description', 'tags') as $key) { + foreach (array('name', 'color', 'description', 'tags', 'system') as $key) { $info[$key] = $this->_vars->get($key); } return Kronolith::addShare($info); diff --git a/kronolith/lib/Forms/EditCalendar.php b/kronolith/lib/Forms/EditCalendar.php index a4673b24e..37526799c 100644 --- a/kronolith/lib/Forms/EditCalendar.php +++ b/kronolith/lib/Forms/EditCalendar.php @@ -38,13 +38,17 @@ class Kronolith_EditCalendarForm extends Horde_Form { $this->addVariable(_("Color"), 'color', 'colorpicker', false); $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60)); $this->addVariable(_("Tags"), 'tags', 'text', false); + if (Horde_Auth::isAdmin()) { + $this->addVariable(_("System Calendar"), 'system', 'boolean', false, false, _("System calendars don't have an owner. Only administrators can change the calendar settings and permissions.")); + } + $this->setButtons(array(_("Save"))); } function execute() { $info = array(); - foreach (array('name', 'color', 'description', 'tags') as $key) { + foreach (array('name', 'color', 'description', 'tags', 'system') as $key) { $info[$key] = $this->_vars->get($key); } return Kronolith::updateShare($this->_calendar, $info); diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 28b1fe548..6ab5d636e 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -1376,6 +1376,9 @@ class Kronolith $calendar->set('name', $info['name']); $calendar->set('color', $info['color']); $calendar->set('desc', $info['description']); + if (!empty($info['system'])) { + $calendar->set('owner', null); + } $tagger = self::getTagger(); $tagger->tag($calendar->getName(), $info['tags'], 'calendar'); @@ -1399,7 +1402,8 @@ class Kronolith public static function updateShare(&$calendar, $info) { if (!Horde_Auth::getAuth() || - $calendar->get('owner') != Horde_Auth::getAuth()) { + ($calendar->get('owner') != Horde_Auth::getAuth() && + (!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin()))) { return PEAR::raiseError(_("You are not allowed to change this calendar.")); } @@ -1407,6 +1411,7 @@ class Kronolith $calendar->set('name', $info['name']); $calendar->set('color', $info['color']); $calendar->set('desc', $info['description']); + $calendar->set('owner', empty($info['system']) ? Horde_Auth::getAuth() : null); if ($original_name != $info['name']) { $result = Kronolith::getDriver()->rename($original_name, $info['name']); if (is_a($result, 'PEAR_Error')) { @@ -1430,15 +1435,16 @@ class Kronolith */ public static function deleteShare($calendar) { - if (!Horde_Auth::getAuth() || - $calendar->get('owner') != Horde_Auth::getAuth()) { - return PEAR::raiseError(_("You are not allowed to delete this calendar.")); - } - if ($calendar->getName() == Horde_Auth::getAuth()) { return PEAR::raiseError(_("This calendar cannot be deleted.")); } + if (!Horde_Auth::getAuth() || + ($calendar->get('owner') != Horde_Auth::getAuth() && + (!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin()))) { + return PEAR::raiseError(_("You are not allowed to delete this calendar.")); + } + // Delete the calendar. $result = Kronolith::getDriver()->delete($calendar->getName()); if (is_a($result, 'PEAR_Error')) { diff --git a/kronolith/templates/calendar_list.php b/kronolith/templates/calendar_list.php index f28bc76aa..5ce0a35e4 100644 --- a/kronolith/templates/calendar_list.php +++ b/kronolith/templates/calendar_list.php @@ -44,7 +44,7 @@ add('url', $calendar['url'])->link(array('title' => _("Unsubscribe"))) . $delete_img . '' ?> get('name')) ?> - + get('owner')) ? _("System") : _("Local") ?> add('display_cal', $calendar->getName()); echo $url->link(array('title' => _("Click or copy this URL to display this calendar"))) . htmlspecialchars(shorten_url($url)) . '' ?> get('owner') ? $calendar->get('owner') : '-system-') . '/' . $calendar->getName() . '.ics'); echo $url->link(array('title' => _("Click or copy this URL to display this calendar"), 'target' => '_blank')) . htmlspecialchars(shorten_url($url)) . '' ?> add('c', $calendar->getName())->link(array('title' => _("Edit"))) . $edit_img . '' ?> diff --git a/nag/docs/CHANGES b/nag/docs/CHANGES index 1a1ef2d6e..77c6293cb 100644 --- a/nag/docs/CHANGES +++ b/nag/docs/CHANGES @@ -2,6 +2,7 @@ v3.0-git -------- +[jan] Add system task lists (Request #2059). [jan] Set colors per task list (Request #7480). [cjh] Quick Add support: there is a javascript UI element for quickly adding tasks, and an API method (tasks/quickAdd) that provides the same diff --git a/nag/lib/Forms/CreateTaskList.php b/nag/lib/Forms/CreateTaskList.php index f9311992a..2f3302ca4 100644 --- a/nag/lib/Forms/CreateTaskList.php +++ b/nag/lib/Forms/CreateTaskList.php @@ -30,6 +30,9 @@ class Nag_CreateTaskListForm extends Horde_Form { $this->addVariable(_("Name"), 'name', 'text', true); $this->addVariable(_("Color"), 'color', 'colorpicker', false); $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60)); + if (Horde_Auth::isAdmin()) { + $this->addVariable(_("System Task List"), 'system', 'boolean', false, false, _("System task lists don't have an owner. Only administrators can change the task list settings and permissions.")); + } $this->setButtons(array(_("Create"))); } @@ -37,7 +40,7 @@ class Nag_CreateTaskListForm extends Horde_Form { function execute() { $info = array(); - foreach (array('name', 'color', 'description') as $key) { + foreach (array('name', 'color', 'description', 'system') as $key) { $info[$key] = $this->_vars->get($key); } return Nag::addTasklist($info); diff --git a/nag/lib/Forms/EditTaskList.php b/nag/lib/Forms/EditTaskList.php index e69e899d2..a4b88d068 100644 --- a/nag/lib/Forms/EditTaskList.php +++ b/nag/lib/Forms/EditTaskList.php @@ -36,6 +36,9 @@ class Nag_EditTaskListForm extends Horde_Form { $this->addHidden('', 't', 'text', true); $this->addVariable(_("Task List Name"), 'name', 'text', true); $this->addVariable(_("Task List Description"), 'description', 'longtext', false, false, null, array(4, 60)); + if (Horde_Auth::isAdmin()) { + $this->addVariable(_("System Task List"), 'system', 'boolean', false, false, _("System task lists don't have an owner. Only administrators can change the task list settings and permissions.")); + } $this->setButtons(array(_("Save"))); } @@ -43,7 +46,7 @@ class Nag_EditTaskListForm extends Horde_Form { function execute() { $info = array(); - foreach (array('name', 'color', 'description') as $key) { + foreach (array('name', 'color', 'description', 'system') as $key) { $info[$key] = $this->_vars->get($key); } return Nag::updateTasklist($this->_tasklist, $info); diff --git a/nag/lib/Nag.php b/nag/lib/Nag.php index b8ac49cee..e9b27f493 100644 --- a/nag/lib/Nag.php +++ b/nag/lib/Nag.php @@ -442,6 +442,9 @@ class Nag $tasklist->set('name', $info['name']); $tasklist->set('color', $info['color']); $tasklist->set('desc', $info['description']); + if (!empty($info['system'])) { + $tasklist->set('owner', null); + } $result = $GLOBALS['nag_shares']->addShare($tasklist); if (is_a($result, 'PEAR_Error')) { @@ -463,13 +466,15 @@ class Nag public static function updateTasklist(&$tasklist, $info) { if (!Horde_Auth::getAuth() || - $tasklist->get('owner') != Horde_Auth::getAuth()) { + ($tasklist->get('owner') != Horde_Auth::getAuth() && + (!is_null($tasklist->get('owner')) || !Horde_Auth::isAdmin()))) { return PEAR::raiseError(_("You are not allowed to change this task list.")); } $tasklist->set('name', $info['name']); $tasklist->set('color', $info['color']); $tasklist->set('desc', $info['description']); + $tasklist->set('owner', empty($info['system']) ? Horde_Auth::getAuth() : null); $result = $tasklist->save(); if (is_a($result, 'PEAR_Error')) { return PEAR::raiseError(sprintf(_("Unable to save task list \"%s\": %s"), $info['name'], $result->getMessage())); @@ -488,7 +493,8 @@ class Nag } if (!Horde_Auth::getAuth() || - $tasklist->get('owner') != Horde_Auth::getAuth()) { + ($tasklist->get('owner') != Horde_Auth::getAuth() && + (!is_null($tasklist->get('owner')) || !Horde_Auth::isAdmin()))) { return PEAR::raiseError(_("You are not allowed to delete this task list.")); } diff --git a/nag/tasklists/delete.php b/nag/tasklists/delete.php index 9345e1c4a..318c1b6c5 100644 --- a/nag/tasklists/delete.php +++ b/nag/tasklists/delete.php @@ -16,12 +16,24 @@ if (!Horde_Auth::getAuth()) { } $vars = Horde_Variables::getDefaultVariables(); -$tasklist = $nag_shares->getShare($vars->get('t')); +$tasklist_id = $vars->get('t'); +if ($tasklist_id == Horde_Auth::getAuth()) { + $notification->push(_("This task list cannot be deleted."), 'horde.warning'); + header('Location: ' . Horde::applicationUrl('tasklists/', true)); + exit; +} +$tasklist = $nag_shares->getShare($tasklist_id); if (is_a($tasklist, 'PEAR_Error')) { $notification->push($tasklist, 'horde.error'); header('Location: ' . Horde::applicationUrl('tasklists/', true)); exit; +} elseif ($tasklist->get('owner') != Horde_Auth::getAuth() && + (!is_null($tasklist->get('owner')) || !Horde_Auth::isAdmin())) { + $notification->push(_("You are not allowed to delete this task list."), 'horde.error'); + header('Location: ' . Horde::applicationUrl('tasklists/', true)); + exit; } + $form = new Nag_DeleteTaskListForm($vars, $tasklist); // Execute if the form is valid (must pass with POST variables only). diff --git a/nag/tasklists/edit.php b/nag/tasklists/edit.php index 72cdc75c6..cd6aba7a5 100644 --- a/nag/tasklists/edit.php +++ b/nag/tasklists/edit.php @@ -21,6 +21,11 @@ if (is_a($tasklist, 'PEAR_Error')) { $notification->push($tasklist, 'horde.error'); header('Location: ' . Horde::applicationUrl('tasklists/', true)); exit; +} elseif ($tasklist->get('owner') != Horde_Auth::getAuth() && + (!is_null($tasklist->get('owner')) || !Horde_Auth::isAdmin())) { + $notification->push(_("You are not allowed to change this task list."), 'horde.error'); + header('Location: ' . Horde::applicationUrl('tasklists/', true)); + exit; } $form = new Nag_EditTaskListForm($vars, $tasklist); @@ -44,6 +49,7 @@ if ($form->validate($vars)) { $vars->set('name', $tasklist->get('name')); $vars->set('description', $tasklist->get('desc')); +$vars->set('system', is_null($tasklist->get('owner'))); $title = $form->getTitle(); require NAG_TEMPLATES . '/common-header.inc'; require NAG_TEMPLATES . '/menu.inc'; diff --git a/nag/tasklists/index.php b/nag/tasklists/index.php index 8a768301b..101294258 100644 --- a/nag/tasklists/index.php +++ b/nag/tasklists/index.php @@ -46,6 +46,13 @@ $sorted_tasklists = array(); foreach ($tasklists as $tasklist) { $sorted_tasklists[$tasklist->getName()] = $tasklist->get('name'); } +if (Horde_Auth::isAdmin()) { + $system_tasklists = $nag_shares->listSystemShares(); + foreach ($system_tasklists as $tasklist) { + $tasklists[$tasklist->getName()] = $tasklist; + $sorted_tasklists[$tasklist->getName()] = $tasklist->get('name'); + } +} asort($sorted_tasklists); $edit_img = Horde::img('edit.png', _("Edit"), null, $registry->getImageDir('horde')); diff --git a/nag/templates/tasklist_list.php b/nag/templates/tasklist_list.php index d8c96100f..69d1d791f 100644 --- a/nag/templates/tasklist_list.php +++ b/nag/templates/tasklist_list.php @@ -15,6 +15,7 @@ +   @@ -26,6 +27,7 @@ get('name')) ?> + get('owner')) ? _("System") : _("Local") ?> getName(), false); echo Horde::link($url, _("Click or copy this URL to display this task list"), '', '_blank') . htmlspecialchars(shorten_url($url)) . '' ?> get('owner') ? $tasklist->get('owner') : '-system-') . '/' . $tasklist->getName() . '.ics'; echo Horde::link($url, _("Click or copy this URL to display this task list"), '', '_blank') . htmlspecialchars(shorten_url($url)) . '' ?> getName()), _("Edit")) . $edit_img . '' ?> -- 2.11.0