$perms_img = Horde::img('perms.png', _("Change Permissions"), null, $registry->getImageDir('horde'));
$delete_img = Horde::img('delete.png', _("Delete"), null, $registry->getImageDir('horde'));
-/* @TODO: Show resources? */
-$resources = array();
-//$resources = Kronolith::listResources();
-//var_dump($resources);
-
-
Horde::addScriptFile('tables.js', 'horde', true);
$title = _("Manage Calendars");
require KRONOLITH_TEMPLATES . '/common-header.inc';
return $resource;
}
+ /**
+ * Delete an event.
+ *
+ * Since this is the Kronolith_Resource's version of the event, if we
+ * delete it, we must also make sure to remove it from the event that
+ * it is attached to. Not sure if there is a better way to do this...
+ *
+ * @see lib/Driver/Kronolith_Driver_Sql#deleteEvent($eventId, $silent)
+ */
public function deleteEvent($event, $silent = false)
{
- parent::deleteEvent($event, $silent);
-
- /* @TODO: Since this is being removed from a resource calendar, need to
- * make sure we remove any acceptance status from the event it's
- * attached to.
+ /* Since this is the Kronolith_Resource's version of the event, if we
+ * delete it, we must also make sure to remove it from the event that
+ * it is attached to. Not sure if there is a better way to do this...
*/
+ $delete_event = $this->getEvent($event);
+ $uid = $delete_event->getUID();
+ $driver = Kronolith::getDriver();
+ $events = $driver->getByUID($uid, null, true);
+ foreach ($events as $e) {
+ $resources = $e->getResources();
+ if (count($resources)) {
+ // found the right entry
+ $r = $this->getResource($this->getResourceIdByCalendar($delete_event->getCalendar()));
+ $e->removeResource($r);
+ $e->save();
+ }
+ }
+
+ parent::deleteEvent($event, $silent);
}
/**
}
/* Remove the event from any resources that are attached to it */
- if (count($resources = $event->getResources())) {
+ $resources = $event->getResources();
+ if (count($resources)) {
$rd = Kronolith::getDriver('Resource');
foreach (array_keys($resources) as $uid) {
$r = $rd->getResource($uid);
*/
function removeResource($resource)
{
- if (isset($this->_resources[$resource->uid])) {
- unset ($this->_resources[$resource->uid]);
+ if (isset($this->_resources[$resource->id])) {
+ unset ($this->_resources[$resource->id]);
}
}
public function checkResources()
{
foreach ($this->_resources as $id => $resource) {
- $r = $this->getDriver()->getResource($id);
+ $r = Kronolith::getDriver('Resource')->getResource($id);
if ($r->isFree($this)) {
$r->addEvent($this);
$this->addResource($r, Kronolith::RESPONSE_ACCEPTED);
/* Resource calendars (this would only be populated if explicitly
* requested in the request, so include them if this is set regardless
* of $calendars value).
+ *
+ * @TODO: Should we disallow even *viewing* these if the user is not an
+ * admin?
*/
if (!empty($GLOBALS['display_resource_calendars'])) {
$driver = self::getDriver('Resource');
public function addEvent($event)
{
/* Get a driver for this resource's calendar */
- $driver = Kronolith::getDriver(null, $this->calendar);
+ $driver = Kronolith::getDriver('Resource', $this->calendar);
/* Make sure it's not already attached. */
$uid = $event->getUID();
$existing = $driver->getByUID($uid, array($this->calendar));
*/
public function removeEvent($event)
{
-
+ $driver = Kronolith::getDriver('Resource', $this->calendar);
+ $re = $driver->getByUID($event->getUID(), array($this->calendar));
+ $driver->deleteEvent($re->getId());
}
/**
$day->mday++;
}
$endDate = new Horde_Date($day);
- $allevents = Kronolith::listEvents($this->startDate, $endDate, $GLOBALS['display_calendars']);
+ $allevents = Kronolith::listEvents($this->startDate, $endDate);
if (is_a($allevents, 'PEAR_Error')) {
$GLOBALS['notification']->push($allevents, 'horde.error');
$allevents = array();
require_once dirname(__FILE__) . '/lib/base.php';
$title = _("Edit resources");
+
+$resources = array();
+$resources = Kronolith::listResources();
+$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;
+}
+var_dump($resources);
/* Test creating a new resource */
//$new = array('name' => _("Another Big Meeting Room"),
// 'category' => 'conference rooms');
//var_dump($results);
/* Test adding resource to event */
-$resource = Kronolith::getResource(9);
+$resource = Kronolith::getDriver('Resource')->getResource(9);
/* Any driver/event */
$driver = Kronolith::getDriver('Sql');
-$event = $driver->getByUID('20090831145736.98833ff01g9m338k@localhost');
+$event = $driver->getByUID('20090903183552.146242hgs864c92c@localhost');
$event->addResource($resource, Kronolith::RESPONSE_NONE);
$event->save();
////var_dump($resource->getFreeBusy(null, null, true));
//
/* Test listing resources */
-//var_dump(Kronolith::listResources());
\ No newline at end of file
+//var_dump(Kronolith::listResources());
+?>
+</div>
\ No newline at end of file