From: Michael J. Rubinsky Date: Thu, 3 Sep 2009 20:34:20 +0000 (-0400) Subject: More tweaks/fleshing out: X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a8e9439900529aab7a9d3d1ede3e80c7de6184e1;p=horde.git More tweaks/fleshing out: - Perms checks - Remove Kronolith::getResource() - use the driver's getResource() method directly. - have K_Driver_Resource::listResources() method return resource objects directly. --- diff --git a/kronolith/attendees.php b/kronolith/attendees.php index e36a37d1f..f4ef39be5 100644 --- a/kronolith/attendees.php +++ b/kronolith/attendees.php @@ -249,12 +249,14 @@ foreach ($attendees as $email => $status) { } // 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); diff --git a/kronolith/calendars/index.php b/kronolith/calendars/index.php index 65425f2be..88c08638c 100644 --- a/kronolith/calendars/index.php +++ b/kronolith/calendars/index.php @@ -61,6 +61,12 @@ $edit_img = Horde::img('edit.png', _("Edit"), null, $registry->getImageDir('hord $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'; diff --git a/kronolith/delete.php b/kronolith/delete.php index ff98fff6b..37ffe6bd2 100644 --- a/kronolith/delete.php +++ b/kronolith/delete.php @@ -11,7 +11,13 @@ 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')) { @@ -21,10 +27,22 @@ if ($eventID = Horde_Util::getFormData('eventID')) { 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')) { diff --git a/kronolith/lib/Driver/Resource.php b/kronolith/lib/Driver/Resource.php index 977e9d489..051a72589 100644 --- a/kronolith/lib/Driver/Resource.php +++ b/kronolith/lib/Driver/Resource.php @@ -383,6 +383,16 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql 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 * @@ -402,12 +412,8 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql 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)); } /** @@ -439,7 +445,7 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql * 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); @@ -447,7 +453,22 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql 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; } /** diff --git a/kronolith/lib/Driver/Sql.php b/kronolith/lib/Driver/Sql.php index f356a8dd1..2955f7c25 100644 --- a/kronolith/lib/Driver/Sql.php +++ b/kronolith/lib/Driver/Sql.php @@ -735,6 +735,15 @@ class Kronolith_Driver_Sql extends Kronolith_Driver $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(); diff --git a/kronolith/lib/Event/Kolab.php b/kronolith/lib/Event/Kolab.php index 0994122ad..6e5a35f2a 100644 --- a/kronolith/lib/Event/Kolab.php +++ b/kronolith/lib/Event/Kolab.php @@ -269,24 +269,4 @@ class Kronolith_Event_Kolab extends Kronolith_Event 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); - } - } - } - } diff --git a/kronolith/lib/Event/Sql.php b/kronolith/lib/Event/Sql.php index 7937e048b..bee52b313 100644 --- a/kronolith/lib/Event/Sql.php +++ b/kronolith/lib/Event/Sql.php @@ -217,7 +217,7 @@ class Kronolith_Event_Sql extends Kronolith_Event 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); diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 727ea9a0a..275404277 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -1825,6 +1825,8 @@ class Kronolith 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')); @@ -1837,8 +1839,12 @@ class Kronolith 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")); @@ -2007,28 +2013,29 @@ class Kronolith } /** + * 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) { diff --git a/kronolith/lib/Resource.php b/kronolith/lib/Resource.php new file mode 100644 index 000000000..db84dda90 --- /dev/null +++ b/kronolith/lib/Resource.php @@ -0,0 +1,42 @@ + + * @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 diff --git a/kronolith/lib/Resource/Base.php b/kronolith/lib/Resource/Base.php index 1c874daf2..35dde643f 100644 --- a/kronolith/lib/Resource/Base.php +++ b/kronolith/lib/Resource/Base.php @@ -37,6 +37,7 @@ abstract class Kronolith_Resource_Base return $this->_id; } + $property = str_replace('resource_', '', $property); if (isset($this->_params[$property])) { return $this->_params[$property]; } else { diff --git a/kronolith/templates/calendar_list.php b/kronolith/templates/calendar_list.php index 4cb611c83..5ba7267d4 100644 --- a/kronolith/templates/calendar_list.php +++ b/kronolith/templates/calendar_list.php @@ -58,4 +58,23 @@ + +

Resources +" cellspacing="0" class="striped sortable"> + + + + + + + + + + + + + +
 
name ?>url ?>get('calendar')), _("Edit")) . $edit_img . '' ?>
+ + diff --git a/kronolith/templates/calendar_titles.inc b/kronolith/templates/calendar_titles.inc index afefc0f23..79495cccf 100644 --- a/kronolith/templates/calendar_titles.inc +++ b/kronolith/templates/calendar_titles.inc @@ -4,8 +4,9 @@ foreach ($GLOBALS['display_calendars'] as $calendarId) { $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); } }