Add management interfaces for system calendars (Request #2059).
authorJan Schneider <jan@horde.org>
Fri, 18 Dec 2009 14:11:44 +0000 (15:11 +0100)
committerJan Schneider <jan@horde.org>
Fri, 18 Dec 2009 14:40:33 +0000 (15:40 +0100)
16 files changed:
kronolith/calendars/delete.php
kronolith/calendars/edit.php
kronolith/calendars/index.php
kronolith/docs/CHANGES
kronolith/lib/Forms/CreateCalendar.php
kronolith/lib/Forms/EditCalendar.php
kronolith/lib/Kronolith.php
kronolith/templates/calendar_list.php
nag/docs/CHANGES
nag/lib/Forms/CreateTaskList.php
nag/lib/Forms/EditTaskList.php
nag/lib/Nag.php
nag/tasklists/delete.php
nag/tasklists/edit.php
nag/tasklists/index.php
nag/templates/tasklist_list.php

index 5310e41..5569c5f 100644 (file)
@@ -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;
index 1cad577..79dea14 100644 (file)
@@ -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';
index 2c14417..b7d7f9a 100644 (file)
@@ -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;
index 5684634..ccb4c35 100644 (file)
@@ -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
       <mail@goncaloqueiros.net>).
 [mjr] Extend listTimeObjects API to include optional links and icons.
index 7a71c52..5bf4f35 100755 (executable)
@@ -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);
index a4673b2..3752679 100644 (file)
@@ -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);
index 28b1fe5..6ab5d63 100644 (file)
@@ -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')) {
index f28bc76..5ce0a35 100644 (file)
@@ -44,7 +44,7 @@
    <td><?php echo $remote_unsubscribe_url_base->add('url', $calendar['url'])->link(array('title' => _("Unsubscribe"))) . $delete_img . '</a>' ?></td>
 <?php else: ?>
    <td><?php echo htmlspecialchars($calendar->get('name')) ?></td>
-   <td><?php echo _("Local") ?></td>
+   <td><?php echo is_null($calendar->get('owner')) ? _("System") : _("Local") ?></td>
    <td><?php $url = $display_url_base->add('display_cal', $calendar->getName()); echo $url->link(array('title' => _("Click or copy this URL to display this calendar"))) . htmlspecialchars(shorten_url($url)) . '</a>' ?></td>
    <td><?php $url = new Horde_Url($subscribe_url_base . ($calendar->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)) . '</a>' ?></td>
    <td><?php echo $edit_url_base->add('c', $calendar->getName())->link(array('title' => _("Edit"))) . $edit_img . '</a>' ?></td>
index 1a1ef2d..77c6293 100644 (file)
@@ -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
index f931199..2f3302c 100644 (file)
@@ -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);
index e69e899..a4b88d0 100644 (file)
@@ -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);
index b8ac49c..e9b27f4 100644 (file)
@@ -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."));
         }
 
index 9345e1c..318c1b6 100644 (file)
@@ -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).
index 72cdc75..cd6aba7 100644 (file)
@@ -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';
index 8a76830..1012942 100644 (file)
@@ -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'));
index d8c9610..69d1d79 100644 (file)
@@ -15,6 +15,7 @@
  <thead>
   <tr>
    <th class="sortdown"><?php echo _("Task List") ?></th>
+   <th><?php echo _("Kind") ?></th>
    <th class="tasklist-list-url nosort"><?php echo _("Display URL") ?></th>
    <th class="tasklist-list-url nosort"><?php echo _("Subscription URL") ?></th>
    <th class="tasklist-list-icon nosort" colspan="<?php echo empty($conf['share']['no_sharing']) ? 3 : 2 ?>">&nbsp;</th>
@@ -26,6 +27,7 @@
  <?php $tasklist = $tasklists[$tasklist_id] ?>
   <tr>
    <td><?php echo htmlspecialchars($tasklist->get('name')) ?></td>
+   <td><?php echo is_null($tasklist->get('owner')) ? _("System") : _("Local") ?></td>
    <td><?php $url = Horde_Util::addParameter($display_url_base, 'display_cal', $tasklist->getName(), false); echo Horde::link($url, _("Click or copy this URL to display this task list"), '', '_blank') . htmlspecialchars(shorten_url($url)) . '</a>' ?></td>
    <td><?php $url = $subscribe_url_base . ($tasklist->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)) . '</a>' ?></td>
    <td><?php echo Horde::link(Horde_Util::addParameter($edit_url_base, 't', $tasklist->getName()), _("Edit")) . $edit_img . '</a>' ?></td>