}
// Add Free/Busy for resources
-foreach ($resources as $r_id => $resource) {
- $r = Kronolith::getResource($r_id);
- $vfb = $r->getFreeBusy(null, null, true);
- $attendee_view->addResourceMember($vfb);
+if (count($resources)) {
+ $driver = Kronolith::getDriver('Resource');
+ foreach ($resources as $r_id => $resource) {
+ $r = $driver->getResource($r_id);
+ $vfb = $r->getFreeBusy(null, null, true);
+ $attendee_view->addResourceMember($vfb);
+ }
}
-
$date = Horde_Util::getFormData('date', date('Ymd')) . '000000';
$date = new Horde_Date($date);
$vfb_html = $attendee_view->render($date);
$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';
require_once dirname(__FILE__) . '/lib/base.php';
-$kronolith_driver = Kronolith::getDriver(null, Horde_Util::getFormData('calendar'));
+if (Kronolith::isResourceCalendar($c = Horde_Util::getFormData('calendar'))) {
+ $driver = 'Resource';
+} else {
+ $driver = null;
+}
+
+$kronolith_driver = Kronolith::getDriver($driver, $c);
if ($eventID = Horde_Util::getFormData('eventID')) {
$event = $kronolith_driver->getEvent($eventID);
if (is_a($event, 'PEAR_Error')) {
header('Location: ' . $url);
exit;
}
- $share = &$kronolith_shares->getShare($event->getCalendar());
- if (!$share->hasPermission(Horde_Auth::getAuth(), PERMS_DELETE, $event->getCreatorID())) {
- $notification->push(_("You do not have permission to delete this event."), 'horde.warning');
+ if ($driver != 'Resource') {
+ $share = &$kronolith_shares->getShare($event->getCalendar());
+ if (!$share->hasPermission(Horde_Auth::getAuth(), PERMS_DELETE, $event->getCreatorID())) {
+ $notification->push(_("You do not have permission to delete this event."), 'horde.warning');
+ } else {
+ $have_perms = true;
+ }
} else {
+ if (!Horde_Auth::isAdmin()) {
+ $notification->push(_("You do not have permission to delete this event."), 'horde.warning');
+ } else {
+ $have_perms = true;
+ }
+ }
+
+ if (!empty($have_perms)) {
$notification_type = Kronolith::ITIP_CANCEL;
$instance = null;
if (Horde_Util::getFormData('future')) {
return $resource;
}
+ 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.
+ */
+ }
+
/**
* Obtain a Kronolith_Resource by the resource's id
*
if (empty($results)) {
throw new Horde_Exception('Resource not found');
}
- $return = array();
- foreach ($results as $field => $value) {
- $return[str_replace('resource_', '', $field)] = $this->convertFromDriver($value);
- }
- return $return;
+ return new Kronolith_Resource_Single($this->_fromDriver($results));
}
/**
* fleshed out.
*
*/
- function listResources($params = array())
+ public function listResources($params = array())
{
$query = 'SELECT resource_id, resource_name, resource_calendar, resource_category FROM kronolith_resources';
$results = $this->_db->getAll($query, null, DB_FETCHMODE_ASSOC);
throw new Horde_Exception($results->getMessage());
}
- return $results;
+ $return = array();
+ foreach ($results as $result) {
+ $return[] = new Kronolith_Resource_Single($this->_fromDriver($result));
+ }
+
+ return $return;
+ }
+
+ protected function _fromDriver($params)
+ {
+ $return = array();
+ foreach ($params as $field => $value) {
+ $return[str_replace('resource_', '', $field)] = $this->convertFromDriver($value);
+ }
+
+ return $return;
}
/**
$history->log('kronolith:' . $this->_calendar . ':' . $event->getUID(), array('action' => 'delete'), true);
}
+ /* Remove the event from any resources that are attached to it */
+ if (count($resources = $event->getResources())) {
+ $rd = Kronolith::getDriver('Resource');
+ foreach (array_keys($resources) as $uid) {
+ $r = $rd->getResource($uid);
+ $r->removeEvent($event);
+ }
+ }
+
/* Remove any pending alarms. */
if (@include_once 'Horde/Alarm.php') {
$alarm = Horde_Alarm::factory();
return $event;
}
- /**
- * Function to check availability and auto accept/decline for each resource
- * attached to this event. Needed here instead of in Kronolith_Driver::saveEvent
- * since the _properties array is already built at that point.
- *
- * @return unknown_type
- */
- public function checkResources()
- {
- foreach ($this->_resources as $id => $resource) {
- $r = Kronolith::getResource($id);
- if ($r->isFree($this)) {
- $r->addEvent($this);
- $this->addResource($r, Kronolith::RESPONSE_ACCEPTED);
- } else {
- $this->addResource($r, Kronolith::RESPONSE_DECLINED);
- }
- }
- }
-
}
public function checkResources()
{
foreach ($this->_resources as $id => $resource) {
- $r = Kronolith::getResource($id);
+ $r = $this->getDriver()->getResource($id);
if ($r->isFree($this)) {
$r->addEvent($this);
$this->addResource($r, Kronolith::RESPONSE_ACCEPTED);
if (Horde_Util::getFormData('calendar') == '**remote') {
$event = self::getDriver('Ical', Horde_Util::getFormData('remoteCal'))
->getEvent(Horde_Util::getFormData('eventID'));
+ } elseif (strncmp(Horde_Util::getFormData('calendar'), 'resource_', 9) === 0) {
+ $event = self::getDriver('Resource', Horde_Util::getFormData('calendar'))->getEvent(Horde_Util::getFormData('eventID'));
} else {
$event = self::getDriver(null, Horde_Util::getFormData('calendar'))
->getEvent(Horde_Util::getFormData('eventID'));
return new Kronolith_View_EditEvent($event);
case 'DeleteEvent':
- $event = self::getDriver(null, Horde_Util::getFormData('calendar'))
- ->getEvent(Horde_Util::getFormData('eventID'));
+ if (strncmp(Horde_Util::getFormData('calendar'), 'resource_', 9) === 0) {
+ $event = self::getDriver('Resource', Horde_Util::getFormData('calendar'))->getEvent(Horde_Util::getFormData('eventID'));
+ } else {
+ $event = self::getDriver(null, Horde_Util::getFormData('calendar'))
+ ->getEvent(Horde_Util::getFormData('eventID'));
+ }
if (!is_a($event, 'PEAR_Error') &&
!$event->hasPermission(PERMS_DELETE)) {
$event = PEAR::raiseError(_("Permission Denied"));
}
/**
+ * Return a list of resources that the current user has access to administer.
*
* @return array of Kronolith_Resource objects
*/
static public function listResources($params = array())
{
+ // For now, keep this check here. Maybe move this to the resource
+ // driver object?
+ if (!Horde_Auth::isAdmin()) {
+ return array();
+ }
+
// Query kronolith_resource table for all(?) available resources?
// maybe by 'type' or 'name'? type would be arbitrary?
$driver = Kronolith::getDriver('Resource');
- $resources = $driver->listResources($params);
- $return = array();
- foreach ($resources as $resource) {
- $return[] = new Kronolith_Resource_Single($resource);
- }
-
- return $return;
+ return $driver->listResources($params);
}
- static public function getResource($id)
- {
- $driver = Kronolith::getDriver('Resource');
- return new Kronolith_Resource_Single($driver->getResource($id));
- }
+// static public function getResource($id)
+// {
+// $driver = Kronolith::getDriver('Resource');
+// return new Kronolith_Resource_Single($driver->getResource($id));
+// }
static public function isResourceCalendar($calendar)
{
--- /dev/null
+<?php
+/**
+ * Base class for dealing with Kronolith_Resource objects. Handles basic
+ * creation/deletion/listing by delegating to the underlying Kronolith_Driver
+ * object.
+ *
+ * For now, assume SQL driver only. Could probably easily extend this to use
+ * different backend drivers if/when support is added to those drivers for
+ * resources.
+ *
+ * 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 Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Kronolith
+ */
+class Kronolith_Resource
+{
+ static protected $_driver;
+
+ /**
+ * Removes a resource from storage
+ *
+ * @param Kronolith_Resource $resource
+ * @return boolean
+ * @throws Horde_Exception
+ */
+ static public function removeResource($resource)
+ {
+
+ }
+
+ static public function isResourceCalendar($calendar)
+ {
+ if (strncmp($calendar, 'resource_', 9) === 0) {
+ return true;
+ }
+ }
+
+}
\ No newline at end of file
return $this->_id;
}
+ $property = str_replace('resource_', '', $property);
if (isset($this->_params[$property])) {
return $this->_params[$property];
} else {
</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 ?>"> </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>
$calendar_names[] = htmlspecialchars($GLOBALS['all_calendars'][$calendarId]->get('name'));
}
if (!empty($GLOBALS['display_resource_calendars'])) {
+ $driver = Kronolith::getDriver('Resource');
foreach ($GLOBALS['display_resource_calendars'] as $c) {
- $rc = Kronolith::getResource(Kronolith::getDriver('Resource')->getResourceIdByCalendar($c));
+ $rc = $driver->getResource($driver->getResourceIdByCalendar($c));
$calendar_names[] = htmlspecialchars($rc->name);
}
}