Lots of stuff:
authorMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 11 Sep 2009 19:09:15 +0000 (15:09 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 29 Sep 2009 20:53:54 +0000 (16:53 -0400)
- Move resource viewing/CRUD related pages to resources/*
- Have Kronolith_Resource objects present a Horde_Share_Object-like interface
- Remove the Resource link from the menu - put it in the panel under the "Manage My Calendars" link
- Various tweaks/corrections

19 files changed:
kronolith/attendees.php
kronolith/lib/Driver/Resource.php
kronolith/lib/Event.php
kronolith/lib/Forms/CreateResource.php [new file with mode: 0644]
kronolith/lib/Forms/DeleteResource.php [new file with mode: 0644]
kronolith/lib/Forms/EditResource.php [new file with mode: 0644]
kronolith/lib/Kronolith.php
kronolith/lib/Resource/Base.php
kronolith/lib/Resource/Single.php
kronolith/resources.php [deleted file]
kronolith/resources/create.php [new file with mode: 0644]
kronolith/resources/delete.php [new file with mode: 0644]
kronolith/resources/edit.php [new file with mode: 0644]
kronolith/resources/index.php [new file with mode: 0644]
kronolith/templates/attendees/attendees.inc
kronolith/templates/calendar_list.php
kronolith/templates/calendar_titles.inc
kronolith/templates/edit/edit.inc
kronolith/templates/panel.inc

index edd990f..d0fce0d 100644 (file)
@@ -108,7 +108,7 @@ case 'add':
         $resources[$newResource] = array(
             'attendance' => Kronolith::PART_IGNORE,
             'response'   => Kronolith::RESPONSE_NONE,
-            'name'       => $resource->name,
+            'name'       => $resource->get('name'),
         );
 
         $_SESSION['kronolith']['resources'] = $resources;
index 5034dac..6a8f50d 100644 (file)
@@ -359,9 +359,9 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql
      */
     public function save($resource)
     {
-        if ($resource->id) {
+        if ($resource->getId()) {
             $query = 'UPDATE kronolith_resources SET resource_name = ?, resource_calendar = ?, resource_category = ? WHERE resource_id = ?';
-            $values = array($resource->name, $resource->calendar, $resource->category, $resource->id);
+            $values = array($resource->get('name'), $resource->get('calendar'), $resource->get('category'), $resource->getId());
             $result = $this->_write_db->query($query, $values);
             if ($result instanceof PEAR_Error) {
                 throw new Horde_Exception($result->getMessage());
@@ -370,7 +370,7 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql
             $query = 'INSERT INTO kronolith_resources (resource_id, resource_name, resource_calendar, resource_category)';
             $cols_values = ' VALUES (?, ?, ?, ?)';
             $id = $this->_db->nextId('kronolity_resources');
-            $values = array($id, $resource->name, $resource->calendar, $resource->category);
+            $values = array($id, $resource->get('name'), $resource->get('calendar'), $resource->get('category'));
             $result = $this->_write_db->query($query . $cols_values, $values);
             if (!($result instanceof PEAR_Error)) {
                 return true;
@@ -391,18 +391,18 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql
      */
     public function delete($resource)
     {
-        if (!$resource->calendar || !$resource->id) {
+        if (!$resource->get('calendar') || !$resource->getId()) {
             var_dump($resource);
             throw new Horde_Exception(_("Resource not valid."));
         }
 
         $query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE calendar_id = ?';
-        $result = $this->_write_db->query($query, array($resource->calendar));
+        $result = $this->_write_db->query($query, array($resource->get('calendar')));
         if ($result instanceof PEAR_Error) {
             throw new Horde_Exception($result->getMessage());
         }
         $query = 'DELETE FROM kronolith_resources WHERE resource_id = ?';
-        $result = $this->_write_db->query($query, array($resource->id));
+        $result = $this->_write_db->query($query, array($resource->getId()));
         if ($result instanceof PEAR_Error) {
             throw new Horde_Exception($result->getMessage());
         }
index 6ed3a61..b6094a6 100644 (file)
@@ -1552,10 +1552,10 @@ abstract class Kronolith_Event
      */
     public function addResource($resource, $response)
     {
-        $this->_resources[$resource->id] = array(
+        $this->_resources[$resource->getId()] = array(
             'attendance' => Kronolith::PART_REQUIRED,
             'response' => $response,
-            'name' => $resource->name
+            'name' => $resource->get('name')
         );
     }
 
diff --git a/kronolith/lib/Forms/CreateResource.php b/kronolith/lib/Forms/CreateResource.php
new file mode 100644 (file)
index 0000000..0e15600
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Horde_Form for creating resource calendars.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Kronolith
+ */
+
+/** Horde_Form */
+require_once 'Horde/Form.php';
+
+/** Horde_Form_Renderer */
+require_once 'Horde/Form/Renderer.php';
+
+/**
+ * The Kronolith_CreateResourceForm class provides the form for
+ * creating a calendar.
+ *
+ * @author  Chuck Hagenbuch <chuck@horde.org>
+ * @author  Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Kronolith
+ */
+class Kronolith_CreateResourceForm extends Horde_Form {
+
+    function Kronolith_CreateResourceForm(&$vars)
+    {
+        parent::Horde_Form($vars, _("Create Resource"));
+
+        $this->addVariable(_("Name"), 'name', 'text', true);
+        $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
+        $this->addVariable(_("Category"), 'category', 'text', false);
+        $this->setButtons(array(_("Create")));
+    }
+
+    function execute()
+    {
+        $new = array('name' => $this->_vars->get('name'),
+                     'category' =>$this->_vars->get('category'));
+
+        $resource = new Kronolith_Resource_Single($new);
+        return $results = Kronolith::addResource($resource);
+    }
+
+}
diff --git a/kronolith/lib/Forms/DeleteResource.php b/kronolith/lib/Forms/DeleteResource.php
new file mode 100644 (file)
index 0000000..6754697
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+/**
+ * Horde_Form for deleting calendars.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Kronolith
+ */
+
+/** Horde_Form */
+require_once 'Horde/Form.php';
+
+/** Horde_Form_Renderer */
+require_once 'Horde/Form/Renderer.php';
+
+/**
+ * The Kronolith_DeleteCalendarForm class provides the form for
+ * deleting a calendar.
+ *
+ * @author  Chuck Hagenbuch <chuck@horde.org>
+ * @package Kronolith
+ */
+class Kronolith_DeleteResourceForm extends Horde_Form {
+
+    /**
+     * Calendar being deleted
+     */
+    var $_calendar;
+
+    function Kronolith_DeleteResourceForm(&$vars, &$resource)
+    {
+        $this->_resource = &$resource;
+        parent::Horde_Form($vars, sprintf(_("Delete %s"), $resource->get('name')));
+
+        $this->addHidden('', 'c', 'text', true);
+        $this->addVariable(sprintf(_("Really delete the resource \"%s\"? This cannot be undone and all data on this resource will be permanently removed."), $this->_resource->get('name')), 'desc', 'description', false);
+
+        $this->setButtons(array(_("Delete"), _("Cancel")));
+    }
+
+    function execute()
+    {
+        // If cancel was clicked, return false.
+        if ($this->_vars->get('submitbutton') == _("Cancel")) {
+            return false;
+        }
+
+        if (!($this->_resource->hasPermission(Horde_Auth::getAuth(), PERMS_DELETE))) {
+            return PEAR::raiseError(_("Permission denied"));
+        }
+
+        // Delete the resource.
+        $result = Kronolith::getDriver('Resource')->delete($this->_resource);
+        if ($result instanceof PEAR_Error) {
+            return PEAR::raiseError(sprintf(_("Unable to delete \"%s\": %s"), $this->_resource->get('name'), $result->getMessage()));
+        }
+
+        return true;
+    }
+
+}
diff --git a/kronolith/lib/Forms/EditResource.php b/kronolith/lib/Forms/EditResource.php
new file mode 100644 (file)
index 0000000..4ca875f
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+/**
+ * Horde_Form for editing resource calendars.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Kronolith
+ */
+
+/** Horde_Form */
+require_once 'Horde/Form.php';
+
+/** Horde_Form_Renderer */
+require_once 'Horde/Form/Renderer.php';
+
+/**
+ * The Kronolith_EditResourceForm class provides the form for
+ * editing a calendar.
+ *
+ * @author  Chuck Hagenbuch <chuck@horde.org>
+ * @package Kronolith
+ */
+class Kronolith_EditResourceForm extends Horde_Form {
+
+    /**
+     * Calendar being edited
+     */
+    var $_resource;
+
+    function Kronolith_EditResourceForm(&$vars, &$resource)
+    {
+        $this->_resource = &$resource;
+        parent::Horde_Form($vars, sprintf(_("Edit %s"), $resource->get('name')));
+
+        $this->addHidden('', 'c', 'text', true);
+        $this->addVariable(_("Name"), 'name', 'text', true);
+        $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
+        $this->addVariable(_("Category"), 'category', 'text', false);
+        $this->setButtons(array(_("Save")));
+    }
+
+    function execute()
+    {
+        $original_name = $this->_resource->get('name');
+        $new_name = $this->_vars->get('name');
+        $this->_resource->set('name', $new_name);
+        $this->_resource->set('description', $this->_vars->get('description'));
+        $this->_resource->set('category', $this->_vars->get('category'));
+        if ($original_name != $new_name) {
+            $result = Kronolith::getDriver()->rename($original_name, $new_name);
+            if (is_a($result, 'PEAR_Error')) {
+                return PEAR::raiseError(sprintf(_("Unable to rename \"%s\": %s"), $original_name, $result->getMessage()));
+            }
+        }
+
+        $result = $this->_resource->save();
+        if (is_a($result, 'PEAR_Error')) {
+            return PEAR::raiseError(sprintf(_("Unable to save resource \"%s\": %s"), $new_name, $result->getMessage()));
+        }
+
+        return $this->_resource;
+
+    }
+
+}
index af832c7..539524b 100644 (file)
@@ -1548,7 +1548,7 @@ class Kronolith
         foreach ($event->getResources() as $id => $resource) {
             if ($resource['response'] == Kronolith::RESPONSE_DECLINED) {
                 $r = Kronolith::getDriver('Resource')->getResource($id);
-                $declined[] = $r->name;
+                $declined[] = $r->get('name');
             }
         }
         if (count($declined)) {
@@ -2008,9 +2008,6 @@ class Kronolith
             $menu->add(Horde::applicationUrl('data.php'), _("_Import/Export"), 'data.png', $registry->getImageDir('horde'));
         }
 
-        /* Resources */
-        $menu->add(Horde::applicationUrl('resources.php'), _("Resources"), 'resource.png');
-
         return $menu;
     }
 
@@ -2047,7 +2044,7 @@ class Kronolith
     {
         // Create a new calendar id.
         $calendar = 'resource_' . hash('md5', microtime());
-        $resource->calendar = $calendar;
+        $resource->set('calendar', $calendar);
         $driver = Kronolith::getDriver('Resource');
 
         return $driver->save($resource);
index e3a4b24..0e6661c 100644 (file)
@@ -1,13 +1,39 @@
 <?php
 /**
- * Kronolith resources
+ * Base class for Kronolith resources. Partially presents a Horde_Share_Object
+ * interface.
+ *
  *
  */
 abstract class Kronolith_Resource_Base
 {
+    /**
+     * Instance copy of parameters
+     *
+     *   name        - Display name of resource.
+     *   calendar    - The calendar associated with this resource.
+     *   category    - The category of this resource...an arbitrary label used
+     *                 to group multiple resources for the resource_group implementation
+     *   description -
+     *
+     * @var array
+     */
     protected $_params = array();
+
+    /**
+     * Resource's internal id
+     *
+     * @var integer
+     */
     protected $_id = '';
 
+    /**
+     * Const'r
+     *
+     * @param array $params
+     *
+     * @return Kronolith_Resource object
+     */
     public function __construct($params = array())
     {
         if (!empty($params['id'])) {
@@ -15,41 +41,39 @@ abstract class Kronolith_Resource_Base
             $this->_id = $params['id'];
         }
 
+        array_merge($params, array('description' => '',
+                                   'category' => ''));
         $this->_params = $params;
     }
 
     /**
+     * Obtain the resource's internal id.
      *
-     *  Properties:
-     * name        - Display name of resource.
-     * calendar    - The calendar associated with this resource.
-     * category    - The category of this resource...an arbitrary label used
-     *               to group multiple resources for the resource_group implementation
-     * properties  - any other properties this resource may have?
-     *               (max capacity of room, size of TV, whatever...)
-     *               probably just for display, not sure how this would work
-     *               if we wanted to be able to search since we are implementing these generically.
-     *               Don't think we want a datatree-style attirbutes table for this.
+     * @return integer  The id.
      */
-    public function __get($property)
+    public function getId()
     {
-        if ($property == 'id') {
-            return $this->_id;
-        }
+        return $this->_id;
+    }
 
-        $property = str_replace('resource_', '', $property);
-        if (isset($this->_params[$property])) {
-            return $this->_params[$property];
-        } else {
-            throw new Horde_Exception(sprintf(_("Invalid property, %s, requested in Kronolith_Resource"), $property));
+    /**
+     * Allow setting of the name and category properties.
+     *
+     * @param string $property  The property to set
+     * @param mixed $value      The value to set to
+     *
+     * @return void
+     */
+    public function set($property, $value)
+    {
+        if (in_array($property, array('name', 'category', 'calendar'))) {
+            $this->_params[$property] = $value;
         }
     }
 
     /**
      * @TODO: need to fine tune this
      *
-     *
-     *
      * @param $user
      * @param $permission
      * @param $restrict
@@ -72,13 +96,36 @@ abstract class Kronolith_Resource_Base
      */
     public function get($property)
     {
-       return $this->{$property};
+       $property = str_replace('resource_', '', $property);
+       return !empty($this->_params[$property]) ? $this->_params[$property] : false;
     }
 
+    /**
+     * Save resource to storage.
+     */
+    public function save()
+    {
+        $d = $this->getDriver();
+        return $d->save($this);
+    }
 
+    /**
+     * Get a storage driver instance for the resource. For now, just instantiate
+     * it here, in future, probably inject it in the const'r.
+     *
+     * @return Kronolith_Driver_Resource
+     */
+    public function getDriver()
+    {
+        if (!$this->get('calendar')) {
+            return Kronolith::getDriver('Resource');
+        } else {
+            return Kronolith::getDriver('Resource', $this->get('calendar'));
+        }
+    }
 
     /**
-     * Should this take an event, or a time range?
+     * Determine if event is free for specified time
      *
      * @param $startTime
      * @param $endTime
index d0a15fb..c8e1818 100644 (file)
@@ -23,7 +23,7 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base
     public function isFree($event)
     {
         /* Fetch events. */
-        $busy = Kronolith::listEvents($event->start, $event->end, array($this->calendar));
+        $busy = Kronolith::listEvents($event->start, $event->end, array($this->get('calendar')));
         if ($busy instanceof PEAR_Error) {
             throw new Horde_Exception($busy->getMessage());
         }
@@ -64,11 +64,11 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base
     public function addEvent($event)
     {
         /* Get a driver for this resource's calendar */
-        $driver = Kronolith::getDriver('Resource', $this->calendar);
+        $driver = Kronolith::getDriver('Resource', $this->get('calendar'));
 
         /* Make sure it's not already attached. */
         $uid = $event->getUID();
-        $existing = $driver->getByUID($uid, array($this->calendar));
+        $existing = $driver->getByUID($uid, array($this->get('calendar')));
         if (!($existing instanceof PEAR_Error)) {
             /* Already attached, just update */
             $existing->fromiCalendar($event->toiCalendar(new Horde_iCalendar('2.0')));
@@ -77,7 +77,7 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base
         } else {
             /* Create a new event */
             $e = $driver->getEvent();
-            $e->setCalendar($this->calendar);
+            $e->setCalendar($this->get('calendar'));
             $e->fromiCalendar($event->toiCalendar(new Horde_iCalendar('2.0')));
             $e->save();
         }
@@ -91,8 +91,8 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base
      */
     public function removeEvent($event)
     {
-        $driver = Kronolith::getDriver('Resource', $this->calendar);
-        $re = $driver->getByUID($event->getUID(), array($this->calendar));
+        $driver = Kronolith::getDriver('Resource', $this->get('calendar'));
+        $re = $driver->getByUID($event->getUID(), array($this->get('calendar')));
         // Event will only be in the calendar if it's been accepted. This error
         // should never happen, but put it here as a safeguard for now.
         if (!($re instanceof PEAR_Error)) {
@@ -107,9 +107,9 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base
      */
     public function getFreeBusy($startstamp = null, $endstamp = null, $asObject = false)
     {
-        $vfb = Kronolith_Freebusy::generate($this->calendar, $startstamp, $endstamp, $asObject);
+        $vfb = Kronolith_Freebusy::generate($this->get('calendar'), $startstamp, $endstamp, $asObject);
         $vfb->removeAttribute('ORGANIZER');
-        $vfb->setAttribute('ORGANIZER', $this->name);
+        $vfb->setAttribute('ORGANIZER', $this->get('name'));
 
         return $vfb;
     }
diff --git a/kronolith/resources.php b/kronolith/resources.php
deleted file mode 100644 (file)
index e64bffa..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-/**
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- */
-require_once dirname(__FILE__) . '/lib/base.php';
-
-$title = _("Edit resources");
-
-$resources = array();
-$resources = Kronolith::listResources((PERMS_DELETE));
-$display_url_base = Horde::applicationUrl('month.php', true, -1);
-
-require KRONOLITH_TEMPLATES . '/common-header.inc';
-require KRONOLITH_TEMPLATES . '/menu.inc';
-
-?>
-<!-- Break out into template -->
-<div id="page">
-
-<h1 class="header">
- <?php echo _("Resources") ?>
-</h1>
-<?php if (Horde_Auth::isAdmin()): ?>
- <form method="get" action="createresource.php">
-  <?php echo Horde_Util::formInput() ?>
-  <input type="submit" class="button" value="<?php echo _("Create a new Resource") ?>" />
- </form>
-<?php endif; ?>
-<table summary="<?php echo _("Resource List") ?>" cellspacing="0" id="calendar-list" class="striped sortable">
- <thead>
-  <tr>
-   <th class="sortdown"><?php echo _("Name") ?></th>
-   <th class="calendar-list-url nosort"><?php echo _("Display URL") ?></th>
-  </tr>
- </thead>
- <tbody>
-<?php foreach ($resources as $resource): ?>
- <tr>
-  <td><?php echo htmlspecialchars($resource->name) ?></td>
-  <td><?php $url = Horde_Util::addParameter($display_url_base, 'display_cal', $resource->calendar, false); echo Horde::link($url, _("Click or copy this URL to display this calendar"), '', '_blank') . htmlspecialchars(shorten_url($url)) . '</a>' ?></td>
- </tr>
-<?php endforeach; ?>
-</tbody>
-</table>
-<?php
-/**
- * Show just the beginning and end of long URLs.
- */
-function shorten_url($url, $separator = '...', $first_chunk_length = 35, $last_chunk_length = 15)
-{
-    $url_length = strlen($url);
-    $max_length = $first_chunk_length + strlen($separator) + $last_chunk_length;
-
-    if ($url_length > $max_length) {
-        return substr_replace($url, $separator, $first_chunk_length, -$last_chunk_length);
-    }
-
-    return $url;
-}
-/* Test creating a new resource */
-//$new = array('name' => _("Another Big Meeting Room"),
-//             'category' => 'conference rooms');
-//
-//$resource = new Kronolith_Resource_Single($new);
-//$results = Kronolith::addResource($resource);
-//var_dump($results);
-?>
-</div>
\ No newline at end of file
diff --git a/kronolith/resources/create.php b/kronolith/resources/create.php
new file mode 100644 (file)
index 0000000..6cdeb6d
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+/**
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ */
+
+@define('KRONOLITH_BASE', dirname(dirname(__FILE__)));
+require_once KRONOLITH_BASE . '/lib/base.php';
+require_once KRONOLITH_BASE . '/lib/Forms/CreateResource.php';
+
+// Exit if this isn't an authenticated, administrative user
+if (!Horde_Auth::isAdmin()) {
+    header('Location: ' . Horde::applicationUrl($prefs->getValue('defaultview') . '.php', true));
+    exit;
+}
+
+$vars = Horde_Variables::getDefaultVariables();
+$form = new Kronolith_CreateResourceForm($vars);
+
+// Execute if the form is valid.
+if ($form->validate($vars)) {
+    $result = $form->execute();
+    if (is_a($result, 'PEAR_Error')) {
+        $notification->push($result, 'horde.error');
+    } else {
+        $notification->push(sprintf(_("The calendar \"%s\" has been created."), $vars->get('name')), 'horde.success');
+    }
+
+    header('Location: ' . Horde::applicationUrl('resources/', true));
+    exit;
+}
+
+$title = $form->getTitle();
+require KRONOLITH_TEMPLATES . '/common-header.inc';
+require KRONOLITH_TEMPLATES . '/menu.inc';
+echo $form->renderActive($form->getRenderer(), $vars, 'create.php', 'post');
+require $registry->get('templates', 'horde') . '/common-footer.inc';
diff --git a/kronolith/resources/delete.php b/kronolith/resources/delete.php
new file mode 100644 (file)
index 0000000..e0500c3
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * Copyright 2002-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ */
+
+require_once dirname(__FILE__) . '/../lib/base.php';
+require_once KRONOLITH_BASE . '/lib/Forms/DeleteResource.php';
+
+// Exit if this isn't an authenticated administrative user.
+if (!Horde_Auth::isAdmin()) {
+    header('Location: ' . Horde::applicationUrl($prefs->getValue('defaultview') . '.php', true));
+    exit;
+}
+
+$vars = Horde_Variables::getDefaultVariables();
+$d = Kronolith::getDriver('Resource');
+$resource = $d->getResource($vars->get('c'));
+
+if ($resource instanceof PEAR_Error) {
+    $notification->push($resoruce, 'horde.error');
+    header('Location: ' . Horde::applicationUrl('resources/', true));
+    exit;
+} elseif (!$resource->hasPermission(Horde_Auth::getAuth(), PERMS_DELETE)) {
+    $notification->push(_("You are not allowed to delete this resource."), 'horde.error');
+    header('Location: ' . Horde::applicationUrl('resources/', true));
+    exit;
+}
+
+$form = new Kronolith_DeleteResourceForm($vars, $resource);
+
+// Execute if the form is valid (must pass with POST variables only).
+if ($form->validate(new Horde_Variables($_POST))) {
+    $result = $form->execute();
+    if ($result instanceof PEAR_Error) {
+        $notification->push($result, 'horde.error');
+    } elseif ($result) {
+        $notification->push(sprintf(_("The resource \"%s\" has been deleted."), $resource->get('name')), 'horde.success');
+    }
+
+    header('Location: ' . Horde::applicationUrl('resources/', true));
+    exit;
+}
+
+$title = $form->getTitle();
+require KRONOLITH_TEMPLATES . '/common-header.inc';
+require KRONOLITH_TEMPLATES . '/menu.inc';
+echo $form->renderActive($form->getRenderer(), $vars, 'delete.php', 'post');
+require $registry->get('templates', 'horde') . '/common-footer.inc';
diff --git a/kronolith/resources/edit.php b/kronolith/resources/edit.php
new file mode 100644 (file)
index 0000000..37306c8
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Copyright 2002-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ */
+
+require_once dirname(__FILE__) . '/../lib/base.php';
+require_once KRONOLITH_BASE . '/lib/Forms/EditResource.php';
+
+// Exit if this isn't an authenticated administrative user.
+if (!Horde_Auth::isAdmin()) {
+    header('Location: ' . Horde::applicationUrl($prefs->getValue('defaultview') . '.php', true));
+    exit;
+}
+
+$vars = Horde_Variables::getDefaultVariables();
+$d = Kronolith::getDriver('Resource');
+$resource = $d->getResource($vars->get('c'));
+
+if ($resource instanceof PEAR_Error) {
+    $notification->push($resource, 'horde.error');
+    header('Location: ' . Horde::applicationUrl('resources/', true));
+    exit;
+} elseif (!$resource->hasPermission(Horde_Auth::getAuth(), PERMS_EDIT)) {
+    $notification->push(_("You are not allowed to change this resource."), 'horde.error');
+    header('Location: ' . Horde::applicationUrl('resources/', true));
+    exit;
+}
+$form = new Kronolith_EditResourceForm($vars, $resource);
+
+// Execute if the form is valid.
+if ($form->validate($vars)) {
+    $original_name = $resource->get('name');
+    $result = $form->execute();
+    if ($result instanceof PEAR_Error) {
+        $notification->push($result, 'horde.error');
+    } else {
+        if ($result->get('name') != $original_name) {
+            $notification->push(sprintf(_("The resource \"%s\" has been renamed to \"%s\"."), $original_name, $resource->get('name')), 'horde.success');
+        } else {
+            $notification->push(sprintf(_("The resource \"%s\" has been saved."), $original_name), 'horde.success');
+        }
+    }
+
+    header('Location: ' . Horde::applicationUrl('resources/', true));
+    exit;
+}
+
+$vars->set('name', $resource->get('name'));
+$vars->set('description', $resource->get('description'));
+$vars->set('category', $resource->get('category'));
+
+$title = $form->getTitle();
+require KRONOLITH_TEMPLATES . '/common-header.inc';
+require KRONOLITH_TEMPLATES . '/menu.inc';
+echo $form->renderActive($form->getRenderer(), $vars, 'edit.php', 'post');
+require $registry->get('templates', 'horde') . '/common-footer.inc';
diff --git a/kronolith/resources/index.php b/kronolith/resources/index.php
new file mode 100644 (file)
index 0000000..cf23398
--- /dev/null
@@ -0,0 +1,95 @@
+<?php
+/**
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ */
+require_once dirname(__FILE__) . '/../lib/base.php';
+
+$title = _("Edit resources");
+
+require KRONOLITH_TEMPLATES . '/common-header.inc';
+require KRONOLITH_TEMPLATES . '/menu.inc';
+
+// Exit if this isn't an authenticated user.
+if (!Horde_Auth::getAuth()) {
+    header('Location: ' . Horde::applicationUrl($prefs->getValue('defaultview') . '.php'));
+    exit;
+}
+$edit_url_base = Horde::applicationUrl('resources/edit.php');
+$edit_img = Horde::img('edit.png', _("Edit"), null, $registry->getImageDir('horde'));
+$resources = Kronolith::listResources();
+$display_url_base = Horde::applicationUrl('month.php', true, -1);
+$delete_url_base = Horde::applicationUrl('resources/delete.php');
+$delete_img = Horde::img('delete.png', _("Delete"), null, $registry->getImageDir('horde'));
+
+?>
+<script type="text/javascript">
+function performAction(action, rid)
+{
+    document.resourceform.actionId.value = action;
+    document.resourceform.actionValue.value = rid;
+    document.resourceform.submit();
+    return false;
+}
+</script>
+<!-- Break out into template -->
+<div id="page">
+
+<h1 class="header">
+ <?php echo _("Resources") ?>
+</h1>
+<?php if ($isAdmin = Horde_Auth::isAdmin()): ?>
+ <form method="get" action="create.php">
+  <?php echo Horde_Util::formInput() ?>
+  <input type="submit" class="button" value="<?php echo _("Create a new Resource") ?>" />
+ </form>
+<?php endif ?>
+<table summary="<?php echo _("Resource List") ?>" cellspacing="0" id="calendar-list" class="striped sortable">
+ <thead>
+  <tr>
+   <th>&nbsp;</th>
+   <th class="sortdown"><?php echo _("Name") ?></th>
+   <th class="calendar-list-url nosort"><?php echo _("Display URL") ?></th>
+  </tr>
+ </thead>
+ <tbody>
+<?php foreach ($resources as $resource): ?>
+ <tr>
+  <?php if ($isAdmin):?>
+  <td>
+       <?php echo Horde::link(Horde_Util::addParameter($delete_url_base, 'c', $resource->getId()), _("Delete")) . $delete_img . '</a>' ?>
+       <?php echo Horde::link(Horde_Util::addParameter($edit_url_base, 'c', $resource->getId()), _("Edit")) . $edit_img . '</a>' ?>
+  <?php else:?>
+  <td>&nbsp;</td>
+  <?php endif;?>
+  <td><?php echo htmlspecialchars($resource->get('name')) ?></td>
+  <td><?php $url = Horde_Util::addParameter($display_url_base, 'display_cal', $resource->get('calendar'), false); echo Horde::link($url, _("Click or copy this URL to display this calendar"), '', '_blank') . htmlspecialchars(shorten_url($url)) . '</a>' ?></td>
+ </tr>
+<?php endforeach; ?>
+</tbody>
+</table>
+
+<?php
+/**
+ * Show just the beginning and end of long URLs.
+ */
+function shorten_url($url, $separator = '...', $first_chunk_length = 35, $last_chunk_length = 15)
+{
+    $url_length = strlen($url);
+    $max_length = $first_chunk_length + strlen($separator) + $last_chunk_length;
+
+    if ($url_length > $max_length) {
+        return substr_replace($url, $separator, $first_chunk_length, -$last_chunk_length);
+    }
+
+    return $url;
+}
+/* Test creating a new resource */
+//$new = array('name' => _("Another Big Meeting Room"),
+//             'category' => 'conference rooms');
+//
+//$resource = new Kronolith_Resource_Single($new);
+//$results = Kronolith::addResource($resource);
+//var_dump($results);
+?>
+</div>
\ No newline at end of file
index 540813a..29a2490 100644 (file)
@@ -131,7 +131,7 @@ function switchDateView(view, date)
     <select id="resourceselect" name="resourceselect">
      <option value="0"><?php echo _("Select resource")?></option>
     <?php foreach ($allResources as $resource):?>
-        <?php printf('<option value="%s">%s</option>', $resource->id, $resource->name) ?>
+        <?php printf('<option value="%s">%s</option>', $resource->getId(), $resource->get('name')) ?>
     <?php endforeach;?>
     </select>
   </td>
@@ -142,7 +142,7 @@ function switchDateView(view, date)
 <div>
  <input type="submit" class="button" name="addNew" value="<?php echo htmlspecialchars(_("Save")) ?>" />
  <input type="submit" class="button" name="addNewClose" value="<?php echo htmlspecialchars(_("Save and Finish")) ?>" />
- <?php if (!empty($attendees)): ?><input type="submit" class="button" name="clearAll" value="<?php echo htmlspecialchars(_("Clear all attendees")) ?>" /><?php endif; ?>
+ <?php if (!empty($attendees)): ?><input type="submit" class="button" name="clearAll" value="<?php echo htmlspecialchars(_("Clear all")) ?>" /><?php endif; ?>
 </div>
 
 <br />
index 5ba7267..63796e3 100644 (file)
 <?php endforeach; ?>
  </tbody>
 </table>
-
-<?php if (count($resources)): ?>
-<h1 class="smallheader">Resources</div>
-<table summary="<?php echo _("Resource Calendars") ?>" cellspacing="0"  class="striped sortable">
- <thead>
-   <th class="sortdown"><?php echo _("Resource Name") ?></th>
-   <th class="calendar-list-url nosort"><?php echo _("Display URL") ?></th>
-   <th class="calendar-list-icon nosort" colspan="<?php echo empty($conf['share']['no_sharing']) ? 3 : 2 ?>">&nbsp;</th>
-  </thead>
-<?php foreach ($resources as $resource): ?>
-<?php var_dump($resource);?>
-  <tr>
-   <td><?php echo $resource->name ?></td>
-   <td><?php //echo $resource->url ?></td>
-   <td><?php echo Horde::link(Horde_Util::addParameter($edit_url_base, 'c', $resource->get('calendar')), _("Edit")) . $edit_img . '</a>' ?></td>
-  </tr>
-<?php endforeach; ?>
-</table>
-<?php endif; ?>
-
 </div>
index 79495cc..e3a5fa3 100644 (file)
@@ -7,7 +7,7 @@ if (!empty($GLOBALS['display_resource_calendars'])) {
     $driver = Kronolith::getDriver('Resource');
     foreach ($GLOBALS['display_resource_calendars'] as $c) {
         $rc = $driver->getResource($driver->getResourceIdByCalendar($c));
-        $calendar_names[] = htmlspecialchars($rc->name);
+        $calendar_names[] = htmlspecialchars($rc->get('name'));
     }
 }
 ?>
index 9dd1e74..1e1eba9 100644 (file)
@@ -75,7 +75,7 @@
             $rd = Kronolith::getDriver('Resource');
             $rc = $rd->getResource($rd->getResourceIdByCalendar($cal));
             printf('<option value="%s"%s>%s</option>',
-                    htmlspecialchars($cal), '', $rc->name) . "\n";
+                    htmlspecialchars($cal), '', $rc->get('name')) . "\n";
         }
     } else {
         // Normal view
index ea9b469..9a4cafe 100644 (file)
@@ -48,7 +48,8 @@ $tagger = Kronolith::getTagger();
 
 <?php if (Horde_Auth::getAuth()): ?>
  <p>
-  <a href="<?php echo Horde::applicationUrl('calendars/') ?>"><?php echo _("[Manage Calendars]") ?></a>
+  <a href="<?php echo Horde::applicationUrl('calendars/') ?>"><?php echo _("[Manage Calendars]") ?></a><br />
+  <a href="<?php echo Horde::applicationUrl('resources/')?>"><?php echo (Horde_Auth::isAdmin() ? _("[Manage Resource Calendars]") : _("[Resource Calendars]"))?></a>
  </p>
 <?php endif; ?>