From 438f7bac25cfe21418937adeeccff49d40566f4d Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Tue, 8 Dec 2009 22:39:39 +0100 Subject: [PATCH] Complete the split of the different event types out of Kronolith_Event. --- kronolith/ajax.php | 40 +++------ kronolith/js/kronolith.js | 10 ++- kronolith/lib/Block/monthlist.php | 10 +-- kronolith/lib/Block/prevmonthlist.php | 10 +-- kronolith/lib/Driver/Horde.php | 12 ++- kronolith/lib/Driver/Ical.php | 6 +- kronolith/lib/Event.php | 148 +++++++++++++--------------------- kronolith/lib/Event/Horde.php | 104 ++++++++++++++++++++---- kronolith/lib/Event/Ical.php | 45 +++++++++++ kronolith/lib/Kronolith.php | 118 +++++++++++++-------------- kronolith/lib/View/EditEvent.php | 11 ++- kronolith/lib/View/Event.php | 4 +- kronolith/lib/View/ExportEvent.php | 16 ++-- kronolith/templates/edit/edit.inc | 4 +- 14 files changed, 298 insertions(+), 240 deletions(-) diff --git a/kronolith/ajax.php b/kronolith/ajax.php index ae32b9159..47240c7fa 100644 --- a/kronolith/ajax.php +++ b/kronolith/ajax.php @@ -16,38 +16,20 @@ function getDriver($cal) { list($driver, $calendar) = explode('|', $cal); - switch ($driver) { - case 'internal': - if (!array_key_exists($calendar, - Kronolith::listCalendars(false, Horde_Perms::SHOW))) { - $GLOBALS['notification']->push(_("Permission Denied"), 'horde.error'); - return false; - } - $driver = ''; - break; - case 'external': - case 'tasklists': - $driver = 'Horde'; - break; - case 'remote': - $driver = 'Ical'; - break; - case 'holiday': - $driver = 'Holidays'; - break; - default: - $GLOBALS['notification']->push('No calendar driver specified', 'horde.error'); - break; + if ($driver == 'internal' && + !array_key_exists($calendar, + Kronolith::listCalendars(false, Horde_Perms::SHOW))) { + $GLOBALS['notification']->push(_("Permission Denied"), 'horde.error'); + return false; } - $kronolith_driver = Kronolith::getDriver($driver, $calendar); - - switch ($driver) { - case 'Ical': + if ($kronolith_driver instanceof PEAR_Error) { + $GLOBALS['notification']->push($kronolith_driver, 'horde.error'); + return false; + } + if ($driver == 'remote') { $kronolith_driver->setParam('timeout', 15); - break; } - return $kronolith_driver; } @@ -132,7 +114,7 @@ try { if (is_null($id = Horde_Util::getFormData('id'))) { break; } - $event = $kronolith_driver->getEvent($id); + $event = $kronolith_driver->getEvent($id, Horde_Util::getFormData('date')); if ($event instanceof PEAR_Error) { $notification->push($event, 'horde.error'); break; diff --git a/kronolith/js/kronolith.js b/kronolith/js/kronolith.js index d83f5e7d6..c22f854d7 100644 --- a/kronolith/js/kronolith.js +++ b/kronolith/js/kronolith.js @@ -390,10 +390,12 @@ KronolithCore = { // New event on a certain date. this.editEvent(null, null, locParts[0]); break; - case 2: + case 3: // Editing event. - this.editEvent(locParts[0], locParts[1]); + this.editEvent(locParts[0], locParts[1], locParts[2]); break; + default: + return; } this.updateMinical(this.date, this.view); this._addHistory(fullloc); @@ -2869,7 +2871,7 @@ KronolithCore = { if (!Object.isUndefined(elt.retrieve('ajax'))) { this.go(elt.retrieve('ajax')); } else { - this.go('event:' + elt.retrieve('calendar') + ':' + elt.retrieve('eventid')); + this.go('event:' + elt.retrieve('calendar') + ':' + elt.retrieve('eventid') + ':' + elt.up().retrieve('date')); } e.stop(); return; @@ -3109,7 +3111,7 @@ KronolithCore = { this.doAction('ListTopTags', {}, this._topTags); if (id) { RedBox.loading(); - this.doAction('GetEvent', { 'cal': calendar, 'id': id }, this._editEvent.bind(this)); + this.doAction('GetEvent', { 'cal': calendar, 'id': id, 'date': date }, this._editEvent.bind(this)); } else { $('kronolithEventTags').autocompleter.init(); var d = date ? this.parseDate(date) : new Date(); diff --git a/kronolith/lib/Block/monthlist.php b/kronolith/lib/Block/monthlist.php index a7eda0b53..5a1c2ae72 100644 --- a/kronolith/lib/Block/monthlist.php +++ b/kronolith/lib/Block/monthlist.php @@ -149,19 +149,11 @@ class Horde_Block_Kronolith_monthlist extends Horde_Block { } else { $html .= $event->getLocation(); } - if ($event->start->compareDate($now) < 0 && $event->end->compareDate($now) > 0) { $html .= ''; } - if (isset($event->eventID)) { - $html .= $event->getLink(null, true, null, true); - } elseif (isset($this->external)) { - $html .= Horde::link(Horde::url($registry->link($this->external . '/show', $event->external_params), - true), $event->getTitle()) . $event->getTitle() . ''; - } else { - $html .= $event->getTitle(); - } + $html .= $event->getLink(null, true, null, true); if ($event->start->compareDate($now) < 0 && $event->end->compareDate($now) > 0) { $html .= ''; diff --git a/kronolith/lib/Block/prevmonthlist.php b/kronolith/lib/Block/prevmonthlist.php index d49638b63..ece26ddac 100644 --- a/kronolith/lib/Block/prevmonthlist.php +++ b/kronolith/lib/Block/prevmonthlist.php @@ -142,19 +142,11 @@ class Horde_Block_Kronolith_prevmonthlist extends Horde_Block { } else { $html .= $event->getLocation(); } - if ($event->start->compareDate($startDate) < 0 && $event->end->compareDate($startDate) > 0) { $html .= ''; } - if (isset($event->eventID)) { - $html .= $event->getLink(null, true, null, true); - } elseif (isset($this->external)) { - $html .= Horde::link(Horde::url($registry->link($this->external . '/show', $event->external_params), - true), $event->getTitle()) . $event->getTitle() . ''; - } else { - $html .= $event->getTitle(); - } + $html .= $event->getLink(null, true, null, true); if ($event->start->compareDate($startDate) < 0 && $event->end->compareDate($startDate) > 0) { $html .= ''; diff --git a/kronolith/lib/Driver/Horde.php b/kronolith/lib/Driver/Horde.php index 198f0209e..ca08175bb 100644 --- a/kronolith/lib/Driver/Horde.php +++ b/kronolith/lib/Driver/Horde.php @@ -107,14 +107,22 @@ class Kronolith_Driver_Horde extends Kronolith_Driver /** * @todo: implement getTimeObject in timeobjects API. */ - public function getEvent($eventId = null) + public function getEvent($eventId = null, $start = null) { - $events = $this->listEvents(); + $end = null; + if ($start) { + $start = new Horde_Date($start); + $end = clone $start; + $end->mday++; + } + + $events = $this->listEvents($start, $end, (bool)$start); foreach ($events as $day) { if (isset($day[$eventId])) { return $day[$eventId]; } } + return PEAR::raiseError(_("Event not found")); } diff --git a/kronolith/lib/Driver/Ical.php b/kronolith/lib/Driver/Ical.php index 36b24bcc2..a047cecf5 100644 --- a/kronolith/lib/Driver/Ical.php +++ b/kronolith/lib/Driver/Ical.php @@ -87,7 +87,7 @@ class Kronolith_Driver_Ical extends Kronolith_Driver $event = new Kronolith_Event_Ical($this); $event->status = Kronolith::STATUS_FREE; $event->fromiCalendar($component); - $event->remoteCal = $this->_calendar; + $event->setCalendar($this->_calendar); // Force string so JSON encoding is consistent across drivers. $event->eventID = 'ical' . $i; @@ -152,8 +152,8 @@ class Kronolith_Driver_Ical extends Kronolith_Driver $event = new Kronolith_Event_Ical($this); $event->status = Kronolith::STATUS_FREE; $event->fromiCalendar($components[$eventId]); - $event->remoteCal = $this->_calendar; - $event->eventID = $eventId; + $event->setCalendar($this->_calendar); + $event->eventID = 'ical' . $eventId; return $event; } diff --git a/kronolith/lib/Event.php b/kronolith/lib/Event.php index 61cb7ad14..2fb2d1ff7 100644 --- a/kronolith/lib/Event.php +++ b/kronolith/lib/Event.php @@ -78,25 +78,25 @@ abstract class Kronolith_Event public $status = Kronolith::STATUS_CONFIRMED; /** - * The description for this event + * URL to an icon of this event. * * @var string */ - public $description = ''; + public $icon = ''; /** - * Remote description of this event (URL). + * The description for this event. * * @var string */ - public $remoteUrl = ''; + public $description = ''; /** - * Remote calendar name. + * URL of this event. * * @var string */ - public $remoteCal = ''; + public $url = ''; /** * Whether the event is private. @@ -316,18 +316,6 @@ abstract class Kronolith_Event $user = Horde_Auth::getAuth(); } - if ($this->remoteCal) { - switch ($permission) { - case Horde_Perms::SHOW: - case Horde_Perms::READ: - case Horde_Perms::EDIT: - return true; - - default: - return false; - } - } - return (!is_a($share = &$this->getShare(), 'PEAR_Error') && $share->hasPermission($user, $permission, $this->getCreatorId())); } @@ -705,7 +693,7 @@ abstract class Kronolith_Event // Remote Url $url = $vEvent->getAttribute('URL'); if (!is_array($url) && !is_a($url, 'PEAR_Error')) { - $this->remoteUrl = $url; + $this->url = $url; } // Location @@ -1147,6 +1135,9 @@ abstract class Kronolith_Event $json->fg = $this->_foregroundColor; $json->pe = $this->hasPermission(Horde_Perms::EDIT); $json->pd = $this->hasPermission(Horde_Perms::DELETE); + if ($this->icon) { + $json->ic = $this->icon; + } if ($this->alarm) { if ($this->alarm % 10080 == 0) { $alarm_value = $this->alarm / 10080; @@ -1355,11 +1346,6 @@ abstract class Kronolith_Event return $this->_calendarType; } - public function isRemote() - { - return (bool)$this->remoteCal; - } - /** * Returns the locally unique identifier for this event. * @@ -1442,12 +1428,6 @@ abstract class Kronolith_Event */ public function getTitle($user = null) { - if (isset($this->external) || - isset($this->contactID) || - $this->remoteCal) { - return !empty($this->title) ? $this->title : _("[Unnamed event]"); - } - if (!$this->isInitialized()) { return ''; } @@ -1692,7 +1672,7 @@ abstract class Kronolith_Event * * @return void */ - function removeResource($resource) + public function removeResource($resource) { if (isset($this->_resources[$resource->getId()])) { unset ($this->_resources[$resource->getId()]); @@ -2288,77 +2268,64 @@ abstract class Kronolith_Event /** * @param array $params * - * @return string + * @return Horde_Url */ public function getViewUrl($params = array(), $full = false) { $params['eventID'] = $this->eventID; - if ($this->remoteUrl) { - return $this->remoteUrl; - } elseif ($this->remoteCal) { - $params['calendar'] = '**remote'; - $params['remoteCal'] = $this->remoteCal; - } elseif (!empty($this->external_link)) { - return $this->external_link; - } else { - $params['calendar'] = $this->getCalendar(); - } + $params['calendar'] = $this->getCalendar(); + $params['type'] = $this->_calendarType; - return Horde::applicationUrl(Horde_Util::addParameter('event.php', $params), $full); + return Horde::applicationUrl('event.php', $full)->add($params); } /** * @param array $params * - * @return string + * @return Horde_Url */ public function getEditUrl($params = array()) { $params['view'] = 'EditEvent'; $params['eventID'] = $this->eventID; - if ($this->remoteCal) { - $params['calendar'] = '**remote'; - $params['remoteCal'] = $this->remoteCal; - } else { - $params['calendar'] = $this->getCalendar(); - } + $params['calendar'] = $this->getCalendar(); + $params['type'] = $this->_calendarType; - return Horde::applicationUrl(Horde_Util::addParameter('event.php', $params)); + return Horde::applicationUrl('event.php')->add($params); } /** * @param array $params * - * @return string + * @return Horde_Url */ public function getDeleteUrl($params = array()) { $params['view'] = 'DeleteEvent'; $params['eventID'] = $this->eventID; $params['calendar'] = $this->getCalendar(); - return Horde::applicationUrl(Horde_Util::addParameter('event.php', $params)); + $params['type'] = $this->_calendarType; + + return Horde::applicationUrl('event.php')->add($params); } /** * @param array $params * - * @return string + * @return Horde_Url */ public function getExportUrl($params = array()) { $params['view'] = 'ExportEvent'; $params['eventID'] = $this->eventID; - if ($this->remoteCal) { - $params['calendar'] = '**remote'; - $params['remoteCal'] = $this->remoteCal; - } else { - $params['calendar'] = $this->getCalendar(); - } + $params['calendar'] = $this->getCalendar(); + $params['type'] = $this->_calendarType; - return Horde::applicationUrl(Horde_Util::addParameter('event.php', $params)); + return Horde::applicationUrl('event.php')->add($params); } - public function getLink($datetime = null, $icons = true, $from_url = null, $full = false) + public function getLink($datetime = null, $icons = true, $from_url = null, + $full = false) { global $prefs, $registry; @@ -2373,22 +2340,19 @@ abstract class Kronolith_Event $view_url = $this->getViewUrl(array('datetime' => $datetime->strftime('%Y%m%d%H%M%S'), 'url' => $from_url), $full); $read_permission = $this->hasPermission(Horde_Perms::READ); - $link = ''; - if (isset($this->external) && !empty($this->external_link)) { - $link = $this->external_link; - $link = Horde::linkTooltip(Horde::url($link), '', 'event-tentative', '', '', nl2br(htmlspecialchars(Horde_String::wrap($this->description)))); - } elseif (isset($this->eventID) && $read_permission) { - $link = Horde::linkTooltip($view_url, + $link = 'getCSSColors() . '>'; + if ($read_permission && $view_url) { + $link .= Horde::linkTooltip($view_url, $event_title, - $this->getStatusClass(), '', '', + $this->getStatusClass(), + '', + '', $this->getTooltip(), '', array('style' => $this->getCSSColors(false))); } - $link .= @htmlspecialchars($event_title, ENT_QUOTES, Horde_Nls::getCharset()); - - if ($read_permission && (isset($this->eventID) || isset($this->external))) { + if ($read_permission && $view_url) { $link .= ''; } @@ -2426,38 +2390,34 @@ abstract class Kronolith_Event $status .= Horde::fullSrcImg('attendees.png', array('attr' => array('alt' => _("Meeting"), 'title' => _("Meeting"), 'class' => 'iconPeople'))); } - if (!empty($this->external) && !empty($this->external_icon)) { - $link = $status . ' ' . $link; - } else if (!empty($status)) { + if (!empty($this->icon)) { + $link = $status . ' ' . $link; + } elseif (!empty($status)) { $link .= ' ' . $status; } - if (!$this->eventID || !empty($this->external)) { - return $link; - } - - $edit = ''; - $delete = ''; - if ((!$this->isPrivate() || $this->getCreatorId() == Horde_Auth::getAuth()) - && $this->hasPermission(Horde_Perms::EDIT)) { - $editurl = Horde_Util::addParameter($view_url, 'view', 'EditEvent', !$full); - $edit = Horde::link($editurl, sprintf(_("Edit %s"), $event_title), 'iconEdit') - . Horde::fullSrcImg('edit-' . $icon_color . '.png', array('attr' => 'alt="' . _("Edit") . '"')) + if (!$this->isPrivate() || + $this->getCreatorId() == Horde_Auth::getAuth()) { + $link .= $this->getEditUrl( + array('datetime' => $datetime->strftime('%Y%m%d%H%M%S'), + 'url' => $from_url)) + ->link(array('title' => sprintf(_("Edit %s"), $event_title), + 'class' => 'iconEdit')) + . Horde::fullSrcImg('edit-' . $icon_color . '.png', + array('attr' => array('alt' => _("Edit")))) . ''; } if ($this->hasPermission(Horde_Perms::DELETE)) { - $delurl = Horde_Util::addParameter($view_url, 'view', 'DeleteEvent', !$full); - $delete = Horde::link($delurl, sprintf(_("Delete %s"), $event_title), 'iconDelete') - . Horde::fullSrcImg('delete-' . $icon_color . '.png', array('attr' => 'alt="' . _("Delete") . '"')) + $link .= $this->getDeleteUrl() + ->link(array('title' => sprintf(_("Delete %s"), $event_title), + 'class' => 'iconDelete')) + . Horde::fullSrcImg('delete-' . $icon_color . '.png', + array('attr' => array('alt' => _("Delete")))) . ''; } - - if ($edit || $delete) { - $link .= $edit . $delete; - } } - return $link; + return $link . ''; } /** diff --git a/kronolith/lib/Event/Horde.php b/kronolith/lib/Event/Horde.php index c3d850d45..2d49b04e7 100644 --- a/kronolith/lib/Event/Horde.php +++ b/kronolith/lib/Event/Horde.php @@ -25,11 +25,25 @@ class Kronolith_Event_Horde extends Kronolith_Event protected $_api; /** + * The link to this event. + * + * @var string + */ + protected $_link; + + /** * The link to this event in the ajax interface. * * @var string */ - public $ajax_link; + protected $_ajax_link; + + /** + * Any parameters to identify the object in the other Horde application. + * + * @var array + */ + protected $_params; /** * Constructor. @@ -50,21 +64,17 @@ class Kronolith_Event_Horde extends Kronolith_Event $eventStart = new Horde_Date($event['start']); $eventEnd = new Horde_Date($event['end']); $this->eventID = '_' . $this->_api . $event['id']; - $this->external = $this->_api; - $this->external_params = $event['params']; - $this->external_icon = !empty($event['icon']) ? $event['icon'] : null; - $this->external_link = !empty($event['link']) ? $event['link'] : null; - $this->ajax_link = !empty($event['ajax_link']) ? $event['ajax_link'] : null; + $this->icon = !empty($event['icon']) ? $event['icon'] : null; $this->title = $event['title']; $this->description = isset($event['description']) ? $event['description'] : ''; $this->start = $eventStart; $this->end = $eventEnd; $this->status = Kronolith::STATUS_FREE; - - if (isset($event['color'])) { - $this->_backgroundColor = $event['color']; - $this->_foregroundColor = Horde_Image::brightness($this->_backgroundColor) < 128 ? '#fff' : '#000'; - } + $this->_params = $event['params']; + $this->_link = !empty($event['link']) ? $event['link'] : null; + $this->_ajax_link = !empty($event['ajax_link']) ? $event['ajax_link'] : null; + $this->_backgroundColor = Kronolith::backgroundColor($event); + $this->_foregroundColor = Kronolith::foregroundColor($event); if (isset($event['recurrence'])) { $recurrence = new Horde_Date_Recurrence($eventStart); @@ -94,16 +104,80 @@ class Kronolith_Event_Horde extends Kronolith_Event $this->stored = true; } + /** + * Encapsulates permissions checking. + * + * @param integer $permission The permission to check for. + * @param string $user The user to check permissions for. + * + * @return boolean + */ + public function hasPermission($permission, $user = null) + { + switch ($permission) { + case Horde_Perms::SHOW: + case Horde_Perms::READ: + return true; + + default: + return false; + } + } + + /** + * Returns the title of this event. + * + * @param string $user The current user. + * + * @return string The title of this event. + */ + public function getTitle($user = null) + { + return !empty($this->title) ? $this->title : _("[Unnamed event]"); + } + + /** + * @param array $params + * + * @return Horde_Url + */ + public function getViewUrl($params = array(), $full = false) + { + if (empty($this->_link)) { + return null; + } + $url = clone $this->_link; + return $this->_link->setRaw($full); + } + + /** + * Returns a simple object suitable for json transport representing this + * event. + * + * @param boolean $allDay If not null, overrides whether the event is + * an all-day event. + * @param boolean $full Whether to return all event details. + * @param string $time_format The date() format to use for time formatting. + * + * @return object A simple object. + */ public function toJson($allDay = null, $full = false, $time_format = 'H:i') { $json = parent::toJson($allDay, $full, $time_format); - $json->ic = $this->external_icon; - if ($this->ajax_link) { - $json->aj = $this->ajax_link; + if ($this->_ajax_link) { + $json->aj = $this->_ajax_link; } else { - $json->ln = $this->getViewUrl(array(), true); + $json->ln = (string)$this->getViewUrl(array(), true); } return $json; } + /** + * @return string A tooltip for quick descriptions of this event. + */ + public function getTooltip() + { + return Horde_String::wrap($this->description); + } + } diff --git a/kronolith/lib/Event/Ical.php b/kronolith/lib/Event/Ical.php index 2531ac4c3..a6dce03f0 100644 --- a/kronolith/lib/Event/Ical.php +++ b/kronolith/lib/Event/Ical.php @@ -30,4 +30,49 @@ class Kronolith_Event_Ical extends Kronolith_Event return $this->toiCalendar(); } + /** + * Encapsulates permissions checking. + * + * @param integer $permission The permission to check for. + * @param string $user The user to check permissions for. + * + * @return boolean + */ + public function hasPermission($permission, $user = null) + { + switch ($permission) { + case Horde_Perms::SHOW: + case Horde_Perms::READ: + return true; + + default: + return false; + } + } + + /** + * Returns the title of this event. + * + * @param string $user The current user. + * + * @return string The title of this event. + */ + public function getTitle($user = null) + { + return !empty($this->title) ? $this->title : _("[Unnamed event]"); + } + + /** + * @param array $params + * + * @return Horde_Url + */ + public function getViewUrl($params = array(), $full = false) + { + if ($this->url) { + return new Horde_Url($this->url, $full); + } + return parent::getViewUrl($params, $full); + } + } diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 3dbcb114c..854744393 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -2083,11 +2083,13 @@ class Kronolith array('tabname' => 'Event', 'id' => 'tabEvent', 'onclick' => 'return ShowTab(\'Event\');')); + /* We check for read permissions, because we can always save a copy if + * we can read the event. */ if ((!$event->isPrivate() || $event->getCreatorId() == Horde_Auth::getAuth()) && - $event->hasPermission(Horde_Perms::EDIT)) { + $event->hasPermission(Horde_Perms::READ)) { $tabs->addTab( - $event->isRemote() ? _("Save As New") : _("_Edit"), + $event->hasPermission(Horde_Perms::EDIT) ? _("_Edit") : _("Save As New"), $event->getEditUrl(), array('tabname' => 'EditEvent', 'id' => 'tabEditEvent', @@ -2127,6 +2129,22 @@ class Kronolith */ public static function getDriver($driver = null, $calendar = null) { + switch ($driver) { + case 'internal': + $driver = ''; + break; + case 'external': + case 'tasklists': + $driver = 'Horde'; + break; + case 'remote': + $driver = 'Ical'; + break; + case 'holiday': + $driver = 'Holidays'; + break; + } + if (empty($driver)) { $driver = Horde_String::ucfirst($GLOBALS['conf']['calendar']['driver']); } @@ -2161,6 +2179,10 @@ class Kronolith } $params['language'] = $GLOBALS['language']; break; + + default: + return PEAR::raiseError('No calendar driver specified'); + break; } self::$_instances[$driver] = Kronolith_Driver::factory($driver, $params); @@ -2220,71 +2242,45 @@ class Kronolith return new $class(self::currentDate()); case 'Event': - 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')); - } elseif ($uid = Horde_Util::getFormData('uid')) { - $event = self::getDriver()->getByUID($uid); - } else { - $event = self::getDriver(null, Horde_Util::getFormData('calendar')) - ->getEvent(Horde_Util::getFormData('eventID')); - } - if (!is_a($event, 'PEAR_Error') && - !$event->hasPermission(Horde_Perms::READ)) { - $event = PEAR::raiseError(_("Permission Denied")); - } - - return new Kronolith_View_Event($event); - case 'EditEvent': - 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')); - } - if (!is_a($event, 'PEAR_Error') && - !$event->hasPermission(Horde_Perms::EDIT)) { - $event = PEAR::raiseError(_("Permission Denied")); - } - - return new Kronolith_View_EditEvent($event); - case 'DeleteEvent': - 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(Horde_Perms::DELETE)) { - $event = PEAR::raiseError(_("Permission Denied")); - } - - return new Kronolith_View_DeleteEvent($event); - case 'ExportEvent': - if (Horde_Util::getFormData('calendar') == '**remote') { - $event = self::getDriver('Ical', Horde_Util::getFormData('remoteCal')) - ->getEvent(Horde_Util::getFormData('eventID')); - } elseif ($uid = Horde_Util::getFormData('uid')) { + if ($uid = Horde_Util::getFormData('uid')) { $event = self::getDriver()->getByUID($uid); } else { - $event = self::getDriver(null, Horde_Util::getFormData('calendar')) - ->getEvent(Horde_Util::getFormData('eventID')); - } - if (!is_a($event, 'PEAR_Error') && - !$event->hasPermission(Horde_Perms::READ)) { - $event = PEAR::raiseError(_("Permission Denied")); + $event = self::getDriver(Horde_Util::getFormData('type'), + Horde_Util::getFormData('calendar')) + ->getEvent(Horde_Util::getFormData('eventID'), + Horde_Util::getFormData('datetime')); + } + switch ($view) { + case 'Event': + if (!is_a($event, 'PEAR_Error') && + !$event->hasPermission(Horde_Perms::READ)) { + $event = PEAR::raiseError(_("Permission Denied")); + } + return new Kronolith_View_Event($event); + case 'EditEvent': + /* We check for read permissions, because we can always save a + * copy if we can read the event. */ + if (!is_a($event, 'PEAR_Error') && + !$event->hasPermission(Horde_Perms::READ)) { + $event = PEAR::raiseError(_("Permission Denied")); + } + return new Kronolith_View_EditEvent($event); + case 'DeleteEvent': + if (!is_a($event, 'PEAR_Error') && + !$event->hasPermission(Horde_Perms::DELETE)) { + $event = PEAR::raiseError(_("Permission Denied")); + } + return new Kronolith_View_DeleteEvent($event); + case 'ExportEvent': + if (!is_a($event, 'PEAR_Error') && + !$event->hasPermission(Horde_Perms::READ)) { + $event = PEAR::raiseError(_("Permission Denied")); + } + return new Kronolith_View_ExportEvent($event); } - - return new Kronolith_View_ExportEvent($event); } } diff --git a/kronolith/lib/View/EditEvent.php b/kronolith/lib/View/EditEvent.php index 00ceeb910..a877dbae4 100644 --- a/kronolith/lib/View/EditEvent.php +++ b/kronolith/lib/View/EditEvent.php @@ -40,10 +40,10 @@ class Kronolith_View_EditEvent { return; } - if ($this->event->isRemote()) { - $calendar_id = Kronolith::getDefaultCalendar(Horde_Perms::EDIT); - } else { + if ($this->event->hasPermission(Horde_Perms::EDIT)) { $calendar_id = $this->event->getCalendar(); + } else { + $calendar_id = Kronolith::getDefaultCalendar(Horde_Perms::EDIT); } if (!$this->event->hasPermission(Horde_Perms::EDIT) && !is_a($share = &$this->event->getShare(), 'PEAR_Error')) { @@ -68,14 +68,13 @@ class Kronolith_View_EditEvent { $calendars = Kronolith::listCalendars(false, $perms); $buttons = array(); - if (($this->event->isRemote() || - !$this->event->hasPermission(Horde_Perms::EDIT)) && + if (!$this->event->hasPermission(Horde_Perms::EDIT) && (!empty($GLOBALS['conf']['hooks']['permsdenied']) || $GLOBALS['perms']->hasAppPermission('max_events') === true || $GLOBALS['perms']->hasAppPermission('max_events') > Kronolith::countEvents())) { $buttons[] = ''; } else { - if (!$this->event->isRemote()) { + if ($this->event->hasPermission(Horde_Perms::EDIT)) { $buttons[] = ''; } if ($this->event->isInitialized()) { diff --git a/kronolith/lib/View/Event.php b/kronolith/lib/View/Event.php index 35a434ead..020e8e51e 100644 --- a/kronolith/lib/View/Event.php +++ b/kronolith/lib/View/Event.php @@ -101,7 +101,9 @@ class Kronolith_View_Event { echo ''; if ($active && $GLOBALS['browser']->hasFeature('dom')) { - if ($this->event->hasPermission(Horde_Perms::EDIT)) { + /* We check for read permissions, because we can always save a + * copy if we can read the event. */ + if ($this->event->hasPermission(Horde_Perms::READ)) { $edit = new Kronolith_View_EditEvent($this->event); $edit->html(false); } diff --git a/kronolith/lib/View/ExportEvent.php b/kronolith/lib/View/ExportEvent.php index 7e46df20e..c408e2050 100644 --- a/kronolith/lib/View/ExportEvent.php +++ b/kronolith/lib/View/ExportEvent.php @@ -13,15 +13,21 @@ class Kronolith_View_ExportEvent { */ function Kronolith_View_ExportEvent(&$event) { + if (!$event || $event instanceof PEAR_Error) { + echo '

' . _("Event not found") . '

'; + exit; + } + $iCal = new Horde_iCalendar('2.0'); - if (!$event->isRemote()) { + if ($event->getCalendarType() == 'internal') { $share = &$GLOBALS['kronolith_shares']->getShare($event->getCalendar()); if (!is_a($share, 'PEAR_Error')) { - $iCal->setAttribute('X-WR-CALNAME', - Horde_String::convertCharset($share->get('name'), - Horde_Nls::getCharset(), - 'utf-8')); + $iCal->setAttribute( + 'X-WR-CALNAME', + Horde_String::convertCharset($share->get('name'), + Horde_Nls::getCharset(), + 'utf-8')); } } diff --git a/kronolith/templates/edit/edit.inc b/kronolith/templates/edit/edit.inc index 3cea00ca4..bfff30f23 100644 --- a/kronolith/templates/edit/edit.inc +++ b/kronolith/templates/edit/edit.inc @@ -1,6 +1,6 @@ isLocked('default_share') && count($calendars) > 1 && empty($GLOBALS['show_resource_calendars'])); ?> -
+ @@ -9,7 +9,7 @@ -isInitialized() && !$event->isRemote()): ?> +isInitialized() && $event->hasPermission(Horde_Perms::EDIT)): ?> -- 2.11.0